pango_font_get_metrics incorrect due to pango_context_load_font choice
Submitted by John Wehle
Link to original bug (#570182)
Description
Please describe the problem: The enclosed patch fixes a problem which prevents abiword-2.6.6 from working correctly. Tracing through the code I see:
-
abiword GR_UnixPangoFont::reloadFont calls pango_context_load_font to create a 8 point Times font for a 1440 dpi device context (the font size in pixels is 160).
-
pango_fc_font_map_load_font calls pango_font_map_load_fontset which eventually gets to pango_fc_font_map_get_patterns which calls pango_fc_make_pattern to make the pattern being requested.
-
FcFontSort is called with the pattern. It returns:
Times 8 pixel size 34.000000 Bitstream Vera Serif 8 pixel size 160.000000 Luxi Serif 8 pixel size 160.000000 ...
-
Upon return to pango_fc_font_map_load_font it selects the first font in the new fontset based on the logic that FcFontSort returns the best fit first. This causes the Times 8 pixel size 34.000000 font to be used which is the exact font and point size desired (though the size in pixels is different).
-
abiword GR_UnixPangoFont::reloadFont calls pango_font_get_metrics which calls pango_fc_font_describe_absolute who notices that the font has FC_PIXEL_SIZE set and calls pango_font_description_set_absolute_size to set the font size based on the font's FC_PIXEL_SIZE of 34 which then proceeds to cause the returned metrics to be incorrect for 8 point Times font built for a 1440 dpi device.
-
As a result the document loaded (or being written) in abiword is displayed as a bunch of black smudges (i.e. the letters are displayed on top of each other).
Steps to reproduce:
-
Build abiword-2.6.6 on FreeBSD 6.4 using X11R7.3, freetype-2.3.8, fontconfig-2.6.0, glib-2.18.4, and pango-1.22.4. This is without gnome and with printing disabled. You'll need the patch in abiword's bug database which fixes the startup crash on FreeBSD due to UCS-2 / USC-4 mapping.
-
Run abiword.
-
Try entering Hello World.
Actual results: Hello World displays as a black smudge.
Expected results: Hello World to display in a readable fashion.
Does this happen every time? Yes.
Other information: This patch appears to fix the problem. --- pango/pangofc-fontmap.c.ORIGINAL 2008-12-16 01:14:00.000000000 -0500 +++ pango/pangofc-fontmap.c 2009-02-02 02:21:35.000000000 -0500 @@ -1100,6 +1100,13 @@ pango_fc_font_map_get_patterns (PangoFon
for (f = 0; f `< font_patterns->`nfont; f++)
{
-
double size;
-
if (FcPatternGetDouble (font_patterns->fonts[f], FC_PIXEL_SIZE,
-
0, &size) == FcResultMatch
-
&& fabs (size - (double)key.scaled_size / 1024) >= .5)
-
continue;
-
font_pattern = FcFontRenderPrepare (NULL, pattern, font_patterns->fonts[f]);
Version: 1.22.x