#!/usr/bin/env tclsh # make TeX files for a set of TrueType dingbat faces # 2001 Jul 13 # Released under the terms of the FSF's General Public License # fixme: i should pull the encodings first, then ttf2afm can # embed the encoding # fixme: sometimes assumes the TTFs are in the current dir. # fixme: see if Ghostscript can see other encodings available, if so # pick the one with best coverage and write dvips map to suit # fixme: some decorative fonts may have ligatures, accents, etc. # which may need to be recoded to suit TeX if {[llength $argv] < 2} { puts stderr "Usage: $argv0 ..." puts { for the collection} puts { TrueType files to include} exit 1 } set name [lindex $argv 0] set argv [lrange $argv 1 end] set dir decor/$name file mkdir texmf/dvips/config file mkdir texmf/fonts/afm/$dir file mkdir texmf/fonts/tfm/$dir file mkdir texmf/fonts/ttf/$dir # pass 1: generate unencoded metrics and mappings set psm [open $name.ps w] set dpm [open texmf/dvips/config/$name.map w] foreach i $argv { set f [file root $i] puts -nonewline "$f " flush stdout exec ttf2afm -a $f.ttf >$f.uam set mf [open $f.uam r] while {-1 < [gets $mf line]} { if {1 == [scan $line {FontName %s} facename]} { puts $psm "($facename) (/usr/pkg/share/texmf/fonts/ttf/$dir/$f.ttf) ;" puts $dpm "$f $facename \"\"" break } } close $mf } close $psm close $dpm # pass 2: use Ghostscript to get the default encodings puts "\nGetting encodings" set gs [open [list | gs -dBATCH -dNOPAUSE -q -sDEVICE=nullpage - >$name.gso] w] puts $gs { /doit { .tryloadfont { exch == % print name % begin Encoding == end /Encoding get == } { pop % discard name } ifelse } def} foreach i $argv { puts -nonewline "$i " flush stdout puts $gs "(./$i) doit" flush $gs } close $gs # pass 3: add encodings to Adobe metrics, # generate TeX metrics, reorganise files puts "\nConverting metrics" set gs [open $name.gso r] while {-1<[gets $gs line]} { # sometimes gs writes a little grumble if {![string match {(./*)} $line]} continue set f [string range $line 3 end-5] puts -nonewline "$f " flush stdout set n -1 foreach s [string range [gets $gs] 1 end-1] { set codeof([string range $s 1 end]) [incr n] } set codeof(.notdef) -1 set ufm [open $f.uam r] set afm [open $f.afm w] while {-1<[gets $ufm line]} { if {7 == [scan $line {C %d ; WX %d ; N %s ; B %d %d %d %d } code width glyph ba bb bc bd] && ![catch {set codeof($glyph)} n]} { set line "C $n ; WX $width ; N $glyph ; B $ba $bb $bc $bd ;" } puts $afm $line } close $afm close $ufm unset codeof exec afm2tfm $f file delete $f.uam foreach i {afm tfm ttf} { file rename -force $f.$i texmf/fonts/$i/$dir } } close $gs file delete $name.gso puts {} puts "\nNow:" puts "* transfer the texmf tree into the TeX space," puts "* run texhash," puts "* add `$name.map' on its own line to extra_modules in texmf/dvips/config/updmap," puts "* run texmf/dvips/config/updmap," puts "* append $name.ps to ghostscript/6.01vflib/lib/Fontmap.GS." #eof