summaryrefslogtreecommitdiff
path: root/Master/tlpkg/dev/multi-updmap.pl
blob: def1831e8aa174fcd51c2f26767e7c924e59b201 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
#!/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$';

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/ ],
  dvipsDownloadBase35   => [ qw/true false/ ],
  pdftexDownloadBase14  => [ qw/true false/ ],
  dvipdfmDownloadBase14 => [ qw/true false/ ],
);

&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 %data;
  for my $l (@l) {
    my $updmap = read_updmap_file($l);
    if (defined($updmap->{'setting'})) {
      for my $k (keys %{$updmap->{'setting'}}) {
        $data{'updmap'}{$l}{'setting'}{$k} = $updmap->{'setting'}{$k};
      }
    }
    if (defined($updmap->{'maps'})) {
      for my $k (keys %{$updmap->{'maps'}}) {
        $data{'updmap'}{$l}{'maps'}{$k} = $updmap->{'maps'}{$k};
      }
    }
  }
  $data{'order'} = \@l;
  return \%data;
}

sub read_updmap_file {
  my $fn = shift;
  if (!open(FN,"<$fn")) {
    log("Cannot read $fn: $!");
    return;
  }
  my $i = 0;
  my %data;
  while (<FN>) {
    $i++;
    chomp;
    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");
    }
    if (defined($settings{$a})) {
      my @possible_values = @{$settings{$a}};
      if (scalar(grep($_ eq $b, @possible_values))) {
        $data{'setting'}{$a} = $b;
      } else {
        warning("updmap: unknown setting for $a: $b, ignored!\n");
      }
    } elsif ($a eq "Map" || $a eq "MixedMap") {
      if (defined($data{'maps'}{$b}) && $data{'maps'}{$b} ne $a) {
        warning("updmap: double mentioning of $b with conflicting types in $fn\n");
      } else {
        $data{'maps'}{$b} = $a;
      }
    } else {
      warning("updmap: unrecognized line $i in $fn: $_\n");
    }
  }
  close(FN) || warn("Cannot close $fn: $!");
  return \%data;
}

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);
  return if (!$fn);
  open(MF,"<$fn") || return;
  my %data;
  while (<MF>) {
    chomp;
    next if /^\s*$/;
    next if /^\s*%/;
    my ($a, $b) = split(' ', $_, 2);
    $data{$a} = $b;
  }
  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: <http://tug.org/texlive/>
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: #