(M)  s i s t e m a   o p e r a c i o n a l   m a g n u x   l i n u x ~/ · documentação · suporte · sobre

  Next Previous Contents

4. Making Fonts Available To X

There are a number of ways fonts can be added to X. Firstly, XFree86 has a font path which is just a list of several directories or font servers where it searches for fonts. A font server is just a background process that makes fonts available to XFree86. An advantage of font servers is that they can send fonts to remote displays.

Recently, xfs ( the ``X font server'' ) has been patched to support TrueType fonts, and run as a stand-alone program. The patched version ships with Redhat and Redhat-based distributions, and is included in XFree86 3.9.17 ( the latest version at the time of writing. It will also be a part of XFree86 4.0 ) xfs is actually just the standard font server that comes with XFree86. It's source code is part of the XFree86 source tree. However, distributions have recently been shipping a version that runs in stand alone mode. The standalone X font server, with the TrueType support patch ( the TrueType support takes place via a font server called xfsft ) is probably the nicest font management solution currently available. Its advantages include:

  • Support for different types of fonts, including Type1, TrueType and bitmap.
  • Makes fonts available to remote displays.
  • Greatly simplifies editing the fontpath -- you can do it via the command line utility chkfontpath, as opposed to having to edit configuration files. This not only makes life easier for users, it makes packaging more safer and more scriptable for packagers.

Because different distributions ship with different configurations, it is not true that one size fits all. We can split users up into three groups:

  • Your distribution ships with a standalone xfs and it has been patched to support TrueType. This group includes Redhat users and users of derivatives of Redhat such as Mandrake, TurboLinux, and Independence. For this group, the wisest strategy is to install both TrueType and Type1 fonts through xfs
  • Some distributions ship with a stand alone xfs package, but no TrueType support (at the time of writing. Note that XFree86 supports TrueType as of version 3.9.17 ). This includes Debian. For these users, the best thing to do is use xfs to install Type1 fonts, and install TrueType fonts via xfstt. Debian users can seek out the TrueType Fonts in Debian mini-HOWTO for information about installing TrueType fonts in Debian.
  • If you don't have xfs then you will need to install Type1 fonts by adding to their XFree86 font path and using xset. You should install TrueType via xfstt.

4.1 The font path

