X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Frrd_gfx.c;h=33621bf0d1188cdb57b50efb04de4ad5da10e76b;hb=5a7eb5b62b485b61ddb80a40ef22f4337cf2289f;hp=6f83bc561fa88b170f9acc2c98d99d42f5bba38f;hpb=0f913ead7c1e1e7ba4976e8763d73c3167f8cf73;p=rrdtool.git diff --git a/src/rrd_gfx.c b/src/rrd_gfx.c index 6f83bc5..33621bf 100644 --- a/src/rrd_gfx.c +++ b/src/rrd_gfx.c @@ -1,5 +1,5 @@ /**************************************************************************** - * RRDtool 1.2.4 Copyright by Tobi Oetiker, 1997-2005 + * RRDtool 1.2.5 Copyright by Tobi Oetiker, 1997-2005 **************************************************************************** * rrd_gfx.c graphics wrapper for rrdtool **************************************************************************/ @@ -19,6 +19,7 @@ #include "rrd_gfx.h" #include "rrd_afm.h" +#include "unused.h" /* lines are better drawn on the pixle than between pixles */ #define LINEOFFSET 0.5 @@ -291,7 +292,7 @@ double gfx_get_text_width ( gfx_canvas_t *canvas, } double gfx_get_text_width_libart ( - gfx_canvas_t *canvas, double start, char* font, double size, + gfx_canvas_t *canvas, double UNUSED(start), char* font, double size, double tabwidth, char* text, int rotation ){ int error; @@ -963,7 +964,7 @@ static void pdf_calc(int page_height, gfx_node_t *node, pdf_coords *g) */ static int svg_indent = 0; static int svg_single_line = 0; -static const char *svg_default_font = "Helvetica"; +static const char *svg_default_font = "-dummy-"; typedef struct svg_dash { int dash_enable; @@ -1341,6 +1342,7 @@ static void svg_area(FILE *fp, gfx_node_t *node) static void svg_text(FILE *fp, gfx_node_t *node) { pdf_coords g; + const char *fontname; /* as svg has 0,0 in top-left corner (like most screens) instead of bottom-left corner like pdf and eps, we have to fake the coords using offset and inverse sin(r) value */ @@ -1362,12 +1364,10 @@ static void svg_text(FILE *fp, gfx_node_t *node) svg_write_number(fp, page_height - g.tmy); fputs("\"", fp); } - -/* if (strcmp(node->filename, svg_default_font)) - fprintf(fp, " font-family=\"%s\"", node->filename); - */ - fputs(" font-family=\"Helvetica", fp); - fputs("\" font-size=\"", fp); + fontname = afm_get_font_name(node->filename); + if (strcmp(fontname, svg_default_font)) + fprintf(fp, " font-family=\"%s\"", fontname); + fputs(" font-size=\"", fp); svg_write_number(fp, node->size); fputs("\"", fp); if (!svg_color_is_black(node->color)) @@ -1384,13 +1384,22 @@ int gfx_render_svg (gfx_canvas_t *canvas, art_u32 width, art_u32 height, gfx_color_t background, FILE *fp){ gfx_node_t *node = canvas->firstnode; + /* Find the first font used, and assume it is the mostly used + one. It reduces the number of font-familty attributes. */ + while (node) { + if (node->type == GFX_TEXT && node->filename) { + svg_default_font = afm_get_font_name(node->filename); + break; + } + node = node->next; + } fputs( "\n" "\n" "