#!/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="$DITEDITDIR":"$DITGENRDIR" 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 # 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 ) ispfb=true; basename="`basename \"$srcfile\" .PFB`";; *.pfb ) ispfb=true; basename="`basename \"$srcfile\" .pfb`";; *.PFA ) ispfb=false; basename="`basename \"$srcfile\" .PFA`";; *.pfa ) ispfb=false; basename="`basename \"$srcfile\" .pfa`";; * ) ispfb=false; basename="`basename \"$srcfile\"`";; esac if test $ispfb = true then tempfile=`tempfile` pfbtops <"$srcfile" >"$tempfile" srcfile="$tempfile" fi # Determine the name of the font the file encodes. fontname=`sed -ne '1,50s%.*/FontName.*/\([^ ]*\).*%\1%p' <"$srcfile"` if test -z "$fontname" then echo "no FontName found. Ignoring file." test $ispfb = true && 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 "$srcfile" "$pfafile" test $ispfb = true && rm "$tempfile" # Try to find a corresponding AFM file. makeafm=true usepfm=false # Look for a customized AFM file. afmfile="$AFMEDITDIR/$fontname.afm" if test -f "$afmfile" then echo " Using custom AFM file." makeafm=false 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 # 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 | *Obl* | *Slanted* | *Script* | CMTI[0-9]* | CMMI[0-9]* ) isitalic=true italic="-i 50" ;; * ) isitalic=false italic="" ;; esac case $fontname in Symbol | Symbol-Bold | CMEX* | CMSY* ) encoding="" special="-s" # mapfile="$DITMAPSDIR/symbolchars" ;; mapfile="$DITMAPSDIR/symbolmap" ;; Symbol-Slanted | *-Symbol-Slanted | *-Symbol-Bold-Slanted ) 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" ;; * ) encoding="-e $DITMAPSDIR/text.enc" special="" mapfile="$DITMAPSDIR/textmap" ;; 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" # 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