XFree86 finds your fonts by searching a font path, a list of directories ( or servers -- we'll explain this further later. ) containing fonts. When an application requests a font, it searches through the directories in your font path one at a time until the font is found. To make fonts available requires you to set your font path. You can add a directory to your font path with the command

        xset fp+ directory
        
Once you have done this, you need to ask the X server to re-scan for available fonts with the command
        xset fp rehash
        
Since you will want these commands to run automatically, you should put them in your .xinitrc file ( or possibly your .Xclients or .xsession file -- this depends on how you start X. It's convenient to make two of these files symlinks to the other to avoid confusion ). Another way to have the commands set automatically is edit XF86Config. For example, to add /usr/share/fonts/myfonts to the fontpath when X is started, edit XF86Config like this:
                ...
                Section "Files"
                ...
                
                FontPath /usr/share/fonts/myfonts
                ...
                EndSection
                ...
The advantage of editing XF86Config is that the resulting changes are system wide.

4.2 Installing Type1 Fonts

Run Type1inst

The easiest way to make Type1 fonts available to X is with the help of the Type1inst utility. This is a perlscript that automatically creates the fonts.dir and fonts.scale files that you need for X to use the fonts. Simply CD to the directory, and run type1inst.

        cd directory
        type1inst
        

If You Have the xfs Package

Now you need to add the fonts to your fontpath. If you already have the standalone xfs running, you do this by editing your xfs configuration file. Redhat users can just use chkfontpath. the format is chkfontpath --add directory

Your fonts should now be available to X. Now you just run

        xset fp rehash
        
and X will be able to find the new fonts.

If You Don't Have The xfs Package

In this case, you need to add the directory containing your new fonts to the font path, as described previously.

4.3 True Type Fonts

Adding TrueType fonts is a little more difficult, because you need to have a font server that is capable of serving TrueType fonts. Two font servers that do this are xfstt and xfs.

xfstt is a TrueType font server. While it's easy to configure, and quite useful, it appear that xfs is becoming more popular. The main advantage of xfs over xfstt is that it supports both Type1 and TrueType fonts.

xfstt

To set up xfstt, just download it and install it. If you have an rpm based distribution, there is a well packaged version of xfstt at http://independence.seul.org/. Once you install it, you need to do the following:

  1. install fonts into the appropriate directory ( read the documentation that comes with the package ).
  2. cd to that directory and run xfstt --sync. This causes it to look for the fonts and create the fonts.dir file.
  3. Now add unix/:7100 to your font path.
Your TrueType fonts should now display and be available to applications such as GIMP and Netscape. You may want to configure it to start every time your system starts up. Check to see if there's a startup file included ( if you are using RPM, you can use rpm -ql xfstt |grep init and look for the file with a name something like this: /etc/rc.d/init.d/xfstt ) If you don't have an init script, just put two lines in /etc/rc.local like this:
        /usr/X11R6/bin/xfstt --sync
        /usr/X11R6/bin/xfstt &
        

4.4 xfs

Some of the newer Linux distributions ship with the X font server xfs configured to run as a stand alone program. Notably, Redhat and all the redhat based distributions use this modularised xfs with TrueType compiled in. Debian also ship xfs, but the version they ship doesn't have built in true type support.

Running xfs as a stand alone server has several benefits, especially if it is compiled with TrueType support. The main advantage is that since the font server is no longer attached to the X server, it is possible to serve fonts to remote displays. Also, it makes it much easier to modify the font path.

The xfs Path

As a font server, xfs has it's own font path. One might wonder where this fits into the picture. It works like this: you can place the xfs font server in XFree86's font path, by adding unix/:port to the XFree86 font path. Once you do this, any font in the xfs font path automatically becomes available to XFree86.

The xfs font path is determined by the xfs configuration file, which is /etc/X11/fs/config on Redhat, and /etc/X11/xfs/config on Debian. Redhat users do not need to explicitly edit this file, they can use the chkfontpath utility. The syntax is simple:

        chkfontpath --add directory
        
Users of other distributions can edit the configuration file as follows:
        catalogue = /usr/X11R6/lib/X11/fonts/misc:unscaled,
        ...
        /usr/share/fonts/my_new_fonts/,
        ...
        /usr/share/fonts/some_other_directory
        # in 12 points, decipoints
        default-point-size = 120
        ...
        
The above would add /usr/share/fonts/my_new_fonts/ to the xfs font path. Note that the last line of the list of directories doesn't have a comma at the end. For these modifications to the font path to become effective, xfs must be restarted. It's also a good idea to restart your X session after restarting xfs.

Installing a Font Into xfs

To prepare a font for xfs, you need to follow the following steps:

  • If you don't have xfs installed, you need to install it.
  • Put the new fonts in a directory.
  • If you are installing Type1 fonts, prepare the new directory for the server by running type1inst in the directory.
  • If you are installing TrueType fonts, ( remember, not all distributions can do TrueType via xfs ! ), prepare the new directory for the server by running
            ttmkfdir -o fonts.scale
            mkfontdir
            
    
    in the directory containing your new fonts. ttmkfdir is part of the freetype package.
  • Now you can add the new directory to your xfs search path. Users of Redhat-like distributions can do this with the chkfontpath utility: Other users can do this by editing their xfs configuration file.
  • if xfs is already installed on your system, you should see which port it is running on. You can do this as follows:
            ps ax|grep xfs
            
    
  • Then check your XFree86 font path.
                    xset -q
            
    
  • If your font path includes something like unix:/port_number were port_number is the port which the server is running on, then you already have xfs set up properly. Otherwise, you should add it to your XFree86 font path.
                    xset fp+ unix/:port_number
                    xset fp rehash
            
    
    You can add it permanently by editing your .xinitrc as explained previously. To add it system wide, edit your XF86Config file ( probably either /etc/X11/XF86Config, /etc/XF86Config or /usr/X11R6/lib/X11/XF86Config ), by adding a line FontPath "unix:/port_number" in the Files section. Here's an example:
                    ...
                    Section "Files"
                    ...
                    
                    FontPath "unix/:-1" 
                    ...
                    EndSection
                    ...
                    
    
  • If xfs is already properly installed, then you can restart it like this:
                    /etc/rc.d/init.d/xfs restart
                    
    
  • After restarting xfs, it's a good idea to restart your X-session.

Next Previous Contents