Adding Extra Fonts for AbiWord on Unix

Tomas Frydrych <tomas@frydrych.uklinux.net>

Contents

1. Introduction

1.1 AbiWord Font Strategy

1.2 The Elementary Procedure

2. pfa / pfb fonts

3. TTF fonts

4. Unicode peculiarities

1. Introduction

AbiWord limits the fonts it makes available to the user to those located in its fonts directory, typically /usr/share/AbiSuite/fonts or /usr/local/AbiSuite/fonts (unless you chose different installation location) and in the locale-specific sub-directories of this directory. A standard set of fonts is provided with AbiWord and these are located in fonts directory.

1.1 AbiWord Font Strategy

We get frequently asked why is AbiWord so picky about fonts, and so I will take some time here to explain the AbiWord font strategy and the reasons behind it. If you are not interested in this, you can just skip to the next section.

The font situation under the X windowing system is very unsatisfactory. It is the result of a long evolution, and carries with it a weighty legacy baggage. It's roots go back to time when display on screen and printing via a printer were entirely separate matters, each one using its own set of fonts. With the advent of WYSIWYG applications this has become a sore point, and in other GUI environments, such as Windows, this was replaced by a common display/print API. In the Unix world this dichotomy between display and printing remains, the former being handled by the X windowing system, the latter with applications that require scalable fonts typically via PostScript output for a printer. (True, the XFree comes with an extension called XPrint, that allows printing via X, but AbiWord runs on many different flavors of Unix, not all of which use XFree.)

The consequence of this is, that the application on the one hand has to use the services of the X server to display its text on the screen, but at the same time has to be able to generate an identically looking PostScript output of the document for printing; this is a non-trivial task, as the PostScript API is nothing like the X API.

The need to generate the PostScript output reduces the fonts the application can use to PostScript fonts. In other words, out of the many fonts available on a typical XFree set up, only a fraction, if any at all, are usable by AbiWord. Now, the X font handling was designed so as to obliterate differences between fonts of different types, and so AbiWord cannot tell whether a font the X server supplies to it on request will be usable in generating the PostScript output. Further more, even if the font which the X server provides is a PostScript font, AbiWord also needs to be able not only to access it via the X server, but also to access it directly and to access the metric file associated with it, so that it can include the font in the PostScript output, and correctly calculate the layout of the PostScript document.

As I way of getting out of this font muddle, i.e., in order to ensure that (1) AbiWord will get only fonts it can use, (2) it will get at least some fonts it can use, and (3) will be able to access the font files and the corresponding metric files, AbiWord (a) only uses fonts that are located in its own font directory, (b) it provides a basic set of PostScript fonts, and (c) dynamically adds and removes this directory from the X server font path. It should be stressed that AbiWord is not limited to using only the fonts it provides, it can use other PostScript fonts as well as TrueType (ttf) fonts, but the user has to set them up manually.

1.2 The Elementary Procedure

If you wish to make an additional font available to AbiWord, you need to do the following:

(1) Place the font into the fonts directory

(2) Update the fonts.dir file.

The detailed procedure for pfa/pfb fonts and for ttf fonts is slightly different and is described below. Also note that the procedure is slightly more involved for non-Latin1 locales, with additional details found in the document NonLatin1UnixLocales.abw.

2. pfa / pfb fonts

Either copy the font file to the fonts directory, or create a symbolic link to it, it it is located elsewhere on your system. If your font came with a vendor provided afm file, you should copy or symlink it alongside the pfa/pfb file. If not AbiWord will generate the afm file automatically, but using a vendor provided afm file is preferable.

To update the fonts.dir file, you should add an entry for the new font into fonts.scale and then either run mkfontdir, or add exactly the same to fonts.dir and increase the font count at the very top of the file accordingly. Your fonts probably came with a sample fonts.dir or fonts.scale file, but if you do not know what the entry in the fonts.scale should be, you can generate it using the utility ttmkfdir.

If you are installing a font for a different encoding than iso8859-1, things are slightly more complicated. First of all, you should be installing the fonts into a subdirectory of the fonts directory (NonLatin1UnixLocales.abw), and also when adding the entry for the font to fonts.scale (and fonts.dir) make sure that the last two parts of the line separated by a dash are set to adobe-fontspecific. Then you have to create a file called fonts.alias in where you alias the font to the actual encoding it is for. For instance if your font called BLAH is for iso8859-8, the entry in fonts.scale/fonts.dir should look something like:

blah.pfa -...-BLAH-.........-adobe-fontspecific

(the dots stand for whatever makes up your specific entry). The fonts.alias file should then contain the following line:

-...-BLAH-.........-iso8859-8 -...-BLAH-.........-adobe-fontspecific

and, if the font name contains spaces, both parts of the alias line need to be enclosed in double quotes:

"-...-BLAH-.........-iso8858-8" "-...-BLAH-.........-adobe-fontspecific"

VERY IMPORTANT !!!: Make sure that you not only modify the fonts.dir file, but that you also make appropriate changes to fonts.scale. On some systems the mkfontdir utility can be executed automatically, and since this utility does not handle scalable fonts, it will truncate your fonts.dir file to 0 unless it can find fonts.scale, in which case it will just copy the contents of this file into the new fonts.dir. This is just another anachronism of the X fonts handling.

3. TTF fonts

** Currently TTF fonts are not supported by GnomePrint; if using Gnome

** build you have to print via 'Print Directly'.

** The ttf support only works for locales using a limited number of encodings, but other

** encodings can be added on request -- please do not hesitate to ask, this is simple to do.

** The following paragraphs contain an overview of the issues; a step by step guide on

** setup of ttf fonts for AW can be found in the document TrueTypeFontsWithUnix.abw.

First of all, your font server must support ttf fonts. Then, just as in the case of pfa fonts, you need to add an entry into fonts.scale and fonts.dir. You can generate the appropriate entries using the utility ttmkfdir (note that the utility will generate multiple entries, for a number of diferent encodings the font supports, just disregard those you do not need). Next, AbiWord needs to generate some support files, using the utility ttftool that comes with it; please follow the step-by-step guide to the whole process in TrueTypeFontsWithUnix.abw.

IMPORTANT: Make sure that you not only modify the fonts.dir file, but that you also make appropriate changes to fonts.scale. On some systems the mkfontdir utility can be executed automatically, and since this utility does not handle scalable fonts, it will truncate your fonts.dir file to 0 unless it can find fonts.scale, in which case it will just copy the contents of this file into the new fonts.dir. This is just another anachronism of the X fonts handling.

IMPORTANT: if you decide to update a ttf font that you have used with AbiWord previously, you will need to remove the support files that AbiWord generated. If your font is called myfont.ttf, look for files myfont.afm, myfont.u2g and myfont.t42 and delete them, then install the updated ttf font.

4. Unicode peculiarities

If are using a UTF-8 locale, you need to install Unicode fonts. To make XFree86 to treat a font as a Unicode font, you need to specify the encoding in the XLFD (the entry in the fonts.dir/fonts.scale file) as iso10646-1. To see if your font is treated as a Unicode font run `xlsfonts -ll -fn font_name'. This will dump out lot of information about your font, and somewhere among it should be values min_byte1 and max_byte1; if both of these are 0, then your font is being treated as 8-bit only font. In my experience it is not possible to use a pfa Type 1 or 2 font under XFree86 4 as a proper Unicode font (if you know how to make XFree treat a pfa font as a Unicode font, please let me know so that I can update this document), which means that you will be limited to TTF fonts only.