Last active
November 21, 2023 21:26
-
-
Save torbiak/3352fe1f559dbfbf99d6f5704adf442e to your computer and use it in GitHub Desktop.
Install ttf and otf fonts for use with groff
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# groff-install-ttf converts a TrueType (ttf) or OpenType (otf) font to a | |
# Printer Font ASCII (pfa) font and a groff font (ditroff) and installs them to | |
# groff's site-font directory. | |
# | |
# Requires fontforge. | |
# | |
# You're the best, Peter Schaffter, but contrary to the verbose and | |
# difficult-to-follow http://www.schaffter.ca/mom/momdoc/appendices.html#fonts, | |
# the t42 file doesn't seem to be necessary, at least with recent versions of | |
# groff. Just copy the groff font and pfa generated by fontforge to both | |
# site-font device directories (devps, devpdf) and update the "download" files | |
# with the internalname -> <pfa> mapping. | |
# | |
# Note that "groffname" needs to match groff's conventions for font styles. | |
# Regular should end with "R", bold with "B", etc. | |
set -eu | |
font=${1:?No font file given}; shift | |
groffname=${1:?No groff font name given, eg TimesR, TimesI, TimesB, etc}; shift | |
name=$(basename "$font" .${font##*.}) | |
prefix=/usr/share/groff | |
fontdir=$prefix/current/font | |
textmap=$fontdir/devps/generate/textmap | |
sitefont=$prefix/site-font | |
trap cleanup EXIT | |
cleanup() { | |
rm -f "$groffname" "$name.pfa" | |
} | |
fontforge -lang=ff -c "Open(\"$font\");Generate(\"$name.pfa\");" | |
afmtodit "$name.afm" "$textmap" "$groffname" | |
mkdir -p "$sitefont" | |
for dir in "$sitefont"/dev{ps,pdf}; do | |
mkdir -p "$dir" | |
cp "$name.pfa" "$groffname" "$dir" | |
done | |
internalname=$(awk '/^internalname/ {print $2}' "$groffname") | |
echo -e "$internalname\t$name.pfa" >>"$fontdir/devps/download" | |
echo -e "\t$internalname\t$name.pfa" >>"$fontdir/devpdf/download" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I think the shebang "/usr/bin/env bash" leads to a problem with the echo flag -e.
Reset it to /usr/bin/bash or /bin/bash (for my Ubuntu Linux).
Also I unpacked the for iteration to make it work:
for dir in "$sitefont"/devps "$sitefont"/devpdf; do
Otherwise the bash script worked well, thank you for sharing it.