15 char *fontdescription,
int fontsize,
16 double *width,
double *height)
18 PangoFontMap *fontmap;
20 int pango_width, pango_height;
23 fontmap = pango_cairo_font_map_get_default();
25 if (!pango_parse_markup
28 PangoContext *
const context = pango_font_map_create_context(fontmap);
29 layout = pango_layout_new(context);
30 g_object_unref(context);
31 pango_layout_set_text(
layout, text, -1);
33 PangoFontDescription *
const desc =
34 pango_font_description_from_string(fontdescription);
35 pango_font_description_set_size(desc, (
int)(fontsize * PANGO_SCALE));
36 pango_layout_set_font_description(
layout, desc);
39 pango_font_description_free(desc);
40 pango_layout_set_alignment(
layout, PANGO_ALIGN_CENTER);
42 pango_layout_get_size(
layout, &pango_width, &pango_height);
44 *width = (double) pango_width / PANGO_SCALE;
45 *height = (double) pango_height / PANGO_SCALE;
51 char *txt, cairo_surface_t **surface,
63 *surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, (
int)width,
66 cairo_t *cr = cairo_create(*surface);
68 cairo_set_source_rgba(cr, 1, 1, 1, 1);
70 pango_cairo_show_layout(cr,
layout);
79 return cairo_image_surface_get_data(*surface);
unsigned char * glCompCreatePangoTexture(char *fontdescription, int fontsize, char *txt, cairo_surface_t **surface, int *w, int *h)