From 68923711e30cffeaa410bbad0511238426c0ca74 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 22 May 2006 20:26:45 +0000 Subject: =?UTF-8?q?Bug=20342525=20=E2=80=93=20With=20PangoFc=20and=20Pango?= =?UTF-8?q?Win32,=20approximate=20digit=20width=20is=20not?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 2006-05-22 Behdad Esfahbod Bug 342525 – With PangoFc and PangoWin32, approximate digit width is not what it says * pango/pangocairo-win32font.c (max_glyph_width), (create_metrics_for_context): Use max digit width instead of average. Reverted the following changes: * pango/pangowin32.c (pango_win32_font_get_metrics): Calculate average digit width correctly, not as max of the digit widths. (#342525) Note that this code doesn't really get much used currently (instead the code in pangocairo-win32font.c is used), fixed only for completeness. (max_glpyh_with): Now unused, drop. --- ChangeLog | 17 +++++++++++++++++ pango/pangocairo-win32font.c | 28 +++++++++++++++++++++++++--- pango/pangowin32.c | 28 +++++++++++++++++++++++++--- 3 files changed, 67 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index 3278f61d..9a7220f8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,20 @@ +2006-05-22 Behdad Esfahbod + + Bug 342525 – With PangoFc and PangoWin32, approximate digit width is + not what it says + + * pango/pangocairo-win32font.c (max_glyph_width), + (create_metrics_for_context): Use max digit width instead of average. + + Reverted the following changes: + + * pango/pangowin32.c (pango_win32_font_get_metrics): Calculate + average digit width correctly, not as max of the digit + widths. (#342525) Note that this code doesn't really get much used + currently (instead the code in pangocairo-win32font.c is used), + fixed only for completeness. + (max_glpyh_with): Now unused, drop. + 2006-05-22 Behdad Esfahbod Bug 339730 – Pango needlessly falls back away from a Type 1 font into diff --git a/pango/pangocairo-win32font.c b/pango/pangocairo-win32font.c index d4df0d6f..1a14a205 100644 --- a/pango/pangocairo-win32font.c +++ b/pango/pangocairo-win32font.c @@ -290,6 +290,30 @@ quantize_position (int *thickness, *thickness = thickness_pixels * PANGO_SCALE; } +static int +max_glyph_width (PangoLayout *layout) +{ + int max_width = 0; + GSList *l, *r; + + for (l = pango_layout_get_lines (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 * create_metrics_for_context (PangoFont *font, PangoContext *context) @@ -336,9 +360,7 @@ create_metrics_for_context (PangoFont *font, metrics->approximate_char_width = extents.width / g_utf8_strlen (sample_str, -1); pango_layout_set_text (layout, "0123456789", -1); - pango_layout_get_extents (layout, NULL, &extents); - - metrics->approximate_digit_width = extents.width / 10; + metrics->approximate_digit_width = max_glyph_width (layout); pango_font_description_free (font_desc); g_object_unref (layout); diff --git a/pango/pangowin32.c b/pango/pangowin32.c index 99035512..a04c4553 100644 --- a/pango/pangowin32.c +++ b/pango/pangowin32.c @@ -525,6 +525,30 @@ pango_win32_font_get_glyph_extents (PangoFont *font, *logical_rect = info->logical_rect; } +static int +max_glyph_width (PangoLayout *layout) +{ + int max_width = 0; + GSList *l, *r; + + for (l = pango_layout_get_lines (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_win32_font_get_metrics (PangoFont *font, PangoLanguage *language) @@ -577,7 +601,6 @@ pango_win32_font_get_metrics (PangoFont *font, PangoContext *context; PangoFontDescription *font_desc; PangoLayout *layout; - PangoRectangle extents; /* Get the average width of the chars in "0123456789" */ context = pango_win32_get_context (); @@ -586,9 +609,8 @@ pango_win32_font_get_metrics (PangoFont *font, pango_context_set_font_description (context, font_desc); layout = pango_layout_new (context); pango_layout_set_text (layout, "0123456789", -1); - pango_layout_get_extents (layout, NULL, &extents); - metrics->approximate_digit_width = extents.width / 10; + metrics->approximate_digit_width = max_glyph_width (layout); pango_font_description_free (font_desc); g_object_unref (layout); -- cgit v1.2.1