Index: plug-ins/svg/render_svg.c =================================================================== --- plug-ins/svg/render_svg.c (révision 3769) +++ plug-ins/svg/render_svg.c (copie de travail) @@ -44,6 +44,7 @@ #include "diagramdata.h" #include "dia_xml_libxml.h" #include "object.h" +#include "textline.h" G_BEGIN_DECLS @@ -52,6 +53,9 @@ #define SVG_RENDERER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), SVG_TYPE_RENDERER, SvgRendererClass)) #define SVG_IS_RENDERER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SVG_TYPE_RENDERER)) #define SVG_RENDERER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), SVG_TYPE_RENDERER, SvgRendererClass)) +#define DTOSTR_BUF_SIZE G_ASCII_DTOSTR_BUF_SIZE +#define dia_svg_dtostr(buf,d) \ + g_ascii_formatd(buf,sizeof(buf),"%g",d) GType svg_renderer_get_type (void) G_GNUC_CONST; @@ -80,7 +84,10 @@ static void fill_rounded_rect (DiaRenderer *renderer, Point *ul_corner, Point *lr_corner, Color *colour, real rounding); +static void draw_text_line (DiaRenderer *self, TextLine *text_line, + Point *pos, Color *colour); + static void svg_renderer_class_init (SvgRendererClass *klass); static gpointer parent_class = NULL; @@ -132,6 +139,7 @@ renderer_class->draw_object = draw_object; renderer_class->draw_rounded_rect = draw_rounded_rect; renderer_class->fill_rounded_rect = fill_rounded_rect; + renderer_class->draw_text_line = draw_text_line; } @@ -278,6 +286,55 @@ } static void +draw_text_line(DiaRenderer *self, TextLine *text_line, + Point *pos, Color *colour) +{ + DiaSvgRenderer *renderer = DIA_SVG_RENDERER (self); + xmlNodePtr node; + char *style, *tmp; + real saved_width; + gchar d_buf[DTOSTR_BUF_SIZE]; + DiaFont *font; + + node = xmlNewChild(renderer->root, renderer->svg_name_space, (const xmlChar *)"text", + (xmlChar *) text_line_get_string(text_line)); + + saved_width = renderer->linewidth; + renderer->linewidth = 0.001; + style = (const xmlChar *) DIA_SVG_RENDERER_GET_CLASS(self)->get_fill_style(renderer, colour); + /* return value must not be freed */ + renderer->linewidth = saved_width; + tmp = g_strdup_printf("%s; font-size: %spt", style, + dia_svg_dtostr(d_buf,text_line_get_height(text_line)/1.84)); + style = tmp; + + tmp = g_strdup_printf("%s; length: %s", style, + dia_svg_dtostr(d_buf, text_line_get_width(text_line))); + g_free (style); + style = tmp; + + font = text_line_get_font(text_line); + tmp = g_strdup_printf("%s; font-family: %s; font-style: %s; " + "font-weight: %s",style, + dia_font_get_family(font), + dia_font_get_slant_string(font), + dia_font_get_weight_string(font)); + g_free(style); + style = tmp; + + /* have to do something about fonts here ... */ + + xmlSetProp(node, (const xmlChar *)"style", (xmlChar *) style); + g_free(style); + + 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); +} + + +static void export_svg(DiagramData *data, const gchar *filename, const gchar *diafilename, void* user_data) {