In search of perfect font rendering on Linux
Important Note: This article is deprecated; in a more recent article I have briefly explained how to achieve better results than those below. Since this is a blog, I’ve left the original article intact for historical reasons.
As a designer and as someone who spends a lot of their time in front of a screen, I’m especially sensitive to how fonts render in the software I use. One of the greatest challenges I’ve had with Linux is getting text to render simultaneously attractively and readably. The good news is, after a lot of tinkering, I think I’ve got it more or less down pat. What follows are some basic instructions as to what I did, although I suggest reading and altering to suit your needs as opposed to outright copying so as to ensure the results you seek.First, a brief definition of what I sought: Antialiased fonts are relatively easy to achieve on Linux in recent times thanks to considerable effort by its advocates. The trick for me was to strike a balance between the smooth, sleek look of Mac OSX’s “antialias the hell out of everything” approach and Microsoft’s cleartype, which produces (in my opinion) clearer and more legible text at frequently-used font sizes (at my screen’s resolution, anyway) but less appealing font shapes at higher resolutions, and fonts get obliterated at lower resolutions.If you’re interested in improving font rendering in Linux and seeing some examples, read on.
The solution turned out to be relatively simple: hybridise the font rendering capabilities depending on your preference criteria. Here are some examples:
Example 1: Hinting Disabled

This is how fonts render with freetype’s Byte Code Interpreter enabled and hinting disabled—Looks similar to how text renders on a Macintosh. If this is what you’re looking for, enable BCI and set hinting to ‘none’, and you’re done. For me, though, the text is blurry enough to make me think I’m having problems focusing; I can’t read large amounts of body copy that looks like this.
Example 2: Hinting Enabled

This image is also with the BCI enabled but with hinting enabled (doesn’t matter what setting; all of them look the same). It looks more like Microsoft’s ClearType, but larger text doesn’t look as good as in the first example, and some smaller text gets obliterated (although not in this example).
Also note there is inconsistent/incorrect kerning between the larger characters (”oo”, “Pe”, “om”, etc.) not present in the first example. The geometric awkwardness of the hinted characters becomes more apparently at larger font sizes: note how the ‘o’ looks somewhat squashed and slightly rectangular.
On the other end of the size spectrum, look at the smaller text—you can’t even tell what’s boldfaced except that the boldfaced text is strangely one pixel wider than the text surrounding it (most easily noticeable with the “e” character).
Example 3: Hybrid Hinting

