In this chapter, I use the term traditional font server to refer to a font server like the xfs program that ships with XFree86, or programs that work much like it. These programs deliver bitmapped fonts to X, based on either bitmapped or outline font files, using the standard font server protocols. These font servers are designed to support font display on monitors ; they provide few or no features that help the computer coordinate on-screen fonts with those that will be printed for programs like word processors. Because XFree86 ships with xfs , chances are you already have such a font server, even if it's not currently running on your system. Configuring this server to run requires editing a few configuration files. If it's already running, you can reconfigure it to run in such a way that X servers running on other computers can access it.
Font Server Options for Linux
The most common font server in Linux is the xfs program that ships with XFree86. In some sense, this program is nothing but the font-handling code from X removed from X proper, and combined with some networking code to run as a server. This server normally resides in /usr/X11R6/bin , and is usually installed from a package called XFree86-xfs or xfs .
If you're running a version of XFree86 prior to 4.0, you may be interested in obtaining an updated font server that can handle TrueType fonts. Two such servers are available:
These two packages implement two different TrueType font renderers, which in turn are different from the ones used by Apple and Microsoft in their OSs. The result is that the same font may look quite different when displayed at the same resolution and size , depending upon the OS and (if applicable ) font server you use. Both xfstt and xfsft do a good job with most fonts, but if you have problems with some fonts or if you're not satisfied with the rendering quality, you may want to investigate alternative font servers.
Although a few details differ , traditional Linux font servers are configured in largely the same way. Fonts must be placed in one or more directories, and configuration overview files listing the fonts in those directories must be created. The font server is then configured to examine those directories and make available the fonts pointed to by the directories' configuration files. The next two sections describe this process for xfs or xfsft , but xfstt 's configuration isn't greatly different.
Common Default Font Server Configurations
When you install Linux and XFree86, the system creates a default XFree86 configuration file called XF86Config , which resides in /etc or /etc/X11 . As noted earlier, this file contains a number of FontPath entries that point to directories on your computer or font servers. For instance, you might see something like the following in the XF86Config file:
FontPath "/usr/X11R6/lib/fonts/Type1/" FontPath "unix/:7100" FontPath "tcp/zapf:7100"
The first of these FontPath lines illustrates the use of local fonts, without the involvement of a font server. Most Linux distributions place their fonts in several directories, so when a distribution uses fonts directly in this way, there will be several FontPath lines, each listing one directory. The system searches each directory in turn when told to look for a font of a specified name , until it's located or the path is exhausted.
The second line illustrates the use of a font server run on the local computer. The unix specifier indicates that the server is running using the UNIX domain sockets system, which permits network-like connections on the local computer. The final number ( 7100 ) is the port on which the server listens for connections. If you see such a line in your system, chances are there are few or no lines that point directly to font directories. You may adjust the configuration to add your own fonts, as described shortly in "Adjusting Font Availability."
The third line shows a network font server. The tcp in the specification indicates that this server uses standard TCP/IP networking. The name following the slash ( / ), zapf in this case, is the name of the font server computer. (This example lists only the machine name, not the full name. It could as easily be a full name, such as zapf.threeroomco.com .) The trailing number ( 7100 ) is the server's port number.
Font servers conventionally use port 7100, both for local servers and for full TCP/IP font servers. (A few distributions use the unusual port number of “1 for local-only connections.) This convention sometimes causes conflicts, though, because a font server other than the one you're configuring may decide to occupy port 7100. This might happen if you run a program that starts an expanded font server, such as those discussed in the upcoming section, "Running an Expanded Font Server," for its own use. In such situations, you can try another port, such as 7101 or 7102.
Font servers require configuration files. The official default location is /etc/X11/fs/conf , but many distributions use the name config rather than conf . These files specify the locations of font files and a few details of how the server operates, as discussed shortly. Font servers are normally started in SysV startup scripts, although if you add one to a system that doesn't start a font server by default, you might do so through a local startup file. The SysV files included with some distributions, such as Red Hat, carefully check the font directories to see if their font lists need to be updated. If they do, these scripts perform these updates automatically. This can make adding fonts easy, because you can simply drop the new fonts into an appropriate directory and restart the font server. On the other hand, if the utilities used to automatically generate the appropriate configuration files don't work well with a font you want to use, you may need to disable this autoconfiguration feature, at least for one font directory, so that you can create a manual configuration that works better.
Adjusting a Font Server for a LAN
Most distributions that start a font server automatically take steps to ensure that it's not readily accessible from other computers. This is done as a security precaution to limit the potential for damage in case the font server has a security problem that could be exploited by outsiders. Therefore, if you want to make your font server available to other computers, you must do one of two things:
There are two main ways that distributions restrict access to a font server that runs by default. Each of these methods requires a different procedure for enabling outside access to the font server:
After adjusting the font server to deliver fonts on your network, you should be able to point other systems' X servers at the one you've reconfigured. You can do so by adding a FontPath entry to the computers' XF86Config files. This entry should resemble the tcp example shown earlier, but of course point to your font server computer and use its port number. Depending upon what fonts are installed on each computer, you may be able to remove some FontPath entries from the client systems, but this may increase the load on the font server. To minimize the load on the font server, add its entry after all other FontPath entries on the clients. This will cause the clients to use their own local fonts whenever possible.
You should be concerned about the security of your font server. If you're on an isolated LAN without Internet connectivity, this may not be a major concern, but running a font server on a computer that's exposed to the Internet can be a security risk, albeit a modest one. Font servers are typically not very complex, and they don't require passwords, so you won't run into password security issues with them. Like all servers, though, font servers can potentially be buggy , and it's conceivable that some future font server bug will lead to the potential to compromise the server computer. For this reason, I recommend running font servers for other computers only on networks that are at least somewhat isolated from the Internet ”for instance, on a subnet that's protected by a dedicated firewall computer. This dedicated firewall should block access to your font server's port from external computers. You should also seriously consider configuring iptables to block access to this port from anything but known local computers, as described in Chapter 25, Configuring iptables.
Adjusting Font Availability
Much of the point of running a font server is to make it comparatively easy to adjust the font configuration for an entire network of Linux or UNIX computers. (X servers for Windows, MacOS, and other OSs can also sometimes use remote font servers, so you can provide a consistent set of fonts even for X servers in these OSs, as well.) There are two steps to adjusting the fonts made available through a font server: adjusting the font server's font path (which is distinct from the X server's font path), and adding or removing fonts from the individual directories in the font path.
Changing a Font Server's Font Path
The font server's font path is set in the server's configuration file (typically /etc/X11/fs/config or /etc/X11/fs/conf ). The font path isn't set using FontPath keywords, as in XF86Config ; instead, this file uses the catalogue keyword, thus:
catalogue = /usr/X11R6/lib/X11/fonts/75dpi:unscaled, /usr/X11R6/lib/X11/fonts/Type1, /usr/X11R6/lib/X11/fonts/TrueType, /usr/X11R6/lib/X11/fonts/75dpi
This listing may span multiple lines. Commas separate directories in the font path. The last entry lacks a trailing comma; this signals the end of the list. If a directory is followed by the string :unscaled , this indicates that bitmapped fonts in this directory are to be served only if their sizes match the requested sizes exactly. If this string is omitted, the font server scales a bitmapped font (usually quite poorly) to match a request, if the name matches but the size doesn't. (This convention is also used in the XF86Config font path specification.) Thus, in the preceding example, the font server uses bitmap fonts from the 75dpi directory that exactly match the size of a requested font. If such a match isn't made, the system tries to find a match in the Type1 and TrueType directories, before going back to 75dpi to provide a scaled bitmap font as a last resort.
You can add or delete entire font directories by modifying this list. You might want to add a directory containing fonts you've collected from assorted sources, or a directory with fonts from a font CD-ROM. Some distributions ship with directories filled with distribution-specific fonts. If you don't want to serve these, you can eliminate them from the list. (Be sure to remove the comma from the last directory in the new list, though, if you remove the original final item.)
Adding Fonts to a Font Directory
The tricky part of X font server configuration is setting up the font directory configuration files. These files are called fonts.dir , and their format is deceptively simple looking in summary:
number font-filename1 XLFD1 font-filename2 XLFD2 ...
The first line contains a number that specifies how many fonts the file describes. Each subsequent line describes one of these fonts. Each of these lines begins with a font filename, such as goodfont.ttf or t1f32.pfb . The specified font file must exist in that directory.
The rest of the line is consumed by an X Logical Font Descriptor (XLFD), which is a string that describes the font. An example looks like this:
This string consists of a series of fields, separated by dashes ( - ). Information in these fields is the font foundry ( bitstream ); the font family name ( charter ); the font's weight, such as light, medium, or bold ( medium ); the slant, such as regular or italic ( r ); the width ( normal ); an additional style name (unused here); assorted size information (the string of values, which denote that the font is scaleable); spacing, namely monospaced or proportional ( p ); average width (again, for a scaleable font); and the encoding ( iso8859-1 ).
The XLFD can be tricky to set up manually, because it contains a lot of unlabelled information that tends to blur together in the human eye. A single typo can render the font unusable. Fortunately, there are programs that can help you create an XLFD for a font, or even a complete fonts.dir file for an entire directory.
The utility to create a fonts.dir file from a directory of Type 1 fonts is called type1inst . This utility ships with many Linux distributions, but it's usually not installed by default. Once you've installed the program, you can change into a directory with Type 1 fonts and run the program, thus:
The program will look through your font files, extract font names and other XLFD information, and create a fonts.dir file based on this information. It will also report to you on its progress and give a summary of its actions. For instance, it may tell you that it created 21 entries in fonts.dir , one of which was for a font for which it couldn't determine the foundry. You may want to edit the fonts.dir file that type1inst creates to smooth over any inconsistencies, such as fonts in the same family that list different foundries. X uses the information in fonts.dir and ignores the information that's embedded in the fonts, so changing such details will not cause problems for X. Indeed, leaving inconsistencies intact can cause problems, such as an inability to obtain a variant of a font when you select it because the foundry information doesn't match.
A similar program exists for TrueType fonts. This program is known as ttmkfdir , and is part of the FreeType library used by xfsft and XFree86 4.0. It works much like typelinst , but you must specify the output filename with the -o parameter. Also, ttmkfdir often omits fonts that are useable but that lack some characters . You can force inclusion of such fonts with the -c parameter. In sum, you can use this program by changing into a directory that contains TrueType fonts and issuing the following command:
# ttmkfdir -c -o fonts.dir
If you find that some fonts are causing problems, you can try this without the -c option. This may create a shorter list of fonts, but the fonts on the list will be more likely to work.
Once you've changed your fonts.dir file, you must restart the font server, as described earlier. You should then either restart all the X servers that use the font server or issue the following command to have the X servers refresh their lists of available fonts:
# xset fp rehash
If you fail to do this, your X servers won't make new fonts available. If you deleted fonts and if users try to use them, the X server may appear to hang as it tries to retrieve the font, so this step is very important if you delete fonts.