Font rendering on desktop Linux

24 Sep 2013

I’ve always seemed to be at odds with the majority of people when it comes to how typefaces should look onscreen. For some reason many people want their fonts to have hard edges, and don’t mind misaligned characters that bump into each other and have completely irregular spacing–things that annoy the heck out of me. Linux desktop distributions have traditionally shipped with defaults that cater to the majority, and I have therefore had to find manual adjustments that will make the fonts behave to my liking.

I found an article about this, which explains in succinct detail how to perform the required adjustments. But it misses one detail that might have you scratching your head for a while before the cluebat hits.

Linux font configuration is done using an XML-based format, and the configuration files can be a bunch of twisty little passages, all different yet seemingly all the same, and it’s difficult to figure out which ones are actually specifying what. In Ubuntu, these files live in the /etc/fonts directory. Much like the apache or nginx configurations, there are a lot of prebuilt configuration files stored in the conf.avail subdirectory, but they aren’t used unless they’re symlinked into the conf.d subdirectory, which is where the font machinery actually looks for them.

The standard setup has a lot of different conffiles symlinked by default, and they have numbers prefixed to them to indicate their functional category. Here I’m only concerned with those that have a “10” prefix, which deals with font rendering.

The problem, in my way of thinking, is that the font rendering system tries too hard to fit the character glyphs into the pixel grid. I want my fonts to be true to the outlines, and I don’t care if they fit on exact pixel boundaries, and I don’t care if the edges are antialiased. The default setup has the “autohinter” turned on, which is the bit that does the step of trying to mash the glyph into hard pixel boundaries. So let’s turn that off, and give our eyes a rest.

I’m just going to give you the whole file, and you can peruse the details at your leisure if desired. Really all you need to do is to place this file into /etc/fonts/conf.d and name it something like 10-kill-autohinter.conf, and remove any other files with the 10 prefix, such as 10-antialias.conf, 10-hinting.conf, etc.

<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<fontconfig>
    <match target="font">
        <edit name="antialias" mode="assign">
            <bool>true</bool>
        </edit>
    </match>
    <match target="font">
        <edit name="rgba" mode="assign">
            <const>none</const>
        </edit>
    </match>
    <match target="font">
        <edit name="hinting" mode="assign">
            <bool>false</bool>
        </edit>
        <edit name="autohint" mode="assign">
            <bool>false</bool>
        </edit>
        <edit name="hintstyle" mode="assign">
            <const>hintnone</const>
        </edit>
    </match>
</fontconfig>

This should get rid of the ugliness and allow your eyes a nice rest, especially in Sublime Text. Happy coding…