Mini HOWTO: Getting Perfect Fonts on Mandrake 10.1

by Noel Llopis
llopis (at) convexhull (dot) com

Version 1.07
Last modified: 4 January 2005
Original creation: 14 November 2004

Introduction

Mandrake is my favorite Linux distribution for general desktop usage: It's extremely easy to install (it detects all your hardware right out of the box), it's very friendly for beginners, it has a great selection of software, and it looks very nice. The default window manager is KDE, which is like an improved version of Windows.

The last two points are key to attracting new users from Windows-land: It looks great out of the box, and it's not a totally alien environment. There's only one problem: the fonts are just plain ugly.

Considering you're constantly reading text, having ugly fonts is a huge problem. They're not just ugly, they're borderline unreadable at times. This document explains how to fix this problem and have the perfect fonts you're used to from Windows.

The procedure described here should work in just about any Linux distribution with KDE with none, or just minor adjustments.

Step 1: Turn off font antialiasing

Maybe it's just me, but I can't stand antialiasing in my fonts. I usually keep my fonts small (7-10 pt) and my resolution high (1600x1200), so antialiasing just makes them blurry and dirty-looking. If you have larger fonts or lower resolutions (or an LCD), you might want to leave antialiasing on. For LCD monitors, you might get particularly good results with sub-pixel hinting on. Try it both ways and decide for yourself.

Go to the file /etc/fonts/local.conf, and add the following:

    <match target="font">
        <test compare="more" name="size" qual="any" >
            <double>0</double>
        </test>
        <test compare="less" name="size" qual="any" >
            <double>72</double>
        </test>
        <edit mode="assign" name="antialias" >
            <bool>false</bool>
        </edit>
    </match>

Unfortunately that doesn't turn off all antialiasing, so go to the KDE Control Center (listed under "Configure your desktop"), select LookNFeel, Fonts, and turn off "Use anti-aliasing for fonts"). You can turn on and off sub-pixel hinting from there as well.

Done. No more antialiasing.

Step 2: Turn on FreeType native hinting

Because the default font rendering in KDE is not that great, turning off antialiasing might actually make some fonts go from being fuzzy, to being really ugly and irregular. Let's fix that.

The font rendering in KDE is done through FreeType, and it already comes installed in your Mandrake installation. FreeType is really a great system, and it's capable of rendering True-Type fonts just as well as Windows or Macs. Unfortunately it's held back by several patents by Apple, which force it to use a less-than-optimal rendering algorithm which causes the ugly fonts you're seeing. Fortunately, we can get around that quite easily. Thank open source for that :-)

Go to the FreeType project page and download the source code for the latest version. It currently is version 2.1.9.

Gunzip/untar it to /usr/local/src. Now go to the file include/freetype/config/ftoption.h and look for the line

/* #define TT_CONFIG_OPTION_BYTECODE_INTERPRETER */
Go ahead and uncomment it:
#define TT_CONFIG_OPTION_BYTECODE_INTERPRETER

Now compile FreeType by typing the following:

# ./configure --prefix=/usr
# make
# make install
You will have to be logged in as root to run the last command.

To make sure it worked, run the following command. It should report 9.7.3:
# freetype-config --version

At this point, the ugly, jaggedy fonts that we saw earlier should be looking a lot better. For a lot of people this could be good enough. But I was still annoyed by the slight irregularities in the default fonts used by KDE.

Step 3: Get good fonts

The best font rendering in the world is no good without good fonts. As much as I'm a Linux fan, I have to take my hat off to Microsoft for their really good fonts. I don't mean the silly Windings font, I mean the ones you don't think about but are used everywhere by the operating system: Tahoma, Verdana, Courier New, etc.

Here you have several options, but it boils down to using the actual True Type fonts straight from Windows. Use whichever method you're most comfortable with. I have personally always used the first method, but the other two are simpler.

First option: Copy fonts from Windows partition

If you already have a Windows installation handy, just look in \Windows\Fonts and copy all .TTF files to /usr/share/fonts/ttf/msfonts

# mkdir -p /usr/local/share/fonts/ttf/msfonts
# cp /mnt/c/windows/fonts/*ttf /usr/local/share/fonts/ttf/msfonts

Change to that directory and run the following commands:

# ttmkfdir -o fonts.scale
# mkfontdir

Almost there. One more change. Edit the /etc/X11/fs/config file to point to the fonts you just added.

catalogue = /usr/share/fonts/ttf/msfonts,
        /usr/X11R6/lib/X11/fonts/misc:unscaled,
        /usr/X11R6/lib/X11/fonts/drakfont/Type1,
        /usr/X11R6/lib/X11/fonts/drakfont/ttf,
	...

Finally, still as root, run the following commands to make sure the new fonts are used.

# xset fp rehash
# /etc/rc.d/init.d/xfs restart

At this point, you should be able to use some of those great Windows fonts. I just set the default KDE fonts to use Tahoma 7pt, and Courier New 7pt for the Fixed Width font. The Konqueror file browser or KMail should look really good now (you might have to set the file browser font in the KDE Control Center under Components | File Manager | Standard font too).

Second option: Import the fonts

Run the Mandrakelinux Control Center ("Configure Your Computer") and select System | Fonts. From this applet you have the opportunity to import fonts. If you have an existing Windows installation on a different partition in your computer, you just need to point it there and it'll take care of copying them over. Earlier versions of Mandrake even used to have a specific button to import Windows fonts.

Third option: Install Microsoft fonts RPM

If you don't have Windows installed, you can just download them from the Web. To be perfectly legal, you need to own a Windows license, but considering how difficult it is to buy a new computer nowadays without Windows bundled, that shouldn't be too hard.

They come bundled in an rpm, and installing it will take care of doing all the manual work from you. So install it and use them right away.

Step 4: Set your screen dpi

The fonts are already looking good, but probably the size in some applications is either too big or too small. Even though you're specifying size 9 or 10, the fonts end up being a different size. How come?

That's because FreeType doesn't use exact pixel sizes for fonts, but rather, final rendered size of the font. In order to do that calculation correctly, your system needs to be aware not just of the resolution of your monitor, but of its actual physical dimensions (or, what is the same, the dpi--dots per inch of your display).

Type the following command:

# xdpyinfo
And look towards the top for these lines:
screen #0:
  dimensions:    1600x1200 pixels (457x342 millimeters)
  resolution:    89x89 dots per inch
Most likely, you haven't set your display dimensions, so it's set to a default of 75 dpi no matter what resolution you have. That's going to cause some completely incorrect font sizes.

Measure your display with a ruler (in mm), and enter the measurements in /etc/X11/XF86Config under the Monitor section with DisplaySize. The example below corresponds to the dimensions of the screen of my 19" CRT monitor.

Section "Monitor"
    Identifier "monitor1"
    ...
    DisplaySize 360 270
Restart XWindows (CTRL-Backspace will do fine), and check out the size of the fonts. You should adjust them so they look correctly now. Alternatively, you can always fudge the DisplaySize number to whatever you want to tweak the fonts (although I recommend leaving the DisplaySize value to represent the correct size of your monitor so other applications like The Gimp can use that information correctly).

Step 5: Misc adjustments

Almost there! Now things should be looking really good. But as you run more programs, you'll probably that some of them still have a few ugly fonts. Why aren't they respecting the font settings we so carefully set?

Gnome applications

It turns out those are probably Gnome applications, which get their font information through different sources than KDE. Don't worry, all the work we did with FreeType, turning off antialiasing, and getting the right fonts is still valid. It's just that those applications are using native fonts instead of the ones we selected.

To change that, edit the .gtkrc file in your home directory to include the following lines:

style "user-font"
{
  fontset="-microsoft-tahoma-medium-r-normal-*-7-*-*-*-p-*-viscii1.1-1"
}
widget_class "*" style "user-font"
Some other applications use GTK 2.0, so we need to make some changes to the .gtkrc-2.0 file as well:
style "default"
{
  font_name = "Tahoma 7"
}
class "*" style "default"
Voila! Gnome applications look gorgeous as well now.

Mozilla Firefox

Mozilla Firefox is a great browser. I can't recommend it highly enough. It's standards-compliant, secure, extensible, and multiplatform. Unfortunately, that last point means it doesn't always behave like a native applications. And as you can imagine, its fonts don't quite behave the way they should under KDE.

First of all, you need to tell it to use better fonts than the default ones. Go to Edit | Preferences | General and click on Fonts and Colors. I have my Serif one set to Times New Roman, the San-serif one to Microsoft Sans Serif, and the monospace one to Courier New. That takes care of the default fonts for rendering web pages.

The menu and toolbar fonts are still looking either too large or just an ugly kind of font. To change those, you need to edit the configuration files by hand. Look for your userChrome.css file (usually under ~/.mozilla/firefox/yourprofile/chrome) and add the following entry:

* {
   font-size: 7pt !important;
   font-family: Tahoma !important;
}          
That should bring Firefox's menu and toolbar fonts in line with the rest of your system.

In my case, after making all those changes, the fonts for the input fields (buttons, text entry, or drop-down menus) in some web pages like Google or Amazon were way too big and still using one of the ugly fonts. To change that, go to userContent.css (that's different from the userChrome.css file we just modified), and add the following entry:

input, textarea, select, button,
input[type="button"], input[type="reset"], input[type="submit"] {
   font-size: 8pt !important;
   font-family: Verdana !important;
}

Avoiding ugly fonts

Some web pages and applications will attempt to use some fairly ugly fonts by default. For example, Mandrake Club uses the Helvetica font by default, or CodeWeavers uses Bitstream Vera. I'd much rather see Arial instead of Helvetica, Verdana instead of Bitstream Vera, or Georgia instead of Palatino.

Instead of uninstalling those fonts (which some applications might require, or you might want to use at some point), you can force the system to substitute in your favorite fonts.

Edit the /etc/fonts/local.conf file and add these lines:

    <match target="pattern">
            <test qual="any" name="family">
                    <string>Bitstream Vera Sans</string>
            </test>
            <edit name="family" mode="assign">
                    <string>Verdana</string>
            </edit>
    </match>
    <match target="pattern">
            <test qual="any" name="family">
                    <string>Helvetica</string>
            </test>
            <edit name="family" mode="assign">
                    <string>Arial</string>
            </edit>
    </match>
    <match target="pattern">
            <test qual="any" name="family">
                    <string>Palatino</string>
            </test>
            <edit name="family" mode="assign">
                    <string>Georgia</string>
            </edit>
    </match>
    <match target="pattern">
        <test qual="any" name="family">
            <string>Times</string>
        </test>
        <edit name="family" mode="assign">
            <string>Times New Roman</string>
        </edit>
    </match>

Root

One last minor tweak: When you run something as root (like packaging applications, system settings, or other configuration utilities), it will use the root's settings. You might want to copy the file ~/.kde/share/config/kdeglobals to /root/.kde/share/config/kdeglobals. That will make it use the same fonts as the ones in your account.

All done

We're finally all done! What a difference, uh? Once you get used to these fonts, it's really hard to go back to the default ones. I really wish that Mandrake would fix this. I'm convinced that they would attract many new users that get put off by the initial ugliness of the fonts.

Email me if you have any corrections, suggestions, or additions. I'll be happy to update this document and give you credit for it. I'll try to post screenshots of how the fonts look at each step of the way so people can see it for themselves what a big difference it makes.

Related links

Acknowledgements