1 /* imposter (OO.org Impress viewer)
2 ** Copyright (C) 2003-2005 Gurer Ozen
3 ** This code is free software; you can redistribute it and/or
4 ** modify it under the terms of GNU General Public License.
12 r_parse_color(const char *color, ImpColor *ic)
16 if (1 != sscanf(color, "#%X", &cval)) return;
18 ic->red = (cval & 0xFF0000) >> 8;
19 ic->green = cval & 0x00FF00;
20 ic->blue = (cval & 0xFF) << 8;
24 r_get_color(ImpRenderCtx *ctx, iks *node, char *name, ImpColor *ic)
28 color = r_get_style(ctx, node, name);
30 r_parse_color(color, ic);
36 fg_color(ImpRenderCtx *ctx, void *drw_data, iks *node, char *name)
40 if (r_get_color(ctx, node, name, &ic)) {
41 ctx->drw->set_fg_color(drw_data, &ic);
46 r_get_x (ImpRenderCtx *ctx, iks *node, char *name)
50 val = iks_find_attrib (node, name);
52 return atof (val) * ctx->fact_x;
56 r_get_y (ImpRenderCtx *ctx, iks *node, char *name)
60 val = iks_find_attrib (node, name);
62 return atof (val) * ctx->fact_y;
66 r_get_angle (iks *node, char *name, int def)
70 tmp = iks_find_attrib (node, name);
75 static int x, y, w, h;
76 static int px, py, pw, ph;
79 r_get_viewbox (iks *node)
83 tmp = iks_find_attrib (node, "svg:viewBox");
85 sscanf (tmp, "%d %d %d %d", &px, &py, &pw, &ph);
89 r_polygon(ImpRenderCtx *ctx, void *drw_data, iks *node)
97 data = r_get_style (ctx, node, "draw:fill");
98 if (!data || strcmp (data, "solid") != 0) fill = 0;
100 x = r_get_x (ctx, node, "svg:x");
101 y = r_get_y (ctx, node, "svg:y");
102 w = r_get_x (ctx, node, "svg:width");
103 h = r_get_y (ctx, node, "svg:height");
104 r_get_viewbox (node);
106 data = iks_find_attrib (node, "draw:points");
107 points = malloc (sizeof (ImpPoint) * strlen (data) / 4);
112 for (i = 0; data[i]; i++) {
113 if (data[i] >= '0' && data[i] <= '9') {
114 if (num == -1) num = i;
118 points[cnt].x = atoi (data + num);
121 points[cnt++].y = atoi (data + num);
130 points[cnt].x = atoi (data + num);
132 points[cnt++].y = atoi (data + num);
135 for (i = 0; i < cnt; i++) {
136 points[i].x = x + points[i].x * w / pw;
137 points[i].y = y + points[i].y * h / ph;
141 fg_color(ctx, drw_data, node, "draw:fill-color");
142 ctx->drw->draw_polygon(drw_data, 1, points, cnt);
144 fg_color(ctx, drw_data, node, "svg:stroke-color");
145 ctx->drw->draw_polygon(drw_data, 0, points, cnt);
151 r_polyline(ImpRenderCtx *ctx, void *drw_data, iks *node)
159 x = r_get_x (ctx, node, "svg:x");
160 y = r_get_y (ctx, node, "svg:y");
161 w = r_get_x (ctx, node, "svg:width");
162 h = r_get_y (ctx, node, "svg:height");
163 r_get_viewbox (node);
165 data = iks_find_attrib (node, "draw:points");
166 points = malloc (sizeof (ImpPoint) * strlen (data) / 4);
171 for (i = 0; data[i]; i++) {
172 if (data[i] >= '0' && data[i] <= '9') {
173 if (num == -1) num = i;
177 points[cnt].x = atoi (data + num);
180 points[cnt++].y = atoi (data + num);
189 points[cnt].x = atoi (data + num);
191 points[cnt++].y = atoi (data + num);
195 pen_x = x + points[0].x * w /pw;
196 pen_y = y + points[0].y * h / ph;
197 fg_color(ctx, drw_data, node, "svg:stroke-color");
198 for (i = 1; i < cnt; i++) {
200 tx = x + points[i].x * w / pw;
201 ty = y + points[i].y * h / ph;
202 ctx->drw->draw_line(drw_data, pen_x, pen_y, tx, ty);