-
-
Save wimstockman/2321e529621161e3c4c936266dac4175 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. | |
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 | |
# Do everything in a temp directory. | |
tmp=$(mktemp -d) | |
cd "$tmp" | |
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 | |
rm -rf "$tmp" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment