Ejemplo n.º 1
0
void glyph_cache_set_font(TGlyphCache *cache, PangoFontDescription *font_desc)
{
	PangoFontMap *font_map;
	PangoFontMetrics *metrics;

	if (cache->hash) {
		g_hash_table_destroy(cache->hash);
		g_object_unref(cache->font_set);
	}

	cache->hash = g_hash_table_new_full(NULL, NULL, NULL, glyph_destroy_gfi);

	font_map = pango_xft_get_font_map(
		GDK_DISPLAY_XDISPLAY(cache->display),
		GDK_SCREEN_XNUMBER(cache->screen)
	);
	g_object_ref (font_map);

	cache->font_set = pango_font_map_load_fontset(
		font_map,
		cache->context,
		font_desc,
		cache->lang
	);

	g_object_unref(font_map);
	font_map = NULL;

	metrics = pango_fontset_get_metrics(cache->font_set);
	pango_font_metrics_ref(metrics);

	cache->ascent = pango_font_metrics_get_ascent(metrics);
	cache->descent = pango_font_metrics_get_descent(metrics);

	cache->width = pango_font_metrics_get_approximate_digit_width(metrics);
	cache->height = cache->ascent + cache->descent;
	if (cache->width <= 0) {
		fprintf (stderr, "Warning: cache->width = %d\n", cache->width);
		cache->width = cache->height / 2;
	}

	pango_font_metrics_unref(metrics);
}
Ejemplo n.º 2
0
static VALUE
fontset_get_metrics(VALUE self)
{
    return BOXED2RVAL(pango_fontset_get_metrics(_SELF(self)), PANGO_TYPE_FONT_METRICS);
}