13.8 Font Management Under X


On most current Unix systems, fonts are made available to applications via the X Window system (although some application packages manage their own font information). In this section, we will consider the main administrative tasks related to managing fonts.

In an ideal world, fonts would be something that users took care of themselves. However, in this world, font handling under X is cumbersome enough that the system administrator often needs to get involved.

In this section, we consider font management using the standard X11R6 tools, and we refer to directory locations as defined by the normal installation of the package. These facilities and locations are often significantly altered (and broken) in some vendors' implementations.

13.8.1 Font Basics

When you think of afont, you probably think of something like Times or Helvetica. These names actually referred tofont families containing a number of different typefaces: for example, regular Times, italic Times, bold Times, bold italic Times, and so on. At the moment, there are quite a few different formats for font files. The most important distinction among them is between bitmap fonts and outline fonts. Bitmap fonts store the information about the characters in a font as bitmap images, while outline fonts define the characters in a font as a series of lines and curves, comprising in this way mathematical representations of the component characters.

From a practical point of view, the main difference between these two font types is scalability. Outline fonts can be scaled up or down any arbitrary amount and look equally good at all sizes. In contrast, bitmap fonts do not scale well, and they look extremely jagged and primitive as they get larger. For this reason, outline fonts are generally preferred to bitmap fonts.

To further complicate matters, there are two competing formats foroutline fonts: Adobe Type 1 and TrueType. In technical terms, the chief difference between them consists of the kind of curves used to represent the characters: Bezier curves and b-splines, respectively. The other major difference between the two formats is price, withType 1 fonts generally being significantly more expensive thanTrueType fonts.

All of these different types of fonts are generally present under X. The most important formats are listed in Table 13-7, along with their corresponding file extensions.

Table 13-7. Common font file formats

Format

Bitmap/outline

Extension(s)

Portable Compiled Font

bitmap

.PCF.gz

Speedo

bitmap

.spd

Ghostscript font

outline

.gsf

Type 1

outline

.pfa, .pfb, .afm

TrueType

outline

.ttf

The PCF fonts are bitmap fonts (generally stored in compressed format) that come as part of the XFree86 system, typically located in directories under /usr/X11R6/lib/X11/fonts or /usr/lib/X11/fonts. The Speedo fonts were donated to the X Window system by Bitstream and are located in the same place. The Ghostscript fonts are Type 1 fonts installed with that facility (using a slight variation in format). In addition, there may be Type 1 and/or TrueType fonts present on the system.

Type 1 fonts consist of multiple files. The .pfa and .pfb files contain the actual font outline representation, in ASCII and binary format, respectively, and the .afm file contains font metrics information in ASCII format. Type 1 fonts on Unix systems generally use the binary .pfb files (probably because they are smaller in size), but .pfa files may also be used. The corresponding .afm file is also required in order to print.

The X window system uses a somewhat arcane naming convention for referring to fonts. Here is its general syntax and an example for a font in the Octavian family:

-foundry-family-weight-slant-stretch-style-pixel-points-xres-yres-spacing-avgwidth- registry-encoding -monotype-octavian mt-medium-i-normal--0-0-0-0-p-0-iso8859-1

The components have the following meanings. The foundry[11] is the organization (often a commercial entity) that provided/sold the font, Monotype in our example. The family indicates the overall grouping of typefaces to which this particular item belongs (for example, Times or Helvetica); our example is from the Octavian MT family (note that spaces commonly appear within the family name). The next few items indicate which member of the family this one is: weight is a keyword indicating the relative darkness of this typefaces with respect to other family members (medium, bold, light, black and so on), slant is a single character indicating whether this typeface is upright (r for roman, i for italic or o for oblique), stretch is a keyword indicating whether the typeface is expanded or compressed with respect to normal lettering (normal, condensed, expanded and so on), and style is a keyword indicating any additional typographic style information relevant to this typeface (e.g., expert, ornaments, oldstylefigures, etc.). Our example typeface is Octavian Italic (not bold, not condensed/expanded, and no additional style designation).

[11] As one of the technical reviewers noted, this term comes "from the days of moveable set type where a iron working foundry was responsible for manufacturing the type sets."

The remaining fields specify the default point size (points), the body size in pixels at that point size (pixels), the typeface's default horizontal and vertical resolution (xres and yres), its spacing class (spacing: one of m for monospace/fixed width, c for character cell and p for proportional), a measure of the average width of the glyphs in the font (avgwidth), and the character set use for coding the font (registry and encoding). Most of the numeric fields tend to be set to zero for outline fonts, indicating the font's default value should be used as they are in our example and the three remaining fields are generally set to the values shown in the example as well.

