#!/usr/bin/perl # Installs .ttf fonts for use by TeX/PDFTeX # By Matt Welsh # DO NOT SIMPLY RUN THIS SCRIPT! You should read through it to # understand how it works first. I take no responsibility for damage to # your TeX installation (or anything else) through use of this script. # Main TeX installation root $TEXHOME = "/usr/share/texmf"; # Location of T1-WGL4.enc file $ENCFILE = "/usr/src/freetype-1.2/contrib/ttf2pk/data/T1-WGL4.enc"; open (CMD, "ls|") || die "Can't run ls\n"; while () { chop; if ((/(\S+)\.ttf$/) || (/(\S+)\.TTF$/)) { $fontnames[$i] = $1; $fonts[$i] = $_; $i++; } } close(CMD); # Places to put TTF font information in TeX installation $TTFDIR = "$TEXHOME/fonts/truetype/mdw"; $AFMDIR = "$TEXHOME/fonts/afm/mdw"; $TFMDIR = "$TEXHOME/fonts/tfm/mdw"; $FDDIR = "$TEXHOME/pdftex/ttfonts/"; `mkdir -p $TTFDIR`; `mkdir -p $AFMDIR`; `mkdir -p $TFMDIR`; `mkdir -p $FDDIR`; $MAPFILE = "$TEXHOME/pdftex/config/ttfonts-mdw.map"; `rm -f $MAPFILE`; for ($i = 0; $i <= $#fontnames; $i++) { print "Processing $fonts[$i]...\n"; $fontnames[$i] = lc($fontnames[$i]); `ttf2afm -e $ENCFILE -o $AFMDIR/rec$fontnames[$i].afm $fonts[$i] 2>/dev/null`; open(PIPE, "afm2tfm $AFMDIR/rec$fontnames[$i].afm -T $ENCFILE $TFMDIR/rec$fontnames[$i].tfm|") || die "Can't run afm2tfm\n"; while () { chop; $OUTPUT = $_; } close(PIPE); $OUTPUT2 = "$OUTPUT < $fonts[$i]\n"; `echo \"$OUTPUT2\" >> $MAPFILE`; open(OUT, ">$FDDIR/t1$fontnames[$i].fd") || die "Can't open fd file for writing\n"; print OUT "\\ProvidesFile{t1$fontnames[$i].fd}[$fontnames[$i]]\n"; print OUT "\\DeclareFontFamily{T1}{$fontnames[$i]}{}\n"; print OUT "\\DeclareFontShape{T1}{$fontnames[$i]}{m}{n}{<-> rec$fontnames[$i]}{}\n"; print OUT "\\endinput\n"; close OUT; `cp $fonts[$i] $TTFDIR`; } print "Updating kpathsea database...\n"; `cd $TEXHOME; mv -f ls-R ls-R.bak; ls -R > ls-R`; print "\nEdit $TEXHOME/pdftex/config/pdftex.cfg and add\n"; print " map +ttfonts-mdw.map\n"; print "If not already there.\n"; print "Done\n";