Improve Your Fonts

From CLFS-HINTS

Jump to: navigation, search

Contents

Introduction

Font rendering in a GUI environment isn't always Linux's strength "out of the box." Fortunately, we can make a few tweaks to rectify this situation. After setting your FreeType configurations below, there should be a noticeable difference in font rendering on your system.

Fonts and FreeType

All recent X servers from X.Org use FreeType2 for font rendering (any other modules loaded in your /etc/X11/xorg.conf for font rendering are no longer used). With the changeover to FreeType2, due to various Apple patents in the US and Japan, the 'bytecode interpreter' is now disabled by default. We fix this problem in the CBLFS instructions for FreeType. If you didn't follow the CBLFS instructions for FreeType, then you may want to go rebuild FreeType following those instructions.

If you're using KDE or GNOME, you'll find they have tools for "assisting" you in editing your ~/.fonts.conf file. In my opinion, their attempts at generating and editing a .fonts.conf file are OK, butit is much more preferable to edit the file yourself. Since it is now done through a well defined XML file, this isn't much of a chore. You can visit http://grc.com/ctwhat.htm for the technical explanation of all of these changes.

Font Configuration

Open your favorite editor and load ~/.fonts.conf or /etc/fonts/local.conf for making changes globally. If ~/.fonts.conf already exists, add these sections inside the <fontconfig></fontconfig> tags. If it doesn't exist, there is a ~/.fonts.conf file later in this article that you can copy and paste.

Adjust Font Hinting

1. Ensure that the sub pixel order is not specified.

X knows the sub pixel order already, and if this is enabled as well, FreeType produces some very strange results. However, if you do still have problems, consider replacing 'none' with 'rgb' (the standard for LCD monitors), 'bgr' (unusual), 'vrgb' (vertical rgb, if you have a monitor that has been rotated by 90 degrees), 'vgbr' (as vrgb, but very rare).

<match target="font" >
    <edit mode="assign" name="rgba" >
        <const>none</const>
    </edit>
</match>

2. Enable sub-pixel hinting

This is what really starts to make the difference.

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

3. Set the amount of hinting

Usually, this should be full. Valid options are 'none', 'hintslight', 'hintmedium' and 'hintfull' which should be fairly self explanatory if you've read the article at the link above.

<match target="font" >
    <edit mode="assign" name="hintstyle" >
        <const>hintfull</const>
    </edit>
</match>

Antialiasing and Autohinting the 'Easy' Way

Essentially, we're going to enable FreeType's non-patented autohinter and antialiasing to improve the appearance of the default Bitstream fonts.

Add the following to ~/.fonts.conf.

1. Enable anti aliasing

This makes the fonts start to look nice, but some of the shapes will be distorted, so we need the FreeType autohinter (see next part).

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

Fluxbox only

I don't know if this true, but someone who uses Fluxbox passed this along. You may need to enable anti aliasing separately on Fluxbox before it takes notice of the changes:

fluxbox menu --> Configure --> AntiAlias

2. Enable the FreeType autohinter

The autohinter is not turned on automatically, so we have to do this manually.

Please note that OpenOffice.org binaries from the OOo website are built against the bytecode interpreter, so even if you have compiled FreeType with the bytecode interpreter and override it with the autohinter, OOo will still use the bytecode interpreter.

<match target="pattern" >
    <edit mode="assign" name="autohint" >
        <bool>true</bool>
    </edit>
</match>

Antialiasing and Autohinting the 'Hard' Way

This is my preferred solution, as I believe it gives better results. This requires FreeType built with the bytecode interpreter enabled, and using the properly hinted fonts from Microsoft. To enable 32-bit/64-bit applications to use the bytecode interpreter, you need to install 32-bit and 64-bit bytecode enabled FreeType repsectively.

Download and install the Microsoft Core Fonts for the Web. Get all of the *.exe files. Use CabExtract to extract the *.ttf's from the *.exe's you downloaded. Move the fonts to to your TTF font directory; most likely /usr/X11/lib/X11/fonts/TTF or /usr/share/fonts/TTF.

If you have a Windows installation, you can copy the TrueType fonts from that installation instead. I. of course, would never encourage or condone you copying the TrueType fonts from your friend's, school's, employer's Windows computer as that would be stealing. However, it would work (so I've heard).

Now add the following to ~/.fonts.conf

1. Disable the autohinter

