[pango/1.28] Bug 625807 - approximate character width is 0 on pangoft2
- From: Behdad Esfahbod <behdad src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pango/1.28] Bug 625807 - approximate character width is 0 on pangoft2
- Date: Tue, 28 Sep 2010 18:33:07 +0000 (UTC)
commit eb00fc677cdf19e99d5e971c72d6aeb15920dc49
Author: Behdad Esfahbod <behdad behdad org>
Date: Fri Aug 6 12:48:10 2010 -0400
Bug 625807 - approximate character width is 0 on pangoft2
Fix regression.
pango/pangofc-font.c | 48 +++++++++++++++++++++++++++++++++++++++++++++---
1 files changed, 45 insertions(+), 3 deletions(-)
---
diff --git a/pango/pangofc-font.c b/pango/pangofc-font.c
index 7c38ab7..d9b6fa8 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);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]