GNOME Bugzilla – Bug 661035
Different font caching in CoreText vs. FontConfig causes messed-up font sizes in some applications
Last modified: 2012-01-28 10:59:41 UTC
Created attachment 198386 [details] [review] Patch to include resolution and size in CoreText _FontHashKey The font cache in PangoFcFontMapPrivate includes the FcPattern in the key into the hash table of the cache. The FcPattern contains information about the font size. On the other hand, the font cache in PangoCairoCoreTextFontMap (font_hash) contains no such information. As a result, the CoreText implementation may return cached fonts with an invalid size in pango_core_text_font_map_load_font: best_font = pango_core_text_font_map_lookup (ctfontmap, context, best_description, best_face); if (best_font) g_object_ref (best_font); else .... This happens for example in the gschem application which uses the pango_cairo_context_set_resolution function to apply a zoom factor: pango_cairo_context_set_resolution (context, 1000. * scale_factor); font_size_pt = o_text_get_font_size_in_points (w_current->toplevel, o_current); desc = pango_font_description_from_string (FONT_NAME); pango_font_description_set_size (desc, (double)PANGO_SCALE * font_size_pt); On a Llinux machine with FontConfig backend, the different scale_factor causes a new font instance to be created. On Mac OS X with the CoreText backend, an existing font with the same name and different size is returned. Attached is a patch which adds the font size and resolution to the _FontHashKey structure. I'm not sure if this is the correct way to solve the issue or may cause side-effects, but gschem works fine with the patch applied to Pango. (In my opinion, the only effect should be that there are less cache-hits, so there should be no side effects.) Thanks and greetings Andreas PS: I've set up a small blog entry with screenshot and some more details, may be this is helpful: http://web.me.com/aschweiz/Website/Blog/Entries/2011/10/6_CoreText_vs._FontConfig.html
Ah, interesting! I will have a look at this after finishing 647969 which will introduce quite some changes to the font map code.
The latest patch in bug 647969 refactors the CoreText backend to be more like the fontconfig backend by introducing PangoCoreTextFontKey and PangoCoreTextFontsetKey. PangoCoreTextFontKey contains pixelsize and resolution fields, which leads me to believe that this should fix your issue. If you could verify that that patch fixes your issues, that would be great!
I've tried your patch. You're right, it fixes this bug. Thanks!
Ok, then I'll close this bug as soon as that patch goes in. Thanks again for your detailed analysis!
The refactoring went into master today. Resolving as fixed.