This isn't strictly necessary – the autohinter is not enabled by default, and if it's not enabled, the bytecode interpreter is used by default. However, it's better safe than sorry.

<match target="pattern" >
    <edit mode="assign" name="autohint" >
        <bool>false</bool>
    </edit>
</match>

2. Set the MS fonts as defaults

<match target="pattern" name="family" >
    <test name="family" qual="any" >
        <string>sans-serif</string>
    </test>
    <edit mode="assign" name="family" >
        <string>Arial</string>
    </edit>
</match>

<match target="pattern" name="family" >
    <test name="family" qual="any" >
        <string>monospace</string>
    </test>
    <edit mode="assign" name="family" >
        <string>Courier New</string>
    </edit>
</match>

<match target="pattern" name="family" >
    <test name="family" qual="any" >
        <string>serif</string>
    </test>
    <edit mode="assign" name="family" >
        <string>Times New Roman</string>
    </edit>
</match>

I also recommend replacing all the Bitstream and Luxi fonts with the MS equivalents or set them to use serif, sans-serif, monospace instead. This section tells FreeType to replace any such fonts with a properly hinted TrueType equivalent. All of the Bitstream and Luxi fonts should be aliased in this way.

This is an example for Helvetica but can be used for any other fonts you want to replace. Just replace 'Helvetica' with the font to replace, and 'sans-serif' with the font you want it to be replaced with. Generic font descriptions serif, sans-serif and monospace are valid entries, as well as specific font names.

<match target="pattern" name="family" >
    <test name="family" qual="any" >
        <string>Helvetica</string>
    </test>
    <edit mode="assign" name="family" >
        <string>sans-serif</string>
    </edit>
</match>

Testing

Just load any application and the changes should be immediately obvious.

Apply Font Configurations Globally

The order of precedence for processing fonts is /etc/fonts/fonts.conf. I wouldn't recommend editing this file. Then /etc/fonts/local.conf and finally ~/.fonts.conf. This mean your ~/.fonts.conf will always override the system settings.

You can apply your changes system wide, using /etc/fonts/local.conf. If it exists, just append the sections you added above to it. If it doesn't, use your .fonts.conf as /etc/fonts/local.conf, and edit it as necessary.

Application Specific Settings

Qt and Gtk settings need to be changed.

Gtk

For gtk, edit .gtkrc-2.0 and set the fonts either to the generic 'serif', 'sans-serif', or specify the MS fonts outright.


Qt

For qt, edit .kde/kderc and .qt/qtrc

Older Versions of Gtk/Qt

Some programs (usually older ones) using these libraries may not always use anti aliased fonts, even if you've specified them in .fonts.conf. This can fixed by:

Gtk

Add the following to /etc/profile: export GDK_USE_XFT='1'

Programs coded using Gtk 1.x don't always support anti aliasing properly. You may want to consider replacing them with ones that use Gtk 2.x.

qt

In ~/.qt/qtrc, ensure the following entry is present under [General]: enableXft=true useXft=true

Sample ~/.fonts.conf

The following is a ~/.fonts.conf or /etc/fonts/local.conf skeleton. Use this to put together a working configuration for your system.

<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<fontconfig>
    <match target="font" >
        <edit mode="assign" name="rgba" >
            <const>none</const>
        </edit>
    </match>

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

    <match target="font" >
        <edit mode="assign" name="hintstyle" >
            <const>hintfull</const>
        </edit>
    </match>
   
    <match target="pattern" >
        <edit mode="assign" name="autohint" >
            <bool>false</bool>
        </edit>
    </match>

    <match target="pattern" name="family" >
        <test name="family" qual="any" >
            <string>sans-serif</string>
        </test>
        <edit mode="assign" name="family" >
            <string>Arial</string>
        </edit>
    </match>

    <match target="pattern" name="family" >
        <test name="family" qual="any" >
            <string>monospace</string>
        </test>
        <edit mode="assign" name="family" >
            <string>Courier New</string>
        </edit>
    </match>

    <match target="pattern" name="family" >
        <test name="family" qual="any" >
            <string>serif</string>
        </test>
        <edit mode="assign" name="family" >
            <string>Times New Roman</string>
        </edit>
    </match>

    <match target="pattern" name="family" >
        <test name="family" qual="any" >
            <string>Helvetica</string>
        </test>
        <edit mode="assign" name="family" >
            <string>sans-serif</string>
        </edit>
    </match>

</fontconfig>
Personal tools