Section B.5. Font Handling

B.5. Font Handling

A perennial thorn in the side of Linux desktop use is font handling. In the past, X programs relied exclusively on X's font features (the X core fonts, as they're now known), which were primitive compared to those of Windows or Mac OS. Since 2000, new font tools have appeared (namely, Xft fonts), and they are now used by many of the most popular X-based Linux programs. Although the new systems are easier to use and present fonts that most users find more visually appealing, they add complexity to the overall Linux font-handling system. Thus, you must understand both these font systems. Many programs also provide their own font-handling tools, although most are converging on Xft. Of those that have not yet adopted Xft, (and its commercial twin, StarOffice) is the most important.

B.5.1. Linux Font-Handling Systems

Linux provides two major GUI font-handling systems: X core fonts and Xft fonts. In addition, individual X-based programs sometimes employ their own font-handling systems. This profusion of font-rendering tools can lead to some confusion if you're not aware of the differences between these systems, each of which has its own unique quirks.

The oldest X font-handling system is the X core fonts system. X core fonts are server-side fonts, meaning that the X server (the system at which the user sits, in most cases) handles the fonts. X clients (that is, X programs) tell the X server what font to display and at what size, and the X server does the rest.

X core fonts were originally designed with bitmap fonts in mind, meaning that individual characters were designed for display at a specific size in pixels. To support scaleable fonts, which can be resized, multiple bitmap font files are required, one for each size. X servers, including the XFree86 and Xorg-X11 X servers for Linux, ship with several bitmap fonts in a variety of sizes, designed for both 72 dots per inch (dpi) and 100-dpi displays. Most modern fonts, though, use scaleable font (a.k.a. outline font) technologies, in which the font is described in terms of mathematical descriptions of lines and curves. These descriptions provide an outline of a character, which the font renderer can scale to any desired resolution and fill in. The two most common scaleable font formats today are PostScript Type 1 (a.k.a. Adobe Type Manager or ATM) fonts and TrueType fonts. XFree86 has supported both formats since Version 4.0 (before that, it didn't support TrueType fonts), and Xorg-X11 also supports both formats.

Because X core fonts are server-side, relatively little data needs to be transferred between the client and server to display text. This feature can be helpful for remote logins but isn't very important for typical desktop operations.

Some Linux distributions implement X core fonts via a font server, which is a server designed to deliver bitmap font data to X servers. X ships with a font server, xfs, which can deliver bitmap font data from bitmap font files or generated from Type 1 or TrueType fonts. This topic is described in more detail shortly, in Section B.5.2.3.

The X core font system was designed years ago, and in the intervening years, font technology has progressed. X core fonts were readily adapted to some new technologies, such as scaleable fonts, but basic limitations in X core fonts have presented more of a challenge. One of these problems has been the fact that X core fonts can't readily handle more than two colors per font (such as black for the foreground and white for the background). This limitation means that a new font technology known as font smoothing or anti-aliasing was slow to come to Linux. Font smoothing uses shades of gray to deliberately blur fonts. Counter-intuitively, this has the subjective effect of improving the appearance of fonts, because it tends to hide the jagged edges along diagonal lines and curves. Not everybody cares for this effect, but many people do, and font smoothing is a standard part of Windows and Mac OS. Another problem with the X core fonts system has been that installing fonts can be tricky, as described in the next section. Finally, X core fonts were not designed with printing in mind, and coordinating the display and print fonts can be a challenge when using these fonts.

The solution to these problems with X core fonts is the Xft font system. Unlike the X core fonts, Xft fonts are client-side, meaning that they're installed on the same computer as the programs that call them. This fact means that more data may need to be transferred over the network when they're used, but if a program relies on particular fonts, it's easier to guarantee that they'll be available because the user's server configuration is irrelevant. Xft was designed around the FreeType library, which was originally a tool for rendering TrueType fonts. Today, though, Xft supports both TrueType and Type 1 fonts. Xft fonts also support font smoothing, although this feature can be shut off. Xft fonts provide a few more hooks to help with printing, although screen/printer font coordination in Linux has improved more because of extra libraries than because of Xft. Installing Xft fonts is easier than installing X core fonts, as well. However, configuring these fonts requires changing yet another system. In the short term, this has caused increased problems because administrators must manage both X core fonts and Xft fonts. In the long term, Xft fonts are likely to increase in importance, and X core fonts may become so unimportant that their configuration will be trivial. In fact, this may have already happened for some environments. The GNOME and KDE projects have both embraced Xft fonts, as have many other programs, so it's possible you'll see very few or no X core fonts in use on some systems.

In addition to X core fonts and Xft fonts, some individual programs handle their own fonts. Traditionally, word processing programs have done this; however, many Linux word processors have now switched to Xft. A few, though, such as and its commercial twin StarOffice, continue to require their own font configuration.

B.5.2. Installing X Core Fonts

Installing X core fonts requires placing font files in directories of your choosing, creating or modifying files in that directory to describe the fonts, and pointing the X server to the fonts. These tasks must be done on the X server computer, so if you use X terminals (as described in Chapter 12), you may need to make these changes on many systems. One way to simplify this task, particularly for a large network, is to use a font server, which places most of the administrative burden on one computer. Some Linux distributions, such as Fedora, Mandrake, and Red Hat, use font servers locally, so you may need to deal with font server configuration even for standalone desktop systems.

B.5.2.1 Preparing font directories

The first task in X core font configuration is to install the fonts. Part of this task is fairly obvious: you copy font files from some source, such as a commercial font CD-ROM or an Internet font download site, to a directory of your choice. For locally installed fonts, /usr/local/fonts or a subdirectory of that directory is a logical choice. Linux systems usually install their default fonts in /usr/share/fonts, although older distributions used /usr/X11R6/lib/X11/fonts or other locations.

Once the font files are installed, you must create a configuration file that describes the fonts. This file is called fonts.dir and resides in the same directory as the fonts themselves. Its first line contains nothing but a number that denotes the number of fonts described in the configuration file. Subsequent lines have a format that looks deceptively simple:

filename.ext  XLFD

The filename.ext is the font filename. For TrueType fonts, this ends in .ttf; for Type 1 fonts, it's either .pfa or .pfb. Various bitmap font formats exist, each with its own extension.

The tricky part of the fonts.dir file is the XLFD field, which describes an X Logical Font Descriptor (XLFD). The XLFD consists of multiple fields of its own, separated by dashes (-). These fields contain the name of the font creator, the name of the font, the weight of the font, a code for its slant, numbers relating to its size, and so on. Even if you understand every field, XLFDs can be difficult to read because the fields tend to blur together in the eye. An example of a complete fonts.dir entry looks like this:

couri.pfa -ibm-courier-medium-i-normal--0-0-0-0-m-0-iso8859-1

As a practical matter, it's usually best to create the fonts.dir file with a helper program. Several such programs exist, each with its own unique qualities:


This program may not be installed in your distribution, although most distributions do provide it under the package name type1inst or font-tools. Once it's installed, type type1inst in the directory that holds Type 1 fonts. You should see a fonts.dir file appear, along with fonts.scale (which is similar to fonts.dir, but describes only scaleable fonts). This program isn't useful for handling TrueType fonts.


This program is essentially a TrueType counterpart to type1inst. It's usually delivered in a package called ttmkfdir or freetype-tools. It sends its output to stdout by default, so you must redirect it, as in ttmkfdir > fonts.dir.


This program ships with Xorg-X11 and XFree86 4.3 and later. It creates a fonts.scale file that describes both TrueType and Type 1 fonts. To create a fonts.dir file, you must type mkfontscale and then either copy this file to fonts.dir or type mkfontdir. This program creates a fonts.dir file from the contents of fonts.scale and information on any bitmap fonts in the directory.

As a general rule, I recommend creating separate directories for each font type you useType 1, TrueType, and bitmap or more exotic font formats you install. This practice gives you greater flexibility in the use of programs that generate fonts.dir files.

B.5.2.2 Setting the X font path

Once you've installed font files, you can move on to editing the X server's configuration file: /etc/X11/XF86Config or /etc/X11/xorg.conf. (This file sometimes appears in /etc rather than /etc/X11.) The XF86Config file controls the XFree86 server, which most distributions abandoned in 2004 because of a licensing change with Version 4.4.0. The xorg.conf file controls Xorg-X11, which is based on the last version of XFree86 prior to the license change, so the two servers are nearly identical, at least as of XFree86 4.4.0 and Xorg-X11 6.7.0 (the first formal release version). Likewise, their configuration files are virtually identical. One important difference, though, is that their default font directories are different.

X looks for fonts in directories in the Files section of XF86Config or xorg.conf. Specifically, the configuration file holds a series of lines that begin with the keyword FontPath, and each line contains a path or other reference in quotes:

FontPath "/usr/share/fonts/75dpi/:unscaled" FontPath "/usr/share/fonts/misc/" FontPath "/usr/share/fonts/Type1/" FontPath "/usr/share/fonts/TTF/" FontPath "/usr/share/fonts/75dpi/" FontPath "tcp/gutenberg:7100" FontPath "unix/:-1"

Most of the entries in this example point to subdirectories of /usr/share/fonts, which is the default location for fonts in Xorg-X11. In an XF86Config file, this location is more likely /usr/X11R6/lib/X11/fonts. In any event, two broad classes of entries may be present:

Local font directories

Entries that look like font directory names are just that. X looks in these directories for font configuration files (described shortly) and displays the fonts they contain when programs ask for them. The first entry in the preceding example deserves elaboration, though: the :unscaled code tells X to deliver bitmap fonts from this directory only if they can be delivered at precisely the requested size. For instance, if a program asks for Times at 10 points, and if the directory holds Times at 9 points and 12 points but not at 10 points, X doesn't display Times from this directory. The idea is that a subsequent directory is likely to hold the font at the precisely requested size or in a scaleable form. Later in this list, the same directory appears without the :unscaled qualifier, so if all the other possibilities don't match the font, X delivers a font bitmap that's been scaled from another bitmap. The result is likely to look quite ugly, but it's better than not delivering a font at all.

Font servers

The last two examples from the preceding example are font servers. The first of these specifications (tcp/gutenberg:7100) tells X to use a remote computer (gutenberg) via TCP/IP on port 7100. The second entry (unix/:-1) tells the system to use Unix domain sockets to connect to a local font server on port -1. Distributions that use local fonts servers are likely to have XF86Config or xorg.conf files that refer exclusively to such a local font server; they may not refer directly to any font directories.

If your X configuration file refers only to a local font server, you can either add your new font directories directly to the X configuration file or modify your X font server configuration. The latter is likely to be less confusing in the long run because your true font path will be accessible from a single location.

B.5.2.3 Configuring a font server

If your distribution uses a font server, you might want to modify its configuration rather than the main X configuration file. The standard location for an xfs configuration file is /etc/X11/fs/config. This file contains several lines that set various options, such as whether to bind to TCP ports (which is required for access by other computers). The lines that adjust the font path, though, begin with the keyword catalogue:

catalogue = /usr/share/fonts/75dpi/:unscaled,             /usr/share/fonts/misc/,             /usr/share/fonts/Type1/,             /usr/share/fonts/TTF/,             /usr/share/fonts/75dpi/

This example sets the font path identically to the one described earlier, except that it refers to no other font servers. (You should point X servers directly at font servers; don't try to point font servers at other font servers.) The rules for :unscaled references are identical, but the format of the font path is different. In the /etc/X11/fs/config file, the font path is a comma-delimited list that may span multiple lines; the last entry does not end in a comma. Although the entries are often split across lines, they need not be; you can present a single very long font path on one line. Quotes are not placed around individual entries.

Both the main X server and font servers require the same configuration in the font directoriesnamely a fonts.dir file that describes the font files.

Once you change this configuration, you must restart your X font server. Typically, you can do this by using a SysV startup script:

# /etc/init.d/xfs restart

The system should shut down and restart the font server, but the fonts won't yet be accessible. To use them, you must tell X to reexamine its font path.

B.5.2.4 Using the fonts

After you change your X font configuration (either via the X server's main configuration file or a font server), you must tell X to use the new fonts. If you've edited your X configuration file, the safest way to do this and to be sure you've made no errors is to shut down X and restart it. On most distributions, logging out of a GUI login will do this job. If you don't want to completely restart X, though, you can type the following commands:

$ xset fp+  /new/font/path $ xset fp rehash

The first of these commands adds a directory to your font path. Be sure to type this directory exactly as you entered it on the FontPath line in your X configuration file. One problem with this approach is that it adds the new font directory to the end of the font path, which may not be where you added it. Thus, results might not exactly match what you'll get when you restart X, particularly if there's overlap in font names.

The second line tells X to reexamine the fonts in its font path, effectively adding the new fonts to the list of available fonts. You should type this command without the previous one if you've modified your X font server configuration and want to use the new fonts that it's now offering.

Modifying the font path while X is running is potentially risky. If you make a mistake, critical fonts might disappear. This can cause programs to hang. In extreme cases, X might crash. Save your work before making such changes and be prepared to log in using some other means (a text-mode console login, SSH from another system, or what have you) to correct any problems that might develop.

B.5.3. Installing Xft Fonts

Compared to installing X core fonts, installing Xft fonts is relatively straightforward. Xft 2.0 and later use a configuration file called /etc/fonts/fonts.conf to control themselves. You shouldn't directly edit this file, however; it can be overwritten in a package upgrade. Instead, Xft sets aside /etc/fonts/local.conf for local changes. To add a font directory to the Xft font path, place this line just above the </fontconfig> line:


Versions of Xft prior to 2.0 used another configuration file, /etc/X11/XftConfig, to control their overall operation. This configuration file is very different from the Xft 2.0 configuration file described here.

This line tells Xft to look in the /usr/local/fonts directory and all its subdirectories for font files. In fact, because Xft looks in subdirectories of the specified font directories means that you may not even need to modify the Xft configuration file at all: simply place your font files in a subdirectory of a directory that's specified in /etc/fonts/fonts.conf. Most Xft configurations list /usr/share/fonts as a directory, so placing new fonts in a subdirectory of that directory should work. Furthermore, most Xft configurations list ~/.fonts as a font directory, meaning that individual users can install fonts themselves by placing them in this directory.

Once the font directories are set, and fonts are placed in them, users can begin using fonts immediately; there's no need to restart X or issue any special commands. There is a modest benefit to using one command, though: fc-cache. If you've installed new fonts in a particular directory, type this command:

# fc-cache  /path/to/fonts 

The fc-cache command is the main interface to FontConfig, which is responsible for configuring Xft fonts. This command creates a font index file (fonts.cache-1) that's conceptually similar to the X core fonts' fonts.dir. Unlike X core fonts, though, Xft enables users to maintain their own font index files, and if Xft detects that directories on the font path have been updated more recently than their matching index files, FontConfig runs fc-cache in a way that updates users' individual font configuration files (~/.fonts.cache-1). Thus, if you fail to perform this step, users can still access new fonts; however, they may experience slight delays when starting new applications soon after you add fonts, as fc-cache does its job.

B.5.4. Installing Fonts in supports its own font-rendering system. As a result, fonts you install as X core fonts or Xft fonts won't appear as options in the menus, at least as of 1.1.2. (Future versions might switch to supporting Xft.) is the open source twin of StarOffice. These two programs are virtually identical, and both work the same way in terms of font configuration. provides a printer and font administration tool in which you can adjust the program's printer list and install or remove fonts. To do the latter, follow these steps:

  1. In a command-prompt window, type oopadmin to launch the program. A window entitled Printer Administration should appear.

  2. Click the Fonts button. A Fonts dialog box should appear, as shown in Figure B-2.

    Figure B-2. provides a GUI tool that adds or deletes fonts

  3. Click Add in the Fonts dialog box to add new fonts. A dialog box entitled Add Fonts should appear, as shown in Figure B-3.

    Figure B-3.'s Add Fonts dialog box lets you locate and select fonts

  4. Type a path to your fonts in the "Source directory" field or click the "..." button to select a directory using a file selector. If you type the path, wait a few seconds after you finish the path. The system should then populate the top field in the Add Fonts dialog box with font names and filenames.

  5. Select any and all fonts you want to add by clicking their names in the Add Fonts dialog box.

  6. Click Add in the Add Fonts dialog box. The system should respond with a report on the number of fonts it added.

  7. Click Close in the Fonts dialog box, followed by Close in the Printer Administration dialog box.

You can perform these steps as either root or as an ordinary user. If the former, the fonts are installed in the main directory; if the latter, they're installed in the user's home directory.

    Linux in a Windows World
    Linux in a Windows World
    ISBN: 0596007582
    EAN: 2147483647
    Year: 2005
    Pages: 152

    Similar book on Amazon © 2008-2017.
    If you may any questions please contact us: