Traditional X Font Configuration

Traditionally, X applications ask the X server to display text in a font that's specified using an X Logical Font Descriptor (XLFD), a rather lengthy string that describes the font. In order to do this, X must know which XLFDs are associated with which font files. Therefore, installing a font is essentially a matter of linking these two pieces of data. You must set up a font directory with a mapping file and tell X about these directories.

Note The upcoming section, "Serving Fonts to Many Computers" describes another way to serve fonts using the traditional X font display mechanism. The upcoming section, "Using Font Smoothing" describes alternative font-display techniques that are being used by an increasing number of programs.

Setting Up a Font Directory

Fonts reside in one of a handful of directories on a Linux computer. Traditionally, they are subdirectories of/usr/X11 R6/lib/X11/fonts/, but if you're installing your own fonts, you may want to use another directory, such as /usr/local/fonts. Copy your font files to this directory or subdirectories of it, such as /usr/local/fonts/tt for TrueType fonts. This is the easy part of the font installation task. Once you've done this, you need to create a file called fonts.dir. This file associates font files to XLFDs. It starts with a line that specifies the number of fonts mapped by the file. Each subsequent line is a font filename followed by an XLFD; for instance:

cour.pfa -adobe-courier-medium-r-normal-0-0-0-0-m-0-iso8859-1

Note Many tools create both fonts.dir and fonts.scale files. Both files have the same format, and the contents will be identical for a directory that contains only outline fonts. The fonts.dir file describes all the fonts in a directory and is the most important file; fonts.scale describes only outline fonts, not bitmap fonts.

This line specifies that the XLFD is to be tied to the cour.pfa font file. Because the XLFD is rather long and includes some repetitive sequences, typing it in manually would be tedious at best. Instead, you can create fonts.dir using special tools. These tools are listed here:

typelinst This program may or may not be installed by default. If not, look for it in a package called font-tools, typelinst, or something similar. You may need to track the package down using RPM Find (http://www.rpmfind.net). Once installed, change into the directory holding your Type 1 fonts and type typelinst. The program creates both a fonts.dir and a fonts.scale file summarizing the fonts it found in that directory.

ttmkfdir This program is the TrueType equivalent of typelinst. It may be available in a package called ttmkfdir, freetype-tools, or something similar. The program is more frequently installed than is typelinst. You use it in a similar way, but ttmkfdir sends its output to stdout by default, so you must redirect it by typing ttmkfdir > fonts.dir if you want to create a fonts.dir file directly. This program occasionally omits fonts from its output if they lack certain characters. You can force the program to include these fonts by adding the -c parameter.

mkfontscale This program is a relative newcomer; it ships with Xfree86 4.3 and later. It does more-or-less what the combination of typel inst and ttmkfdir do—it creates a fonts.scale file that contains information on both Type 1 and TrueType fonts within a directory. You can then copy this file to fonts.dir or, if you prefer or if the directory also includes bitmap fonts, type mkfontdirto combine information on the outline and bitmap fonts in the directory into a fonts.dir file.

All of these tools are helpful, but none is without its flaws. You may want to examine the output files to be sure they include entries for all the fonts in the directory. If not, you may be able to copy an entry for another font and change the font name, weight (medium, bold, light, and so on), slant (r for Roman, i for italic, o for oblique, and so on), or other relevant features. Sometimes you'll find that different styles of the same font vary in important ways—for instance, one may have a typo in the name, or the font foundry may not match. Such problems can prevent you from using styles in word processors or the like. It's possible that the output will include more than one entry per font file. For instance, you may find several encodings for each font. These are the strings near the end of the XLFD, such as iso8859-1, which denote what characters are available in the font. Such duplication isn't normally a problem, but it can make the fonts.dir file much longer than it might otherwise be. Sometimes mkfontscale does a much better or worse job with particular fonts than do typel inst or ttmkfdir, so if you have problems with one tool, you may want to try another.

Setting X's Font Path

Once you've set up a font directory, you must add the directory to X's font path. With Mandrake and Red Hat, you do this by altering a font server's configuration, as described in the next section, "Serving Fonts to Many Computers." With Debian, Slackware, or SuSE, you edit the font path directly in the XF86Config file. Locate the Files section. It should contain a series of lines like this:

FontPath 7usr/X11 R6/lib/X11/fonts/Type 1"

Note Some Debian systems, as well as some custom configurations for other distributions, use both font directories and font servers.

The FontPath line indicates that the specified directory is part of the font path—X will check that directory for a fonts.dir file when it starts up, and deliver the fonts specified in that file to applications. To add your new font directory to the X font path, you can add a similar line pointing to your directory. X searches the font paths in order, so if a font appears in two directories, X uses the one from the earlier font path. If a directory doesn't exist, it's automatically removed from the font path. As a general rule, bitmap font directories appear first in the font path, with :unscaled added to the directory name. This string indicates that X is to use fonts in the directory only at their specified sizes, without attempting to scale them. Next up are outline fonts. The bitmap font directories often appear again at the end of the list, but without the :unscaled addendum. This placement allows X to scale a bitmapped font only as a last resort.

Once you've added your new font directory to XF86Config, you can tell X to begin using the changed font path by typing the following commands in an xterm:

$ xset fp rehash

The first of these commands appends the new diectory to the font path dynamically, without restarting X. The second command tells X to rescan its font path, adding fonts as necessary.

Warning If you make a mistake, typing xset fp rehash can cause X to misbehave.

Typically, programs will hang or refuse to launch. Therefore, I recommend you type this command only after saving work in all your open applications. If you run into serious problems, you may have to terminate X by pressing Ctrl+Alt+Backspace.

0 0

Post a comment