Adding Fonts to Groff
Published at 08:28 on 2 May 2018
Because I’ve had a strange fixation on how to do it (it’s not really practical, given the many limitations and deficiencies of the program), here’s how to add fonts to Groff. Note that when I write “Groff” here, I mean Groff with the PostScript output option.
- Obtain Ghostscript and Fontforge. You will need both in order to add fonts (and if you don’t have Ghostscript, Groff’s usefulness is severely compromised, as per the first link in this article).
- Determine the location of your installation of Groff’s textmap file. Typically this will be in a location like /usr/share/groff/version/font/devps/generate/textmap.
- Create a directory to hold the Groff fonts and font metrics files you will be generating.
- Create a devps subdirectory to this directory. All the files you create should be in this subdirectory.
- Open each font in Fontforge. Note that a typical font family contains four fonts: a normal font, an italic font, a bold font, and a bold italic font. You will have to do the steps below for each of the four fonts in each font family you wish to use.
- Perform the editing steps in the list immediately below on each font.
- Close Fontforge, if desired.
- For each type 42 font you generated, extract an AFM file:
printafm name.t42 > name.afm - Think of a name you wish to call the font on the Groff side. The Groff convention is to have families of fonts that end in “R,” “I,” “B,” and “BI” (for roman, italic, bold, and bold italic variants). E.g. “BaskervilleR,” “BaskervilleI,” “BaskervilleB,” and “BaskervilleBI.”
- For each AFM file, generate a Groff font metrics file (replace textmap-path with the location of the textmap file you determined in step 2 and groff-font-name with the name you came up with in the previous step). If the font is not italic, type:
afmtodit -i0 -m name.afm textmap-path groff-font-name
If it is italic, type:
afmtodit -i50 name.afm textmap-path groff-font-name - If your font contained ligatures, verify the ligatures line in your Groff metrics file is present and contains all ligatures.
- Create a download file in the font directory by following the final list of instructions below.
Editing steps in Fontforge:
- Disable all Apple Mac features, as they are broken in Fontforge: Go to File > Preferences > Mac, delete all entries in the Features tab, then verify the list in the Mapping tab is empty as well. You should only have to do this once for each editing session.
- Open the font file you wish to add to Groff. You will typically have to know where your system keeps fonts in order to do this. This of course varies from system to system.
- Clean up the ligature substitution tables. Modern font files can have complex ligature substitution rules, which tend to confuse Groff. The only thing Groff can support is a single liga table. Select Element > Font Info > Lookups and examine the GSUB tab. If there’s any more than one liga entry, you will have to delete the all but one. If there’s any clig, alig, or dlig entries, they will have to be deleted. Then edit the single remaining liga table and make sure it does what you want. Note that since Groff only supports the fi, ff, fl, ffi, and ffl ligatures, these should be the only ones listed in your table.
- Correct the names of your ligature glyphs. Some fonts use ligature names like “f_i,” “f_l,” “f_f_i,” etc. These will confuse Groff. Only names that exactly mirror the character sequence to be replaced by the ligatures (e.g “fi,” “fl,” “ffi,” etc.) are supported. To do this you must locate the ligatures in the glyphs list (they start at Unicode codepoint FB00), click on the glyph of the appropriate ligature, then use the dialog in Element > Glyph Info to set the name of the glyph.
- Save the font (using File > Save) as a .sfd file. This step is optional, but can be useful if you forget or botch one of the editing steps listed above.
- Generate a type 42 font using File > Generate Fonts. Click on the “Options” button and make sure “TrueType Hints,” “PS Glyph Names,” “OpenType,” “Dummy DSIG,” and “Lookup Names” are checked. No other boxes should be checked. Fontforge may complain about some things being slightly amiss when you try to generate the font. In my experience it has usually been safe to ignore the warnings and just generate the font file.
Steps to create the download file:
- Start by copying the download file from the existing fonts storage area to the Groff font directory you have created (it will typically be in a file like /usr/share/groff/version/font/devps/download).
- For each font file you added, you will have to add a line to the download file. Each line in the file contains the “internalname” value from the Groff font metrics file and the name of the type 42 font file, separated by one or more tab characters.
And that’s “all” you need to do. If you set the GROFF_FONT_PATH environment variable to point to the font directory you created, you should now be able to use those fonts in Groff. The font names you use in Groff will match the names of the Groff font metrics files.
(Updated 16 May 2016 with corrected instructions for running afmtodit
.)