Running a Traditional Font
Server
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: xfstt This
package is a TrueType-only font serverthat is, it doesn't serve Type 1, BDF,
or any other font formats. It's a useful way to add TrueType support to older
systems running pre-4.0 versions of XFree86, and it can even be used as a network
font server if you only want to serve TrueType fonts. There is a major caveat,
though: If your network includes machines that use different byte orders
internally (such as x 86 and PowerPC systems),
you won't be able to share the server among them. This is because xfstt delivers fonts in a format that's
dependent upon the CPU's internal byte order. You can download it from href=" target="_blank">ftp://ftp.metalab.unc.edu/pub/Linux/X11/fonts/ ,
in the xfstt-1.1.tar.gz file
(this filename may change if the program is updated in the future). xfsft This
is a modified version of the standard XFree86 3.3.x
xfs package. The modifications
incorporate the FreeType (target="_blank">http://freetype.sourceforge.net/index2l )
TrueType renderer. The result is a font server that's capable of handling
TrueType as well as Type 1, BDF, and other font formats. These modifications
have been folded into the standard xfs
program with XFree86 4.0, so you may be able to use the standard program even
if you're running an older version of XFree86. If you prefer to use the pre-4.0
code, check the xfsft Web page
at http://www.dcs.ed.ac.uk/home/jec/programs/xfsft/ .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.NOTE

Both Windows and MacOS optionally implement a feature known
as font smoothing or anti-aliasing, in which some pixels are shaded
grey, rather than a complete black or white. The result is that fonts appear
to the human eye to have smoother outlines than they otherwise would. Some
people like this effect, but others dislike it. Some X programs implement
their own anti-aliasing, but most don't, and X didn't support it natively
until version 4.0.2. Support for this feature is still rare, and configuring
it requires taking some extra steps, which are documented at href="http://sdb.suse.de/en/sdb/html/chofman_ttf_72l" target="_blank">http://sdb.suse.de/en/sdb/html/chofman_ttf_72l
for SuSE Linux.
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"
NOTE

No Linux distribution ships with a font path like the
preceding one by default. These three entries illustrate the three major
forms that the FontPath
entries may take, though.
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 "href="http:// /JVXSL.asp?x=1&mode=section&sortKey=insertDate&sortOrder=desc&view=&xmlid=0-201-77423-2/ch15lev1sec3&open=true&title=New%20This%20Week&catid=&s=1&b=1&f=1&t=1&c=1&u=1#ch15lev2sec6#ch15lev2sec6"> 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, "href="http:// /?xmlid=0-201-77423-2/ch15lev1sec4#ch15lev1sec4"> 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: Make a second font server
instance available in addition to the first. If you follow this path, you can
modify your font server startup script or launch a second server in some other
way. You may need to use the -config /path/to/config/file
option to xfs to tell the second
server to use a different configuration file than the first. Modify the configuration of the font server so that the blocks
that prevent it from being accessed from outside are lifted. This may be the
more efficient option in many ways, but it may not be the best choice if you
want to make a different set of fonts available to clients than are available
locally.NOTE

You can run a font server even on a computer that doesn't
run X. Of course, you must install any packages on which the server depends,
which may include much of X, but you need not actually run an X server to run
a font server.
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: No listening for TCP connections
Red Hat 7.2 includes an option line in its /etc/X11/fs/config
file that prevents the server from listening for TCP connections. This line is no-listen = tcp . The server is otherwise
configured normally, and runs on port 7100. Therefore, commenting out this
line, shutting down the server, and starting it up again will make the server
available to any computer that connects to it on port 7100. Red Hat uses a SysV
startup script called xfs to start
and stop the server, so you can use that to shut it down and start it up again,
as described in href="http:// /?xmlid=0-201-77423-2/ch04#ch04"> Chapter 4 , Starting Servers. Port -1 Mandrake 8.1 configures
its font server to run on port 1, which is highly unusual and effectively
prevents outside connections. To change this configuration, you must edit the
startup script file ( /etc/rc.d/init.d/xfs )
so that the server starts on another port. Locate the line that begins daemon xfs -port -1 and change the port
number from -1 to 7100 , or to some other positive port
number. You must also edit your /etc/XF86Config
file (or, depending upon your X server, the XF86Config
or XF86Config-4 file in /etc/X11 ) to look for the font server on
its new port number. Locate the FontPath
line that refers to unix/:-1 and
change it to point to unix/:7100
(or whatever port number you used). You must then shut down and start up xfs and restart the X server (the Restart
X Server button on the default Mandrake login screen can do this).WARNING

Reconfiguring a font server for a system that is currently
running X can be tricky. If the font server becomes unavailable, running programs
may hang for lack of access to fonts. It's therefore best to reconfigure the
font server using text-mode programs from a text-mode login. The SysV scripts
for xfs used by both Red Hat
and Mandrake do not implement your changes if
you pass them the restart
option, so you must explicitly send them the stop
option and then start them anew with start .
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.WARNING

If you configure a computer to only
use an external font server, that system's X installation will become
unusable should the font server become unavailable. It's generally best to
leave a distribution's default font installation untouched, and add a font
server to the existing font path. (You might want to trim fonts from some
distributions, though; some come with a huge number of fonts that you may not
like. You should leave the core X fonts intact, though.)
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 Internetfor 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.NOTE

Type 1 fonts come in a multi-file format. The Printer Font
Binary (PFB) file contains most of the font data, and is the filename you
normally list in the fonts.dir
file. Alternatively, you may list a Printer Font ASCII (PFA) file, which
contains the same data but in a slightly different format. Additional
filenames may end in .pfm , .afb , .afm ,
and others. Other utilities may use these files, but they aren't strictly
necessary for the font server itself.
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: -bitstream-charter-medium-r-normal--0-0-0-0-p-0-iso8859-1
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 0
values, which denote that the font is scaleable); spacing, namely monospaced or
proportional ( p ); average width
(again, 0 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.NOTE

An X font server, like the underlying tools in many other
font-handling systems, may use several font files for a complete font family.
For instance, you may want to use Times in a word processing document, and
apply italic, bold, or other styles to this font. In a full font
installation, these variants are actually different fonts, derived from separate
font files, each with its own XLFD entry in the appropriate fonts.dir file. Many word processors and
other programs can derive an approximation of bold, italic, and similar
attributes, but using customized files almost always produces noticeably better
results, especially for italics.
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: # type1inst
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.WARNING

Used as described, both type1inst and ttmkfdir overwrite any existing fonts.dir file. If
you've added fonts to a directory, you may want to back up the existing file
so you can restore it or use only the new entries from the new file. As
already mentioned, you may need to edit the automatically created file, and
if such edits have been done in the current file, you probably don't want to
lose them.
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.