#! /usr/bin/perl -w # ttfi - a crappy teTeX font install script # Written by Duncan Martin - www.codebunny.org # Released under the BSD licence. Reuse freely, no warranties. # version 1 # known base directories $dir{'base'} = "/usr/local/share/texmf/"; $dir{'dvips'} = "$dir{'base'}dvips/"; $dir{'fontname'} = "$dir{'base'}fontname/"; $file{'updmap'} = "$dir{'base'}web2c/updmap.cfg"; # sub-routines sub search($); sub mv($$); print "foundry (e.g. adobe): "; my $foundry = ; chomp $foundry; print "short font name (e.g. galliard): "; my $shortname = ; chomp $shortname; print "> foundry=$foundry\n> short font name=$shortname\ncontinue? (yes/no) "; my $yes = lc ; chomp $yes; if ($yes ne "yes") { exit 0; } # make sure all directories end with a slash foreach my $onedir (keys %dir) { if ($dir{$onedir} !~ /\/$/g) { $dir{$onedir} .= "/"; } } # look for font files in the current directory opendir DIR, "." or die "couldn't open dir"; foreach my $one (readdir DIR) { if ($one !~ /^(.*)\.(afm|inf|pfb|pfm)$/) { next; } push @all, $one; } closedir DIR; if (@all == 0) { die "no files"; } # read in all the fontname maps foreach my $onefile ("$dir{'fontname'}$foundry.map", glob "$dir{'fontname'}*.map") { print "> fontname map: $onefile\n"; if (! -f $onefile) { next; } open IN, $onefile or die "couldn't open map"; while () { if (/^\@/) { next; } my @line = split; if (!defined $line[4]) { next; } if (!exists $nameconv{$line[4]}) { $nameconv{$line[4]} = $line[0]; } } close IN; } # rename files foreach my $onefile (@all) { my ($l, $r) = ($onefile =~ /(.*)\.(.*)/g); my $newname; if (exists $nameconv{$l}) { $newname = $nameconv{$l}; # print "changing $onefile to $newname.$2\n"; } else { for (;;) { print "enter new name for $l: "; $newname = ; chomp $newname; print "change $l to $newname? (yes/no) "; my $yes = lc ; chomp $yes; if ($yes eq "yes") { last; } } $nameconv{$l} = $newname; } `mv $onefile $newname.$2`; $newname =~ /^(.*?)[_\.]/g; $base{$newname}++; } # determin root my $len = 1; my $first = (keys %base)[0]; OUTER: for (;;) { if ($len > length $first) { last; } foreach my $key (keys %base) { if ((substr $key,0,$len) ne (substr $first,0,$len)) { last OUTER; } } $len++; } $len--; $root = substr $first, 0, $len; if ($len == 0) { die "no common root"; } print "> root=$root\n"; # run fontinst my $fi = `kpsewhich fontinst.sty`; chomp $fi; open OUT,"| latex $fi" or die "couldn't open fontinst"; print OUT "\\latinfamily{$root}{}\n\\bye\n"; close OUT; # convert to bin format foreach (glob "*.pl") { `pltotf $_`; } foreach (glob "*.vpl") { `vptovf $_`; } `rm -f *.vpl *.pl *.mtx`; # get list of new file names my @allfull = ((glob "*.pfa"), (glob "*.pfb")); foreach (@allfull) { /^(.*)\.(.*)$/g; $newshort{$1}++; $end{$1} = $2; } foreach my $key (keys %newshort) { my $name = ""; open IN, "$key.afm" or die "no afm file for $key"; while () { s/\s+$//g; if (/FontName\s+(.*)$/g) { $name = $1; last; } } close IN; if ($name eq "") { die "no name in $key.afm"; } # print "name: $key\n"; my $sc = $key; $sc =~ s/8a/8r/g; push @pslines, "$sc\t$name \" TeXBase1Encoding ReEncodeFont \" ". "<8r.enc <$key.$end{$key}"; } # write style open OUT, "> $shortname.sty" or die "couldn't write style"; print OUT <> $dir{'dvips'}$shortname/$shortname.map" or die "couldn't add to map"; foreach (@pslines) { print OUT "$_\n"; } close OUT; # add style to updmap $foundmap = 0; open IN, $file{'updmap'} or die "couldn't open updmap.cfg"; while () { if (/Map\s+(.*)$/g) { if ($1 eq $shortname.".map") { $foundmap = 1; last; } } } close IN; if (!$foundmap) { `echo "Map $shortname.map" >> $file{'updmap'}`; } `texhash`; `updmap`; # ----- sub mv($$) { my $final = $_[1]; `install -d -m 0755 $final`; `mv $_[0] $final`; } sub search($) { if (-d $dir{'base'}.$_[0]) { return $dir{'base'}.$_[0]; } die "couldn't find $_[0]"; }