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.
13 r_parse_color(const char *color, ImpColor *ic)
17 if (1 != sscanf(color, "#%X", &cval)) return;
19 ic->red = (cval & 0xFF0000) >> 8;
20 ic->green = cval & 0x00FF00;
21 ic->blue = (cval & 0xFF) << 8;
25 r_get_color(ImpRenderCtx *ctx, iks *node, char *name, ImpColor *ic)
29 color = r_get_style(ctx, node, name);
31 r_parse_color(color, ic);
37 fg_color(ImpRenderCtx *ctx, void *drw_data, iks *node, char *name)
41 if (r_get_color(ctx, node, name, &ic)) {
42 ctx->drw->set_fg_color(drw_data, &ic);
47 r_get_x (ImpRenderCtx *ctx, iks *node, char *name)
51 val = iks_find_attrib (node, name);
53 return atof (val) * ctx->fact_x;
57 r_get_y (ImpRenderCtx *ctx, iks *node, char *name)
61 val = iks_find_attrib (node, name);
63 return atof (val) * ctx->fact_y;
67 r_get_angle (iks *node, char *name, int def)
71 tmp = iks_find_attrib (node, name);
76 static int x, y, w, h;
77 static int px, py, pw, ph;
80 r_get_viewbox (iks *node)
84 tmp = iks_find_attrib (node, "svg:viewBox");
86 sscanf (tmp, "%d %d %d %d", &px, &py, &pw, &ph);
90 r_polygon(ImpRenderCtx *ctx, void *drw_data, iks *node)
98 data = r_get_style (ctx, node, "draw:fill");
99 if (!data || strcmp (data, "solid") != 0) fill = 0;
101 x = r_get_x (ctx, node, "svg:x");
102 y = r_get_y (ctx, node, "svg:y");
103 w = r_get_x (ctx, node, "svg:width");
104 h = r_get_y (ctx, node, "svg:height");
105 r_get_viewbox (node);
107 data = iks_find_attrib (node, "draw:points");
108 points = malloc (sizeof (ImpPoint) * strlen (data) / 4);
113 for (i = 0; data[i]; i++) {
114 if (data[i] >= '0' && data[i] <= '9') {
115 if (num == -1) num = i;
119 points[cnt].x = atoi (data + num);
122 points[cnt++].y = atoi (data + num);
131 points[cnt].x = atoi (data + num);
133 points[cnt++].y = atoi (data + num);
136 for (i = 0; i < cnt; i++) {
137 points[i].x = x + points[i].x * w / pw;
138 points[i].y = y + points[i].y * h / ph;
142 fg_color(ctx, drw_data, node, "draw:fill-color");
143 ctx->drw->draw_polygon(drw_data, 1, points, cnt);
145 fg_color(ctx, drw_data, node, "svg:stroke-color");
146 ctx->drw->draw_polygon(drw_data, 0, points, cnt);
152 r_polyline(ImpRenderCtx *ctx, void *drw_data, iks *node)
160 x = r_get_x (ctx, node, "svg:x");
161 y = r_get_y (ctx, node, "svg:y");
162 w = r_get_x (ctx, node, "svg:width");
163 h = r_get_y (ctx, node, "svg:height");
164 r_get_viewbox (node);
166 data = iks_find_attrib (node, "draw:points");
167 points = malloc (sizeof (ImpPoint) * strlen (data) / 4);
172 for (i = 0; data[i]; i++) {
173 if (data[i] >= '0' && data[i] <= '9') {
174 if (num == -1) num = i;
178 points[cnt].x = atoi (data + num);
181 points[cnt++].y = atoi (data + num);
190 points[cnt].x = atoi (data + num);
192 points[cnt++].y = atoi (data + num);
196 pen_x = x + points[0].x * w /pw;
197 pen_y = y + points[0].y * h / ph;
198 fg_color(ctx, drw_data, node, "svg:stroke-color");
199 for (i = 1; i < cnt; i++) {
201 tx = x + points[i].x * w / pw;
202 ty = y + points[i].y * h / ph;
203 ctx->drw->draw_line(drw_data, pen_x, pen_y, tx, ty);