7. Using Type 1 Fonts with Groff

Now that the new font can be used by both X11 and Ghostscript, how can one use the new font with groff? First of all, since we are dealing with type 1 PostScript® fonts, the groff device that is applicable is the ps device. A font file must be created for each font that groff can use. A groff font name is just a file in /usr/share/groff_font/devps. With our example, the font file could be /usr/share/groff_font/devps/SHOWBOAT. The file must be created using tools provided by groff.

The first tool is afmtodit. This is not normally installed, so it must be retrieved from the source distribution. I found I had to change the first line of the file, so I did:

% cp /usr/src/gnu/usr.bin/groff/afmtodit/afmtodit.pl /tmp
% ex /tmp/afmtodit.pl
:1c
#!/usr/bin/perl -P-
.
:wq

This tool will create the groff font file from the metrics file (.afm suffix.) Continuing with our example:

Many .afm files are in Mac format… ^M delimited lines
We need to convert them to UNIX® style ^J delimited lines
% cd /tmp
% cat /usr/local/share/fonts/type1/showboat.afm |
	tr '\015' '\012' >showboat.afm

Now create the groff font file
% cd /usr/share/groff_font/devps
% /tmp/afmtodit.pl -d DESC -e text.enc /tmp/showboat.afm generate/textmap SHOWBOAT

The font can now be referenced with the name SHOWBOAT.

If Ghostscript is used to drive the printers on the system, then nothing more needs to be done. However, if true PostScript® printers are used, then the font must be downloaded to the printer in order for the font to be used (unless the printer happens to have the showboat font built in or on an accessible font disk.) The final step is to create a downloadable font. The pfbtops tool is used to create the .pfa format of the font, and download is modified to reference the new font. The download must reference the internal name of the font. This can easily be determined from the groff font file as illustrated:

Create the .pfa font file
% pfbtops /usr/local/share/fonts/type1/showboat.pfb >showboat.pfa

Of course, if .pfa is already available, just use a symbolic link to reference it.

Get the internal font name
% fgrep internalname SHOWBOAT
internalname Showboat

Tell groff that the font must be downloaded
% ex download
:$a
Showboat      showboat.pfa
.
:wq

To test the font:

% cd /tmp
% cat >example.t <<EOF
.sp 5
.ps 16
This is an example of the Showboat font:
.br
.ps 48
.vs (\n(.s+2)p
.sp
.ft SHOWBOAT
ABCDEFGHI
.br
JKLMNOPQR
.br
STUVWXYZ
.sp
.ps 16
.vs (\n(.s+2)p
.fp 5 SHOWBOAT
.ft R
To use it for the first letter of a paragraph, it will look like:
.sp 50p
\s(48\f5H\s0\fRere is the first sentence of a paragraph that uses the
showboat font as its first letter.
Additional vertical space must be used to allow room for the larger
letter.
EOF
% groff -Tps example.t >example.ps

To use ghostscript/ghostview
% ghostview example.ps

To print it
% lpr -Ppostscript example.ps

References: /usr/src/gnu/usr.bin/groff/afmtodit/afmtodit.man, groff_font(5), groff_char(7), pfbtops(1).

All FreeBSD documents are available for download at https://download.freebsd.org/ftp/doc/

Questions that are not answered by the documentation may be sent to <freebsd-questions@FreeBSD.org>.
Send questions about this document to <freebsd-doc@FreeBSD.org>.