part of rrd_gfx.c [...] /* create a text node */ static PangoLayout *gfx_prep_text( image_desc_t *im, double x, gfx_color_t color, char *font, double size, double tabwidth, const char *text) { static PangoLayout *layout = NULL; static PangoContext *pango_context = NULL; static PangoFontMap *pango_fontmap = NULL; static char* last_font = NULL; static double last_size = -1; static double last_tabwidth = -1; cairo_t *cr = im->cr; 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; /* initialize pango only once ... */ if (!pango_fontmap){ pango_fontmap = pango_cairo_font_map_get_default (); } if (!pango_context){ // fprintf(stderr,"c"); pango_context = pango_cairo_font_map_create_context ((PangoCairoFontMap *) (pango_fontmap)); pango_cairo_context_set_resolution(pango_context, 100); } if (!layout){ // fprintf(stderr,"l"); layout = pango_layout_new (pango_context); } pango_cairo_context_set_font_options(pango_context, im->font_options); pango_cairo_update_context (cr, pango_context); if (last_tabwidth < 0 || last_tabwidth != tabwidth){ PangoTabArray *tab_array; // fprintf(stderr,"t"); last_tabwidth = tabwidth; 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 + border); } pango_layout_set_tabs(layout, tab_array); pango_tab_array_free(tab_array); } if (last_font == NULL || strcmp(font,last_font) != 0){ PangoFontDescription *font_desc; // fprintf(stderr,"f:%s",font); if (last_font) free(last_font); last_font = strdup(font); font_desc = pango_font_description_from_string(font); pango_layout_set_font_description(layout, font_desc); pango_font_description_free(font_desc); } if (last_size < 0 || last_size != size ){ PangoFontDescription *font_desc; font_desc = pango_layout_get_font_description (layout); pango_font_description_set_size(font_desc, size * PANGO_SCALE); pango_layout_set_font_description(layout, font_desc); } cairo_new_path(cr); cairo_set_source_rgba(cr, color.red, color.green, color.blue, color.alpha); 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; }