In most instances, you'll never need to construct one of these names by hand. Instead, you can use utilities which create them for you automatically for various contexts. However, if you ever do need to generate one yourself, you can find all the essential information by running the strings command on the (binary) font file and looking at the information displayed at the beginning of its output (if you have an ASCII font file, you can look at that file's contents directly).

For more general information about fonts, consult the FAQ from the comp.fonts newsgroup (version 2.1.5, dated August 1996, is the most recent, available at www.nwalsh.com/comp.fonts/FAQ). For additional information about TrueType fonts, consult the TrueType HowTo (available on the web at pobox.com/~brion/linux/TrueType-HOWTO.html).

13.8.2 Managing Fonts under X

We now turn to the question of how X applications locate fonts they need. As we noted previously, the fonts that come with the X window system conventionally reside under /usr/X11R6/lib/X11/fonts. In fact, though, when an application needs a font to display on the screen, it checks the current font path to find it. Traditionally, the default font path is defined in the XF86Config configuration file (generally located in /etc or /etc/X11, with several links to other places) via FontPath lines in the Files section:

Section "Files"     RgbPath        "/usr/X11R6/lib/X11/rgb"     FontPath       "/usr/X11R6/lib/X11/fonts/misc"     FontPath       "/usr/X11R6/lib/X11/fonts/75dpi     ... EndSection

Each successive FontPath entry adds an additional directory to the font path.

On more recent systems, these lines have been replaced by one like this:

FontPath     "tcp/localhost:7100"

This indicates that a font server is in use, listening for font requests on TCP port 7100 on the local machine.[12] Additional FontPath entries may again be present, specifying either local directories or ports on other computers. The introduction of the font server in X11R5 made life easier since it allowed files to be shared between systems. The font server process actually runs the xfs program.[13]

[12] Note that on some systems running RedHat Linux, the entry appears like one of these:

FontPath "unix/:-1" FontPath "unix/:7100"

This format indicates that the system is using the Red Hat modified version of the X font server from which networking capabilities have been removed.

[13] The font server may be enabled on any of the systems we are considering (it is often installed by default). Doing so consists of installing the software, setting up its configuration file (discussed in brief a bit later), and modifying the system boot scripts so that the server process is started automatically.

However the default font path is set up, and individual user can always modify it via the xset command, using its fp option.

13.8.3 Adding Fonts to X

