After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 661035 - Different font caching in CoreText vs. FontConfig causes messed-up font sizes in some applications
Different font caching in CoreText vs. FontConfig causes messed-up font sizes...
Status: RESOLVED FIXED
Product: pango
Classification: Platform
Component: coretext
1.29.x
Other Mac OS
: Normal normal
: ---
Assigned To: gtk-quartz maintainers
pango-maint
Depends on: 647969
Blocks:
 
 
Reported: 2011-10-05 23:21 UTC by Andreas Schweizer
Modified: 2012-01-28 10:59 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Patch to include resolution and size in CoreText _FontHashKey (5.36 KB, patch)
2011-10-05 23:21 UTC, Andreas Schweizer
none Details | Review

Description Andreas Schweizer 2011-10-05 23:21:17 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
Comment 1 Kristian Rietveld 2011-10-06 05:54:59 UTC
Ah, interesting!  I will have a look at this after finishing 647969 which will introduce quite some changes to the font map code.
Comment 2 Kristian Rietveld 2011-10-22 19:36:37 UTC
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!
Comment 3 Andreas Schweizer 2011-10-24 17:43:51 UTC
I've tried your patch. You're right, it fixes this bug. Thanks!
Comment 4 Kristian Rietveld 2011-10-24 20:26:02 UTC
Ok, then I'll close this bug as soon as that patch goes in.  Thanks again for your detailed analysis!
Comment 5 Kristian Rietveld 2012-01-28 10:59:41 UTC
The refactoring went into master today.  Resolving as fixed.