[pango] Bug 583250 – pango_font_metrics_get_approximate_char_width is wrong when LANG=fa_IR



commit f0e5e54917286dd18471d76ed099bccf0eb85053
Author: Behdad Esfahbod <behdad behdad org>
Date:   Sat May 30 23:40:35 2009 -0400

    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.
---
 pango/pango-context.c |   29 ++++++++++-------------------
 1 files changed, 10 insertions(+), 19 deletions(-)

diff --git a/pango/pango-context.c b/pango/pango-context.c
index 0b70f59..c00338e 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);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]