diff options
author | Behdad Esfahbod <behdad@gnome.org> | 2008-12-06 01:44:03 +0000 |
---|---|---|
committer | Behdad Esfahbod <behdad@src.gnome.org> | 2008-12-06 01:44:03 +0000 |
commit | 1ec099a51c7faec59e4b639cea95d08faf886615 (patch) | |
tree | 5cbadfb1747c90ac967b44b83a753efcc4dc338e | |
parent | 74cc07c44afd2879418389cce57a4129b60d61e6 (diff) | |
download | pango-1ec099a51c7faec59e4b639cea95d08faf886615.tar.gz |
Bug 563356 – The input area of firefox and the blank width after text in
2008-12-05 Behdad Esfahbod <behdad@gnome.org>
Bug 563356 – The input area of firefox and the blank width after text
in gnome-menu was stretched too wide, under pango-1.22.3
* docs/tmpl/fonts.sgml:
* pango/pango-impl-utils.h:
* pango/pangocairo-atsuifont.c
(pango_cairo_atsui_font_create_metrics_for_context):
* pango/pangocairo-win32font.c
(pango_cairo_win32_font_create_metrics_for_context):
* pango/pangofc-font.c (pango_fc_font_create_metrics_for_context):
For approximate_char_width calculation take each char's width into
account. That is, do a weighted average instead of uniform average.
g_unichar_iszerowidth() chars count as 0, g_unichar_iswide() chars
count 2, and the rest count as 1. Pretty much wcwidth() behavior.
See bug report for rationale.
svn path=/trunk/; revision=2747
-rw-r--r-- | ChangeLog | 18 | ||||
-rw-r--r-- | docs/tmpl/fonts.sgml | 5 | ||||
-rw-r--r-- | pango/pango-impl-utils.h | 31 | ||||
-rw-r--r-- | pango/pangocairo-atsuifont.c | 3 | ||||
-rw-r--r-- | pango/pangocairo-win32font.c | 2 | ||||
-rw-r--r-- | pango/pangofc-font.c | 2 |
6 files changed, 57 insertions, 4 deletions
@@ -1,3 +1,21 @@ +2008-12-05 Behdad Esfahbod <behdad@gnome.org> + + Bug 563356 – The input area of firefox and the blank width after text + in gnome-menu was stretched too wide, under pango-1.22.3 + + * docs/tmpl/fonts.sgml: + * pango/pango-impl-utils.h: + * pango/pangocairo-atsuifont.c + (pango_cairo_atsui_font_create_metrics_for_context): + * pango/pangocairo-win32font.c + (pango_cairo_win32_font_create_metrics_for_context): + * pango/pangofc-font.c (pango_fc_font_create_metrics_for_context): + For approximate_char_width calculation take each char's width into + account. That is, do a weighted average instead of uniform average. + g_unichar_iszerowidth() chars count as 0, g_unichar_iswide() chars + count 2, and the rest count as 1. Pretty much wcwidth() behavior. + See bug report for rationale. + 2008-11-28 Behdad Esfahbod <behdad@gnome.org> Bug 562574 – Pangocariowin32 is leaking every cairo font it ever diff --git a/docs/tmpl/fonts.sgml b/docs/tmpl/fonts.sgml index 460e60b8..4b91624b 100644 --- a/docs/tmpl/fonts.sgml +++ b/docs/tmpl/fonts.sgml @@ -441,7 +441,10 @@ of their meaning. @descent: the distance from the baseline to the lowest point of the glyphs of the font. This is positive in practically all fonts. @approximate_char_width: approximate average width of the regular glyphs of - the font. + the font. Note that for this calculation, East Asian characters + (those passing g_unichar_iswide()) are counted as double-width. + This produces a more uniform value for this measure across languages + and results in more uniform and more expected UI sizes. @approximate_digit_width: approximate average width of the glyphs for digits of the font. @underline_position: position of the underline. This is normally negative. diff --git a/pango/pango-impl-utils.h b/pango/pango-impl-utils.h index e21988f1..a04d4241 100644 --- a/pango/pango-impl-utils.h +++ b/pango/pango-impl-utils.h @@ -23,6 +23,7 @@ #ifndef __PANGO_IMPL_UTILS_H__ #define __PANGO_IMPL_UTILS_H__ +#include <glib.h> #include <glib-object.h> #include <pango/pango.h> @@ -92,6 +93,36 @@ void _pango_shape_get_extents (gint n_chars, PangoRectangle *ink_rect, PangoRectangle *logical_rect); + +/* We define these functions static here because we don't want to add public API + * for them (if anything, it belongs to glib, but glib found it trivial enough + * not to add API for). At some point metrics calculations will be + * centralized and this mess can be minimized. Or so I hope. + */ + +static inline G_GNUC_UNUSED int +pango_unichar_width (gunichar c) +{ + return G_UNLIKELY (g_unichar_iszerowidth (c)) ? 0 : + G_UNLIKELY (g_unichar_iswide (c)) ? 2 : 1; +} + +static G_GNUC_UNUSED glong +pango_utf8_strwidth (const gchar *p) +{ + glong len = 0; + g_return_val_if_fail (p != NULL, 0); + + while (*p) + { + len += pango_unichar_width (g_utf8_get_char (p)); + p = g_utf8_next_char (p); + } + + return len; +} + + G_END_DECLS #endif /* __PANGO_IMPL_UTILS_H__ */ diff --git a/pango/pangocairo-atsuifont.c b/pango/pangocairo-atsuifont.c index 7706fbf8..ac060ccd 100644 --- a/pango/pangocairo-atsuifont.c +++ b/pango/pangocairo-atsuifont.c @@ -24,6 +24,7 @@ #import <Cocoa/Cocoa.h> +#include "pango-impl-utils.h" #include "pangoatsui-private.h" #include "pangocairo.h" #include "pangocairo-private.h" @@ -148,7 +149,7 @@ pango_cairo_atsui_font_create_metrics_for_context (PangoCairoFont *font, pango_layout_set_text (layout, sample_str, -1); pango_layout_get_extents (layout, NULL, &extents); - metrics->approximate_char_width = extents.width / g_utf8_strlen (sample_str, -1); + metrics->approximate_char_width = extents.width / pango_utf8_strwidth (sample_str); pango_layout_set_text (layout, "0123456789", -1); metrics->approximate_digit_width = max_glyph_width (layout); diff --git a/pango/pangocairo-win32font.c b/pango/pangocairo-win32font.c index 875f9526..4dda4ece 100644 --- a/pango/pangocairo-win32font.c +++ b/pango/pangocairo-win32font.c @@ -150,7 +150,7 @@ pango_cairo_win32_font_create_metrics_for_context (PangoCairoFont *font, pango_layout_set_text (layout, sample_str, -1); pango_layout_get_extents (layout, NULL, &extents); - metrics->approximate_char_width = extents.width / g_utf8_strlen (sample_str, -1); + metrics->approximate_char_width = extents.width / pango_utf8_strwidth (sample_str); pango_layout_set_text (layout, "0123456789", -1); metrics->approximate_digit_width = max_glyph_width (layout); diff --git a/pango/pangofc-font.c b/pango/pangofc-font.c index b5d65ca6..8a5b9ac8 100644 --- a/pango/pangofc-font.c +++ b/pango/pangofc-font.c @@ -496,7 +496,7 @@ pango_fc_font_create_metrics_for_context (PangoFcFont *fcfont, pango_layout_get_extents (layout, NULL, &extents); metrics->approximate_char_width = - extents.width / g_utf8_strlen (sample_str, -1); + extents.width / pango_utf8_strwidth (sample_str); pango_layout_set_text (layout, "0123456789", -1); metrics->approximate_digit_width = max_glyph_width (layout); |