diff options
author | Karl Berry <karl@freefriends.org> | 2018-03-06 22:50:46 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2018-03-06 22:50:46 +0000 |
commit | 1b9f9a630e0dbc13f5af1f9f8e0153ff67f615e9 (patch) | |
tree | 0e1a7ac8d4b419f87c3016500bca1686bf35b2f2 /Master/texmf-dist/scripts | |
parent | ce82e0db1ca237293778afa35ee3e88a58df53aa (diff) |
ptex-fontmaps (6mar18)
git-svn-id: svn://tug.org/texlive/trunk@46861 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/scripts')
-rwxr-xr-x | Master/texmf-dist/scripts/ptex-fontmaps/kanji-config-updmap.pl | 425 | ||||
-rwxr-xr-x | Master/texmf-dist/scripts/ptex-fontmaps/kanji-fontmap-creator.pl | 8 |
2 files changed, 245 insertions, 188 deletions
diff --git a/Master/texmf-dist/scripts/ptex-fontmaps/kanji-config-updmap.pl b/Master/texmf-dist/scripts/ptex-fontmaps/kanji-config-updmap.pl index dad978ee90a..a5159f26786 100755 --- a/Master/texmf-dist/scripts/ptex-fontmaps/kanji-config-updmap.pl +++ b/Master/texmf-dist/scripts/ptex-fontmaps/kanji-config-updmap.pl @@ -1,12 +1,12 @@ #!/usr/bin/env perl # kanji-config-updmap: setup Japanese font embedding -# Version 20170624.0 +# Version 20180306.0 # # formerly known as updmap-setup-kanji # # Copyright 2004-2006 by KOBAYASHI R. Taizo for the shell version (updmap-otf) -# Copyright 2011-2017 by PREINING Norbert -# Copyright 2016-2017 by Japanese TeX Development Community +# Copyright 2011-2018 by PREINING Norbert +# Copyright 2016-2018 by Japanese TeX Development Community # # This file is licensed under GPL version 3 or any later version. # For copyright statements see end of file. @@ -15,14 +15,14 @@ # https://github.com/texjporg/jfontmaps # # For a changelog see the git log -# +# $^W = 1; use Getopt::Long qw(:config no_autoabbrev ignore_case_always); use strict; my $prg = "kanji-config-updmap"; -my $version = '20170624.0'; +my $version = '20180306.0'; my $updmap_real = "updmap"; my $updmap = $updmap_real; @@ -32,18 +32,23 @@ my $opt_help = 0; my $opt_jis = 0; my $opt_sys = 0; my $opt_user = 0; -my $opt_mode = "ja"; my $opt_old = 0; +my @opt_mode_list; +my $opt_mode_one; +my $opt_mode_ja; +my $opt_mode_sc; +my $opt_mode_tc; +my $opt_mode_ko; if (! GetOptions( "n|dry-run" => \$dry_run, "h|help" => \$opt_help, "jis2004" => \$opt_jis, - "mode=s" => \$opt_mode, - "ja" => sub { $opt_mode = "ja"; }, - "sc" => sub { $opt_mode = "sc"; }, - "tc" => sub { $opt_mode = "tc"; }, - "ko" => sub { $opt_mode = "ko"; }, + "mode=s" => \$opt_mode_one, + "ja=s" => \$opt_mode_ja, + "sc=s" => \$opt_mode_sc, + "tc=s" => \$opt_mode_tc, + "ko=s" => \$opt_mode_ko, "sys" => \$opt_sys, "user" => \$opt_user, "old" => \$opt_old, @@ -51,25 +56,48 @@ if (! GetOptions( die "Try \"$0 --help\" for more information.\n"; } +if ($opt_mode_one) { + if (defined($opt_mode_ja) || defined($opt_mode_sc) || + defined($opt_mode_tc) || defined($opt_mode_ko)) { + die "Options --ja/--sc/--tc/--ko are invalid with --mode=NN!\n"; + } + # define a corresponding option by empty string + if ($opt_mode_one eq "ja") { + $opt_mode_ja = ''; + } elsif ($opt_mode_one eq "sc") { + $opt_mode_sc = ''; + } elsif ($opt_mode_one eq "tc") { + $opt_mode_tc = ''; + } elsif ($opt_mode_one eq "ko") { + $opt_mode_ko = ''; + } else { + die "Unknown mode $opt_mode_one!"; + } +} +push @opt_mode_list, "ja" if (defined($opt_mode_ja)); +push @opt_mode_list, "sc" if (defined($opt_mode_sc)); +push @opt_mode_list, "tc" if (defined($opt_mode_tc)); +push @opt_mode_list, "ko" if (defined($opt_mode_ko)); +if (!@opt_mode_list) { + # default mode needs to be set, define it by empty string + $opt_mode_one = "ja"; + $opt_mode_ja = ''; + push @opt_mode_list, "ja"; +} sub win32 { return ($^O=~/^MSWin(32|64)$/i); } - my $nul = (win32() ? 'nul' : '/dev/null') ; -if ($opt_user && $opt_sys) { - die "Only one of -user and -sys can be used!"; -} - if (defined($ARGV[0]) && $ARGV[0] ne "status") { if (!($opt_user || $opt_sys)) { die "Either -user or -sys mode is required."; } } - -if ($dry_run) { - $updmap = "echo updmap"; +if ($opt_user && $opt_sys) { + die "Only one of -user and -sys can be used!"; } + if ($opt_sys) { $updmap = "$updmap --sys" ; $updmap_real = "$updmap_real --sys" ; @@ -90,158 +118,173 @@ if ($opt_sys) { } } } +if ($dry_run) { + $updmap = "echo updmap"; +} if ($opt_help) { Usage(); - exit 0; + exit(0); } # # representatives of support font families # -my %representatives = ( - "ja" => { - "hiragino" => "HiraMinPro-W3.otf", - "hiragino-pron" => "HiraMinProN-W3.otf", - "hiragino-elcapitan" => "HiraginoSerif-W3.ttc", - "hiragino-elcapitan-pron" => "HiraginoSerif-W3.ttc", - "toppanbunkyu-sierra" => "ToppanBunkyuGothic.ttc", - "morisawa" => "A-OTF-RyuminPro-Light.otf", - "morisawa-pr6n" => "A-OTF-RyuminPr6N-Light.otf", - "kozuka" => "KozMinPro-Regular.otf", - "kozuka-pr6n" => "KozMinPr6N-Regular.otf", - "kozuka-pr6" => "KozMinProVI-Regular.otf", - "ipa" => "ipam.ttf", - "ipaex" => "ipaexm.ttf", - "moga-mobo" => "mogam.ttc", - "moga-mobo-ex" => "mogam.ttc", - "ume" => "ume-tmo3.ttf", - "ms" => "msgothic.ttc", - "ms-osx" => "MS-Gothic.ttf", - "yu-win" => "yugothib.ttf", - "yu-win10" => "YuGothB.ttc", - "yu-osx" => "YuMin-Medium.otf", - "canon" => "FGCCHMW3.TTC", - }, - "sc" => { - "ms" => "simsun.ttc", - #"sinotype" => "STSong.ttf", # removed - "adobe" => "AdobeSongStd-Light.otf", - "fandol" => "FandolSong-Regular.otf", - "founder" => "FZSSK.TTF", - "arphic" => "gbsn00lp.ttf", - "cjkunifonts" => "uming.ttc", - "cjkunifonts-ttf" => "uming.ttf", - }, - "tc" => { - "ms" => "msjh.ttf", - "ms-win10" => "msjh.ttc", - "dynacomware" => "LiSongPro.ttf", - "adobe" => "AdobeMingStd-Light.otf", - "arphic" => "bsmi00lp.ttf", - "cjkunifonts" => "uming.ttc", - "cjkunifonts-ttf" => "uming.ttf", - }, - "ko" => { - "ms" => "batang.ttc", - "apple" => "AppleMyungjo.ttf", - "adobe" => "AdobeMyungjoStd-Medium.otf", - "baekmuk" => "dotum.ttf", # slightly safer than batang.ttf on case-insentive systems - "unfonts" => "UnBatang.ttf", - "solaris" => "h2mjsm.ttf", - } -); -my %available; +my %representatives; +my @databaselist = "ptex-fontmaps-data.dat"; +push @databaselist, "ptex-fontmaps-macos-data.dat"; main(@ARGV); sub version { - my $ret = sprintf "%s version %s\n", - $prg, $version; + my $ret = sprintf "%s version %s\n", $prg, $version; return $ret; } sub Usage { my $usage = <<"EOF"; - $prg Set up embedding of Japanese/Chinese/Korean fonts via updmap.cfg. - - This script searches for some of the most common fonts - for embedding into pdfs by dvipdfmx. - - In addition it allows to set up arbitrary font families - to be embedded into the generated pdf files, as long - as at least the map file otf-<family>.map is present. - Other map files that will be used if available are - - For Japanese: - ptex-<family>.map - uptex-<family>.map - otf-<family>.map - otf-up-<family>.map - - For Korean, Traditional Chinese and Simplified Chinese: - uptex-<NN>-<family>.map - otf-<NN>-<family>.map - (NN being: ko, tc, sc) + $prg $version + Set up embedding of Japanese/Chinese/Korean fonts via updmap.cfg. + + This script searches for some of the most common fonts + for embedding into pdfs by dvipdfmx. + + In addition it allows to set up arbitrary font families + to be embedded into the generated pdf files, as long + as at least the representative map file is present. + Other map files will be used if available: + + For Japanese: + ptex-<family>.map (representative map file) + uptex-<family>.map + otf-<family>.map + otf-up-<family>.map + + For Simplified Chinese, Traditional Chinese and Korean: + uptex-<NN>-<family>.map (representative map file) + otf-<NN>-<family>.map + (NN being: sc, tc, ko) Please see the documentation of updmap for details (updmap --help). Usage: $prg [OPTION] {<fontname>|auto|nofont|status} - <family> embed an arbitrary font family <family>, at least the - map file otf-<family>.map has to be available. - auto: embed one of the following supported font families - automatically: - hiragino, hiragino-pron, hiragino-elcapitan, - hiragino-elcapitan-pron, toppanbunkyu-sierra, - morisawa, morisawa-pr6n, - kozuka, kozuka-pr6n, kozuka-pr6, - ipa, ipaex, moga-mobo, moga-mobo-ex, ume, - ms, ms-osx, - yu-win, yu-win10, yu-osx, - canon - and fall back to not embedding any font if none of them - is available - nofont: embed no fonts (and rely on system fonts when displaying pdfs) - If your system does not have any of the supported font - families as specified above, this target is selected - automatically. - status: get information about current environment and usable font map + <family> Embed an arbitrary font family <family>, at least + the representative map file has to be available. + auto: If the current status is noEmbed or unknown, try to embed + one of the supported font families automatically. + If none of them is available, fall back to nofont + nofont: Embed no fonts (and rely on system fonts when displaying pdfs). + If your system does not have any of the supported font + families, this target is selected automatically. + status: Get information about current environment and usable font maps. Options: - -n, --dry-run do not actually run updmap - -h, --help show this message and exit - --mode=NN setup for Japanese (NN=ja), Korean (NN=ko), + -n, --dry-run Do not actually run updmap + -h, --help Show this message and exit + --mode=NN Setup for Japanese (NN=ja), Korean (NN=ko), Simplified Chinese (NN=sc), Traditional Chinese (NN=tc) - --NN short for --mode=NN - --jis2004 use JIS2004 variants for default fonts of (u)pTeX - --sys run in sys mode, i.e., call updmap -sys - --user run in user mode, i.e., call updmap -user or updmap - by checking the version of the updmap script. If a - non-parsable output of `updmap --version' is found, a new - updmap with --user option is assumed. If this is not the - case, use --old. + --NN Shorthand for --mode=NN + --jis2004 Use JIS2004 variants for default fonts of (u)pTeX + --sys Run in sys mode, i.e., call updmap -sys + --user Run in user mode, i.e., call updmap -user or updmap, + by checking the version of the updmap script. + If a non-parsable output of `updmap --version' is found, + a new updmap with --user option is assumed. + If this is not the case, explicitly use --old. --old Makes $prg call `updmap' without --user argument in user mode. - --version show version information and exit + --version Show version information and exit EOF ; print $usage; - exit 0; + exit(0); } ### +### Collect Database Lines +### + +sub InitDatabase { + %representatives = (); +} + +sub ReadDatabase { + my @curdbl; + # open database + for my $f (@databaselist) { + my $foo = kpse_miscfont($f); + if (!open(FDB, "<$foo")) { + printf STDERR "Cannot find $f, skipping!\n"; + next; + } + @curdbl = <FDB>; + close(FDB); + # parse lines + my $lineno = 0; + chomp(@curdbl); + push @curdbl, ""; # add a "final empty line" to easy parsing + for my $l (@curdbl) { + $lineno++; + next if ($l =~ m/^\s*$/); # skip empty line + next if ($l =~ m/^\s*#/); # skip comment line + $l =~ s/\s*#.*$//; # skip comment after '#' + if ($l =~ m/^JA\((\d+)\):\s*(.*):\s*(.*)$/) { + $representatives{'ja'}{$2}{'priority'} = $1; + $representatives{'ja'}{$2}{'file'} = $3; + next; + } + if ($l =~ m/^SC\((\d+)\):\s*(.*):\s*(.*)$/) { + $representatives{'sc'}{$2}{'priority'} = $1; + $representatives{'sc'}{$2}{'file'} = $3; + next; + } + if ($l =~ m/^TC\((\d+)\):\s*(.*):\s*(.*)$/) { + $representatives{'tc'}{$2}{'priority'} = $1; + $representatives{'tc'}{$2}{'file'} = $3; + next; + } + if ($l =~ m/^KO\((\d+)\):\s*(.*):\s*(.*)$/) { + $representatives{'ko'}{$2}{'priority'} = $1; + $representatives{'ko'}{$2}{'file'} = $3; + next; + } + # we are still here?? + die "Cannot parse \"$foo\" at line $lineno, + exiting. Strange line: >>>$l<<<\n"; + } + } + if (!%representatives) { + die "Candidate list is empty, cannot proceed!\n"; + } +} + +sub kpse_miscfont { + my ($file) = @_; + chomp(my $foo = `kpsewhich -format=miscfont $file`); + # for GitHub repository diretory structure + if ($foo eq "") { + $foo = "database/$file" if (-f "database/$file"); + } + return $foo; +} + +### ### Check Installed Font ### sub CheckInstallFont { - for my $k (keys %{$representatives{$opt_mode}}) { - my $f = `kpsewhich $representatives{$opt_mode}{$k}`; - if (! $?) { - $available{$k} = chomp($f); + for my $opt_mode (@opt_mode_list) { + for my $k (keys %{$representatives{$opt_mode}}) { + my $f = `kpsewhich $representatives{$opt_mode}{$k}{'file'}`; + if ($?) { + $representatives{$opt_mode}{$k}{'available'} = ""; + } else { + $representatives{$opt_mode}{$k}{'available'} = chomp($f); + } } } } @@ -262,27 +305,27 @@ sub check_mapfile { } sub GetStatus { + my $opt_mode = shift; my $val = `$updmap_real --quiet --showoption ${opt_mode}Embed`; my $STATUS; if ($val =~ m/^${opt_mode}Embed=([^()\s]*)(\s+\()?/) { $STATUS = $1; } else { - printf STDERR "Cannot find status of current ${opt_mode}Embed setting via updmap --showoption!\n"; - exit 1; + die "Cannot find status of current ${opt_mode}Embed setting via updmap --showoption!\n"; } my $testmap = ($opt_mode eq "ja" ? "ptex-$STATUS.map" : "uptex-${opt_mode}-$STATUS.map"); if (check_mapfile($testmap)) { print "CURRENT family for $opt_mode: $STATUS\n"; } else { - print "WARNING: Currently selected map file for $opt_mode cannot be found: $testmap\n"; + print STDERR "WARNING: Currently selected map file for $opt_mode cannot be found: $testmap\n"; } for my $k (sort keys %{$representatives{$opt_mode}}) { my $MAPFILE = ($opt_mode eq "ja" ? "ptex-$k.map" : "uptex-${opt_mode}-$k.map"); next if ($MAPFILE eq $testmap); if (check_mapfile($MAPFILE)) { - if ($available{$k}) { + if ($representatives{$opt_mode}{$k}{'available'}) { print "Standby family : $k\n"; } } @@ -295,6 +338,7 @@ sub GetStatus { ### sub SetupMapFile { + my $opt_mode = shift; my $rep = shift; my $MAPFILE = ($opt_mode eq "ja" ? "ptex-$rep.map" : "uptex-${opt_mode}-$rep.map"); if (check_mapfile($MAPFILE)) { @@ -305,70 +349,52 @@ sub SetupMapFile { } else { system("$updmap --quiet --nomkmap --nohash -setoption jaVariant \"\""); } - system("$updmap"); } else { - print "NOT EXIST $MAPFILE\n"; - exit 1; + die "NOT EXIST $MAPFILE\n"; } } sub SetupReplacement { + my $opt_mode = shift; my $rep = shift; if (defined($representatives{$opt_mode}{$rep})) { - if ($available{$rep}) { - return SetupMapFile($rep); + if ($representatives{$opt_mode}{$rep}{'available'}) { + SetupMapFile($opt_mode, $rep); } else { printf STDERR "$rep not available, falling back to auto!\n"; - return SetupReplacement("auto"); + SetupReplacement($opt_mode, "auto"); } } else { if ($rep eq "nofont") { - return SetupMapFile("noEmbed"); + SetupMapFile($opt_mode, "noEmbed"); } elsif ($rep eq "auto") { - my $STATUS = GetStatus(); + my $STATUS = GetStatus($opt_mode); # first check if we have a status set and the font is installed # in this case don't change anything, just make sure - if (defined($representatives{$opt_mode}{$STATUS}) && $available{$STATUS}) { - return SetupMapFile($STATUS); + if (defined($representatives{$opt_mode}{$STATUS}) && + $representatives{$opt_mode}{$STATUS}{'available'}) { + SetupMapFile($opt_mode, $STATUS); } else { if (!($STATUS eq "noEmbed" || $STATUS eq "")) { # some unknown setting is set up currently, overwrite, but warn - print "Previous setting $STATUS for $opt_mode is unknown, replacing it!\n" + print STDERR "Previous setting $STATUS for $opt_mode is unknown, replacing it!\n" } - # if we are in the noEmbed or nothing set case, but one - # of the supported fonts are present then use them - # (originally it said "three fonts hiragino/morisawa/kozuka", but the code below - # was different from this statement; changed to "supported fonts" on 2016/12/08) - my @testlist; - if ($opt_mode eq 'ja') { - @testlist = qw/ - morisawa-pr6n morisawa - hiragino-pron hiragino hiragino-elcapitan-pron hiragino-elcapitan - kozuka-pr6n kozuka-pr6 kozuka - toppanbunkyu-sierra - yu-osx yu-win10 yu-win10 canon - ms ms-osx moga-mobo moga-mobo-ex ume - ipa ipaex/; - } elsif ($opt_mode eq 'tc') { - @testlist = qw/dynacomware adobe ms-win10 ms arphic cjkunifonts cjkunifonts-ttf/; - } elsif ($opt_mode eq 'sc') { - @testlist = qw/fandol adobe ms arphic cjkunifonts cjkunifonts-ttf/; - } elsif ($opt_mode eq 'ko') { - @testlist = qw/apple adobe ms baekmuk unfonts solaris/; - } - # else cannot happen unless getopt is broken - - for my $i (@testlist) { - if ($available{$i}) { - return SetupMapFile($i); + # if we are in the noEmbed or nothing set case, + # and if one of the supported fonts are present, then use them + for my $i (sort { $representatives{$opt_mode}{$a}{'priority'} + <=> + $representatives{$opt_mode}{$b}{'priority'} } + keys %{$representatives{$opt_mode}}) { + if ($representatives{$opt_mode}{$i}{'available'}) { + SetupMapFile($opt_mode, $i); } } # still here, no map file found! - return SetupMapFile("noEmbed"); + SetupMapFile($opt_mode, "noEmbed"); } } else { # anything else is treated as a map file name - return SetupMapFile($rep); + SetupMapFile($opt_mode, $rep); } } } @@ -378,21 +404,52 @@ sub SetupReplacement { ### sub main { + # Number of arguments allowed: + # 0: should be only --NN=<family> lists ('=' can be omitted) + # 1: treated as [--mode=NN] <family> ('=' can be omitted) + # 2 or more: I can't handle! my ($a, $b) = @_; + if (defined($b)) { + die "Number of the arguments should be at most one!\n"; + } + if ($a) { + die "Strange argument found! >>>$a<<<\n" if (!$opt_mode_one); + # argument is passed to defined-but-empty language mode + if (defined($opt_mode_ja) && !$opt_mode_ja) { + $opt_mode_ja = $a; + } elsif (defined($opt_mode_sc) && !$opt_mode_sc) { + $opt_mode_sc = $a; + } elsif (defined($opt_mode_tc) && !$opt_mode_tc) { + $opt_mode_tc = $a; + } elsif (defined($opt_mode_ko) && !$opt_mode_ko) { + $opt_mode_ko = $a; + } + } else { + die "No family or operation is specified for $opt_mode_one!\n", + "Try \"$0 --help\" for more information.\n" if ($opt_mode_one); + } + InitDatabase(); + ReadDatabase(); CheckInstallFont(); - if (!defined($a) || defined($b)) { - Usage(); - exit 1; - } - - if ($a eq "status") { - GetStatus(); - exit 0; + # if one of <family> arguments is "status", then + # all arguments are forced into "status" + if (($opt_mode_ja && ($opt_mode_ja eq "status")) || + ($opt_mode_sc && ($opt_mode_sc eq "status")) || + ($opt_mode_tc && ($opt_mode_tc eq "status")) || + ($opt_mode_ko && ($opt_mode_ko eq "status"))) { + GetStatus("ja") if ($opt_mode_ja); + GetStatus("sc") if ($opt_mode_sc); + GetStatus("tc") if ($opt_mode_tc); + GetStatus("ko") if ($opt_mode_ko); + } else { + SetupReplacement("ja", $opt_mode_ja) if ($opt_mode_ja); + SetupReplacement("sc", $opt_mode_sc) if ($opt_mode_sc); + SetupReplacement("tc", $opt_mode_tc) if ($opt_mode_tc); + SetupReplacement("ko", $opt_mode_ko) if ($opt_mode_ko); + system("$updmap"); } - - return SetupReplacement($a); } # diff --git a/Master/texmf-dist/scripts/ptex-fontmaps/kanji-fontmap-creator.pl b/Master/texmf-dist/scripts/ptex-fontmaps/kanji-fontmap-creator.pl index 6e64d6bc1bf..dc67800d5f2 100755 --- a/Master/texmf-dist/scripts/ptex-fontmaps/kanji-fontmap-creator.pl +++ b/Master/texmf-dist/scripts/ptex-fontmaps/kanji-fontmap-creator.pl @@ -2,10 +2,10 @@ # # kanji-fontmap-creator # (c) 2012-2014 Norbert Preining -# Version: 20170624.0 +# Version: 20180306.0 # Licenced under the GPLv2 or any higher version # -# gui to create map files for updmap(-setup-kanji) +# gui to create map files for (kanji-config-)updmap # # ptex/uptex: # 2 fonts (rml/gbm) @@ -41,7 +41,7 @@ my $opt_help = 0; my $opt_version = 0; my $prg = "kanji-fontmap-creator"; -my $version = "20170624.0"; +my $version = "20180306.0"; # # global vars configuring operation @@ -552,7 +552,7 @@ kanji-fontmap-creator [I<option>] =head1 DESCRIPTION -Create fontmap families for updmap's C<kanjiEmbed> setting. For details +Create fontmap families for updmap's C<jaEmbed> setting. For details see the man page of B<updmap>(1) and the web page L<http://tug.org/texlive/updmap-kanji.html> |