summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBehdad Esfahbod <behdad@behdad.org>2009-05-30 23:40:35 -0400
committerBehdad Esfahbod <behdad@behdad.org>2009-05-30 23:40:35 -0400
commitf0e5e54917286dd18471d76ed099bccf0eb85053 (patch)
tree283095621421d47e2b2c8b6ffbd6aca9e2b229d7
parent8cf1dc67718227b27e79ba2694a93f4005d51db1 (diff)
downloadpango-f0e5e54917286dd18471d76ed099bccf0eb85053.tar.gz
Bug 583250 – pango_font_metrics_get_approximate_char_width is wrong when LANG=fa_IR
When computing approximate char width for context metrics use the actual size the sample string renders to. Previously it was taking average over all the fonts used by the sample str.
-rw-r--r--pango/pango-context.c29
1 files changed, 10 insertions, 19 deletions
diff --git a/pango/pango-context.c b/pango/pango-context.c
index 0b70f596..c00338e0 100644
--- a/pango/pango-context.c
+++ b/pango/pango-context.c
@@ -1575,13 +1575,16 @@ get_base_metrics (PangoFontset *fontset)
static void
update_metrics_from_items (PangoFontMetrics *metrics,
PangoLanguage *language,
+ const char *text,
GList *items)
{
GHashTable *fonts_seen = g_hash_table_new (NULL, NULL);
- int count = 0;
+ PangoGlyphString *glyphs = pango_glyph_string_new ();
GList *l;
+ metrics->approximate_char_width = 0;
+
for (l = items; l; l = l->next)
{
PangoItem *item = l->data;
@@ -1595,29 +1598,17 @@ update_metrics_from_items (PangoFontMetrics *metrics,
/* metrics will already be initialized from the first font in the fontset */
metrics->ascent = MAX (metrics->ascent, raw_metrics->ascent);
metrics->descent = MAX (metrics->descent, raw_metrics->descent);
-
- if (count == 0)
- {
- metrics->approximate_char_width = raw_metrics->approximate_char_width;
- metrics->approximate_digit_width = raw_metrics->approximate_digit_width;
- }
- else
- {
- metrics->approximate_char_width += raw_metrics->approximate_char_width;
- metrics->approximate_digit_width += raw_metrics->approximate_digit_width;
- }
- count++;
pango_font_metrics_unref (raw_metrics);
}
+
+ pango_shape (text + item->offset, item->length, &item->analysis, glyphs);
+ metrics->approximate_char_width += pango_glyph_string_get_width (glyphs);
}
+ pango_glyph_string_free (glyphs);
g_hash_table_destroy (fonts_seen);
- if (count)
- {
- metrics->approximate_char_width /= count;
- metrics->approximate_digit_width /= count;
- }
+ metrics->approximate_char_width /= pango_utf8_strwidth (text);
}
/**
@@ -1671,7 +1662,7 @@ pango_context_get_metrics (PangoContext *context,
sample_str = pango_language_get_sample_string (language);
items = itemize_with_font (context, sample_str, 0, strlen (sample_str), desc);
- update_metrics_from_items (metrics, language, items);
+ update_metrics_from_items (metrics, language, sample_str, items);
g_list_foreach (items, (GFunc)pango_item_free, NULL);
g_list_free (items);