From f6d97752a1aef30cc7808f63802cdbdbbed720de Mon Sep 17 00:00:00 2001 From: Norbert Preining Date: Tue, 16 Aug 2011 07:32:43 +0000 Subject: work on multi-updmap.pl git-svn-id: svn://tug.org/texlive/trunk@23574 c570f23f-e606-0410-a88d-b1316a301751 --- Master/tlpkg/dev/multi-updmap.pl | 298 ++++++++++++++++++++++++++++++++++----- 1 file changed, 261 insertions(+), 37 deletions(-) diff --git a/Master/tlpkg/dev/multi-updmap.pl b/Master/tlpkg/dev/multi-updmap.pl index 006367e9a6a..def1831e8aa 100644 --- a/Master/tlpkg/dev/multi-updmap.pl +++ b/Master/tlpkg/dev/multi-updmap.pl @@ -1,10 +1,42 @@ -#!/usr/bin/perl +#!/usr/bin/env perl +# updmap: utility to maintain map files for outline fonts. +# +# +# Copyright 2011 Norbert Preining +# This file is licensed under the GNU General Public License version 2 +# or any later version. +# +# History: +# Original shell script (C) 2002 Thomas Esser +# first perl variant (C) Fabrice Popineau +# the original version where licensed under the following agreement: +# Anyone may freely use, modify, and/or distribute this file, without +# limitation. +# + +BEGIN { + $^W=1; + $TEXMFROOT = `kpsewhich -var-value=TEXMFROOT`; + if ($?) { + print STDERR "updmap: Cannot find TEXMFROOT, aborting!\n"; + exit 1; + } + chomp($TEXMFROOT = `kpsewhich -var-value=TEXMFROOT`); + unshift (@INC, "$TEXMFROOT/tlpkg"); +} + +my $version = '$Id$'; -$^W = 1; use strict; +use TeXLive::TLUtils qw(mkdirhier mktexupd win32 log); +use Getopt::Long qw(:config no_autoabbrev ignore_case_always); +use Pod::Usage; + +my $short_progname = "updmap"; use Data::Dumper; +my %opts; my %settings = ( dvipsPreferOutline => [ qw/true false/ ], LW35 => [ qw/URW URWkb ADOBE ADOBEkb/ ], @@ -15,43 +47,63 @@ my %settings = ( &main(); +############### + sub main { + testmain(); +} + +sub testmain { + $Data::Dumper::Indent = 1; + my $data = read_updmap_files(); + $data = read_map_files($data); + print Data::Dumper->Dump([$data], [qw(mapdata)]); +} + +##################### +# +# reading updmap-cfg files and the actual map files +# +# the following hash saves *all* the information and is passed around +# we do not fill everything from the very beginning to make sure that +# we only read what is necessary (speed!) +# +# initialized by read_updmap_files +# $data->{'order'} = [ list of updmap in decreasing priority ] +# $data->{'updmap'}{$full_path_name_of_updmap}{'setting'}{$key} = $val +# $data->{'updmap'}{$full_path_name_of_updmap}{'maps'}{$mapname} +# = 'Map'|'MixedMap'|'disabled' +# +# initialized by read_map_files +# $data->{'maps'}{$m}{$font} = $rest +# +# initialized by merge_data +# $data->{'merged'}{'setting'}{$key} = $val +# $data->{'merged'}{'fonts'}{$fontdef} = $rest +# + +sub read_updmap_files { my (@l) = `kpsewhich -all updmap.cfg`; chomp(@l); - my @UpdMaps; - my %MergedData; - # we read it in *reverse* order and simple fill up the combined data - # thus if there are multiple definitions/settings, the one coming from - # the first in the original list will win! - for my $l (reverse @l) { - my $updmap = readUpdmap($l); + my %data; + for my $l (@l) { + my $updmap = read_updmap_file($l); if (defined($updmap->{'setting'})) { for my $k (keys %{$updmap->{'setting'}}) { - $MergedData{'setting'}{$k} = $updmap->{'setting'}{$k}; - } - } - if (defined($updmap->{'MixedMap'})) { - for my $k (keys %{$updmap->{'MixedMap'}}) { - my $mapdata = $updmap->{'MixedMap'}{$k}; - for my $f (keys %$mapdata) { - $MergedData{'fonts'}{$f} = $mapdata->{$f}; - } + $data{'updmap'}{$l}{'setting'}{$k} = $updmap->{'setting'}{$k}; } } - if (defined($updmap->{'Map'})) { - for my $k (keys %{$updmap->{'Map'}}) { - my $mapdata = $updmap->{'Map'}{$k}; - for my $f (keys %$mapdata) { - $MergedData{'fonts'}{$f} = $mapdata->{$f}; - } + if (defined($updmap->{'maps'})) { + for my $k (keys %{$updmap->{'maps'}}) { + $data{'updmap'}{$l}{'maps'}{$k} = $updmap->{'maps'}{$k}; } } } - $Data::Dumper::Indent = 1; - print Data::Dumper->Dump([\%MergedData], [qw(mapdata)]); + $data{'order'} = \@l; + return \%data; } -sub readUpdmap { +sub read_updmap_file { my $fn = shift; if (!open(FN,"<$fn")) { log("Cannot read $fn: $!"); @@ -63,8 +115,24 @@ sub readUpdmap { $i++; chomp; next if /^\s*$/; - next if /^\s*#/; + next if /^\s*#$/; + next if /^\s*#[^!]/; + next if /^#![^ ]/; my ($a, $b, @rest) = split ' '; + if ($a eq "#!") { + if ($b eq "Map" || $b eq "MixedMap") { + my $c = shift @rest; + if (!defined($c)) { + warning("updmap: apparently not a real disable line, ignored: $_\n"); + } else { + if (defined($data{'maps'}{$c})) { + warning("updmap: double mentioning of $c in $fn\n"); + } + $data{'maps'}{$c} = 'disabled'; + } + } + next; + } if (@rest) { warning("updmap: line $i in $fn contains a syntax error, more than two words!\n"); } @@ -76,15 +144,10 @@ sub readUpdmap { warning("updmap: unknown setting for $a: $b, ignored!\n"); } } elsif ($a eq "Map" || $a eq "MixedMap") { - if (defined($data{$a}{$b})) { - warning("updmap: double mentioning of $b in $fn\n"); + if (defined($data{'maps'}{$b}) && $data{'maps'}{$b} ne $a) { + warning("updmap: double mentioning of $b with conflicting types in $fn\n"); } else { - my $ret = readMapFile($b); - if (defined($ret)) { - $data{$a}{$b} = readMapFile($b); - } else { - warning("updmap: map file $b mentioned in $fn cannot be found!\n"); - } + $data{'maps'}{$b} = $a; } } else { warning("updmap: unrecognized line $i in $fn: $_\n"); @@ -94,7 +157,29 @@ sub readUpdmap { return \%data; } -sub readMapFile { +sub read_map_files { + my $data = shift; + if (!defined($data->{'updmap'})) { + return $data; + } + for my $f (keys %{$data->{'updmap'}}) { + next if !defined($data->{'updmap'}{$f}{'maps'}); + for my $m (keys %{$data->{'updmap'}{$f}{'maps'}}) { + # we do not read a map file multiple times, if $data{'maps'}{$m} is + # defined we expect that it was read and do skip it + next if defined($data->{'maps'}{$m}); + my $ret = read_map_file($m); + if (defined($ret)) { + for my $font (keys %$ret) { + $data->{'maps'}{$m}{$font} = $ret->{$font}; + } + } + } + } + return $data; +} + +sub read_map_file { my $mn = shift; my $fn = `kpsewhich $mn`; chomp($fn); @@ -111,6 +196,145 @@ sub readMapFile { return \%data; } + + +sub merge_data { + my $data = shift; + my @l = @{$data->{'order'}}; + # we read it in *reverse* order and simple fill up the combined data + # thus if there are multiple definitions/settings, the one coming from + # the first in the original list will win! + for my $l (reverse @l) { + # merge settings + if (defined($data->{'updmap'}{$l}{'setting'})) { + for my $k (keys %{$data->{'updmap'}{$l}{'setting'}}) { + $data->{'merged'}{'setting'}{$k} = $data->{'updmap'}{$l}{'setting'}{$k}; + } + } + } +} + sub warning { print STDERR @_; } + +# +# help, version etc etc +# + +sub version { + my $ret = sprintf "%s (TeX Live, multi) version %s\n", $short_progname, $version; + return $ret; +} + +sub help { + my $usage = <<"EOF"; +Usage: $short_progname [OPTION] ... [COMMAND] + or: $short_progname-sys [OPTION] ... [COMMAND] + +Update the default font map files used by pdftex, dvips, and dvipdfm(x), +as determined by the configuration file updmap.cfg (the one returned by +running "kpsewhich updmap.cfg"). + +Among other things, these map files are used to determine which fonts +should be used as bitmaps and which as outlines, and to determine which +fonts are included in the output. + +By default, the TeX filename database (ls-R) is also updated. + +Options: + --cnffile FILE read FILE for the updmap configuration + --dvipsoutputdir DIR specify output directory (dvips syntax) + --pdftexoutputdir DIR specify output directory (pdftex syntax) + --outputdir DIR specify output directory (for all files) + --copy cp generic files rather than using symlinks + --force recreate files even if config hasn't changed + --nomkmap do not recreate map files + --nohash do not run texhash + -n, --dry-run only show the configuration, no output + --quiet, --silent reduce verbosity + +Commands: + --help show this message and exit + --version show version information and exit + --showoptions ITEM show alternatives for options + --setoption OPTION VALUE set option, where OPTION is one of: + LW35, dvipsPreferOutline, dvipsDownloadBase35, + or pdftexDownloadBase14 + --setoption OPTION=VALUE as above, just different syntax + --enable MAPTYPE MAPFILE add "MAPTYPE MAPFILE" to updmap.cfg, + where MAPTYPE is either Map or MixedMap + --enable Map=MAPFILE add \"Map MAPFILE\" to updmap.cfg + --enable MixedMap=MAPFILE add \"MixedMap MAPFILE\" to updmap.cfg + --disable MAPFILE disable MAPFILE, whether Map or MixedMap + --listmaps list all active and inactive maps + --listavailablemaps same as --listmaps, but without + unavailable map files + --syncwithtrees disable unavailable map files in updmap.cfg + +Explanation of the map types: the (only) difference between Map and +MixedMap is that MixedMap entries are not added to psfonts_pk.map. +The purpose is to help users with printers that render Type 1 outline +fonts worse than mode-tuned Type 1 bitmap fonts. So, MixedMap is used +for fonts that are available as both Type 1 and Metafont. + +Explanation of the --setoption possibilities: + + dvipsPreferOutline true|false (default true) + Whether dvips uses bitmaps or outlines, when both are available. + dvipsDownloadBase35 true|false (default false) + Whether dvips includes the standard 35 PostScript fonts in its output. + pdftexDownloadBase14 true|false (default true) + Whether pdftex includes the standard 14 PDF fonts in its output. + LW35 URWkb|URW|ADOBEkb|ADOBE (default URWkb) + Adapt the font and file names of the standard 35 PostScript fonts. + URWkb URW fonts with "berry" filenames (e.g. uhvbo8ac.pfb) + URW URW fonts with "vendor" filenames (e.g. n019064l.pfb) + ADOBEkb Adobe fonts with "berry" filenames (e.g. phvbo8an.pfb) + ADOBE Adobe fonts with "vendor" filenames (e.g. hvnbo___.pfb) + + These options are only read and acted on by updmap; dvips, pdftex, etc., + do not know anything about them. They work by changing the default map + file which the programs read, so they can be overridden by specifying + command-line options or configuration files to the programs, as + explained at the beginning of updmap.cfg. + +Explanation of trees and files normally used: + + updmap both reads and writes TEXMFCONFIG/web2c/updmap.cfg, according to + the actions specified. + + updmap writes the map files for dvips (psfonts.map) and pdftex + (pdftex.map) to the TEXMFVAR/fonts/map/updmap/{dvips,pdftex}/ + directories. + + The log file is written to TEXMFVAR/web2c/updmap.log. + + When updmap-sys is run, TEXMFSYSCONFIG and TEXMFSYSVAR are used + instead. This is the only difference between updmap-sys and updmap. + + Other locations can be used if overridden on the command line, or these + trees don't exist, or you are not using the original TeX Live. + + To see the precise locations of the various files that + will be read and written, give the -n option (or read the man page). + +For step-by-step instructions on making new fonts known to TeX, read +http://tug.org/fonts/fontinstall.html. For even more terse +instructions, read the beginning of updmap.cfg. + +Report bugs to: tex-k\@tug.org +TeX Live home page: +EOF +; + print &version(); + print $usage; + exit 0; +} + +### Local Variables: +### perl-indent-level: 2 +### tab-width: 2 +### indent-tabs-mode: nil +### End: +# vim:set tabstop=2 expandtab: # -- cgit v1.2.3