Fonts in X11R6.8 : Installing fonts
Previous: Introduction
Next: Fonts included with X11R6.8

2. Installing fonts

This section explains how to configure both Xft and the core fonts system to access newly-installed fonts.

2.1. Configuring Xft

Xft has no configuration mechanism itself, rather it relies upon the fontconfig library to configure and customize fonts. That library is not specific to X11R6.8 or indeed on any particular font output mechanism. This discussion describes how fontconfig, rather than Xft, works.

2.1.1. Installing fonts in Xft

Fontconfig looks for fonts in a set of well-known directories that include all of X11R6.8's standard font directories (`/usr/X11R6/lib/X11/lib/fonts/*') by default) as well as a directory called `.fonts/' in the user's home directory. Installing a font for use by Xft applications is as simple as copying a font file into one of these directories.

$ cp lucbr.ttf ~/.fonts/
Fontconfig will notice the new font at the next opportunity and rebuild its list of fonts. If you want to trigger this update from the command line (for example in order to globally update the system-wide Fontconfig information), you may run the command `fc-cache'.
$ fc-cache

2.1.2. Fine-tuning Xft

Fontconfig's behaviour is controlled by a set of configuration files: a system-wide configuration file, `/etc/fonts/fonts.conf', and a user-specific file called `.fonts.conf' in the user's home directory (this can be overridden with the `FONTCONFIG_FILE' environment variable).

Every Fontconfig configuration file must start with the following boilerplate:

<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
In addition, every Fontconfig configuration file must end with the following line:

The default Fontconfig configuration file includes the directory `~/.fonts/' in the list of directories searched for font files, and this is where user-specific font files should be installed. In the unlikely case that a new font directory needs to be added, this can be done with the following syntax:


Another useful option is the ability to disable anti-aliasing (font smoothing) for selected fonts. This can be done with the following syntax:

<match target="font">
    <test qual="any" name="family">
        <string>Lucida Console</string>
    <edit name="antialias" mode="assign">
Anti-aliasing can be disabled for all fonts by the following incantation:
<match target="font">
    <edit name="antialias" mode="assign">

Xft supports sub-pixel rasterisation on LCD displays. X11R6.8 should automatically enable this feature on laptops and when using an LCD monitor connected with a DVI cable; you can check whether this was done by typing

$ xdpyinfo -ext RENDER | grep sub-pixel
If this doesn't print anything, you will need to configure Render for your particular LCD hardware manually; this is done with the following syntax:
<match target="font">
    <edit name="rgba" mode="assign">
The string `rgb' within the `<const>'...`</const>' specifies the order of pixel components on your display, and should be changed to match your hardware; it can be one of `rgb (normal LCD screen), `bgr' (backwards LCD screen), `vrgb' (LCD screen rotated clockwise) or `vbgr' (LCD screen rotated counterclockwise).

2.1.3. Configuring applications

Because most current applications use the core fonts system by default, it is necessary to explicitly configure them to use Xft. How this is done depends on the application.

XTerm can be set to use Xft by using the `-fa' command line option or by setting the `XTerm*faceName' resource:

XTerm*faceName: Courier
$ xterm -fa "Courier"

For applications based on GTK+ 2.0 (including GNOME 2 applications), the environment variable `GDK_USE_XFT' should be set to `1':

$ export GDK_USE_XFT=1

GTK+ 2.2 uses Xft by default.

For KDE applications, you should select ``Anti-alias fonts'' in the ``Fonts'' panel of KDE's ``Control Center''. Note that this option is misnamed: it switches KDE to using Xft but doesn't enable anti-aliasing in case it was disabled by your Xft configuration file.

(What about Mozilla?)

2.1.4. Troubleshooting

If some Xft-based applications don't seem to notice the changes you are making to your configuration files, they may be linked against an old version of Xft. In order to fix the problem, you should relink them against a current version of Xft; on most systems, it is enough to install the current version of the Xft and Fontconfig libraries.

If, for some reason, you cannot upgrade the shared libraries, please check the Xft(3) manual page included with XFree86 4.2 for the configuration mechanisms of the previous version of Xft.

2.2. Configuring the core X11 fonts system

Installing fonts in the core system is a two step process. First, you need to create a font directory that contains all the relevant font files as well as some index files. You then need to inform the X server of the existence of this new directory by including it in the font path.

2.2.1. Installing bitmap fonts

The X11R6.8 server can use bitmap fonts in both the cross-platform BDF format and the somewhat more efficient binary PCF format. (X11R6.8 also supports the obsolete SNF format.)

Bitmap fonts are normally distributed in the BDF format. Before installing such fonts, it is desirable (but not absolutely necessary) to convert the font files to the PCF format. This is done by using the command `bdftopcf', e.g.

$ bdftopcf courier12.bdf
You will then want to compress the resulting PCF font files:
$ gzip courier12.pcf

After the fonts have been converted, you should copy all the font files that you wish to make available into a arbitrary directory, say `/usr/local/share/fonts/bitmap/'. You should then create the index file `fonts.dir' by running the command `mkfontdir' (please see the mkfontdir(1) manual page for more information):

$ mkdir /usr/local/share/fonts/bitmap/
$ cp *.pcf.gz /usr/local/share/fonts/bitmap/
$ mkfontdir /usr/local/share/fonts/bitmap/

All that remains is to tell the X server about the existence of the new font directory; see Setting the server font path below.

2.2.2. Installing scalable fonts

The X11R6.8 server supports scalable fonts in four formats: Type 1, Speedo, TrueType and CIDFont. This section only applies to the former three; for information on CIDFonts, please see Installing CIDFonts later in this document.

Installing scalable fonts is very similar to installing bitmap fonts: you create a directory with the font files, and run `mkfontdir' to create an index file called `fonts.dir'.

There is, however, a big difference: `mkfontdir' cannot automatically recognise scalable font files. For that reason, you must first index all the font files in a file called `fonts.scale'. While this can be done by hand, it is best done by using the `mkfontscale' utility.

$ mkfontscale /usr/local/share/fonts/Type1/
$ mkfontdir /usr/local/share/fonts/Type1/
Under some circumstances, it may be necessary to modify the `fonts.scale' file generated by mkfontscale; for more information, please see the mkfontdir(1) and mkfontscale(1) manual pages and Core fonts and internationalisation later in this document.

2.2.3. Installing CID-keyed fonts

The CID-keyed font format was designed by Adobe Systems for fonts with large character sets. A CID-keyed font, or CIDFont for short, contains a collection of glyphs indexed by character ID (CID).

In order to map such glyphs to meaningful indices, Adobe provide a set of CMap files. The PostScript name of a font generated from a CIDFont consists of the name of the CIDFont and the name of the CMap separated by two dashes. For example, the font generated from the CIDFont `Munhwa-Regular' using the CMap `UniKS-UCS2-H' is called


The CIDFont code in X11R6.8 requires a very rigid directory structure. The main directory must be called `CID' (its location defaults to `/usr/X11R6/lib/X11/fonts/CID' but it may be located anywhere), and it should contain a subdirectory for every CID collection. Every subdirectory must contain subdirectories called CIDFont (containing the actual CIDFont files), CMap (containing all the needed CMaps), AFM (containing the font metric files) and CFM (initially empty). For example, in the case of the font Munhwa-Regular that uses the CID collection Adobe-Korea1-0, the directory structure should be as follows:


After creating this directory structure and copying the relevant files, you should create a `fonts.scale' file. This file has the same format as in the case of (non-CID) scalable fonts, except that its first column contains PostScript font names with the extension `.cid' appended rather than actual filenames:

Adobe-Korea1/Munhwa-Regular--UniKS-UCS2-H.cid \
(both names on the same line). Running `mkfontdir' creates the `fonts.dir' file:
$ cd /usr/local/share/fonts/CID
$ mkfontdir

Finally, you should create the font metrics summary files in the directory `CFM' by running the command `mkcfm':

$ mkcfm /usr/local/share/fonts/CID
If no CFM files are available, the server will still be able to use the CID fonts but querying them will take a long time. You should run `mkcfm' again whenever a change is made to any of the CID-keyed fonts, or when the CID-keyed fonts are copied to a machine with a different architecture.

2.2.4. Setting the server's font path

The list of directories where the server looks for fonts is known as the font path. Informing the server of the existence of a new font directory consists of putting it on the font path.

The font path is an ordered list; if a client's request matches multiple fonts, the first one in the font path is the one that gets used. When matching fonts, the server makes two passes over the font path: during the first pass, it searches for an exact match; during the second, it searches for fonts suitable for scaling.

For best results, scalable fonts should appear in the font path before the bitmap fonts; this way, the server will prefer bitmap fonts to scalable fonts when an exact match is possible, but will avoid scaling bitmap fonts when a scalable font can be used. (The `:unscaled' hack, while still supported, should no longer be necessary in X11R6.8.)

You may check the font path of the running server by typing the command

$ xset q Temporary modification of the font path

The `xset' utility may be used to modify the font path for the current session. The font path is set with the command xset fp; a new element is added to the front with xset +fp, and added to the end with xset fp+. For example,

$ xset +fp /usr/local/fonts/Type1
$ xset fp+ /usr/local/fonts/bitmap

Conversely, an element may be removed from the front of the font path with `xset -fp', and removed from the end with `xset fp-'. You may reset the font path to its default value with `xset fp default'.

For more information, please consult the xset(1) manual page. Permanent modification of the font path

The default font path (the one used just after server startup or after `xset fp default') is specified in the X server's `xorg.conf' file. It is computed by appending all the directories mentioned in the `FontPath' entries of the `Files' section in the order in which they appear.

FontPath "/usr/local/fonts/Type1"
FontPath "/usr/local/fonts/bitmap"

For more information, please consult the xorg.conf(5) manual page.

2.2.5. Troubleshooting

If you seem to be unable to use some of the fonts you have installed, the first thing to check is that the `fonts.dir' files are correct and that they are readable by the server (the X server usually runs as root, beware of NFS-mounted font directories). If this doesn't help, it is quite possible that you are trying to use a font in a format that is not supported by your server.

X11R6.8 supports the BDF, PCF, SNF, Type 1, Speedo, TrueType, OpenType and CIDFont font formats. However, not all X11R6.8 servers come with all the font backends configured in.

On most platforms, the X11R6.8 servers are modular: the font backends are included in modules that are loaded at runtime. The modules to be loaded are specified in the `xorg.conf' file using the `Load' directive:

Load "type1"
If you have trouble installing fonts in a specific format, you may want to check the server's log file in order to see whether the relevant modules are properly loaded. The list of font modules distributed with X11R6.8 is as follows: Please note that the argument of the `Load' directive is case-sensitive.

Fonts in X11R6.8 : Installing fonts
Previous: Introduction
Next: Fonts included with X11R6.8