By way of comparison, this is a screenshot of the same image using a simple hybrid approach explained below; you can see larger and smaller fonts are smoother and rounder, and body copy retains its crisp, legible appearance.
If hybrid hinting looks interesting to you, read on for a basic seat-of-your-pants walkthrough on how to do it. I apologise if you’re looking for a complete how-to on configuring fonts on Linux; I assume you’re already most of the way there for this article. Help on the brief points below is available in heaps elsewhere.
First, you’re going to have to get a copy of Freetype with the the Byte Code Interpreter (BCI) enabled. You can do this in several ways:
- Downloading and compiling the freetype libraries yourself from source with the appropriate flag enabled;
- Locating a pre-compiled package for your particular distribution that has the BCI enabled (this will likely be in the non-free/commercial packages repositories, as BCI is covered under a patent by Apple). Ubuntu users can find information here; users of other distributions are on their own (although it shouldn’t be difficult to find).
- If you’re a Gentoo user, you can read the Wiki for how to do it all in portage—but the short version is, set the
-bindistflag in/etc/make.conf’s USE flags andemerge --newuse --deep freetype.
It should go without saying that you should install commonly-used truetype fonts. I highly recommend installing Microsoft’s core web fonts as well as the OSX fonts; you can find both packages very easily with a brief search on Google. Alternatively, you can use bundled Linux fonts if you prefer, and ensure they’re used on web pages by writing substitutions—an example of how this is done is at the top of the example file below. If you used the command line to copy over fonts, be sure to run /usr/bin/fc-cache once your new fonts are installed to make them show up in KDE/Gnome. A reboot shouldn’t be necessary, but you’ll have to restart the relevant application to see them.
You should be able to see the improved rendering of Antialiased truetype fonts right away (if you don’t, go to the relevant control center and edit fonts, enable font anti-aliasing, then change the Hinting Style from “None” to anything else).
You will probably notice that under a hinting style of “None”, the fonts are all very smooth and OSX-like, but somewhat blurry and difficult to read at common copy sizes.
By contrast, enabling any hinting style besides “None” (it doesn’t matter whether you “Slight”, “Medium” or “Full” as they all look identical with the BCI compiled into freetype) results in very crisp, thin, highly geometric fonts. These look and read great at “normal” text resolutions, but break down at very small sizes and look somewhat rectangular when rendered at larger sizes.
You can also choose whether or not to enable sub-pixel hinting at this point if you own an LCD; Personally I think the technology is a bit immature in Linux and still results in some discolouration toward the edges of some text (particularly narrow/smaller fonts) no matter which ordering you employ. You can enable/disable this selectively later on if you want as well.
This is where my instructions diverge a bit from what I’ve read elsewhere: I edited my personal fonts.conf file (~/.fonts.conf) and set up exceptions to how font hinting is handled. Specifically, I turned autohinting on in some cases (which negates BCI, apparently) or disabled hinting entirely (both appear to have the same effect on the font). I also completely disabled hinting on the OSX fonts on my system so that they have that “Mac-esque” appearance whenever they’re used regardless of their size. This incidentally results in the Apple website looking virtually indistinguishable from how it appears in OSX, as I understand it, although YMMV.
Below is my ~/.fonts.conf file; you should feel free to modify it to suit your tastes once you get the basic idea. One very important note is that you must place the exceptions to the rules after the rules themselves, or they will be overridden. That is to say, last rules get the final word; more specific rules don’t take precedence over less-specific ones.
I should also point out that you should probably back up your existing .fonts.conf file in case something goes horribly wrong—you don’t want things to get worse by having this go wrong then not being able to at least get things back to the way they were previously. Just copy it over to another file name like fonts_conf.bak so you’ll be able to find it easily later if need be.
Download my fonts.conf file . Rename it to ~/.fonts.conf once you’ve backed up your local copy of the file.
Once you’ve created or modified your ~/.fonts.conf file, you should restart a “test” application to see how things look—a web browser is a good bet as you can easily display a variety of fonts and change the sizes quickly to see how they render. When you think you’re satisfied with the appearance, restart X (or simply reboot your computer) for the effect to take with the window manager itself and all of your applications.
Please consider taking a moment to leave me a note if there are any errors in my article, or if this worked for you. Good luck, and happy reading!
Thanks for the useful howto, I really needed it. Never had any idea what this “hinting” thing actually meant. Also, since you asked, yes, I did notice two errors in this article, and I am sure they will soon be fixed.
Dear Kevin,
Thanks for the information. I tried out your config file but noticed that on certain web pages it blows the font size up so large that only the upper half of the text is displayed. That said, the text that was displayed was very superior to the default settings I was using. Why would it be doing this?
Kind regards,
Andrew
Hi Andrew! Thanks for dropping me a line. Regarding your question: There’s nothing in the configuration file above that should be altering the size of fonts (although my post on ‘fixing’ Georgia does mention how I’ve done this on a smaller scale than what you’re experiencing).
My initial reaction to your problem suggests that it may be being cause by a couple of things: First, some setting in Firefox: I would test with another browser before doing anything else to see how fonts rendered. In my case, I spend weeks fiddling around trying to make Firefox look good until I (eventually) realised it wasn’t the fonts that were at fault, but Firefox, which was statically linked to its own internal copy of the freetype library (I was using Gentoo’s mozilla-firefox-bin package to make plugins work)! Looking at my test pages in Konqueror sorted me out, although just about any browser should work.
If other browsers render everything the same as Firefox, then the problem is somewhere else—But I suspect it’s going to be Firefox that’s the problem.