CLASS="SECT1" BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#840084" ALINK="#0000FF" >

3. TrueType Fonts

Historically, the Unix world relied on Type 1 fonts for high quality scalable fonts. Linux supports Type 1 quite well, both for printing and for screen output. But, Type 1 never was widely adopted by web designers, and on other platforms. TrueType, due to its association with Windows, is the preferred web font. And XFree86 seems to render TrueType a little better.

You won't find many decent TrueType fonts included with any distribution, however. The reason is that there are not many quality TrueType fonts available under a suitable license at this time. In fact, many of the "free" ones, are rather poor. Many distributions are including some TrueType fonts, and also including tools for automating the process of adding TrueType fonts from external sources. See if that is an option for you. This will be easiest route. You will definitely want to add some quality TrueType fonts, one way or another.

Because the boys in Redmond are very concerned with the appearance of their software (as opposed to the internal workings ;), they built TrueType font support into Windows. And of course no big surprise, but they got the idea from Apple. In fact, TrueType is a registered trademark of Apple Computer, Inc. Windows 9x, NT, 2K and nearly every other incarnation of Windows comes with Arial, Times New Roman, and Courier New, which are roughly equivalent to Helvetica, Times and Courier. TrueType fonts are scalable, so they look good in large sizes, and they are well hinted, so they are readable at small sizes. Many windows applications come with dozens more TrueType fonts. And let's face it, those MS and Apple fonts are, generally speaking, just plain better than the freely available ones with a suitable license. Don't microwave your Windows CD yet, you'll want to get those quality fonts first!

3.1. Making TrueType Fonts Available

Let's start with the fonts first. Any TrueType font included with the various MS Windows incarnations should work. Don't forget word processors and other apps that may include their own fonts. MacOS fonts will only work if converted to a usable format. (See the links section for converter packages.) There are also some 'free' TrueType fonts available for download if you have already nuked that CD (see links section).

Many distributions are now bundling tools for automating the process of including quality TrueType fonts. SuSE, Debian, and Mandrake do (Red Hat 7.x does not at this time). See what packages you might have for this as this will be the most painless way to go. Essentially, these tools help migrate fonts from a Windows installation, or download those available from Microsoft [note 08/15/02 MS has recently removed these fonts!] , and then handle the installation and configuration all in one neat utility. If you do have such a utility, the below information may not be necessary!

In order to use TrueType, the fonts will have to be always accessible to X. This means they will have to be on a filesystem that is always mounted. This can conceivably be a Windows partition on a dual boot system. Alternately, the fonts can be copied to Linux. First su to root:

 # su -
 # mkdir -p /usr/local/share/fonts/ttfonts
   

Now, change to the new font directory:

  # cd  /usr/local/share/fonts/ttfonts
   

Then, add the fonts to this directory, either by copying them from your Windows system:

 # cp /mnt/<path_to_fonts>/*ttf  .
   

or by downloading those available directly from Microsoft: http://www.microsoft.com/typography/fontpack/default.htm. Note 08/17/02: Microsoft has recently discontinued this page. At this time, the following pages (may!) still have these fonts available (or google search for them):

    http://nuoriso.hel.fi/__files/ms_truetype_core_fonts_for_the_web/Win95-98-NT/index.html
    http://web.archive.org/web/20000420210719/http://www.microsoft.com/opentype/fontpack/default.htm

These can be unarchived under Linux with cabextract, which can be found http://www.kyz.uklinux.net/cabextract.php3. This would now seem to be the best way to go at this time.

A slick solution to this from Sebastiano Vigna is his http://freshmeat.net/webFonts4Linux, which automates the downloading, extracting and installation of the Microsoft fonts all in one neat package. A utility designed primarily for Red Hat can be found: http://sourceforge.net/projects/font-tool/, which includes all the core MS web fonts, plus relevant system configuration. There is a tarball, as well as RPMs (both require cabextract).

You can also get an RPM of WebFonts that contains some of the MS Web fonts from ftp://ftp.rpmfind.net/linux/contrib/noarch/noarch/webfonts-1-3.noarch.rpm. This has enough basic fonts to keep Mozilla and other web browsers happy. Something similar for Debian is http://packages.debian.org/unstable/graphics/msttcorefonts.html. This does not include the actual fonts, but facilitates the installation.

