[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Bug#956612: libpango-1.0-0: broken kerning since 1.44



Hi,

On Fri, Jun 26, 2020 at 10:53:09AM +0100, Simon McVittie wrote:
> https://github.com/harfbuzz/harfbuzz/issues/1892 appears to be related. A
> comment on that issue suggests that the way forward for pango involves
> getting an upstream cairo release out, possibly so that pango and
> cairo agree on the way they use harfbuzz (same hinting settings, etc.),
> or so that text can be rendered with subpixel positioning so the rounding
> becomes unnecessary? (This is really not my area of expertise, so I might
> be entirely wrong about this, and I am not the right person to be
> developing a patch.)

I'd gotten the same impression when I read these comments a few weeks/months
ago, but it turns out the situation isn't as optimistic as that. The only
thing that a new release of cairo brings is the possibility to enable subpixel
positioning in pango, but that's just a possibility, nothing more, no change
in behaviour, no fix, nothing.

The core of the issue with pango is that in 1.44 they dropped support for full
horizontal hinting, presumably because pango (and cairo) is largely
unmaintained:
https://blogs.gnome.org/mclasen/2019/05/25/pango-future-directions/#:~:text=Unhinted%20rendering

Chromium and Firefox (via the Skia library) and Qt still support full hinting,
but gtk (via pango/cairo) no longer does, and probably never will as there
aren't any developers willing to maintain that support.

The point of full hinting is to both align the glyphs to the pixel grid and
change the glyph shape to align individual stems to the pixel grid as well, in
order to obtain sharp rendering with minimal need for antialiasing. The
downsides of this approach are described in detail in this document:
https://docs.google.com/document/d/14IQEWrVS0wydzpTAMbvJep7HnX9t-ljuxFwTToSbOVk/edit
From my personal experience as a user, the primary downside is that kerning is
often suboptimal (rn sometimes looks like m, that sort of stuff) but the
sharpness of text is so good that the suboptimal kerning seemed to be a minor
issue for me for many years. It's also worth noting that to obtain really
sharp text, one also needs to set FREETYPE_PROPERTIES="truetype:interpreter-version=35".
For interested readers, there's a lot more (possibly outdated) info at
https://pandasauce.org/post/linux-fonts/.

Anyway, in pango 1.44 full hinting is no longer supported (results in abysmal
kerning/glyph placement, as the glyphs are positioned without applying hinting
to adjust the stem positions and thus glyph width, but then rendered using the
hinted glyphs). The only officially supported way forward is to disable full
hinting and retrain your eyes and brain to the new rendering of fonts. The
good news is that by disabling full (horizontal) hinting, kerning is improved
significantly.

Or… to be more precisue, kerning _would_be_ improved significantly, if
subpixel positioning was enabled as well. This is a good idea now as neither
the glyphs themselves nor the stems in them are aligned to the pixel grid, and
the rendering relies on (subpixel) antialiasing and LCD filtering (to make it
look sharp enough yet without color artifacts), so it doesn't really matter
which of the three color subpixels a glyph is positioned to, it will always
look almost the same (more blurry than full hinted, but also more like the
font designer intended, more like a larger size version of itself, etc.).

The bad news is that subpixel positioning is only supported in cairo git, and
there's no knob to enable it in pango/gtk. The good news is that Chromium,
Firefox and Qt do not have this problem and will use subpixel positioning as
soon as full hinting is disabled. There may some bugs here and there, so
there are knobs in e.g. about:config that make it possible to force this, but
the functionaly is there, as opposed to pango/gtk. The wiring of subpixel
positioning in pango/gtk is "tracked" here:
https://gitlab.gnome.org/GNOME/gtk/-/issues/7#note_795665

I really wanted to have subpixel positioning everywhere, so I built a cairo
package from a git snapshot (https://salsa.debian.org/liskin/cairo) and
created a shared library hack to force-enable subpixel positioning in cairo:
https://github.com/liskin/dotfiles/tree/e64efabf6db10a7e57f49b844f66a0d8331a0e5c/src/pango-force-subpixel-positioning
https://github.com/liskin/dotfiles/blob/e64efabf6db10a7e57f49b844f66a0d8331a0e5c/.bashrc.d/10_env.sh#L15
It's ugly and doesn't work with apparmor-protected apps like evince. Patching
and rebuilding pango might be a better option, actually. But I've been using
it for the last 2 months and it's nice that gtk apps like liferea render fonts
as good as the browser does.

More importantly, this is only relevant once you accept that full hinting is
gone, freetype interpreter v35 is gone, fonts will be more blurry than they
were your entire life, and you just want to make the most out of "kerning
might be a bit better now". Now that I think about it, switching away from gtk
apps might have been a better idea. Or get a 4K screen (not really an option
if you don't live in a first world country, or if you're obsessively unwilling
to let of of the 7-row ThinkPad keyboard).

Hope this clears the situation up for others. :-)

-- 
Tomáš Janoušek, a.k.a. Pivník, a.k.a. Liskni_si, http://work.lisk.in/


Reply to: