X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Frrd_gfx.c;h=5841d50867883e5c9d27581261ba31b649ab82bd;hb=556f0365aa699c7dd4b6b08437f7c667abdf3c42;hp=a241fc28bc9088dbd0d1e44e8cc5ac08405715df;hpb=7006a00dd484cfe2cfe7b58eb5e4391fdb1fd1d4;p=rrdtool.git diff --git a/src/rrd_gfx.c b/src/rrd_gfx.c index a241fc2..5841d50 100644 --- a/src/rrd_gfx.c +++ b/src/rrd_gfx.c @@ -1,5 +1,5 @@ /**************************************************************************** - * RRDtool 1.2.9 Copyright by Tobi Oetiker, 1997-2005 + * RRDtool 1.2.12 Copyright by Tobi Oetiker, 1997-2005 **************************************************************************** * rrd_gfx.c graphics wrapper for rrdtool **************************************************************************/ @@ -7,9 +7,9 @@ /* #define DEBUG */ #ifdef DEBUG -# define DPRINTF(x,...) fprintf(stderr, x, ## __VA_ARGS__); +# define DPRINTF(...) fprintf(stderr, __VA_ARGS__); #else -# define DPRINTF(x,...) +# define DPRINTF(...) #endif #include "rrd_tool.h" #include @@ -303,10 +303,15 @@ double gfx_get_text_width_libart ( FT_Init_FreeType( &library ); error = FT_New_Face( library, font, 0, &face ); - if ( error ) return -1; + if ( error ) { + FT_Done_FreeType(library); + return -1; + } error = FT_Set_Char_Size(face, size*64,size*64, 100,100); - if ( error ) return -1; - + if ( error ) { + FT_Done_FreeType(library); + return -1; + } string = gfx_string_create( canvas, face, text, rotation, tabwidth, size ); text_width = string->width; gfx_string_destroy(string); @@ -386,7 +391,11 @@ gfx_string gfx_string_create(gfx_canvas_t *canvas, FT_Face face,const char *text cstr = malloc(sizeof(wchar_t) * clen); /* yes we are allocating probably too much here, I know */ string->count=mbstowcs(cstr,text,clen); if ( string->count == -1){ - string->count=mbstowcs(cstr,"Enc-Err",6); + /* conversion did not work, so lets fall back to just use what we got */ + string->count=clen-1; + for(n=0;text[n] != '\0';n++){ + cstr[n]=(unsigned char)text[n]; + } } #else char *cstr = strdup(text); @@ -598,6 +607,7 @@ int gfx_render_png (gfx_canvas_t *canvas, &face ); if ( error ) { rrd_set_error("failed to load %s",node->filename); + break; } error = FT_Set_Char_Size(face, /* handle to face object */ @@ -1071,9 +1081,11 @@ static void svg_write_text(FILE *fp, const char *text) case '"': fputs(""", fp); break; default: if (ch == 32) { +#ifdef HAVE_MBSTOWCS if (p <= cstr + 1 || !*p || *p == 32) fputs(" ", fp); /* non-breaking space in unicode */ else +#endif fputc(32, fp); } else if (ch < 32 || ch >= 127) fprintf(fp, "&#%d;", (int)ch); @@ -1430,9 +1442,9 @@ int gfx_render_svg (gfx_canvas_t *canvas, "-->\n", fp); svg_start_tag(fp, "svg"); fputs(" width=\"", fp); - svg_write_number(fp, width * canvas->zoom); + svg_write_number(fp, width * canvas->zoom); fputs("\" height=\"", fp); - svg_write_number(fp, height * canvas->zoom); + svg_write_number(fp, height * canvas->zoom); fputs("\" x=\"0\" y=\"0\" viewBox=\"", fp); svg_write_number(fp, -LINEOFFSET); fputs(" ", fp); @@ -1442,8 +1454,10 @@ int gfx_render_svg (gfx_canvas_t *canvas, fputs(" ", fp); svg_write_number(fp, height - LINEOFFSET); fputs("\" preserveAspectRatio=\"xMidYMid\"", fp); - fprintf(fp, " font-family=\"%s\"", svg_default_font); /* default font */ - fputs(" stroke-linecap=\"round\" stroke-linejoin=\"round\"", fp); + fprintf(fp, " font-family=\"%s\"", svg_default_font); /* default font */ + fputs(" stroke-linecap=\"round\" stroke-linejoin=\"round\"", fp); + fputs(" xmlns=\"http://www.w3.org/2000/svg\"", fp); + fputs(" xmlns:xlink=\"http://www.w3.org/1999/xlink\"", fp); svg_close_tag(fp); svg_start_tag(fp, "rect"); fprintf(fp, " x=\"0\" y=\"0\" width=\"%d\" height=\"%d\"", width, height); @@ -1779,7 +1793,7 @@ static void eps_write_text(eps_state *state, gfx_node_t *node) if (ch > 255) { fputc('?', fp); } else if (ch >= 126 || ch < 32) { - fprintf(fp, "\\%03o", ch); + fprintf(fp, "\\%03o", (unsigned int)ch); lineLen += 3; } else { fputc(ch, fp); @@ -2020,9 +2034,9 @@ static void pdf_put_string_contents_wide(pdf_buffer *buf, const afm_char *text) default: if (ch > 255) { pdf_put_char(buf, '?'); - } else if (ch >= 126 || ch < 32) { + } else if (ch > 125 || ch < 32) { pdf_put_char(buf, ch); - } else if (ch >= 0 && ch <= 255) { + } else { char tmp[10]; snprintf(tmp, sizeof(tmp), "\\%03o", (int)ch); pdf_puts(buf, tmp);