Better Linux LCD Font Rendering

Jan 16 2010

After doing a font rendering comparison on Linux and Windows, I thought there was more that can be done in Linux. The script I wrote to display fonts at different pixel sizes helped to pin down the places where I noticed display artifacts. I notice font problems most often when browsing the web. A site like LifeHacker uses a font that’s not installed my Linux box. At other times, random colors appear on the edges of fonts at certain pixel sizes. However, the following font configuration file will make font on every page appear smooth if Firefox is configured to use system fonts. More on that in a later post.

/etc/fonts/local.conf
<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<!-- /etc/fonts/local.conf file to configure system font access -->
<fontconfig>

<!-- Use the Autohinter -->
<match target="pattern" >
    <edit mode="assign" name="autohint" >
        <bool>true</bool>
    </edit>
</match>

<!-- Disable Autohinting for bold fonts -->
    <match target="font">
        <test name="weight" compare="more"><const>medium</const></test>
        <edit name="autohint" mode="assign"><bool>false</bool></edit>
    </match>

<!-- Enable sub-pixel rendering -->
<!-- Uncomment this if you have an LCD screen -->
        <match target="font">
                <edit name="rgba" mode="assign"><const>rgb</const></edit>
        </match>

<!-- Font hinting to increase edge contrast -->
    <match target="font">
        <edit name="hinting" mode="assign"><bool>true</bool></edit>
        <edit name="hintstyle" mode="assign"><const>hintmedium</const></edit>
    </match>

<match target="font" >
    <edit mode="assign" name="antialias" >
        <bool>true</bool>
    </edit>
</match>

<!-- Exclude/Include a range of fonts for Anti Aliasing
    <match target="font">
        <test qual="any" name="size" compare="more"><double>8</double></test>
        <test qual="any" name="size" compare="less"><double>18</double></test>
        <edit name="antialias" mode="assign"><bool>true</bool></edit>
    </match>
-->

<!-- And/Or disable Anti Aliasing for a range on pixel-based size.
    Disabling this using both methods seems to fix Firefox.
    <match target="font">
        <test compare="less" name="pixelsize" qual="any"><double>20</double></test>
        <edit mode="assign" name="antialias"><bool>false</bool></edit>
    </match>
-->

<!-- Strong hinting for small fonts, increases sharpness.
    Enabling this seems to fix Firefox.-->
    <match target="font">
        <test compare="less" name="pixelsize" qual="any"><double>9</double></test>
        <edit mode="assign" name="hintstyle"><const>hintfull</const></edit>
    </match>


<!-- Light hinting for large fonts, reduces sharpness.
    Enabling this seems to fix Firefox.-->
    <match target="font">
        <test compare="more" name="pixelsize" qual="any"><double>13</double></test>
        <edit mode="assign" name="hintstyle"><const>hintslight</const></edit>
    </match>

<!-- Ignore any embedded bitmaps in TTF, etc (Microsoft's Calibri and others from Office 07/Vista have these) -->
        <match target="font" >
          <edit name="embeddedbitmap" mode="assign" >
            <bool>false</bool>
          </edit>
        </match>

</fontconfig>

After editing the file, a restart of your application is required for the settings to take effect (for me it was Firefox, since I was testing font configuration).

No responses yet