From 5c91b9f8a88e06f057a6a08b0a755a224d08e019 Mon Sep 17 00:00:00 2001 From: Karl Berry Date: Sat, 18 Nov 2006 01:37:52 +0000 Subject: context 17nov06 update git-svn-id: svn://tug.org/texlive/trunk@2449 c570f23f-e606-0410-a88d-b1316a301751 --- Master/texmf-dist/scripts/context/perl/texfont.pl | 525 +++++++++++++++------- 1 file changed, 370 insertions(+), 155 deletions(-) (limited to 'Master/texmf-dist/scripts/context/perl/texfont.pl') diff --git a/Master/texmf-dist/scripts/context/perl/texfont.pl b/Master/texmf-dist/scripts/context/perl/texfont.pl index 425417374de..ec875e5b472 100644 --- a/Master/texmf-dist/scripts/context/perl/texfont.pl +++ b/Master/texmf-dist/scripts/context/perl/texfont.pl @@ -42,6 +42,7 @@ use Config ; use FindBin ; use File::Copy ; use Getopt::Long ; +use Data::Dumper; $Getopt::Long::passthrough = 1 ; # no error message $Getopt::Long::autoabbrev = 1 ; # partial switch accepted @@ -146,6 +147,7 @@ my $trace = 0 ; my $afmpl = 0 ; my $trees = 'TEXMFFONTS,TEXMFLOCAL,TEXMFEXTRA,TEXMFMAIN,TEXMFDIST' ; my $pattern = '' ; +my $uselmencodings = 0 ; my $fontsuffix = "" ; my $namesuffix = "" ; @@ -198,6 +200,7 @@ my @cleanup = () ; # atl: build list of generated files to delete "expert" => \$expert, "afmpl" => \$afmpl, "afm2pl" => \$afmpl, + "lm" => \$uselmencodings, "rootlist=s" => \$trees, "pattern=s" => \$pattern, "trace" => \$trace, # --verbose conflicts with --ve @@ -549,7 +552,6 @@ if ($sourcepath eq "auto") # todo uppercase root foreach my $sub ("tfm","vf") { foreach my $typ ("","-raw") { my $nam = "$path/fonts/$sub/$vendor/$collection/$encoding$varlabel$typ-$file.$sub" ; - # { my $nam = "$path/fonts/$sub/$vendor/$collection/$encoding$varlabel$typ-$file$fontsuffix.$sub" ; if (-s $nam) { report ("removing : $encoding$varlabel$typ-$file.$sub") ; unlink $nam } } } } @@ -558,11 +560,12 @@ if ($sourcepath eq "auto") # todo uppercase root { report ("removing : $nam") ; unlink "$nam" } my $mapfile = "$encoding$varlabel-$vendor-$collection" ; - my $maproot = "$fontroot/fonts/map/pdftex/context"; - if (-e "$maproot$mapfile.map") - { report ("renaming : $mapfile.map -> $mapfile.bak") ; - unlink "$maproot$mapfile.bak" ; - rename "$maproot$mapfile.map", "$maproot$mapfile.bak" } + foreach my $map ("pdftex","dvips", "dvipdfm") + { my $maproot = "$fontroot/fonts/map/$map/context/"; + if (-e "$maproot$mapfile.map") + { report ("renaming : $mapfile.map -> $mapfile.bak") ; + unlink "$maproot$mapfile.bak" ; + rename "$maproot$mapfile.map", "$maproot$mapfile.bak" } } exit } else { last } } } } @@ -576,9 +579,13 @@ my $tfmpath = "$fontroot/fonts/tfm/$vendor/$collection" ; my $vfpath = "$fontroot/fonts/vf/$vendor/$collection" ; my $pfbpath = "$fontroot/fonts/type1/$vendor/$collection" ; my $ttfpath = "$fontroot/fonts/truetype/$vendor/$collection" ; -my $mappath = "$fontroot/fonts/map/pdftex/context" ; +my $otfpath = "$fontroot/fonts/opentype/$vendor/$collection" ; my $encpath = "$fontroot/fonts/enc/dvips/context" ; +sub mappath + { my $str = shift ; + return "$fontroot/fonts/map/$str/context" } + # are not on local path ! ! ! ! foreach my $path ($afmpath, $pfbpath) @@ -597,20 +604,19 @@ if (($fontroot =~ /texmf\-fonts/o) || (-e "$fontroot/ls-R") || (-e "$fontroot/ls sub do_make_path { my $str = shift ; if ($str =~ /^(.*)\/.*?$/) - { do_make_path($1) } + { do_make_path($1); } mkdir $str, 0755 unless -d $str } sub make_path { my $str = shift ; - do_make_path("$fontroot/fonts") ; - do_make_path("$fontroot/fonts/$str") ; - do_make_path("$fontroot/fonts/$str/$vendor") ; do_make_path("$fontroot/fonts/$str/$vendor/$collection") } if ($makepath&&$install) { make_path ("afm") ; make_path ("type1") } -do_make_path($mappath) ; +do_make_path(mappath("pdftex")) ; +do_make_path(mappath("dvips")) ; +do_make_path(mappath("dvipdfm")) ; do_make_path($encpath) ; # now fonts/map and fonts/enc @@ -624,21 +630,23 @@ if ($install) error ("unknown tfm path $tfmpath") unless -d $tfmpath ; error ("unknown vf path $vfpath" ) unless -d $vfpath ; -error ("unknown map path $mappath") unless -d $mappath ; +error ("unknown map path " . mappath("pdftex")) unless -d mappath("pdftex"); +error ("unknown map path " . mappath("dvips")) unless -d mappath("dvips"); +error ("unknown map path " . mappath("dvipdfm")) unless -d mappath("dvipdfm"); my $mapfile = "$identifier.map" ; my $bakfile = "$identifier.bak" ; my $texfile = "$identifier.tex" ; - report "encoding vector : $encoding" ; + report "encoding vector : $encoding" ; if ($variant) { report "encoding variant : $variant" } report "vendor name : $vendor" ; report " source path : $sourcepath" ; report "font collection : $collection" ; report "texmf font root : $lcfontroot" ; - report "pdftex map file : $mapfile" ; + report " map file name : $mapfile" ; -if ($install) { report "source path : $sourcepath" } +if ($install) { report "source path : $sourcepath" } my $fntlist = "" ; @@ -736,45 +744,74 @@ if ($install) copy_files("ttf",$sourcepath,$ttfpath) } if ($extension eq "otf") { make_path("truetype") ; - copy_files("otf",$sourcepath,$ttfpath) } } + copy_files("otf",$sourcepath,$ttfpath) } } error ("no afm files found") unless @files ; -my $map = my $tex = 0 ; my $mapdata = my $texdata = "" ; - -copy ("$mappath/$mapfile","$mappath/$bakfile") ; - -if (open (MAP,"<$mappath/$mapfile")) - { report ("extending map file : $mappath/$mapfile") ; - while () { unless (/^\%/o) { $mapdata .= $_ } } - close (MAP) } -else - { report ("no map file at : $mappath/$mapfile") } +sub open_mapfile + { my $type = shift; + my $mappath = mappath($type); + my $mapdata = ""; + my $mapptr = undef; + my $fullmapfile = $mapfile; + $fullmapfile = "$type-$fullmapfile" unless $type eq "pdftex"; + if ($install) + { copy ("$mappath/$mapfile","$mappath/$bakfile") ; } + if (open ($mapptr,"<$mappath/$mapfile")) + { report ("extending map file : $mappath/$mapfile") ; + while (<$mapptr>) { unless (/^\%/o) { $mapdata .= $_ } } + close ($mapptr) } + else + { report ("no map file at : $mappath/$mapfile") } + #~ unless (open ($mapptr,">$fullmapfile") ) +do_make_path($mappath) ; + unless (open ($mapptr,">$mappath/$fullmapfile") ) + { report "warning : can't open $fullmapfile" } + else + { if ($type eq "pdftex") + { print $mapptr "% This file is generated by the TeXFont Perl script.\n"; + print $mapptr "%\n" ; + print $mapptr "% You need to add the following line to your file:\n" ; + print $mapptr "%\n" ; + print $mapptr "% \\pdfmapfile{+$mapfile}\n" ; + print $mapptr "%\n" ; + print $mapptr "% In ConTeXt you can best use:\n" ; + print $mapptr "%\n" ; + print $mapptr "% \\loadmapfile\[$mapfile\]\n\n" } } + return ($mapptr,$mapdata) ; } + +sub finish_mapfile + { my ($type, $mapptr, $mapdata ) = @_; + my $fullmapfile = $mapfile; + $fullmapfile = "$type-$fullmapfile" unless $type eq "pdftex"; + if (defined $mapptr) + { report ("updating map file : $mapfile (for $type)") ; + while ($mapdata =~ s/\n\n+/\n/mois) {} ; + $mapdata =~ s/^\s*//gmois ; + print $mapptr $mapdata ; + close ($mapptr) ; + if ($install) + { copy ("$fullmapfile", mappath($type) . "/$mapfile") ; } } } + + +my ($PDFTEXMAP,$pdftexmapdata) = open_mapfile("pdftex"); +my ($DVIPSMAP,$dvipsmapdata) = open_mapfile("dvips"); +my ($DVIPDFMMAP,$dvipdfmmapdata) = open_mapfile("dvipdfm"); + +my $tex = 0 ; +my $texdata = "" ; if (open (TEX,"<$texfile")) { while () { unless (/stoptext/o) { $texdata .= $_ } } close (TEX) } -$map = open (MAP,">$mapfile") ; $tex = open (TEX,">$texfile") ; -unless ($map) { report "warning : can't open $mapfile" } unless ($tex) { report "warning : can't open $texfile" } -if ($map) - { print MAP "% This file is generated by the TeXFont Perl script.\n" ; - print MAP "%\n" ; - print MAP "% You need to add the following line to your file:\n" ; - print MAP "%\n" ; - print MAP "% \\pdfmapfile{+$mapfile}\n" ; - print MAP "%\n" ; - print MAP "% In ConTeXt you can best use:\n" ; - print MAP "%\n" ; - print MAP "% \\loadmapfile\[$mapfile\]\n\n" } - if ($tex) { if ($texdata eq "") - { print TEX "% output=pdftex interface=en\n" ; + { print TEX "% interface=en\n" ; print TEX "\n" ; print TEX "\\usemodule[fnt-01]\n" ; print TEX "\n" ; @@ -811,6 +848,227 @@ if ($encoding ne "") # evt -progname=context { $encfil = `kpsewhich -progname=pdftex $encoding$varlabel.enc` ; chomp $encfil ; if ($encfil eq "") { $encfil = "$encoding$varlabel.enc" } } +sub build_pdftex_mapline + { my ($option, $usename, $fontname, $rawname, $cleanfont, $encoding, $varlabel, $strange) = @_; + my $cleanname = $fontname; + $cleanname =~ s/\_//gio ; + $option =~ s/^\s+(.*)/$1/o ; + $option =~ s/(.*)\s+$/$1/o ; + $option =~ s/ / /g ; + if ($option ne "") + { $option = "\"$option\" 4" } + else + { $option = "4" } + # adding cleanfont is kind of dangerous + my $thename = ""; + my $str = ""; + my $theencoding = "" ; + if ($strange ne "") + { $thename = $cleanname ; $theencoding = "" ; } + elsif ($lcdf) + { $thename = $usename ; $theencoding = " $encoding$varlabel-$cleanname.enc" } + elsif ($afmpl) + { $thename = $usename ; $theencoding = " $encoding$varlabel.enc" } + elsif ($virtual) + { $thename = $rawname ; $theencoding = " $encoding$varlabel.enc" } + else + { $thename = $usename ; $theencoding = " $encoding$varlabel.enc" } +if ($uselmencodings) { + $theencoding =~ s/^(ec)\.enc/lm\-$1.enc/ ; +} + # quit rest if no type 1 file + my $pfb_sourcepath = $sourcepath ; + $pfb_sourcepath =~ s@/afm/@/type1/@ ; + unless ((-e "$pfbpath/$fontname.$extension")|| + (-e "$pfb_sourcepath/$fontname.$extension")|| + (-e "$sourcepath/$fontname.$extension")|| + (-e "$ttfpath/$fontname.$extension")) + { if ($tex) { $report .= "missing file: \\type \{$fontname.pfb\}\n" } + report ("missing pfb file : $fontname.pfb") } + # now add entry to map + if ($strange eq "") { + if ($extension eq "otf") { + if ($lcdf) { + my $mapline = "" ; + if (open(ALTMAP,"texfont.map")) { + while () { + chomp ; + # atl: we assume this b/c we always force otftotfm --no-type1 + if (/<<(.*)\.otf$/oi) { + $mapline = $_ ; last ; + } + } + close(ALTMAP) ; + } else { + report("no mapfile from otftotfm : texfont.map") ; + } + if ($preproc) { + $mapline =~ s/<\[/) + { if (/^\/([^ ]+)\s*\[/) + { $encname = $1; + last; } } + close ENC; } } + if ($strange ne "") + { $thename = $cleanname ; + $optionencoding = "\"$option\"" if length($option)>1; } + elsif ($lcdf) + { $thename = $usename ; + $optionencoding = "\"$option $encname ReEncodeFont\" <$encoding$varlabel-$cleanname.enc" } + elsif ($afmpl) + { $thename = $usename ; + $optionencoding = "\"$option $encname ReEncodeFont\" <$encoding$varlabel.enc" } + elsif ($virtual) + { $thename = $rawname ; + $optionencoding = "\"$option $encname ReEncodeFont\" <$encoding$varlabel.enc" } + else + { $thename = $usename ; + $optionencoding = "\"$option $encname ReEncodeFont\" <$encoding$varlabel.enc" } +if ($uselmencodings) { + $theencoding =~ s/^(ec)\.enc/lm\-$1.enc/ ; +} + # quit rest if no type 1 file + my $pfb_sourcepath = $sourcepath ; + $pfb_sourcepath =~ s@/afm/@/type1/@ ; + unless ((-e "$pfbpath/$fontname.$extension")|| + (-e "$pfb_sourcepath/$fontname.$extension")|| + (-e "$sourcepath/$fontname.$extension")|| + (-e "$ttfpath/$fontname.$extension")) + { if ($tex) { $report .= "missing file: \\type \{$fontname.pfb\}\n" } + report ("missing pfb file : $fontname.pfb") } + # now add entry to map + if ($strange eq "") { + if ($extension eq "otf") { + if ($lcdf) { + my $mapline = "" ; + if (open(ALTMAP,"texfont.map")) { + while () { + chomp ; + # atl: we assume this b/c we always force otftotfm --no-type1 + if (/<<(.*)\.otf$/oi) { + $mapline = $_ ; last ; + } + } + close(ALTMAP) ; + } else { + report("no mapfile from otftotfm : texfont.map") ; + } + if ($preproc) { + $mapline =~ s/<\[/) { - chomp ; - # atl: we assume this b/c we always force otftotfm --no-type1 - if (/<<(.*)\.otf$/oi) { - $mapline = $_ ; last ; - } - } - close(ALTMAP) ; - } else { - report("no mapfile from otftotfm : texfont.map") ; - } - if ($preproc) { - $mapline =~ s/<\[/