TrueType Fonts in Debian mini-HOWTO

Bear Giles, bgiles@coyotesong.com

v0.3, 10 January 2000

This document describes how to configure a Debian system to use TrueType fonts for display and printing. The most recent version of this document can be obtained in HTML format at http://www.dimensional.com/~bgiles/debian-tt.html

1. Introduction

2. Display (what they never told you)

3. Display (X and the font servers)

4. Printing (ghostscript)

5. Content Generation

6. Unanswered questions

7. Obtaining TrueType Fonts

8. Legalities

1. Introduction


Needless to say, these fonts are not coordinated.


1.1 Disclaimer


So have fun, but play it safe and keep backups.

1.2 Credits

Created by Bear Giles, <bgiles@coyotesong.com>

Thanks go to:

1.3 Additional links


1.4 Change log

1.5 Feedback

Comments, corrections, additions and critiques are always welcome. You can reach me at bgiles@coyotesong.com.

1.6 Related projects

1.7 Distribution

This is the first draft and I expect it to change significantly after publication, I ask that you refer to the latest version at http://www.dimensional.com/~bgiles/debian-tt.html. The permanent home for this document will eventually be at http://www.coyotesong.com/

2. Display (what they never told you)

Before we dive into setting up TrueType fonts under X, we should review the difference between points and pixels... and why we care.

All displayed fonts are measured in points. One inch is exactly 72 points. Why 72? Partly because of the limitations of mechanical typesetting machines and partly because it's evenly divisible by 2, 3, 4, 6, 8, 9, 12, 18 and 24. It's also worth noting that the default unit in PostScript is one point.

(Historical note: I lied. Until the introduction of PostScript an inch was exactly 72.27 points, but that point size was set in the era of mechanical printers with metal stamps in a handful of standard sizes. With computer displays and laser printers, it's easy to get fonts in any size and 72 makes much more sense for the reason mentioned above.)

As a general rule, most text should be between 7 and 12 points. Anything smaller than 6 points is literally "the fine print." Line printers used 9 or 12 point type (for 8 or 6 lines/inch, respectively).

In contrast, all video drivers must ultimately measure fonts in pixels. To your video driver, your screen is 1024x800 pixels, not 10 by 8 inches (or 720 by 576 points).

To map from points (which we use to specify a font size) to pixels (which we use to blit the video memory) we must know our screen's resolution. This is usually measured in "dots per inch (dpi)," although it's really pixels per inch. These are the units used in the two sets of bitmap fonts included with XFree86: fonts-75 is intended for use on low-end displays with a resolution of approximately 75 dpi, fonts-100 is intended for use on mid-range displays with a resolution of approximately 100 dpi. There are no bitmap fonts intended for use on high-end displays with a resolution of over 120 dpi.

As a concrete example, a 13" diagonal screen (11.1" usable) displaying a 640x480 pixel image has a resolution of 72.0 dpi. This Is Not A Coincidence. In fact, most web pages (and Microsoft applications) are designed around a canonical display with a resolution of exactly 72 dpi. XFree86's default configuration assumes a display with a resolution of 75 dpi.

