2007-07-13 07:53:14 +04:00
|
|
|
/*
|
2008-02-03 22:11:36 +03:00
|
|
|
* Copyright 2007-2008 James Bursa <bursa@users.sourceforge.net>
|
2007-08-08 20:16:03 +04:00
|
|
|
*
|
|
|
|
* This file is part of NetSurf, http://www.netsurf-browser.org/
|
|
|
|
*
|
|
|
|
* NetSurf is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; version 2 of the License.
|
|
|
|
*
|
|
|
|
* NetSurf is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2007-07-13 07:53:14 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
/** \file
|
|
|
|
* Content for image/svg (implementation).
|
|
|
|
*/
|
|
|
|
|
2007-07-18 18:49:26 +04:00
|
|
|
#include "utils/config.h"
|
|
|
|
#ifdef WITH_NS_SVG
|
2008-07-27 03:42:24 +04:00
|
|
|
|
|
|
|
#include <assert.h>
|
2009-03-27 05:47:16 +03:00
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include <svgtiny.h>
|
|
|
|
|
2007-07-13 07:53:14 +04:00
|
|
|
#include "content/content.h"
|
2007-07-16 03:22:54 +04:00
|
|
|
#include "css/css.h"
|
2007-07-13 07:53:14 +04:00
|
|
|
#include "desktop/plotters.h"
|
|
|
|
#include "image/svg.h"
|
|
|
|
#include "utils/messages.h"
|
|
|
|
#include "utils/utils.h"
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a CONTENT_SVG.
|
|
|
|
*/
|
|
|
|
|
|
|
|
bool svg_create(struct content *c, const char *params[])
|
|
|
|
{
|
2008-02-03 22:11:36 +03:00
|
|
|
union content_msg_data msg_data;
|
|
|
|
|
|
|
|
c->data.svg.diagram = svgtiny_create();
|
|
|
|
if (!c->data.svg.diagram)
|
|
|
|
goto no_memory;
|
2007-07-13 07:53:14 +04:00
|
|
|
|
|
|
|
return true;
|
2008-02-03 22:11:36 +03:00
|
|
|
|
|
|
|
no_memory:
|
|
|
|
msg_data.error = messages_get("NoMemory");
|
|
|
|
content_broadcast(c, CONTENT_MSG_ERROR, msg_data);
|
|
|
|
return false;
|
2007-07-13 07:53:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Convert a CONTENT_SVG for display.
|
|
|
|
*/
|
|
|
|
|
|
|
|
bool svg_convert(struct content *c, int w, int h)
|
|
|
|
{
|
2008-02-03 22:11:36 +03:00
|
|
|
assert(c->data.svg.diagram);
|
2007-07-13 07:53:14 +04:00
|
|
|
|
2008-02-03 22:11:36 +03:00
|
|
|
svgtiny_parse(c->data.svg.diagram, c->source_data, c->source_size,
|
|
|
|
c->url, w, h);
|
2007-07-13 07:53:14 +04:00
|
|
|
|
2008-02-03 22:11:36 +03:00
|
|
|
c->width = c->data.svg.diagram->width;
|
|
|
|
c->height = c->data.svg.diagram->height;
|
2007-07-13 07:53:14 +04:00
|
|
|
|
|
|
|
/*c->title = malloc(100);
|
|
|
|
if (c->title)
|
|
|
|
snprintf(c->title, 100, messages_get("svgTitle"),
|
|
|
|
width, height, c->source_size);*/
|
|
|
|
//c->size += ?;
|
|
|
|
c->status = CONTENT_STATUS_DONE;
|
2008-03-10 15:41:41 +03:00
|
|
|
/* Done: update status bar */
|
|
|
|
content_set_status(c, "");
|
2008-02-03 22:11:36 +03:00
|
|
|
|
2007-07-13 07:53:14 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Redraw a CONTENT_SVG.
|
|
|
|
*/
|
|
|
|
|
|
|
|
bool svg_redraw(struct content *c, int x, int y,
|
|
|
|
int width, int height,
|
|
|
|
int clip_x0, int clip_y0, int clip_x1, int clip_y1,
|
2008-09-29 02:37:13 +04:00
|
|
|
float scale, colour background_colour)
|
2007-07-13 07:53:14 +04:00
|
|
|
{
|
2008-02-03 22:11:36 +03:00
|
|
|
float transform[6];
|
|
|
|
struct svgtiny_diagram *diagram = c->data.svg.diagram;
|
|
|
|
bool ok;
|
|
|
|
int px, py;
|
2008-11-30 01:53:58 +03:00
|
|
|
unsigned int i;
|
2008-02-03 22:11:36 +03:00
|
|
|
|
|
|
|
assert(diagram);
|
|
|
|
|
|
|
|
transform[0] = (float) width / (float) c->width;
|
|
|
|
transform[1] = 0;
|
|
|
|
transform[2] = 0;
|
|
|
|
transform[3] = (float) height / (float) c->height;
|
|
|
|
transform[4] = x;
|
|
|
|
transform[5] = y;
|
|
|
|
|
2008-07-29 03:26:54 +04:00
|
|
|
#define BGR(c) ((c) == svgtiny_TRANSPARENT ? TRANSPARENT : ((svgtiny_RED((c))) | (svgtiny_GREEN((c)) << 8) | (svgtiny_BLUE((c)) << 16)))
|
|
|
|
|
2008-11-30 01:53:58 +03:00
|
|
|
for (i = 0; i != diagram->shape_count; i++) {
|
2008-02-03 22:11:36 +03:00
|
|
|
if (diagram->shape[i].path) {
|
|
|
|
ok = plot.path(diagram->shape[i].path,
|
|
|
|
diagram->shape[i].path_length,
|
2008-07-29 03:26:54 +04:00
|
|
|
BGR(diagram->shape[i].fill),
|
2008-02-03 22:11:36 +03:00
|
|
|
diagram->shape[i].stroke_width,
|
2008-07-29 03:26:54 +04:00
|
|
|
BGR(diagram->shape[i].stroke),
|
2008-02-03 22:11:36 +03:00
|
|
|
transform);
|
|
|
|
if (!ok)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
} else if (diagram->shape[i].text) {
|
|
|
|
px = transform[0] * diagram->shape[i].text_x +
|
|
|
|
transform[2] * diagram->shape[i].text_y +
|
|
|
|
transform[4];
|
|
|
|
py = transform[1] * diagram->shape[i].text_x +
|
|
|
|
transform[3] * diagram->shape[i].text_y +
|
|
|
|
transform[5];
|
2007-07-16 03:22:54 +04:00
|
|
|
ok = plot.text(px, py,
|
|
|
|
&css_base_style,
|
2008-02-03 22:11:36 +03:00
|
|
|
diagram->shape[i].text,
|
|
|
|
strlen(diagram->shape[i].text),
|
2007-07-13 07:53:14 +04:00
|
|
|
0xffffff, 0x000000);
|
2009-05-28 20:21:32 +04:00
|
|
|
if (!ok)
|
|
|
|
return false;
|
2007-07-16 03:22:54 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-07-29 03:26:54 +04:00
|
|
|
#undef BGR
|
|
|
|
|
2008-02-03 22:11:36 +03:00
|
|
|
return true;
|
2007-11-29 08:56:57 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-07-13 07:53:14 +04:00
|
|
|
/**
|
|
|
|
* Destroy a CONTENT_SVG and free all resources it owns.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void svg_destroy(struct content *c)
|
|
|
|
{
|
2008-02-03 22:11:36 +03:00
|
|
|
if (c->data.svg.diagram)
|
|
|
|
svgtiny_free(c->data.svg.diagram);
|
2007-07-13 07:53:14 +04:00
|
|
|
}
|
2007-07-18 18:49:26 +04:00
|
|
|
|
2008-02-03 22:11:36 +03:00
|
|
|
|
2007-07-18 18:49:26 +04:00
|
|
|
#endif /* WITH_NS_SVG */
|