Table of Contents

1. Installation of fonts for groff

Below is a script for adding additional fonts for gnu troff. YAD and Fontforge are required for it to run. It accepts True Type (ttf) and Open Type (otf) Fonts and generates device independent typesetter roff fonts (ditroff). It puts them in a postscript device directory (​/usr/share/groff/site-font/devps​/) directory, so that groff can generate postscript files. A command such as

groff -Tps FILE.groff | zathura -

can display such a file.

If you would like to make a Portable Document Format (pdf) file, ps2pdf may be used.

i.e., groff -Tps FILE.groff | ps2pdf - | zathura -

Instead of piping the output to a reader, it may also be sent to a file.

i.e., groff -Tps FILE.groff | ps2pdf - > FILE.pdf

To use the file, it must be executable and have #!/bin/sh at the top. The script must be run as root to put the file in the correct directory.

2. The script

# Choose a font (TTF or OTF) and covert it to be used by groff for making Postscript files
# Needs to be run with root privileges to copy the font to the groff postscript device directory (/usr/share/groff/site-font/devps/)
# Depends on yad and fontforge 

myFONT="$(yad --file\
		--title="Choose a .TTF or .OTF file to convert for groff usage"\

[ -z "$myFONT"] && exit

myDIR=$(dirname "$myFONT")

# Get the font name without its path or extension



groffNAME="$(yad --entry --title="Groff Device Independent Font Name (End with R, B, I, or BI.)"\
		--text="Enter the groff font name you want to use for $myNAME"\
		--mouse --selectable-labels)"

[ -z "$groffNAME"] && exit

# Generate Printer Font Ascii (pfa) and Adobe Font Metrics (afm) files with Fontforge
fontforge -lang=py -c "open(\""$myFONT"\").generate(\""$pfaNAME"\")"

# Convert the AFM file to a Device Independent Typesetter file
afmtodit "$myDIR$myNAME.afm" "$TEXTMAP" "$myDIR$groffNAME"

mkdir -p "$SITEFONT"
[ -f "$myDIR$groffNAME" ] && mv "$myDIR$groffNAME" $SITEFONT/devps/
[ -f "$myDIR$myNAME.afm" ] && rm "$myDIR$myNAME.afm" "$pfaNAME"

yad --title="Groff font installed"\
    --text="The font ($groffNAME) was install."\

Author: marcel

Created: 2022-07-28 Thu 01:42