Adding fonts for use in screen display by the X Window system is very easy. For Type 1 fonts, the procedure is as follows:

  • Create a directory to hold the new fonts (if necessary) and copy the font files there. Generally, you will need to put in both the .pfa or .pfb file and the .afm file there.

  • Generate the required configuration files, named fonts.dir and fonts.scale (although, in fact, these two files are identical for the case of Type 1 fonts). This can be done manually, or you can use a utility to do it for you; some versions of the standard X mkfontdir command work well for this task, and the type1inst command is very reliable (available at http://sunsite.unc.edu/pub/Linux/X11/xutils/). Both of them are run from within the directory holding the new fonts.

    The entry in the files corresponding to our Octavian Italic typeface looks like this (we've wrapped it to fit):

    oci_ _ _ _ _.pfb      -monotype-octavian mt-medium-i-normal--0-0-0-0-p-0-iso8859-1

    The first item is the filename dictating the Type 1 font (oci_ _ _ _ _.pfb in this case), and the second item is the standard X typeface designation.

  • If you created a new font directory, add it to the font path. If you are not using a font server, this is done by adding another FontPath entry to the XF86Config file. If you are using a font server, then you must edit an entry in its configuration file. The xfs font server typically stores its configuration file as /etc/X11/fs/config. You'll need to an additional component to the catalogue list:

    catalogue = /usr/share/fonts/ISO8859-7/Type1,             /usr/share/fonts/default/Type1,             /usr/X11R6/lib/X11/fonts/misc,             /usr/X11R6/lib/X11/fonts/Type1,             /usr/X11R6/lib/X11/fonts/Speedo,             /more/fonts/type1

    Here we have added the /more/fonts/type directory as the final component of the catalogue. Note that the various catalogue entries are separated by commas.

  • Restart the font server (e.g., a command like /etc/init.d/xfs restart). Also restart any current X session.

Once this is all complete, the new fonts should be available to any application that uses the standard X font facilities. You can verify that the fonts are installed correctly using the X commands xfontsel and xfd; the gimp application provides another very pleasant way of exploring the new fonts. The first two commands can also be useful for exploring what fonts are available on the system and displaying all the characters within a given typeface. However, the latter job is better handled by the freely-available gfontview utility, whose output is displayed in Figure 13-10. This facility allows you to view a single character, a short string, or a palette containing every character within it (in the example display, I've been somewhat self-absorbed in my choice of test character and character string). You can get this utility at http://gfontview.sourceforge.net.

Figure 13-10. The gfontview font display utility
figs/esa3.1310.gif
13.8.3.1 Printing support

Printing the newly installed fonts introduces a few additional wrinkles. In order to be printed, Type 1 fonts must be rendered (technically, rasterized). Under X, this is usually handled by the Ghostscript facility (http://www.ghostscript.org), which must be configured for any new fonts.

Ghostscript font configuration occurs via its Fontmap configuration file, located in the /usr/share/ghostscript/n.nn directory, where the final component of the path corresponds to the package version (under FreeBSD, the path begins at /usr/local/share).

Here are some sample entries from this file:

/NimbusRomNo9L-Regu              (n021003l.pfb)  ; /NimbusRomNo9L-ReguItal          (n021023l.pfb)  ; /Times-Roman                     /NimbusRomNo9L-Regu       ; /Times-Italic                    /NimbusRomNo9L-ReguItal   ;

Each line contains three fields: a name preceded by a slash, a filename enclosed in parentheses or another name, and finally a semicolon; spaces and/or tabs separate the fields from one another. If the second field is a filename, print requests for the correspondingly named font will use this font file. If the second field is another name (indicated by an initial slash), then the first field becomes an alias an alternate name for the same typeface. For example, the preceding entries will result in the file n021003I.pfb being used when someone wants to print the Times-Roman font.[14]

[14] Occasionally, you will need to create aliases for fonts in order to get them to print properly. The most common example occurs with "regular" typefaces that do not have "Roman" in their name. This can confuse some environments and applications. In such cases, creating an alias in the expected format will often do the trick. For example:

In order to print our Octavian typeface, we need to add a line like the following to this file:

/OctavianMT-Italic               (oci_ _ _ _ _.pfb)  ;

The type1inst utility mentioned earlier creates a Fontmap file within the current directory along with the fonts.dir and fonts.scale files, making it easy to add the required entries to the actual Ghostscript font configuration file.

The filename field may contain either an absolute path or a simple file name. In the latter case, the Ghostscript font path will be searched for that file. The default path is set up when the facility is compiled and typically consists of subdirectories under /usr/share/fonts/default (e.g., ghostscript and Type1). You can make fonts available to Ghostscript by adding them to these existing locations (and modifying the current fonts.dir and fonts.scale files accordingly), or by using a new location, which can be added to the Ghostscript path by setting the GS_LIB environment variable.

13.8.4 Handling TrueType Fonts

With TrueType fonts, the fun really begins. Basically, the X font facilities and Ghostscript were designed around bitmap and Type 1 fonts and PostScript printing. However, users tend to have access to lots of TrueType fonts, and they naturally want to use them on Unix systems. Fortunately, support for TrueType fonts within traditional X facilities has become available.

The main facility that needs to understand TrueType fonts is the font server. Unfortunately, many vanilla xfs programs do not. However, TrueType compatibility font servers have been merged into the main XFree86 distribution as modules. See the "Fonts in Xfree86" document at http://www.xfree.org for full details (currently, http://www.xfree86.org/4.0.3/fonts.html) as well as the X TrueType Server Project home page, http://x-tt.dsl.gr.jp, and the FreeType Project homepage, http://www.freetype.org.

The module based on the excellent xfsft server can be included by editing the Modules section of the XF86Config file and adding a Load entry for the module freetype.

Once you have a TrueType-capable font server, the procedure for adding new TrueType fonts is almost identical to that for adding Type 1 fonts. The difference lies in using the ttmkfdir utility instead of type1inst (available at http://www.joerg-pommnitz.de/TrueType/xfsft.html; click on the link in the paragraph referring to the "tool that creates the fonts.scale file").

Here are three fonts.dir entries for TrueType fonts, Eras Light and Eras Bold:

eraslght.ttf    -itc-Eras Light ITC-medium-r-normal--0-0-0-0-p-0-iso8859-1 erasbd.ttf      -itc-Eras Bold ITC-medium-r-normal--0-0-0-0-p-0-iso8859-1 :2:mincho.ttc   -misc-mincho- . . . 

The final entry shows the method for referring to individual fonts with a TrueType Collection file.

For printing TrueType fonts from general X applications the best option is to use a version of Ghostscript which has been compiled with ttfont option, enabling TrueType support with the facility (it must be a version 5 revision of Ghostscript). In this case, you simply add entries as usual to the Fontmap file pointing to the TrueType font files.



Essential System Administration
Essential System Administration, Third Edition
ISBN: 0596003439
EAN: 2147483647
Year: 2002
Pages: 162

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net