GNOME Bugzilla – 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
Last modified: 2009-01-05 13:58:28 UTC
Please describe the problem: Under pango-1.22.3, When GTK+ program running under LC_MESSAGES=zh_CN.UTF-8 the blank area width was very large, about the same size of text; the firefox running under LC_MESSAGES=zh_CN.UTF-8, the input area in webpages will be stretch to very wide. when downgraded to pango-1.20.5, everything displayed correctly. Steps to reproduce: 1. export LC_ALL=zh_CN.UTF-8 2. run firefox 3. open www.g.cn Actual results: See the stretched input area Expected results: the correct inut area width Does this happen every time? verytime Other information: xorg-server: 1.5.2 glib: 2.18.3 gtk+: 2.14.5 cairo: 1.8.4
Created attachment 124010 [details] the stretched google, invoked under LC_ALL=zh_CN.UTF-8
Created attachment 124011 [details] correct google invoke under LC_ALL=en_US.UTF-8
lots of Chinese users complaint about this bug.
That's a Google or Firefox bug. Under a Chinese locale, the default font has metrics for Chinese characters, which is typically twice wider than Latin chars. The Google text box has size="55", that is, 55 chars wide. I know the firefox guys wanted to work around this. Anyway, take it to firefox please.
Created attachment 124032 [details] The screenshot of gnome-menu under pango-1.20.5
Created attachment 124033 [details] The screenshot of gnome-menu under pango-1.22.3
Created attachment 124035 [details] This page under pango-1.20.5
Created attachment 124036 [details] This page under pango-1.22.3
Seems not the bug of google, because lots of pages have this problem in firefox under pango-1.22.3, including current page as show in the attached screenshots. I should be specific, the gnome-menu suffer this problem. The attached screenshots illustrate it. I still think this problems are caused by pango :)
Ok, I see what's going on. This is an old known issue. The thing is, CJK characters are more information dense than non-CJK characters. For example, a three/four word sentence in English translates to perhaps two CJK chars. So, when someone sets the width of their input box to, say, 20 chars, they don't mean 20 CJK chars. Another way to interpret it is "enough for a 20-char English sentence to fit". When filling in with CJK, it typically takes much less. So, by interpreting text box size as information size rather than strict character size, we can divide by an information density ratio for the language, which one can simply take as 2 for CJK and 1 for normal. Good old double-width and single-width... Expanding this further, we can redefine PangoFontMetrics' approximate_char_width in the same tune and so adjust for CJK. Then you get your right-sized boxes back. They will in fact become a bit shorter than then used to. Owen, Matthias, does this make sense to you? Oh, the reason this changed between 1.20.x and 1.22.x is that before 1.22, we were using a half English half Chinese string to measure the approximate width of Chinese. That was obviously wrong. When fixing that to measure a Chinese-only string, you now see the full reality of it...
Ok, committed the fix to SVN trunk. Didn't test much. Please test and report. New screenshots appreciated! 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.
Created attachment 124043 [details] this page displayed correctly under pango svn
Created attachment 124044 [details] google also displayed correctly in firefox invoked under zh_CN.UTF-8 with pango svn
Created attachment 124045 [details] gnome-menu also correct under pango svn :) Behdad, Thanks for your effects and explanation, you did a great work :)
effects -> efforts sorry for type :)
Thanks Yu. Looks great.
Created attachment 125781 [details] the input correct input field on firefox 3.0.5 spec: pango svn + cairo git + firefox 3.0.5 + ubuntu 8.10 amd64
Created attachment 125782 [details] long input field length with fifty chinese charactors spec: pango svn + cairo git + firefox 3.0.5 + ubuntu 8.10 amd64
Created attachment 125783 [details] long input field length with fifty letters spec: pango svn + cairo git + firefox 3.0.5 + ubuntu 8.10 amd64
check the attachments from comment #17 to #19, I think the bug is still exist on firefox 3.1 PS: comment #18, #19 I had stated the wrong system spec, those two screenshots, are taken on firefox 3.1 not firefox 3.0.5, sorry.