Back in the real world, nobody runs 640x480 video anymore. Nobody uses 13" diagonal screens anymore. Since video cards have improved faster than video monitors it's not uncommon to have a configuration like mine: 19" diagonal screen, (17+" usable), 1600x1200 pixels, 117 dpi resolution.

If I run a stock X configuration, all of my fonts are approximately 2/3 of the intended size. It's not an exaggeration to say that all fonts are cut down by a full size: large fonts (12 pts) appear medium (9). Medium fonts (9 pts) appear small (6).

There are three things we can do to fix this. First, We should tell the X server our actual screen resolution:

#:0 local /usr/X11R6/bin/X -bpp 16
:0 local /usr/X11R6/bin/X -bpp 16 -dpi 120

Second, we should ensure that we use the 100 dpi bitmapped fonts in preference to the 75 dpi fonts.

Section "Files"

Finally, if one of our bitmapped fonts isn't an exact match the X server will attempt to "scale" a similar font via pixel replication. The results are rarely pleasant to use. Assuming we have a reasonably powerful system, we can tell the server to use scaled fonts by default, then bitmaps which are exact matches, and scaled bitmaps as a last resort.

Section "Files"

2.1 A look ahead to XFree86 4.0

I've just been informed that XFree86 will support DDC communications, if the video card and monitor both support it. This will allow the X server to query the monitor for its physical dimensions and the server will automatically compute the correct DPI setting.

You will still need to make the appropriate changes to your font path, since the server should not second guess your explicit configuration.

2.2 Review: Preparation before changing X configuration files.

Any time we make changes to the X11 configuration files, it's an excellent idea to disable XDM by putting exit 0 somewhere near the top of the file. If you don't do this and X is unable to start for some reason, XDM will put your system into a nasty busy loop that is an unspeakable pain to correct. You Have Been Warned.

3. Display (X and the font servers)

Strictly speaking, it is not absolutely necessary to set up font servers to use TrueType fonts with X servers. If you wish to use static files instead of a font server, please see the instructions for setting up TrueType fonts for ghostscript.

3.1 Setting up the xfs Font Server

At this point I assume you have a working /etc/X11/XF86Config file that loads explicitly specifies each directory in the FontPath. We will convert it to use the xfs Font Server.

3.2 Setting up the xfstt Font Server and installing TrueType fonts

At this point I assume you have a working xfs font server and wish to add TrueType support via xfstt.

3.3 Using TrueType fonts

At this point it should be possible to use a TrueType font in applications like GIMP, Netscape or StarOffice. Since most TrueType fonts aren't monospaced you probably don't want to use one of them with xterm - these programs use monospacing the size of the largest character cell.

3.4 Installing additional TrueType fonts

If you are using the xfstt font server, it's trivial to install additional TrueType fonts.

3.5 Internationalization

xfstt has the ability to generate multiple font encodings, provided that the TrueType font contains the necessary glyphs. To enable fonts other than iso8859-1/unicode-1, you must manually edit the /etc/init.d/xfstt script:

- start-stop-daemon --start --quiet --exec $XFSTT -- \
      --port $portno --daemon 
      --port $portno --encoding iso8859-1,koi8-r,windows-1252,symbol-0 \

The recognized encodings in Debian 2.1 are:

The first 128 characters in the iso8859-x encodings is always ASCII. The windows- fonts embrace and extend iso8859-1 with additional characters such as "smart quotes." (Since these extensions, such as "smart quotes" are undefined in iso8859-1, they are usually rendered as question marks.)

Excellent source for additional information on character set encodings are at

3.6 Security Issues

I used Unix sockets above, but the standard Debian packages also configure xfs and xfstt to listen to TCP/IP ports 7100 and 7101, respectively. Access to these ports should be controlled by the trusted-clients field in /etc/X11/xfs/config, but this option is not implemented in XFree86

This means that anyone, anywhere, can connect to your font server. Since xfs (and presumably xfsts) "clone" to support more users there's a trivial denial-of-service attack against these systems. It's probably safe to use the font servers on dialup lines (since you're present to handle problems), but DSL and cable modem users should use a firewall.

4. Printing (ghostscript)

Starting with version 4, ghostscript has supported TrueType fonts as a compile-time option. Two Debian packages provide ghostscript:

Both versions support TrueType fonts.

4.1 Configuring Ghostscript to use TrueType fonts

If you have a working xfstt server, it is easy to configure ghostscript to use TrueType fonts. We simply execute the following command:

# xfstt --gslist --sync >> /etc/gs.Fontmap

In practice, I've found it beneficial to make several small changes to the font definitions generated by xfstt. First, if a font name does not contain any spaces, I change the name to the usual notation. If a font name does contain spaces, I replace all spaces with dashes and the original name is added as an alias to the new name.

Finally, I prepend TTF- (or MS-) to all font names to minimize problems caused by a TrueType font having an identical name to an preexisting font.


(Arial)               (/usr/share/fonts/truetype/arial.ttf)   ;
(Arial Bold Italic)   (/usr/share/fonts/truetype/arialbi.ttf) ;


/MS-Arial             (/usr/share/fonts/truetype/arial.ttf)   ;
/MS-Arial-Bold-Italic (/usr/share/fonts/truetype/arialbi.ttf) ;
(Arial Bold Italic)   /MS-Arial-Bold-Italic                   ;
/Arial                /MS-Arial                               ;

The aliases ensure that ghostscript and xfstt can still specify the same font by a common name.

Much more significantly, with the change in the font names it's possible to instruct ghostscript to use TrueType fonts instead of the standard fonts. The documentation claims that this is also possible with parenthetical notation, but I could not get it to work.

For instance, we can instruct ghostscript to replace Helvetica fonts with Microsoft's free Arial fonts by appending the following lines to the /etc/gs.Fontmap file:

/Helvetica               /MS-Arial              ;
/Helvetica-Oblique       /MS-Arial-Italic       ;
/Helvetica-Bold          /MS-Arial-Bold         ;
/Helvetica-BoldOblique   /MS-Arial-Bold-Italic  ;

Similar aliases can be defined for the other standard fonts. These aliases would be most useful on samba printers serving Windows clients.

4.2 Printing TrueType font specimens

The best way to verify that ghostscript is properly configured to use TrueType fonts is to print font specimen pages. Assuming that you're running ghostscript 5.50 and that it is your default print queue, you can print all TrueType fonts with the following command:

# xfstt --gslist --sync | printfont

where printfont is the following shell script


set -e
IFS= ')'

while read fontname rest
    cat << EOM | lpr
(/usr/lib/ghostscript/5.50/prfont.ps) run
$fontname) DoFont

If you wish to print only a few fonts, the following script will be easier to use:


set -e
while read -p "Font name, or ^D to exit: " fontname
    cat << EOM | lpr
$fontname DoFont

5. Content Generation

5.1 Generating AFM font metrics

AFM font metrics files are not required for display existing files with TrueType fonts, but they are necessary to create new files. The ghostscript program /usr/lib/ghostscript/5.50/printafm.ps could be used to generate these metric files, but I have found the ttf2afm program from the tetex-bin package to be easier to use.

The following script will generate an afm file for all TrueType fonts in a directory:


set -e

for i in *.TTF
    /usr/bin/ttf2afm $i > ${i%TTF}afm

for i in *.ttf
    /usr/bin/ttf2afm $i > ${i%ttf}afm

One minor problem with ttf2afm is that some applications expect afm files to start with the StartFontMetrics tag, but files created by ttf2afm start with a comment. This "problem" is easily fixed by hitting each file with a text editor.

5.2 Generating font.map files

Once we have our afm files, we need to tell the system how to find them. This is often done via the font.map file.

I have been unable to find documentation on this file format, unlike fonts.dir, fonts.scale, and fonts.alias, all created by the mkfontdir program. However the minimum format appears to be quite simple:

Aliases appear to be implemented via multiple entries, and the filename extension must be in lowercase.

5.3 Image manipulation: GIMP

GIMP is the Gnu image manipulation and paint program. I did not have to make any additional changes to use TrueType fonts in gimp.

5.4 ASCII to PostScript conversion: enscript

Enscript is a program that converts ASCII to PostScript. Other programs which serve a similiar purpose are a2ps and mpage. Enscript allows two-up rotation, watermarks, headers, and keyword-based syntax coloring. It does not reformat text and is commonly used to print source listing.

To use TrueType fonts with enscript, you must do two things:

For details, see the enscript documentation.

Once I had made these changes, I had no problem using TrueType fonts.

5.5 Text Formatting and Typesetting: groff

Groff is the Gnu front end of the groff/troff document formatting system. The power of Groff is best seen with man pages.

user shell
$ zcat /usr/man/man1/groff.1.gz | groff -man | lpr

Besides man pages, an incredible amount of Unix documentation uses troff formatting with ms (and occasionally me) macros. The Debian xbooks package, for example, has 43 files using troff with ms macros. With groff, this material can be attractively printed.

Groff is a very powerful system, but it's the grandchild (or great-grandchild) of a program used to typeset 1960's era printing presses. Font support in groff reflects that heritage. Groff, in contrast to its predecessors, uses PostScript as the default output format so our earlier work with ghostscript takes care of half of the problem -- groff does not have to deal with reading TrueType font files. It does need to have accurate font metrics, and this section describes how to regenerate the necessary groff files:

Groff PostScript description files
    Device description file
    Encoding used for text fonts
    Standard mapping.
    Standard makefile

We must edit the Makefile,

- afmdir=/usr/local/afm
+ afmdir=/usr/share/fonts/truetype

change the name of the fonts to their TrueType equivalent (e.g., if we're using Microsoft's free TrueType fonts we would replace Helvetica with Arial), and change TEXTFONTS and the like to only include those fonts we are redefining.

We must also edit /usr/share/groff/font/devps/generate/afmname to use the TrueType font names and afm files, and to remove an "-e" flag from awk.

After all of this, we can rebuild the groff tables with

user shell
$ cd /usr/share/groff/font/devps
$ make -f generate/Makefile

As usual, the best way to verify the changes is to use a visually distinctive font. E.g., if you are using the Microsoft free TrueType fonts you can use Mistral for TR.

(I expect royalties from everyone who reconfigures their system to print manual pages in Old English fonts next April First!)

5.6 Text Formatting and Typesetting: TeX

TeX is the other common set of text formatting and typesetting programs on most GNU/Linux systems.

TeX fonts can created with mktexmf, but I have little information on the exact process. More details will be provided shortly.

6. Unanswered questions

7. Obtaining TrueType Fonts


7.1 A comment about using Microsoft's free TrueType fonts


Q. What can I do with these fonts?
   · Anyone can download and install these fonts for 
     their own use.
   · [Web page] designers can specify the fonts within 
     their own Web pages.







8. Legalities

Copyright © 1999 by Bear Giles.



