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/program@1457
a5681a0c-68f1-0310-ab6d-
d61299d08faa
long tab_shift = fmod(x, tabwidth);
int border = im->text_prop[TEXT_PROP_LEGEND].size * 2.0;
long tab_shift = fmod(x, tabwidth);
int border = im->text_prop[TEXT_PROP_LEGEND].size * 2.0;
PangoTabArray *tab_array;
PangoContext *pango_context;
PangoTabArray *tab_array;
PangoContext *pango_context;
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);
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. */
- pango_layout_set_markup(layout, text, -1);
+ pango_layout_set_markup(layout, utf8_text ? utf8_text : text, -1);
- pango_layout_set_text(layout, text, -1);
+ pango_layout_set_text(layout, utf8_text ? utf8_text : text, -1);
+
+ g_free(utf8_text);