#!/bin/bash # set -x TERMSGR0=`tput sgr0` # normal (all attributes off) TERMBOLD=`tput bold` # bold or extra bright TERMSMSO=`tput smso` # standout (usually reverse video) FONTDIR="$HOME/lib/fonts" DITMAPSDIR="$FONTDIR"/DIT-edited/devps/generate DITEDITDIR="$FONTDIR"/DIT-edited/devps DITGENRDIR="$FONTDIR"/DIT-generated/devps AFMORIGDIR="$FONTDIR"/AFM-original AFMGENRDIR="$FONTDIR"/AFM-generated AFMEDITDIR="$FONTDIR"/AFM-edited PFAORIGDIR="$FONTDIR"/PFA-original # PFAEDITDIR="$FONTDIR"/PFA-edited GROFF_FONT_PATH="$FONTDIR"/DIT-edited:"$FONTDIR"/DIT-generated GS_FONTPATH="$PFAORIGDIR" GS_LIB="$FONTDIR/utils" export GS_FONTPATH GS_LIB GROFF_FONT_PATH if test $# -eq 0 then echo "Create font description files for groff." echo "Usage: `basename \"$0\"` _postscript-font-file_ ..." echo "Edit the script itself to change installation directories." exit fi if test "$1" = "-scosf" then scosf=yes shift else scosf=no fi # Main loop: process all file names on the command line. for file do echo -n "${TERMSMSO}$file:${TERMSGR0} " srcfile="$file" dirname="`dirname \"$file\"`" # Binary or ASCII? # Could also use file magic here, but we assume the user is # smart enough to not throw junk at this script. case "$srcfile" in *.PFB ) fonttype=pfb; basename="`basename \"$srcfile\" .PFB`" ;; *.pfb ) fonttype=pfb; basename="`basename \"$srcfile\" .pfb`" ;; *.PFA ) fonttype=pfa; basename="`basename \"$srcfile\" .PFA`" ;; *.pfa ) fonttype=pfa; basename="`basename \"$srcfile\" .pfa`" ;; *.OTF ) fonttype=otf; basename="`basename \"$srcfile\" .OTF`" ;; *.otf ) fonttype=otf; basename="`basename \"$srcfile\" .otf`" ;; * ) fonttype=pfb; basename="`basename \"$srcfile\"`" ;; esac if test $fonttype = pfa then copyfile="$srcfile" elif test $fonttype = pfb then tempfile=`tempfile` pfbtops <"$srcfile" >"$tempfile" copyfile="$tempfile" elif test $fonttype = otf then tempfile=`tempfile` cfftot1 -a "$srcfile" >"$tempfile" copyfile="$tempfile" fi # Determine the name of the font the file encodes. fontname=`sed -ne '1,50s%.*/FontName.*/\([^ ]*\).*%\1%p' <"$copyfile"` if test -z "$fontname" then echo "no FontName found. Ignoring file." test $fonttype = pfb -o $fonttype = otf && rm "$tempfile" continue fi echo "$fontname" ditfile="$DITGENRDIR/$fontname" pfafile="$PFAORIGDIR/$fontname.pfa" # Overwrite without warning, because the installation directory is where # we put copies of the fonts we use, we *never* keep our master copies # of the font files there. echo " Copying file..." cp "$copyfile" "$pfafile" test $fonttype = pfb -o $fonttype = otf && rm "$tempfile" makeafm=true usepfm=false # Look for a customized AFM file. if test $makeafm = true then afmfile="$AFMEDITDIR/$fontname.afm" if test -f "$afmfile" then echo " Using custom AFM file." makeafm=false fi fi # Look for an installed AFM file. if test $makeafm = true then afmfile="$AFMORIGDIR/$fontname.afm" if test -f "$afmfile" then echo " Using installed AFM file." makeafm=false fi fi # Opentype fonts normally don't come with AFM files, # so don't bother looking for one. if test $fonttype = otf then makeafm=false afmfile="$AFMGENRDIR/$fontname.afm" t1rawafm "$pfafile" | head -n -1 >"$afmfile" ot2kpx "$srcfile" >>"$afmfile" echo "EndFontMetrics" >>"$afmfile" fi # Look for an AFM file in the vicinity of the source file. if test $makeafm = true then afmfile="$AFMORIGDIR/$fontname.afm" for tryfile in \ "$dirname"/"$basename".[Aa][Ff][Mm] \ "$dirname"/[Aa][Ff][Mm]/"$basename".[Aa][Ff][Mm] \ "$dirname"/../[Aa][Ff][Mm]/"$basename".[Aa][Ff][Mm] do if test -f "$tryfile" then echo " Found an AFM file." cp "$tryfile" "$afmfile" makeafm=false break fi done fi # Look for a PFM file in the vicinity of the source file. if test $makeafm = true then pfmfile="$PFAORIGDIR/$fontname.pfm" for tryfile in \ "$dirname"/"$basename".[Pp][Ff][Mm] \ "$dirname"/[Pp][Ff][Mm]/"$basename".[Pp][Ff][Mm] \ "$dirname"/../[Pp][Ff][Mm]/"$basename".[Pp][Ff][Mm] do if test -f "$tryfile" then echo " Found a PFM file." cp "$tryfile" "$pfmfile" usepfm=true break fi done fi # No AFM file found. Generate one, possibly with the aid of a PFM file. if test $makeafm = true then echo " Generating AFM file..." # An AFM file generated with the help of a PFM file is more like # an original AFM file than a generated AFM file, so perhaps put it # in AFMORIGDIR? afmfile="$AFMGENRDIR/$fontname.afm" gs -q -dNODISPLAY -dSAFER -dDELAYSAFER \ MakeTransformedFont.ps \ -- pf2afm.ps "$PFAORIGDIR/$fontname" test $usepfm = true && rm -f "$pfmfile" # Sometimes pf2afm fails. Fall back to getafm. if test -s "$PFAORIGDIR/$fontname.afm" then mv "$PFAORIGDIR/$fontname.afm" "$afmfile" else echo "${TERMBOLD}pf2afm failed! Using getafm...${TERMSGR0}" rm "$PFAORIGDIR/$fontname.afm" getafm $fontname | cat $FONTDIR/utils/MakeTransformedFont.ps "$pfafile" - | gs -q -DNODISPLAY -dSAFER - >"$afmfile" fi fi # case $fontname in # *Ital* | *It | *I | *Obl* | *Slanted* | *Script* | CMTI[0-9]* | CMMI[0-9]* ) # isitalic=true ;; # * ) # isitalic=false ;; # esac italicangle=`sed -ne '1,50s%.*/ItalicAngle *\([-0-9.]*\) .*%\1%p' <"$pfafile"` if test -z "$italicangle" -o "$italicangle" = 0 then isitalic=false else isitalic=true fi if test $isitalic = true then italic="-i 50" else italic="" fi # The map file says which Postscript character name is mapped onto which groff character name. # The same Postscript character name can occur multiple times in the file, # but each groff character name may occur at most once (says the manpage). # However, afmtodit does not complain about two Postscript names being mapped to the same # groff name if the font includes only one (but not both) of the Postscript characters. # The encoding file says how grops should encode the PostScript font. # Together with the groff character/number pairs in the font description file, # it is a mapping of groff characters to Postscript characters. case $fontname in Symbol | Symbol-Bold | *-Symbol | *-Symbol-Bold | CMEX* | CMSY* | ESSTIX-Ten) encoding="" special="-s" # mapfile="$DITMAPSDIR/symbolchars" ;; mapfile="$DITMAPSDIR/symbolmap" ;; Symbol-Slanted | *-Symbol-Slanted | *-Symbol-Bold-Slanted | ESSTIX-Nine) encoding="" special="-s" mapfile="$DITMAPSDIR/lgreekmap" ;; CMMI* ) encoding="-e $$DITMAPSDIR/text.enc" special="-s" mapfile="$DITMAPSDIR/mathitalicmap" ;; ZapfDingbats ) encoding="" special="-s" mapfile="$DITMAPSDIR/dingbats.map" ;; * ) special="" if test "$scosf" = "yes" then encoding="-e $DITMAPSDIR/scosf.enc" mapfile="$DITMAPSDIR/scosfmap" ditext="-SC" else encoding="-e $DITMAPSDIR/text.enc" mapfile="$DITMAPSDIR/textmap" ditext="" fi ;; esac test $makeafm = true -a $isitalic = true && echo "${TERMBOLD}Check AFM file for ItalicAngle!${TERMSGR0}" echo " Generating DIT file..." echo " $special $italic $encoding $mapfile" afmtodit $special $italic $encoding -d "$DITEDITDIR"/DESC \ $afmfile $mapfile "$ditfile"$ditext # Ugh! grops doesn't understand absolute file names??? echo " Updating \"download\" file..." if grep -q "^$fontname " "$DITEDITDIR"/download then sed -i -e "/^$fontname /c\ $fontname ../../PFA-original/$fontname.pfa" "$DITEDITDIR"/download else echo "$fontname ../../PFA-original/$fontname.pfa" >>"$DITEDITDIR"/download fi # End of main loop. done