If doing it yourself, you will also have to include the new TrueType directory(s) in the X server's fontpath. So with your text editor of choice add the line(s) as appropriate:

FontPath        "/usr/local/share/fonts/ttfonts"
FontPath        "/usr/X11R6/lib/X11/fonts/misc:unscaled"
FontPath        "/usr/X11R6/lib/X11/fonts/100dpi:unscaled"
FontPath        "/usr/X11R6/lib/X11/fonts/75dpi:unscaled"
FontPath        "/usr/X11R6/lib/X11/fonts/Type1"
FontPath        "/usr/X11R6/lib/X11/fonts/Speedo"
FontPath        "/usr/X11R6/lib/X11/fonts/misc"
FontPath        "/usr/X11R6/lib/X11/fonts/100dpi"
FontPath        "/usr/X11R6/lib/X11/fonts/75dpi"
    

This configuration is for "core X font" support. For additional configuration relating to the new Xft rendering engine, see the sections below on XFT and anti-aliasing.

3.2. TrueType Hinting

"Hinting" is a TrueType specific feature, that is generally considered to be a useful technique that improves the appearance of TrueType fonts. Unfortunately, there are some licensing and patent issues involved with this, and it is disabled by default in the freetype sources! And also quite likely that if you are using vendor supplied binaries, it is disabled there as well.

To enable this feature, the sources need to be rebuilt. Look for include/freetype/config/ftoption.h in the freetype source tree, and then search for:

  #undef TT_CONFIG_OPTION_BYTECODE_INTERPRETER
 

And very simply, make this small change:

  #define TT_CONFIG_OPTION_BYTECODE_INTERPRETER
 

Red Hat users can rebuild the src.rpm by toggling one setting at the top, and accomplish the same thing:

  %define without_bytecode_interpreter    1
 

And change to:

  %define without_bytecode_interpreter    0
 

Other vendors may have a similar, easy-to-use mechanism.

Then rebuild and install the finished binaries. Be sure to restart X as well since the freetype code is already loaded into memory by X.

Note that "hinting", "anti-aliasing", and "sub-pixel rendering" are separate concepts (see the section on Xft below for more). Again, this is not a cure-all for "ugly" fonts, but one more piece in the puzzle of font "beautification".

3.3. Configuration

This section pertains to installing and configuring TrueType fonts for any "freetype" based font renderer. This would include the freetype font module from XFree86-4.x, Red Hat's xfs, and the xfsft font server. Again, if you have used a distro supplied tool for migrating TrueType fonts, it is likely this has been done for you already. The steps described below would only be necessary for manual font installation.

There is still more work to be done before we can actually use any TrueType fonts. First, all font files must have lower case names. Secondly, they shouldn't have embedded spaces. And then, we will need to create a couple of configuration files to make things go.

Su to root, and change to the directory where the TrueType fonts are.

 # su -
 # cd /usr/local/share/fonts/ttfonts
   

If there are any upper case font names, you can use the following script to convert all names to lower case:

 

 #!/bin/sh
 #
 ## -------- convert upper to lower case ---------
 
 ls * | while read f
  do
    if [ -f $f ]; then
      if [ "$f" != "`echo \"$f\" | tr A-Z a-z`" ]; then
       #Note that 'This' will overwrite 'this'!
       mv -iv "$f" "`echo \"$f\" | tr A-Z a-z`"
      fi
    fi
  done

 ## eof
 
   

Note the punctuation -- the backquotes are important! Remove any spaces from font names too. Once the TrueType fonts are properly installed, you must create both fonts.dir and fonts.scale files. The following commands do this:

 # ttmkfdir -o fonts.scale
 # mkfontdir
   

If you don't have ttmkfdir installed, check your distribution's repository, or it can be downloaded from: http://www.joerg-pommnitz.de/TrueType/ttmkfdir.tar.gz. This is necessary!

As of Red Hat 7.1, the above commands are run from the xfs init script. So restarting xfs (/etc/rc.d/init.d/xfs restart) will accomplish the same thing for Red Hat users. Other distros may have similar shortcuts.

You should now have fonts.dir and fonts.scale files in your TrueType font directory. ttmkfdir is in the Freetype RPM for Red Hat users, and must be run before mkfontdir. With Debian based distros, there is a similar utility called mkttfdir, and is in the fttools Deb package. Though this apparently does not generate as many encodings as ttmkfdir. These commands may not always report errors, so verify that they were created and are not empty files:

 $ ls -l fonts.*
  -rw-r--r--  1 root   root    11657 Aug 17 10:31 fonts.dir
  -rw-r--r--  1 root   root    11657 Aug 17 10:31 fonts.scale
   

