From f0e5e54917286dd18471d76ed099bccf0eb85053 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Sat, 30 May 2009 23:40:35 -0400 Subject: =?UTF-8?q?Bug=20583250=20=E2=80=93=20pango=5Ffont=5Fmetrics=5Fget?= =?UTF-8?q?=5Fapproximate=5Fchar=5Fwidth=20is=20wrong=20when=20LANG=3Dfa?= =?UTF-8?q?=5FIR?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- pango/pango-context.c | 29 ++++++++++------------------- 1 file 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); -- cgit v1.2.1