Font rendering config on Linux - What they didn't tell you


2022-12-12

Font rendering woes again


While others never had a problem with font rendering, I find myself part of the group that is quite sensitive to changes in font appearances, more so than the majority probably.

Yet for years, I didn't have to bother with font rendering aspects on "Linux" no longer. I thought it was a thing of the past. After all, patented tech expired, we got subpixel rendering in freetype everywhere, good modern fonts and so on.

But recently, I switched a laptop of mine from Kubuntu to Voidlinux. I made sure to have the same configs in effect, migrated /etc/fonts and user configs, selected the exact font settings, installed the same fonts and configured the font dialog of KDE in the same way. I diffed the individual files. However, the full hinting that looked nice in Kubuntu didn't look nice for me in Voidlinux. This lead to eye strain. I compared screenshots of the same applications in GIMP, zoomed in on the same text and could clearly see the exact same config was rendering differently.

voidlinux is not to blame though. This would be true with any distribution. It's generally due to many factors. I believe it's good to be aware of them when tinkering with fontconfig. You find an endless amount of discussions, tutorials, wiki pages and flame wars on how to get font rendering on "Linux" (= fontconfig, freetype, pango, cairo... usually on Xorg) right. The aspects mentioned in this post are, in my opinion, not stressed enough and in most cases are a source of disappointment, as users don't get the results they are supposed to get. A factor that comes into play here is that people giving the advice are probably unaware of those issues often enough (especially in forums).

I am not going to provide config options and explain rendering techniques here. There are better resources by people with more clue than me on this matter.

Configuring the font stack - Things to keep in mind


Most tips you will find will tell you to enable a bunch of symlinks in /etc/fonts/conf.d and may ask you to put a certain fontconfig XML in $HOME/.config/fontconfig/fonts.conf. If you are running KDE/GNOME/Xfce or any desktop environment, you also have a settings dialog where you can play around with smoothing etc. That dialog may merely just modify $HOME/.config/fontconfig/fonts.conf or do some other magic, who knows. You may also change individual GTK/Qt configuration files or xsettings.

Changing configs is not a problem. They do influence the rendering and may improve what you get after all. Thus, chances are lcdfilter, some hinting and subpixel rendering is probably what you indeed want to have enabled there.

However, these options have to be seen in their context. Here are a few aspects one should never forget when getting frustrated by bad results from configs other people say fixed everything for them. Or when updates make things worse. Or after installing a new distro. They are for the most part actually rather obvious, but appear to be forgotten about often enough.

(1) The rendering is not stable between library versions


So you are not happy with the way your distro renders fonts. You are following a few steps you found on the internet that change fontconfig or something else. Those are supposed to fix your problem. If it's a forum post, it may even have many "that did it for me, thx!" comments. You try it out expecting the same great results only to end up disappointed.

You should realize that even if you never touch fontconfig, what gets rendered may not stay the same forever. The reason is trivial: The font libraries involved in rendering, among them freetype, pango, harfbuzz and cairo, do get updates. Updates change things. Sometimes the rendering...

So a fontconfig that used to look good for somebody, or maybe even for you too, may stop doing so after a while, once one of these libraries decides to change (with the intent to improve/modernize) the rendering.

Naturally, you are more likely to encounter that case in rolling distributions than LTS versions.

Examples:

"Aggressive" hinting no longer supported in pango:
https://gitlab.gnome.org/GNOME/pango/-/issues/463
https://github.com/harfbuzz/harfbuzz/issues/2394
https://blogs.gnome.org/mclasen/2019/05/25/pango-future-directions/

Changes in the font stack suddenly simply made the rendering (in the opinion of some) worse, seemingly overnight.

GTK4 changing things again:
https://gitlab.gnome.org/GNOME/gtk/-/issues/3787

As you see, your fonts.conf etc. won't help if libs decide not to no longer obey some of the options, simply change their logic, or shift their focus towards HiDPI displays. Configuration examples from years ago may have been great for almost everyone at some point, but may have become obsolete these days.

(2) Build options and distro patches


If a configuration looks amazing for the majority of Ubuntu users, the same config may not work for Fedora or Gentoo etc. users. Even in the unlikely case that all libraries in the font stack have the same version, they may have been compiled with different build options and custom patches set by the distro.

A common example is that for a long type Fedora did not enable subpixel rendering in freetype (they seem to be doing it now). Sometimes freetype is built with the harfbuzz dependency, sometimes it isn't. Different freetype engines may also be selectable, like on Gentoo.

