summaryrefslogtreecommitdiff
path: root/pango/pangofc-font.c
diff options
context:
space:
mode:
authorBehdad Esfahbod <behdad@behdad.org>2010-08-06 12:48:10 -0400
committerBehdad Esfahbod <behdad@behdad.org>2010-08-06 12:48:10 -0400
commit955b51cc5221a2624ea6c49c3f42e6f32f127419 (patch)
treed7a44e4c5aedaa1b6d45865ff6fdb8adaa601350 /pango/pangofc-font.c
parent9b43da625483b68aa8702d217523bf9d8a8100d6 (diff)
downloadpango-955b51cc5221a2624ea6c49c3f42e6f32f127419.tar.gz
Bug 625807 - approximate character width is 0 on pangoft2
Fix regression.
Diffstat (limited to 'pango/pangofc-font.c')
-rw-r--r--pango/pangofc-font.c48
1 files changed, 45 insertions, 3 deletions
diff --git a/pango/pangofc-font.c b/pango/pangofc-font.c
index 7c38ab76..d9b6fa8a 100644
--- a/pango/pangofc-font.c
+++ b/pango/pangofc-font.c
@@ -491,9 +491,30 @@ pango_fc_font_create_base_metrics_for_context (PangoFcFont *fcfont,
return metrics;
}
-/* This function is cut-and-pasted into pangocairo-fcfont.c - it might be
- * better to add a virtual fcfont->create_context (font).
- */
+static int
+max_glyph_width (PangoLayout *layout)
+{
+ int max_width = 0;
+ GSList *l, *r;
+
+ for (l = pango_layout_get_lines_readonly (layout); l; l = l->next)
+ {
+ PangoLayoutLine *line = l->data;
+
+ for (r = line->runs; r; r = r->next)
+ {
+ PangoGlyphString *glyphs = ((PangoGlyphItem *)r->data)->glyphs;
+ int i;
+
+ for (i = 0; i < glyphs->num_glyphs; i++)
+ if (glyphs->glyphs[i].geometry.width > max_width)
+ max_width = glyphs->glyphs[i].geometry.width;
+ }
+ }
+
+ return max_width;
+}
+
static PangoFontMetrics *
pango_fc_font_get_metrics (PangoFont *font,
PangoLanguage *language)
@@ -538,6 +559,27 @@ pango_fc_font_get_metrics (PangoFont *font,
info->metrics = pango_fc_font_create_base_metrics_for_context (fcfont, context);
+ { /* Compute derived metrics */
+ PangoLayout *layout;
+ PangoRectangle extents;
+ const char *sample_str = pango_language_get_sample_string (language);
+ PangoFontDescription *desc = pango_font_describe_with_absolute_size (font);
+
+ layout = pango_layout_new (context);
+ pango_layout_set_font_description (layout, desc);
+ pango_font_description_free (desc);
+
+ pango_layout_set_text (layout, sample_str, -1);
+ pango_layout_get_extents (layout, NULL, &extents);
+
+ info->metrics->approximate_char_width = extents.width / pango_utf8_strwidth (sample_str);
+
+ pango_layout_set_text (layout, "0123456789", -1);
+ info->metrics->approximate_digit_width = max_glyph_width (layout);
+
+ g_object_unref (layout);
+ }
+
g_object_unref (context);
g_object_unref (fontmap);
}