If you encounter any problems, try ttmkfdir with the - m switch. This will discard bad characters from the font file. Specify a number such as 50 or l00 (ttmkfdir -m 50). The files themselves are text files. Have a look:

 
 $ less  fonts.dir
  114
  webdings.ttf  -microsoft-Webdings-medium-r-normal--0-0-0-0-p-0-microsoft-symbol
  verdanaz.ttf  -microsoft-Verdana-bold-i-normal--0-0-0-0-p-0-ascii-0
  verdanaz.ttf  -microsoft-Verdana-bold-i-normal--0-0-0-0-p-0-fcd8859-15
  verdanaz.ttf  -microsoft-Verdana-bold-i-normal--0-0-0-0-p-0-iso8859-15
  verdanaz.ttf  -microsoft-Verdana-bold-i-normal--0-0-0-0-p-0-iso8859-9
  verdanaz.ttf  -microsoft-Verdana-bold-i-normal--0-0-0-0-p-0-iso8859-1
 [...]
   

If ttmkfdir is persistently giving problems by not generating a proper output file, there may be one or more "bad" fonts (ie fonts it can't handle). In that case, just start with a few common ones, like Arial and Verdana. If this works, then add a few at a time.

Now be sure the new fonts are included in the FontPath. And either restart X (Ctrl-Alt-BS), or the font server (if using one). You could also try refreshing the FontPath:

 # xset fp rehash
   

Red Hat 6.x/7.x users can update the FontPath and xfs:

 # chkfontpath --add /usr/local/share/fonts/ttfonts
 # /etc/rc.d/init.d/xfs restart
   

You should now be in business. You can check which fonts are available to X:

$ xlsfonts | less

or check them out further with xfontsel, or gfontsel. If they are visible to xlsfonts, then they are available to X and vice versa. If they are not there, try restarting X with Ctrl-Alt-BS.

This gets you as far as X knows about your new fonts. Individual applications will need to be configured to use them. GNOME and KDE will require additional steps as well (see the respective docs). You will also want to configure Xft (see below), if using XFree86 v4.x or later.

3.4. Font Servers

Historically, font servers were used to serve fonts over a network. Font resources could then reside on one host, and clients could access them as needed. But, the developers have enhanced these to include features such as the ability to render TrueType fonts. XFree86 4.x does have built in support for TrueType (see Section 4), making a font server not a necessity, though some distros default to using a font server for other reasons now.

XFree86 3.x does not come with built in TrueType support, so you'll have to add it yourself if you are using a 3.x version. This will mean installing a supplemental font server that does support TrueType. And, of course, installing the fonts themselves (see above). See the Appendix for font server installation, and related tips.

Any recent distro will have one or more font servers included, and the important configuration should be done by the installation program.

3.5. The fonts.alias File

fonts.alias is yet another font configuration file that can be used to tweak how fonts are handled. Like fonts.scale and fonts.dir, fonts.alias must be in the same directory as the fonts you are aliasing. It is not mandatory however, but does solve certain potential problems. Here is an example from the first line of/usr/X11R6/lib/X11/fonts/misc/fonts.alias on a Red Hat system:

 fixed    -misc-fixed-medium-r-semicondensed--13-120-75-75-c-60-iso8859-1
   

fixed is the 'alias' here. Any time this is requested, we actually get the font definition from the second column. Font too small? Just change the definition. (Warning: this is a critical file, at least on Red Hat.) The same principle applies to all fonts, including TrueType. In fact, if you don't have TrueType, you could conceivably use this trick to have a comparable Type 1, or other, font aliased as a TrueType.

fonts.alias is important for some applications that don't handle the data provided by fonts.scale well. Most notably here is Netscape. Without a fonts.alias you will find that Netscape will only show point sizes of 0 and 12 available. fonts.alias fixes this. You might also find that if you a specify another size with the scalable font option under Preferences, Netscape will not remember this setting. Annoying! This is also fixed. So we really need this file. Sample excerpt from a fonts.scale:

 
 arial.ttf   -monotype-Arial-medium-r-normal--0-0-0-0-p-0-ascii-0
 arial.ttf   -monotype-Arial-medium-r-normal--0-0-0-0-p-0-fcd8859-15
 arial.ttf   -monotype-Arial-medium-r-normal--0-0-0-0-p-0-iso8859-15
 arial.ttf   -monotype-Arial-medium-r-normal--0-0-0-0-p-0-iso8859-1
   

These are scalable so we don't get any predefined point sizes. We will need to create our fonts.alias something like this excerpt for Arial:


 -monotype-Arial-medium-r-normal--6-60-0-0-p-0-iso8859-1 \
             -monotype-Arial-medium-r-normal--9-90-75-75-p-0-iso8859-1

 -monotype-Arial-medium-r-normal--7-70-0-0-p-0-iso8859-1 \
             -monotype-Arial-medium-r-normal--9-90-75-75-p-0-iso8859-1

 -monotype-Arial-medium-r-normal--8-80-0-0-p-0-iso8859-1 \
             -monotype-Arial-medium-r-normal--10-100-75-75-p-0-iso8859-1

 -monotype-Arial-medium-r-normal--9-90-0-0-p-0-iso8859-1 \
             -monotype-Arial-medium-r-normal--11-110-75-75-p-0-iso8859-1

 -monotype-Arial-medium-r-normal--10-100-0-0-p-0-iso8859-1 \
             -monotype-Arial-medium-r-normal--12-120-75-75-p-0-iso8859-1

 -monotype-Arial-medium-r-normal--11-110-0-0-p-0-iso8859-1 \
             -monotype-Arial-medium-r-normal--12-120-75-75-p-0-iso8859-1

 -monotype-Arial-medium-r-normal--12-120-0-0-p-0-iso8859-1 \
             -monotype-Arial-medium-r-normal--12-120-75-75-p-0-iso8859-1

 -monotype-Arial-medium-r-normal--13-130-0-0-p-0-iso8859-1 \
             -monotype-Arial-medium-r-normal--13-130-75-75-p-0-iso8859-1

 -monotype-Arial-medium-r-normal--14-140-0-0-p-0-iso8859-1 \
             -monotype-Arial-medium-r-normal--14-140-75-75-p-0-iso8859-1

 -monotype-Arial-medium-r-normal--15-150-0-0-p-0-iso8859-1 \
             -monotype-Arial-medium-r-normal--15-150-75-75-p-0-iso8859-1

 -monotype-Arial-medium-r-normal--18-180-0-0-p-0-iso8859-1 \
            -monotype-Arial-medium-r-normal--18-180-75-75-p-0-iso8859-1

 -monotype-Arial-medium-r-normal--24-240-0-0-p-0-iso8859-1 \
            -monotype-Arial-medium-r-normal--24-240-75-75-p-0-iso8859-1

   

(Please note that I have split each line for readability. There should be two columns all on one line, without the "\", and separated by at least one space.) This will keep Netscape happy. Also, if font names should have embedded spaces, then you should enclose the filename in quotes. You might also note the pointsize discrepancy between the first and second columns of the first few rows. The first column of the first entry has a '6', whereas this is aliased to a '9' in the second column, and thus '9' point. This is by design and is an excellent way to overcome the Netscape 'damn tiny fonts' syndrome. Adjust to suit your tastes, resolution, and eyesight.

This file can be created manually with a text editor, or conceivably with some fancy sed or awk scripting. There is an excellent discussion of this file, and other font related topics at Kristin Aanestad's site at http://home.c2i.net/dark/linux.html. There is also a link to a python script which can reportedly automatically generate a fonts.alias file at this same site. A perl version of this script is re-printed in the Appendix. Thanks to Kristin whose work and insight was the inspiration for this section!

Another potential use of fonts.alias would be to map one font to something quite different. Say you don't have TrueType fonts, and didn't want to install Microsoft's. You could alias nice, scalable Type 1 fonts to a TrueType. That way when the system (or some web page) wants a TrueType, you'd get something of comparable quality instead of bitmap that doesn't scale well.

Note that with XFree86 4.0.2 and greater, there are new font handling mechanisms available via the Xft extensions. Font aliasing is done in Xft's own configuration file: XftConfig. This is the preferred method where anti-aliasing, and the other new rendering features are desired. See the Anti-aliasing Section for more on this and de-mystification. This is only true where the application (i.e. the toolkit, e.g QT) itself supports the new extensions! At this time, not all do (yet).