Font antialiasing issue on GTK in MacOS

Below is the screenshot from gtk4-demo (4.18.3) built from jhbuild modulesets-unstable/gtk-osx.modules on MacOS 12.x (Monterey).

The text font doesn’t look great. GTK inspector shows coretext for Pango Fontmap.

On my Debian Unstable, GTK inspector shows fontconfig for Pango Fontmap as below.

I guess I’ve built Pango, Cairo with fontconfig (as I haven’t changed the deps in .modules for Pango / Cairo).

Ideas?

Yes, Pango defaults to CoreText on macOS. If you wish to use FontConfig + FreeType2, set the environment variable PANGOCAIRO_BACKEND=fc

1 Like

set the environment variable PANGOCAIRO_BACKEND=fc

That works. Any reason why it’s not the default on macOS.

Screenshot with font scaling set to 1.1.

Point being text in GTK apps should look good:

  • the GNOME way (fontconfig etc) -or-
  • macOS way (for native look and feel).

But the text in GTK demo app looks quite different from other native macOS apps.

FWIW, GTK Inspector shows the selected font as .AppleSystemUIFont when using coretext backend.

Taking a close look at the image samples, the main issue with the Core Text rendering appears to be that subpixel positioning of glyphs isn’t being applied, resulting in inconsistent spacing between glyphs (some too tight together, others too far apart).

Core text does support subpixel glyph positioning; it might be a limitation somewhere in Pango or cairo which results in it not being used here?

Also, I’m a bit suspicious that the first column of pixels in the capital “K” and “D” in the large “GTK Demo” header might have gotten cropped off - those stems are quite a bit thinner than expected, given what the “T” and “m” look like.

1 Like

Indeed _cairo_quartz_init_glyph_surface doesn’t call _cairo_scaled_glyph_xphase (scaled_glyph) (and y). It should be easy to implement, see for example the DWrite code: https://gitlab.freedesktop.org/cairo/cairo/-/blob/master/src/win32/cairo-dwrite-font.cpp#L1112

1 Like