From: oetiker Date: Mon, 4 Aug 2008 20:35:45 +0000 (+0000) Subject: The attached patch converts the given string to UTF-8 using glib's X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=8bb42b2460b6271011cd902077bbc45eece93127;p=rrdtool-all.git The attached patch converts the given string to UTF-8 using glib's g_locale_to_utf8() function. This function expects the string to be encoded as specified by the locale settings, so this will fail if e.g. you're using some script which is encoded in some way incompatible to the locale settings. In this case, the patch falls back to use the original string as provided by the user as there is no way to tell how to interpret that string. So, in this case, you will still get the old behavior (that pango warning and messed up strings in the graph). However, imho this is perfectly fine since it should be up to the user to take care of a sane environment. -- Sebastian Harl git-svn-id: svn://svn.oetiker.ch/rrdtool/trunk@1457 a5681a0c-68f1-0310-ab6d-d61299d08faa --- diff --git a/program/src/rrd_gfx.c b/program/src/rrd_gfx.c index 865d018f..74dce6b7 100644 --- a/program/src/rrd_gfx.c +++ b/program/src/rrd_gfx.c @@ -136,6 +136,8 @@ static PangoLayout *gfx_prep_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; @@ -159,10 +161,19 @@ static PangoLayout *gfx_prep_text( 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 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, text, -1); + pango_layout_set_markup(layout, utf8_text ? utf8_text : text, -1); else - pango_layout_set_text(layout, text, -1); + pango_layout_set_text(layout, utf8_text ? utf8_text : text, -1); + + g_free(utf8_text); return layout; }