X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Frrd_gfx.c;h=cb42b8f2465d1831c47a3c77653feee5af2b4d80;hb=728d3d0bb29ba4a73b9c7c19f03e7e4ba687be84;hp=f91240cf5af54733f8485114595af64ac7bc0c53;hpb=7383625ce0413ce5dbcc0ced4ee4873c6df37735;p=rrdtool.git diff --git a/src/rrd_gfx.c b/src/rrd_gfx.c index f91240c..cb42b8f 100644 --- a/src/rrd_gfx.c +++ b/src/rrd_gfx.c @@ -1,5 +1,5 @@ /**************************************************************************** - * RRDtool 1.2.99907080300 Copyright by Tobi Oetiker, 1997-2007 + * RRDtool 1.3.1 Copyright by Tobi Oetiker, 1997-2008 **************************************************************************** * rrd_gfx.c graphics wrapper for rrdtool **************************************************************************/ @@ -46,10 +46,13 @@ void gfx_dashed_line( double dash_off) { cairo_t *cr = im->cr; - double dashes[] = { dash_on, dash_off }; + double dashes[2]; double x = 0; double y = 0; + dashes[0] = dash_on; + dashes[1] = dash_off; + cairo_save(cr); cairo_new_path(cr); cairo_set_line_width(cr, width); @@ -131,6 +134,9 @@ static PangoLayout *gfx_prep_text( long i; long tab_count = strlen(text); long tab_shift = fmod(x, tabwidth); + int border = im->text_prop[TEXT_PROP_LEGEND].size * 2.0; + + gchar *utf8_text; PangoTabArray *tab_array; PangoContext *pango_context; @@ -138,7 +144,8 @@ static PangoLayout *gfx_prep_text( tab_array = pango_tab_array_new(tab_count, (gboolean) (1)); for (i = 1; i <= tab_count; i++) { pango_tab_array_set_tab(tab_array, - i, PANGO_TAB_LEFT, tabwidth * i - tab_shift); + i, PANGO_TAB_LEFT, + tabwidth * i - tab_shift + border); } cairo_new_path(cr); cairo_set_source_rgba(cr, color.red, color.green, color.blue, @@ -146,13 +153,27 @@ static PangoLayout *gfx_prep_text( layout = pango_cairo_create_layout(cr); pango_context = pango_layout_get_context(layout); pango_cairo_context_set_font_options(pango_context, im->font_options); - pango_cairo_update_context(cr, pango_context); + pango_cairo_context_set_resolution(pango_context, 100); + +/* pango_cairo_update_context(cr, pango_context); */ pango_layout_set_tabs(layout, tab_array); font_desc = pango_font_description_from_string(font); pango_font_description_set_size(font_desc, size * PANGO_SCALE); pango_layout_set_font_description(layout, font_desc); - pango_layout_set_markup(layout, text, -1); + + /* pango expects the string to be utf-8 encoded */ + utf8_text = g_locale_to_utf8((const gchar *) text, -1, NULL, NULL, NULL); + + /* In case of an error, i.e. utf8_text == NULL (locale settings messed + * up?), we fall back to a possible "invalid UTF-8 string" warning instead + * of provoking a failed assertion in libpango. */ + if (im->with_markup) + pango_layout_set_markup(layout, utf8_text ? utf8_text : text, -1); + else + pango_layout_set_text(layout, utf8_text ? utf8_text : text, -1); + + g_free(utf8_text); return layout; } @@ -168,13 +189,6 @@ double gfx_get_text_width( PangoLayout *layout; PangoRectangle log_rect; gfx_color_t color = { 0, 0, 0, 0 }; - char *tab; - - /* turn \\t into tab */ - while ((tab = strstr(text, "\\t"))) { - memmove(tab + 1, tab + 2, strlen(tab + 2)); - tab[0] = (char) 9; - } layout = gfx_prep_text(im, start, color, font, size, tabwidth, text); pango_layout_get_pixel_extents(layout, NULL, &log_rect); pango_tab_array_free(pango_layout_get_tabs(layout));