static void draw_polygon (DiaRenderer *self, Point *points, int num_points, Color *fill, Color *stroke) { DiaSvgRenderer *renderer = DIA_SVG_RENDERER (self); int i; xmlNodePtr node; GString *str; gchar px_buf[DTOSTR_BUF_SIZE]; gchar py_buf[DTOSTR_BUF_SIZE]; node = xmlNewChild(renderer->root, renderer->svg_name_space, (const xmlChar *)"polygon", NULL); xmlSetProp(node, (const xmlChar *)"style", (xmlChar *) get_draw_style (renderer, fill, stroke)); if (fill) xmlSetProp(node, (const xmlChar *)"fill-rule", (const xmlChar *) "evenodd"); str = g_string_new(NULL); for (i = 0; i < num_points; i++) g_string_append_printf(str, "%s,%s ", dia_svg_dtostr(px_buf, points[i].x), dia_svg_dtostr(py_buf, points[i].y) ); xmlSetProp(node, (const xmlChar *)"points", (xmlChar *) str->str); g_string_free(str, TRUE); }
static void draw_bezier(DiaRenderer *self, BezPoint *points, int numpoints, Color *colour) { DiaSvgRenderer *renderer = DIA_SVG_RENDERER (self); int i; xmlNodePtr node; GString *str; gchar p1x_buf[DTOSTR_BUF_SIZE]; gchar p1y_buf[DTOSTR_BUF_SIZE]; gchar p2x_buf[DTOSTR_BUF_SIZE]; gchar p2y_buf[DTOSTR_BUF_SIZE]; gchar p3x_buf[DTOSTR_BUF_SIZE]; gchar p3y_buf[DTOSTR_BUF_SIZE]; node = xmlNewChild(renderer->root, renderer->svg_name_space, (const xmlChar *)"path", NULL); xmlSetProp(node, (const xmlChar *)"style", (xmlChar *) get_draw_style(renderer, colour)); str = g_string_new(NULL); if (points[0].type != BEZ_MOVE_TO) g_warning("first BezPoint must be a BEZ_MOVE_TO"); g_string_printf(str, "M %s %s", dia_svg_dtostr(p1x_buf, (gdouble) points[0].p1.x), dia_svg_dtostr(p1y_buf, (gdouble) points[0].p1.y) ); for (i = 1; i < numpoints; i++) switch (points[i].type) { case BEZ_MOVE_TO: g_warning("only first BezPoint shoul be a BEZ_MOVE_TO"); g_string_printf(str, "M %s %s", dia_svg_dtostr(p1x_buf, (gdouble) points[i].p1.x), dia_svg_dtostr(p1y_buf, (gdouble) points[i].p1.y) ); break; case BEZ_LINE_TO: g_string_append_printf(str, " L %s,%s", dia_svg_dtostr(p1x_buf, (gdouble) points[i].p1.x), dia_svg_dtostr(p1y_buf, (gdouble) points[i].p1.y) ); break; case BEZ_CURVE_TO: g_string_append_printf(str, " C %s,%s %s,%s %s,%s", dia_svg_dtostr(p1x_buf, (gdouble) points[i].p1.x), dia_svg_dtostr(p1y_buf, (gdouble) points[i].p1.y), dia_svg_dtostr(p2x_buf, (gdouble) points[i].p2.x), dia_svg_dtostr(p2y_buf, (gdouble) points[i].p2.y), dia_svg_dtostr(p3x_buf, (gdouble) points[i].p3.x), dia_svg_dtostr(p3y_buf, (gdouble) points[i].p3.y) ); break; } xmlSetProp(node, (const xmlChar *)"d", (xmlChar *) str->str); g_string_free(str, TRUE); }
static void fill_arc(DiaRenderer *self, Point *center, real width, real height, real angle1, real angle2, Color *colour) { DiaSvgRenderer *renderer = DIA_SVG_RENDERER (self); xmlNodePtr node; char buf[512]; real rx = width / 2, ry = height / 2; real sx=center->x + rx*cos(angle1*G_PI/180); real sy=center->y - ry*sin(angle1*G_PI/180); real ex=center->x + rx*cos(angle2*G_PI/180); real ey=center->y - ry*sin(angle2*G_PI/180); int swp = (angle2 > angle1) ? 0 : 1; /* preserve direction */ int large_arc = (fabs(angle2 - angle1) >= 180); gchar sx_buf[DTOSTR_BUF_SIZE]; gchar sy_buf[DTOSTR_BUF_SIZE]; gchar rx_buf[DTOSTR_BUF_SIZE]; gchar ry_buf[DTOSTR_BUF_SIZE]; gchar ex_buf[DTOSTR_BUF_SIZE]; gchar ey_buf[DTOSTR_BUF_SIZE]; gchar cx_buf[DTOSTR_BUF_SIZE]; gchar cy_buf[DTOSTR_BUF_SIZE]; node = xmlNewChild(renderer->root, NULL, (const xmlChar *)"path", NULL); xmlSetProp(node, (const xmlChar *)"style", (xmlChar *)get_draw_style(renderer, colour, NULL)); g_snprintf(buf, sizeof(buf), "M %s,%s A %s,%s 0 %d %d %s,%s L %s,%s z", dia_svg_dtostr(sx_buf, sx), dia_svg_dtostr(sy_buf, sy), dia_svg_dtostr(rx_buf, rx), dia_svg_dtostr(ry_buf, ry), large_arc, swp, dia_svg_dtostr(ex_buf, ex), dia_svg_dtostr(ey_buf, ey), dia_svg_dtostr(cx_buf, center->x), dia_svg_dtostr(cy_buf, center->y) ); xmlSetProp(node, (const xmlChar *)"d", (xmlChar *) buf); }
static void draw_rect(DiaRenderer *self, Point *ul_corner, Point *lr_corner, Color *fill, Color *stroke) { DiaSvgRenderer *renderer = DIA_SVG_RENDERER (self); xmlNodePtr node; gchar d_buf[DTOSTR_BUF_SIZE]; node = xmlNewChild(renderer->root, NULL, (const xmlChar *)"rect", NULL); xmlSetProp(node, (const xmlChar *)"style", (xmlChar *) get_draw_style (renderer, fill, stroke)); dia_svg_dtostr(d_buf, ul_corner->x); xmlSetProp(node, (const xmlChar *)"x", (xmlChar *) d_buf); dia_svg_dtostr(d_buf, ul_corner->y); xmlSetProp(node, (const xmlChar *)"y", (xmlChar *) d_buf); dia_svg_dtostr(d_buf, lr_corner->x - ul_corner->x); xmlSetProp(node, (const xmlChar *)"width", (xmlChar *) d_buf); dia_svg_dtostr(d_buf, lr_corner->y - ul_corner->y); xmlSetProp(node, (const xmlChar *)"height", (xmlChar *) d_buf); }
static void draw_line(DiaRenderer *self, Point *start, Point *end, Color *line_colour) { DiaSvgRenderer *renderer = DIA_SVG_RENDERER (self); xmlNodePtr node; gchar d_buf[DTOSTR_BUF_SIZE]; node = xmlNewChild(renderer->root, renderer->svg_name_space, (const xmlChar *)"line", NULL); xmlSetProp(node, (const xmlChar *)"style", (xmlChar *) get_draw_style(renderer, NULL, line_colour)); dia_svg_dtostr(d_buf, start->x); xmlSetProp(node, (const xmlChar *)"x1", (xmlChar *) d_buf); dia_svg_dtostr(d_buf, start->y); xmlSetProp(node, (const xmlChar *)"y1", (xmlChar *) d_buf); dia_svg_dtostr(d_buf, end->x); xmlSetProp(node, (const xmlChar *)"x2", (xmlChar *) d_buf); dia_svg_dtostr(d_buf, end->y); xmlSetProp(node, (const xmlChar *)"y2", (xmlChar *) d_buf); }
static void draw_ellipse(DiaRenderer *self, Point *center, real width, real height, Color *fill, Color *stroke) { DiaSvgRenderer *renderer = DIA_SVG_RENDERER (self); xmlNodePtr node; gchar d_buf[DTOSTR_BUF_SIZE]; node = xmlNewChild(renderer->root, renderer->svg_name_space, (const xmlChar *)"ellipse", NULL); xmlSetProp(node, (const xmlChar *)"style", (xmlChar *) get_draw_style (renderer, fill, stroke)); dia_svg_dtostr(d_buf, center->x); xmlSetProp(node, (const xmlChar *)"cx", (xmlChar *) d_buf); dia_svg_dtostr(d_buf, center->y); xmlSetProp(node, (const xmlChar *)"cy", (xmlChar *) d_buf); dia_svg_dtostr(d_buf, width / 2); xmlSetProp(node, (const xmlChar *)"rx", (xmlChar *) d_buf); dia_svg_dtostr(d_buf, height / 2); xmlSetProp(node, (const xmlChar *)"ry", (xmlChar *) d_buf); }
static void draw_text_line(DiaRenderer *self, TextLine *text_line, Point *pos, Alignment alignment, Color *colour) { DiaSvgRenderer *renderer = DIA_SVG_RENDERER (self); xmlNodePtr node; real saved_width; gchar d_buf[DTOSTR_BUF_SIZE]; DiaFont *font; GString *style; node = xmlNewTextChild(renderer->root, renderer->svg_name_space, (const xmlChar *)"text", (xmlChar *) text_line_get_string(text_line)); saved_width = renderer->linewidth; renderer->linewidth = 0.001; /* return value must not be freed */ renderer->linewidth = saved_width; #if 0 /* would need a unit: https://bugzilla.mozilla.org/show_bug.cgi?id=707071#c4 */ style = g_strdup_printf("%s; font-size: %s", get_draw_style(renderer, colour, NULL), dia_svg_dtostr(d_buf, text_line_get_height(text_line))); #else /* get_draw_style: the return value of this function must not be saved * anywhere. And of course it must not be free'd */ style = g_string_new (get_draw_style(renderer, colour, NULL)); #endif /* This is going to break for non-LTR texts, as SVG thinks 'start' is * 'right' for those. */ switch (alignment) { case ALIGN_LEFT: g_string_append (style, "; text-anchor:start"); break; case ALIGN_CENTER: g_string_append (style, "; text-anchor:middle"); break; case ALIGN_RIGHT: g_string_append (style, "; text-anchor:end"); break; default: break; } font = text_line_get_font(text_line); g_string_append_printf (style, "font-family: %s; font-style: %s; font-weight: %s", dia_font_get_family(font), dia_font_get_slant_string(font), dia_font_get_weight_string(font)); xmlSetProp(node, (const xmlChar *)"style", (xmlChar *) style->str); g_string_free (style, TRUE); dia_svg_dtostr(d_buf, pos->x); xmlSetProp(node, (const xmlChar *)"x", (xmlChar *) d_buf); dia_svg_dtostr(d_buf, pos->y); xmlSetProp(node, (const xmlChar *)"y", (xmlChar *) d_buf); /* font-size as single attribute can work like the other length w/o unit */ dia_svg_dtostr(d_buf, text_line_get_height(text_line)); xmlSetProp(node, (const xmlChar *)"font-size", (xmlChar *) d_buf); dia_svg_dtostr(d_buf, text_line_get_width(text_line)); xmlSetProp(node, (const xmlChar*)"textLength", (xmlChar *) d_buf); }
static void _bezier(DiaRenderer *self, BezPoint *points, int numpoints, Color *fill, Color *stroke, gboolean closed) { DiaSvgRenderer *renderer = DIA_SVG_RENDERER (self); int i; xmlNodePtr node; GString *str; gchar p1x_buf[DTOSTR_BUF_SIZE]; gchar p1y_buf[DTOSTR_BUF_SIZE]; gchar p2x_buf[DTOSTR_BUF_SIZE]; gchar p2y_buf[DTOSTR_BUF_SIZE]; gchar p3x_buf[DTOSTR_BUF_SIZE]; gchar p3y_buf[DTOSTR_BUF_SIZE]; node = xmlNewChild(renderer->root, renderer->svg_name_space, (const xmlChar *)"path", NULL); if (fill || stroke) xmlSetProp(node, (const xmlChar *)"style", (xmlChar *)get_draw_style(renderer, fill, stroke)); str = g_string_new(NULL); if (points[0].type != BEZ_MOVE_TO) g_warning("first BezPoint must be a BEZ_MOVE_TO"); g_string_printf(str, "M %s %s", dia_svg_dtostr(p1x_buf, (gdouble) points[0].p1.x), dia_svg_dtostr(p1y_buf, (gdouble) points[0].p1.y) ); for (i = 1; i < numpoints; i++) switch (points[i].type) { case BEZ_MOVE_TO: if (!DIA_RENDERER_GET_CLASS (self)->is_capable_to(self, RENDER_HOLES)) { g_warning("only first BezPoint should be a BEZ_MOVE_TO"); g_string_printf(str, "M %s %s", dia_svg_dtostr(p1x_buf, (gdouble) points[i].p1.x), dia_svg_dtostr(p1y_buf, (gdouble) points[i].p1.y) ); } else { g_string_append_printf(str, "M %s %s", dia_svg_dtostr(p1x_buf, (gdouble) points[i].p1.x), dia_svg_dtostr(p1y_buf, (gdouble) points[i].p1.y) ); } break; case BEZ_LINE_TO: g_string_append_printf(str, " L %s,%s", dia_svg_dtostr(p1x_buf, (gdouble) points[i].p1.x), dia_svg_dtostr(p1y_buf, (gdouble) points[i].p1.y) ); break; case BEZ_CURVE_TO: g_string_append_printf(str, " C %s,%s %s,%s %s,%s", dia_svg_dtostr(p1x_buf, (gdouble) points[i].p1.x), dia_svg_dtostr(p1y_buf, (gdouble) points[i].p1.y), dia_svg_dtostr(p2x_buf, (gdouble) points[i].p2.x), dia_svg_dtostr(p2y_buf, (gdouble) points[i].p2.y), dia_svg_dtostr(p3x_buf, (gdouble) points[i].p3.x), dia_svg_dtostr(p3y_buf, (gdouble) points[i].p3.y) ); break; } if (fill) { xmlSetProp(node, (const xmlChar *)"fill-rule", (const xmlChar *) "evenodd"); g_string_append(str, "z"); } xmlSetProp(node, (const xmlChar *)"d", (xmlChar *) str->str); g_string_free(str, TRUE); }