The main point here is that the way distros build freetype (and all other libraries) may not overlap. This may easily lead to different font appearances. Don't expect suggestions tailored to a distro to look great on yours.

(3) Some softwares ignores system libraries


Assuming you have a result you are happy with, that is most software renders fonts in an acceptable way for you now, there is another problem you have to deal with.

Sometimes fontconfig is ignored by programs. Others don't use your systems versions of e. g. harfubzz, hence they render text differently. In my experience, distributions try to make sure that your distros libraries are used if possible, at least for software in the official package repositories. But keep in mind, especially with appimage, flatpak, snap and tarballs with pre-built binaries, that this may not be the case there. They may ship outdated libraries, or have not compiled them with options that look great on your system.

Example:
https://github.com/flatpak/flatpak/issues/4571


(4) The config and libs are good, your installed fonts maybe aren't


I don't mean the often mentioned bitmap vs TTF fonts issues, although that's relevant. It's just that some fonts are simply better than others. For example, "Noto sans" may simply be a font that looks better for you with your settings than "Dejavu Sans".

There other issues though. Sometimes, newer versions of the same fonts may make things worse.

Example:
OpenSuSE updates breaks noto fonts as hinting information was lost in an update:

https://bugzilla.opensuse.org/show_bug.cgi?id=1199938

This example is interesting, No font libraries were changed here. Just a seemingly innocent update of a font can break things. While this case is probably rather rare to occur, it proves that the reasons for bad rendering are not always found in config files or libraries.

(5) Displays, DPIs and screenshots


It's obvious, but no config in the world can change the capabilities of your display. It's a different game for someone with a 4K display than for someone with 1080p on 22''. There is a difference between 1080p on 24'' and the same resolution on 15.6'', the latter will have greater DPI and may get away with less hinting. And naturally, lots of other properties of displays come into play.

You often find threads where people argue about font configs. Despite it being subjective anyway, sometimes during the discussion between users it gets revealed that they are using completely different display sizes. This aspect should also be considered when sharing screenshots.

(6) You are an individual


It's a very subjective topic overall. It's trivial, but what looks bad for you may look good for others. You may also simply be used to certain rendering techniques. Windows renders fonts differently than Mac, which gets noted by people when they switch from one to the other. As already pointed out, Linux distributions differ too. Smartphones are also a different game, but usually no meaningful problems here.

Thus, maybe the font rendering you got is not bad, your eyes may need some time to adjust. Sometimes, you may realize the rendering you perceived as perfect is actually inferior.

For some, there also may be certain eye conditions that may cause them to have problems with font rendering techniques the majority would consider fine.

(7) Wayland, Xorg, Qt, GTK


Certain inconsistencies can be observed between the same apps running on Xorg vs Wayland, as well as between Qt and GTK and generally even between different versions (i. e. GTK3 vs GTK4). This always was a pain point. A lot has been said about this elsewhere.

(8) Conclusion, Solutions


As we see, if you give/receive advice on font configuration, remember it may look only great/bad for you on your display, on versions installed on your distribution with patches applied by your distribution.

Overall it became clear to me that I personally am more sensitive to font rendering than most users. In the past, I used to just use Ubuntu's libraries in my Gentoo installation because they seemed to do the best job. As there packages in AUR for Archlinux for that it seems, so this approach may not be so uncommon. At some point, this became unnecessary though as lots of improvements found their way upstream (new engines in freetype, subpixel rendering etc.). Of course, using compiled libraries from another distro is annoying. It can break things, you can't expect API/ABI compatibility and is generally something you don't want to waste your time on anyway.

If the rendering changes for worse after an upgrade, assuming you have time and nerves, you may perform downgrades of libraries. But that's not a sustainable solution either. You can run LTS versions of distributions so updates are less likely to change the font rendering. This is naturally your best bet if you really are not a fan of (surprising) changes in font rendering.

You can consider getting displays with higher resolutions (WQHD, 4K) as then sub-pixel rendering techniques become less of a problem, or can be turned off. But then different problems may pop up such as proper scaling.

Overall, you have to accept that font rendering changes. It seems inevitable that you may need to go through a readjustment period from time to time. So if you have to, tweak the config to the best thing you can currently get. What looks unusual at first may become the new normal, or even good. Or at least good enough.

I personally switched to slight hinting now. I've used full hinting my whole life before. So far, after an adjustment period, it appears to work out. Again, with the current libraries on my system. Hopefully with future versions too.

For comments/remarks: Contact me

Disclaimer: Opinions are my own. If you act on the information presented in this post, you are doing so at your own risk.