diff options
-rwxr-xr-x | Build/source/texk/texlive/linked_scripts/cjk-gs-integrate/cjk-gs-integrate.pl | 155 | ||||
-rwxr-xr-x | Build/source/texk/texlive/linked_scripts/texlive/tlmgr.pl | 23 | ||||
-rw-r--r-- | Master/texmf-dist/doc/fonts/cjk-gs-integrate/ChangeLog | 64 | ||||
-rw-r--r-- | Master/texmf-dist/doc/fonts/cjk-gs-integrate/README.md (renamed from Master/texmf-dist/doc/fonts/cjk-gs-integrate/README) | 0 | ||||
-rw-r--r-- | Master/texmf-dist/doc/fonts/cjk-gs-integrate/macosx-filelist | 45 | ||||
-rwxr-xr-x | Master/texmf-dist/doc/fonts/cjk-gs-integrate/tools/release.sh | 3 | ||||
-rwxr-xr-x | Master/texmf-dist/scripts/cjk-gs-integrate/cjk-gs-integrate.pl | 155 |
7 files changed, 302 insertions, 143 deletions
diff --git a/Build/source/texk/texlive/linked_scripts/cjk-gs-integrate/cjk-gs-integrate.pl b/Build/source/texk/texlive/linked_scripts/cjk-gs-integrate/cjk-gs-integrate.pl index 7641cbcb26b..5a8abcd471d 100755 --- a/Build/source/texk/texlive/linked_scripts/cjk-gs-integrate/cjk-gs-integrate.pl +++ b/Build/source/texk/texlive/linked_scripts/cjk-gs-integrate/cjk-gs-integrate.pl @@ -23,10 +23,11 @@ $^W = 1; use Getopt::Long qw(:config no_autoabbrev ignore_case_always); use File::Basename; use File::Path qw(make_path); +use Cwd 'abs_path'; use strict; (my $prg = basename($0)) =~ s/\.pl$//; -my $version = '20151002.0'; +my $version = '20160115.0'; if (win32()) { print_error("Sorry, currently not supported on Windows!\n"); @@ -216,6 +217,12 @@ my %encode_list = ( UniKS-UTF8-H UniKS-UTF8-V/ ] ); +# +# location where links to fonts in texmf are created, relative to TEXMF +my $otf_pathpart = "fonts/opentype/cjk-gs-integrate"; +my $ttf_pathpart = "fonts/truetype/cjk-gs-integrate"; + + my $dry_run = 0; my $opt_help = 0; my $opt_quiet = 0; @@ -289,7 +296,6 @@ if (defined($opt_texmflink)) { $opt_texmflink = $foo; } - main(@ARGV); # @@ -451,7 +457,7 @@ sub do_otf_fonts { my $ciddest = "$opt_output/CIDFont"; make_dir($fontdest, "cannot create CID snippets there!"); make_dir($ciddest, "cannot link CID fonts there!"); - make_dir("$opt_texmflink/fonts/opentype/cjk-gs-integrate", + make_dir("$opt_texmflink/$otf_pathpart", "cannot link fonts to it!") if $opt_texmflink; for my $k (keys %fontdb) { @@ -459,7 +465,7 @@ sub do_otf_fonts { generate_font_snippet($fontdest, $k, $fontdb{$k}{'class'}, $fontdb{$k}{'target'}); link_font($fontdb{$k}{'target'}, $ciddest, $k); - link_font($fontdb{$k}{'target'}, "$opt_texmflink/fonts/opentype/cjk-gs-integrate") + link_font($fontdb{$k}{'target'}, "$opt_texmflink/$otf_pathpart", "$k.otf") if $opt_texmflink; } } @@ -491,6 +497,35 @@ pop } } +# +# link_font operation +# $opt_force is *not* treated first to warn only +# at really critical cases +# case 1: +# exists, is link, link targets agree +# $opt_force is ignored +# remove or remove+add according to $opt_remove +# case 2: +# exists, is link, dangling symlink +# $opt_force is ignored +# remove or remove+add according to $opt_remove +# case 3: +# exists, is link, link target different +# if $opt_force +# warn, remove or remove+add according to $opt_remove +# else +# error message +# case 4: +# exists, not a link +# if $opt_force +# warn, remove or remove+add according to $opt_remove +# else +# error message +# case 5: +# not exists +# $opt_force is ignored +# do nothing or add according to $opt_remove +# sub link_font { my ($f, $cd, $n) = @_; return if $dry_run; @@ -498,36 +533,47 @@ sub link_font { $n = basename($f); } my $target = "$cd/$n"; - if ($opt_force && -e $target) { - print_info("Removing $target prior to recreation due to --force\n"); - unlink($target) || die "Cannot unlink $target prior to recreation under --force: $!"; - return if $opt_remove; - } + my $do_unlink = 0; if (-l $target) { my $linkt = readlink($target); - if ($linkt && -r $linkt) { + if ($linkt) { if ($linkt eq $f) { - unlink($target) if $opt_remove; - # do nothing, it is the same link + # case 1: exists, link, targets agree + $do_unlink = 1; + } elsif (-r $linkt) { + # case 3: exists, link, targets different + if ($opt_force) { + print_info("Removing link $target due to --force!\n"); + $do_unlink = 1; + } else { + print_error("Link $target already existing, but different target then $target, exiting!\n"); + exit(1); + } } else { - print_error("link $target already existing, but different target then $target, exiting!\n"); - exit(1); + # case 2: dangling symlink + print_warning("Removing dangling symlink $target to $linkt\n"); + $do_unlink = 1; } } else { - print_warning("removing dangling symlink $target to $linkt\n"); - unlink($target); - } - } else { - if (-e $target) { - print_error("$target already existing, but not a link, exiting!\n"); + print_error("This should not happen, we have a link but cannot read the target?\n"); exit(1); + } + } elsif (-r $target) { + # case 4: exists, but not link + if ($opt_force) { + print_info("Removing $target due to --force!\n"); + $do_unlink = 1; } else { - if ($opt_remove) { - unlink($target); - } else { - symlink($f, $target) || die("Cannot link font $f to $target: $!"); - } + print_error("$target already existing, exiting!\n"); + exit(1); } + } # otherwise it is not existing! + + # if we are still here and $do_unlink is set, remove it + unlink($target) if $do_unlink; + # recreate link if we are not in the remove case + if (! $opt_remove) { + symlink($f, $target) || die("Cannot link font $f to $target: $!"); } } @@ -537,7 +583,7 @@ sub do_ttf_fonts { my $outp = ''; make_dir($fontdest, "cannot create CID snippets there!"); make_dir($cidfsubst, "cannot link TTF fonts there!"); - make_dir("$opt_texmflink/fonts/truetype/cjk-gs-integrate", + make_dir("$opt_texmflink/$ttf_pathpart", "cannot link fonts to it!") if $opt_texmflink; for my $k (keys %fontdb) { @@ -546,7 +592,7 @@ sub do_ttf_fonts { $k, $fontdb{$k}{'class'}, $fontdb{$k}{'target'}); $outp .= generate_cidfmap_entry($k, $fontdb{$k}{'class'}, $fontdb{$k}{'ttfname'}, $fontdb{$k}{'subfont'}); link_font($fontdb{$k}{'target'}, $cidfsubst, $fontdb{$k}{'ttfname'}); - link_font($fontdb{$k}{'target'}, "$opt_texmflink/fonts/truetype/cjk-gs-integrate", $fontdb{$k}{'ttfname'}) + link_font($fontdb{$k}{'target'}, "$opt_texmflink/$ttf_pathpart", $fontdb{$k}{'ttfname'}) if $opt_texmflink; } } @@ -689,6 +735,18 @@ sub info_found_fonts { if ($fontdb{$k}{'type'} eq 'TTF') { print "Link: $fontdb{$k}{'ttfname'}\n"; } + my @ks = sort { $fontdb{$k}{'files'}{$a}{'priority'} + <=> + $fontdb{$k}{'files'}{$b}{'priority'} } + keys %{$fontdb{$k}{'files'}}; + # remove the top element which is the winner and shown above + shift @ks; + if (@ks) { + print "Other candidates in decreasing order:\n"; + for my $f (@ks) { + print " ", $fontdb{$k}{'files'}{$f}{'target'}, "\n"; + } + } print "\n"; } } @@ -741,16 +799,22 @@ sub check_for_files { } # if (@extradirs) { - # final dummy directory - push @extradirs, "/this/does/not/really/exists/unless/you/are/stupid"; + # we want that files in OSFONTDIR are found first, before + # links that we have created in TEXMFLOCAL + # Thus, instead of setting OSFONTDIR which is at the *END* of + # the kpsewhich variables OPENTYPEFONTS and TTFONTS, we put + # all these fonts at the front of them # push current value of OSFONTDIR push @extradirs, $ENV{'OSFONTDIR'} if $ENV{'OSFONTDIR'}; - # compose OSFONTDIR - my $osfontdir = join ':', @extradirs; - $ENV{'OSFONTDIR'} = $osfontdir; - } - if ($ENV{'OSFONTDIR'}) { - print_debug("final setting of OSFONTDIR: $ENV{'OSFONTDIR'}\n"); + # update OPENTYPEFONTS and TTFONTS + if (@extradirs) { + my $newotf = join(':', @extradirs) . ':'; + my $newttf = $newotf; + $newotf .= $ENV{'OPENTYPEFONTS'} if ($ENV{'OPENTYPEFONTS'}); + $newttf .= $ENV{'TTFONTS'} if ($ENV{'TTFONTS'}); + $ENV{'OPENTYPEFONTS'} = $newotf; + $ENV{'TTFONTS'} = $newttf; + } } # prepare for kpsewhich call, we need to do quoting my $cmdl = 'kpsewhich '; @@ -766,8 +830,13 @@ sub check_for_files { # map basenames to filenames my %bntofn; for my $f (@foundfiles) { + my $realf = abs_path($f); + if (!$realf) { + print_warning("dead link or strange file found: $f - ignored!\n"); + next; + } my $bn = basename($f); - $bntofn{$bn} = $f; + $bntofn{$bn} = $realf; } if ($opt_debug > 0) { print_debug("dumping font database before file check:\n"); @@ -814,7 +883,7 @@ sub check_for_files { $fontdb{$k}{'subfont'} = $sf if ($fontdb{$k}{'type'} eq 'TTF'); } # not needed anymore - delete $fontdb{$k}{'files'}; + # delete $fontdb{$k}{'files'}; } if ($opt_debug > 0) { print_debug("dumping font database:\n"); @@ -973,7 +1042,7 @@ sub read_font_database { sub find_gs_resource { # we assume that gs is in the path # on Windows we probably have to try something else - my @ret = `gs --help 2>$nul`; + chomp( my @ret = `gs --help 2>$nul` ); my $foundres = ''; if ($?) { print_error("Cannot find gs ...\n"); @@ -982,9 +1051,9 @@ sub find_gs_resource { for (@ret) { if (m!Resource/Font!) { $foundres = $_; - $foundres =~ s/^\s*//; - $foundres =~ s/\s*:\s*$//; - $foundres =~ s!/Font!!; + # extract the first substring of non-space chars + # up to Resource/Font and drop the /Font part + $foundres =~ s!^.*\s(\S*Resource)/Font.*$!$1!; last; } } @@ -1018,9 +1087,9 @@ sub Usage { --filelist FILE read list of available font files from FILE instead of searching with kpathsea --link-texmf [DIR] link fonts into - DIR/fonts/opentype/cjk-gs-integrate + DIR/$otf_pathpart and - DIR/fonts/truetype/cjk-gs-integrate + DIR/$ttf_pathpart where DIR defaults to TEXMFLOCAL --machine-readable output of --list-aliases is machine readable --force do not bail out if linked fonts already exist diff --git a/Build/source/texk/texlive/linked_scripts/texlive/tlmgr.pl b/Build/source/texk/texlive/linked_scripts/texlive/tlmgr.pl index ffddf3b7aa3..98a6b7dcecf 100755 --- a/Build/source/texk/texlive/linked_scripts/texlive/tlmgr.pl +++ b/Build/source/texk/texlive/linked_scripts/texlive/tlmgr.pl @@ -1,13 +1,13 @@ #!/usr/bin/env perl -# $Id: tlmgr.pl 39198 2015-12-25 03:12:03Z preining $ +# $Id: tlmgr.pl 39384 2016-01-14 17:57:13Z karl $ # # Copyright 2008-2015 Norbert Preining # This file is licensed under the GNU General Public License version 2 # or any later version. # -my $svnrev = '$Revision: 39198 $'; -my $datrev = '$Date: 2015-12-25 04:12:03 +0100 (Fri, 25 Dec 2015) $'; +my $svnrev = '$Revision: 39384 $'; +my $datrev = '$Date: 2016-01-14 18:57:13 +0100 (Thu, 14 Jan 2016) $'; my $tlmgrrevision; my $prg; if ($svnrev =~ m/: ([0-9]+) /) { @@ -3182,8 +3182,9 @@ sub action_update { $remove_unwind_container = 1; $unwind_package = $newname; } - my $instret = TeXLive::TLPDB->_install_package("$unwind_package", 0, - [], $localtlpdb); + + my ($instret, $msg) = TeXLive::TLUtils::unpack("$unwind_package", + $localtlpdb->root); if ($instret) { # now we have to include the tlpobj my $tlpobj = TeXLive::TLPOBJ->new; @@ -3196,6 +3197,7 @@ sub action_update { } else { logpackage("failed restore: $pkg ($rev)"); tlwarn("$prg: Restoring of old package did NOT succeed.\n"); + tlwarn("$prg: Error message from unpack: $msg\n"); tlwarn("$prg: Most likely repair: run tlmgr install $pkg and hope.\n"); # TODO_ERRORCHECKING # should we return F_ERROR here??? If we would do this, then @@ -3668,9 +3670,12 @@ sub action_install { info("[$currnr/$totalnr, $estrem/$esttot] ${re}install: $pkg$tagstr [${kb}k]\n"); } if (!$opts{"dry-run"}) { - $remotetlpdb->install_package($pkg, $localtlpdb, - ($packs{$pkg} ? $packs{$pkg} : undef) ); - logpackage("${re}install: $pkg$tagstr"); + if ($remotetlpdb->install_package($pkg, $localtlpdb, + ($packs{$pkg} ? $packs{$pkg} : undef) )) { + logpackage("${re}install: $pkg$tagstr"); + } else { + logpackage("failed ${re}install: $pkg$tagstr"); + } } $donesize += $sizes{$pkg}; $currnr++; @@ -4122,7 +4127,7 @@ sub action_option { init_local_db(); my $ret = $F_OK; if ($what =~ m/^show$/i) { - for my $o (keys %{$localtlpdb->options}) { + for my $o (sort keys %{$localtlpdb->options}) { # ignore some things which are w32 specific next if ($o eq "desktop_integration" && !win32()); next if ($o eq "file_assocs" && !win32()); diff --git a/Master/texmf-dist/doc/fonts/cjk-gs-integrate/ChangeLog b/Master/texmf-dist/doc/fonts/cjk-gs-integrate/ChangeLog index c973e827363..67676d5c93d 100644 --- a/Master/texmf-dist/doc/fonts/cjk-gs-integrate/ChangeLog +++ b/Master/texmf-dist/doc/fonts/cjk-gs-integrate/ChangeLog @@ -1,6 +1,66 @@ +2016-01-15 Norbert Preining <norbert@preining.info> + + * Release 20160115.0 (HEAD -> master) [bfb2c76] + +2016-01-15 Norbert Preining <norbert@preining.info> + + * ship README.md as is, supported by CTAN now [ad27d2b] + +2016-01-15 Norbert Preining <norbert@preining.info> + + * remove unrelated file [5f10f56] + +2016-01-15 Norbert Preining <norbert@preining.info> + + * Release 20160115.0 [5a42230] + +2016-01-14 Norbert Preining <norbert@preining.info> + + * if --link-texmf is passed without argument use TEXMFLOCAL again (origin/master, origin/HEAD) [a4a8228] + +2015-10-21 Norbert Preining <norbert@preining.info> + + * remove cleanup_link and bruteforce [1f9649d] + +2015-10-21 Norbert Preining <norbert@preining.info> + + * fix TTFONT env name [2eee0ce] + +2015-10-20 Norbert Preining <norbert@preining.info> + + * resolve symlinks to make sure we don't catch the wrong files [9f68007] + +2015-10-20 Norbert Preining <norbert@preining.info> + + * put OSFONTDIR before OPENTYPEFONTS and TTFFONTS [c28684d] + +2015-10-19 Norbert Preining <norbert@preining.info> + + * fix problems with links pointing to itself [76e5f82] + +2015-10-19 Norbert Preining <norbert@preining.info> + + * fix name of otf font links in texmf dir [0fc6e58] + +2015-10-11 Norbert Preining <norbert@preining.info> + + * rework link_font to warn only if necessary [c2b986d] + +2015-10-11 Norbert Preining <norbert@preining.info> + + * remove end-of-lines of gs output [157a150] + +2015-10-10 Norbert Preining <norbert@preining.info> + + * better extraction of gs resource (Issue: #6) [c01d79e] + +2015-10-10 Norbert Preining <norbert@preining.info> + + * list other candidates for --list-fonts and --info [bb03240] + 2015-10-02 Norbert Preining <norbert@preining.info> - * Release 20151002.0 (HEAD -> master) [0cab259] + * Release 20151002.0 (tag: 20151002.0) [0cab259] 2015-10-02 Norbert Preining <norbert@preining.info> @@ -8,7 +68,7 @@ 2015-09-28 Norbert Preining <norbert@preining.info> - * update README.md for current status (origin/master, origin/HEAD) [789f124] + * update README.md for current status [789f124] 2015-09-28 Norbert Preining <norbert@preining.info> diff --git a/Master/texmf-dist/doc/fonts/cjk-gs-integrate/README b/Master/texmf-dist/doc/fonts/cjk-gs-integrate/README.md index 8742f2d890f..8742f2d890f 100644 --- a/Master/texmf-dist/doc/fonts/cjk-gs-integrate/README +++ b/Master/texmf-dist/doc/fonts/cjk-gs-integrate/README.md diff --git a/Master/texmf-dist/doc/fonts/cjk-gs-integrate/macosx-filelist b/Master/texmf-dist/doc/fonts/cjk-gs-integrate/macosx-filelist deleted file mode 100644 index 1dcba5e404e..00000000000 --- a/Master/texmf-dist/doc/fonts/cjk-gs-integrate/macosx-filelist +++ /dev/null @@ -1,45 +0,0 @@ -/Library/Fonts/Yu Mincho Medium.otf -/Library/Fonts/Yu Mincho Demibold.otf -/Library/Fonts/Yu Gothic Medium.otf -/Library/Fonts/Yu Gothic Bold.otf -/System/Library/Fonts/ヒラギノ明朝 ProN W6.otf -/System/Library/Fonts/ヒラギノ明朝 ProN W3.otf -/Library/Fonts/ヒラギノ明朝 Pro W6.otf -/Library/Fonts/ヒラギノ明朝 Pro W3.otf -/Library/Fonts/ヒラギノ丸ゴ ProN W4.otf -/Library/Fonts/ヒラギノ丸ゴ Pro W4.otf -/Library/Fonts/ヒラギノ角ゴ StdN W8.otf -/Library/Fonts/ヒラギノ角ゴ Std W8.otf -/System/Library/Fonts/ヒラギノ角ゴ ProN W6.otf -/System/Library/Fonts/ヒラギノ角ゴ ProN W3.otf -/Library/Fonts/ヒラギノ角ゴ Pro W6.otf -/Library/Fonts/ヒラギノ角ゴ Pro W3.otf -/Library/Fonts/Hiragino Sans GB W6.otf -/Library/Fonts/Hiragino Sans GB W3.otf -/Library/Fonts/AppleSDGothicNeo-UltraLight.otf -/Library/Fonts/AppleSDGothicNeo-Thin.otf -/Library/Fonts/AppleSDGothicNeo-SemiBold.otf -/System/Library/Fonts/AppleSDGothicNeo-Regular.otf -/Library/Fonts/AppleSDGothicNeo-Medium.otf -/Library/Fonts/AppleSDGothicNeo-Light.otf -/Library/Fonts/AppleSDGothicNeo-Heavy.otf -/Library/Fonts/AppleSDGothicNeo-ExtraBold.otf -/System/Library/Fonts/AppleSDGothicNeo-Bold.otf -/Library/Fonts/华文细黑.ttf -/Library/Fonts/华文黑体.ttf -/System/Library/Fonts/STHeiti Medium.ttc -/System/Library/Fonts/STHeiti Light.ttc -/Library/Fonts/华文仿宋.ttf -/Library/Fonts/Songti.ttc -/Library/Fonts/NanumScript.ttc -/Library/Fonts/NanumMyeongjo.ttc -/Library/Fonts/NanumGothic.ttc -/Library/Fonts/儷宋 Pro.ttf -/Library/Fonts/儷黑 Pro.ttf -/Library/Fonts/Kaiti.ttc -/Library/TeX/Root/texmf-dist/fonts/truetype/public/ipaex/ipam.ttf -/Library/TeX/Root/texmf-dist/fonts/truetype/public/ipaex/ipag.ttf -/Library/TeX/Root/texmf-dist/fonts/truetype/public/ipaex/ipaexm.ttf -/Library/TeX/Root/texmf-dist/fonts/truetype/public/ipaex/ipaexg.ttf -/Library/Fonts/AppleMyungjo.ttf -/Library/Fonts/AppleGothic.ttf diff --git a/Master/texmf-dist/doc/fonts/cjk-gs-integrate/tools/release.sh b/Master/texmf-dist/doc/fonts/cjk-gs-integrate/tools/release.sh index 4ca8afc93c3..7871fba69de 100755 --- a/Master/texmf-dist/doc/fonts/cjk-gs-integrate/tools/release.sh +++ b/Master/texmf-dist/doc/fonts/cjk-gs-integrate/tools/release.sh @@ -37,7 +37,8 @@ for i in cjk-gs-integrate.pl ; do rm -f ${i}.bak done # rename README.md to README for CTAN -mv README.md README +# not necessary anymore, README.md is acceptable +#mv README.md README cd .. diff -urN $PROJECT-$VER-orig $PROJECT-$VER tar zcf $DIR/$PROJECT-$VER.tar.gz $PROJECT-$VER diff --git a/Master/texmf-dist/scripts/cjk-gs-integrate/cjk-gs-integrate.pl b/Master/texmf-dist/scripts/cjk-gs-integrate/cjk-gs-integrate.pl index 7641cbcb26b..5a8abcd471d 100755 --- a/Master/texmf-dist/scripts/cjk-gs-integrate/cjk-gs-integrate.pl +++ b/Master/texmf-dist/scripts/cjk-gs-integrate/cjk-gs-integrate.pl @@ -23,10 +23,11 @@ $^W = 1; use Getopt::Long qw(:config no_autoabbrev ignore_case_always); use File::Basename; use File::Path qw(make_path); +use Cwd 'abs_path'; use strict; (my $prg = basename($0)) =~ s/\.pl$//; -my $version = '20151002.0'; +my $version = '20160115.0'; if (win32()) { print_error("Sorry, currently not supported on Windows!\n"); @@ -216,6 +217,12 @@ my %encode_list = ( UniKS-UTF8-H UniKS-UTF8-V/ ] ); +# +# location where links to fonts in texmf are created, relative to TEXMF +my $otf_pathpart = "fonts/opentype/cjk-gs-integrate"; +my $ttf_pathpart = "fonts/truetype/cjk-gs-integrate"; + + my $dry_run = 0; my $opt_help = 0; my $opt_quiet = 0; @@ -289,7 +296,6 @@ if (defined($opt_texmflink)) { $opt_texmflink = $foo; } - main(@ARGV); # @@ -451,7 +457,7 @@ sub do_otf_fonts { my $ciddest = "$opt_output/CIDFont"; make_dir($fontdest, "cannot create CID snippets there!"); make_dir($ciddest, "cannot link CID fonts there!"); - make_dir("$opt_texmflink/fonts/opentype/cjk-gs-integrate", + make_dir("$opt_texmflink/$otf_pathpart", "cannot link fonts to it!") if $opt_texmflink; for my $k (keys %fontdb) { @@ -459,7 +465,7 @@ sub do_otf_fonts { generate_font_snippet($fontdest, $k, $fontdb{$k}{'class'}, $fontdb{$k}{'target'}); link_font($fontdb{$k}{'target'}, $ciddest, $k); - link_font($fontdb{$k}{'target'}, "$opt_texmflink/fonts/opentype/cjk-gs-integrate") + link_font($fontdb{$k}{'target'}, "$opt_texmflink/$otf_pathpart", "$k.otf") if $opt_texmflink; } } @@ -491,6 +497,35 @@ pop } } +# +# link_font operation +# $opt_force is *not* treated first to warn only +# at really critical cases +# case 1: +# exists, is link, link targets agree +# $opt_force is ignored +# remove or remove+add according to $opt_remove +# case 2: +# exists, is link, dangling symlink +# $opt_force is ignored +# remove or remove+add according to $opt_remove +# case 3: +# exists, is link, link target different +# if $opt_force +# warn, remove or remove+add according to $opt_remove +# else +# error message +# case 4: +# exists, not a link +# if $opt_force +# warn, remove or remove+add according to $opt_remove +# else +# error message +# case 5: +# not exists +# $opt_force is ignored +# do nothing or add according to $opt_remove +# sub link_font { my ($f, $cd, $n) = @_; return if $dry_run; @@ -498,36 +533,47 @@ sub link_font { $n = basename($f); } my $target = "$cd/$n"; - if ($opt_force && -e $target) { - print_info("Removing $target prior to recreation due to --force\n"); - unlink($target) || die "Cannot unlink $target prior to recreation under --force: $!"; - return if $opt_remove; - } + my $do_unlink = 0; if (-l $target) { my $linkt = readlink($target); - if ($linkt && -r $linkt) { + if ($linkt) { if ($linkt eq $f) { - unlink($target) if $opt_remove; - # do nothing, it is the same link + # case 1: exists, link, targets agree + $do_unlink = 1; + } elsif (-r $linkt) { + # case 3: exists, link, targets different + if ($opt_force) { + print_info("Removing link $target due to --force!\n"); + $do_unlink = 1; + } else { + print_error("Link $target already existing, but different target then $target, exiting!\n"); + exit(1); + } } else { - print_error("link $target already existing, but different target then $target, exiting!\n"); - exit(1); + # case 2: dangling symlink + print_warning("Removing dangling symlink $target to $linkt\n"); + $do_unlink = 1; } } else { - print_warning("removing dangling symlink $target to $linkt\n"); - unlink($target); - } - } else { - if (-e $target) { - print_error("$target already existing, but not a link, exiting!\n"); + print_error("This should not happen, we have a link but cannot read the target?\n"); exit(1); + } + } elsif (-r $target) { + # case 4: exists, but not link + if ($opt_force) { + print_info("Removing $target due to --force!\n"); + $do_unlink = 1; } else { - if ($opt_remove) { - unlink($target); - } else { - symlink($f, $target) || die("Cannot link font $f to $target: $!"); - } + print_error("$target already existing, exiting!\n"); + exit(1); } + } # otherwise it is not existing! + + # if we are still here and $do_unlink is set, remove it + unlink($target) if $do_unlink; + # recreate link if we are not in the remove case + if (! $opt_remove) { + symlink($f, $target) || die("Cannot link font $f to $target: $!"); } } @@ -537,7 +583,7 @@ sub do_ttf_fonts { my $outp = ''; make_dir($fontdest, "cannot create CID snippets there!"); make_dir($cidfsubst, "cannot link TTF fonts there!"); - make_dir("$opt_texmflink/fonts/truetype/cjk-gs-integrate", + make_dir("$opt_texmflink/$ttf_pathpart", "cannot link fonts to it!") if $opt_texmflink; for my $k (keys %fontdb) { @@ -546,7 +592,7 @@ sub do_ttf_fonts { $k, $fontdb{$k}{'class'}, $fontdb{$k}{'target'}); $outp .= generate_cidfmap_entry($k, $fontdb{$k}{'class'}, $fontdb{$k}{'ttfname'}, $fontdb{$k}{'subfont'}); link_font($fontdb{$k}{'target'}, $cidfsubst, $fontdb{$k}{'ttfname'}); - link_font($fontdb{$k}{'target'}, "$opt_texmflink/fonts/truetype/cjk-gs-integrate", $fontdb{$k}{'ttfname'}) + link_font($fontdb{$k}{'target'}, "$opt_texmflink/$ttf_pathpart", $fontdb{$k}{'ttfname'}) if $opt_texmflink; } } @@ -689,6 +735,18 @@ sub info_found_fonts { if ($fontdb{$k}{'type'} eq 'TTF') { print "Link: $fontdb{$k}{'ttfname'}\n"; } + my @ks = sort { $fontdb{$k}{'files'}{$a}{'priority'} + <=> + $fontdb{$k}{'files'}{$b}{'priority'} } + keys %{$fontdb{$k}{'files'}}; + # remove the top element which is the winner and shown above + shift @ks; + if (@ks) { + print "Other candidates in decreasing order:\n"; + for my $f (@ks) { + print " ", $fontdb{$k}{'files'}{$f}{'target'}, "\n"; + } + } print "\n"; } } @@ -741,16 +799,22 @@ sub check_for_files { } # if (@extradirs) { - # final dummy directory - push @extradirs, "/this/does/not/really/exists/unless/you/are/stupid"; + # we want that files in OSFONTDIR are found first, before + # links that we have created in TEXMFLOCAL + # Thus, instead of setting OSFONTDIR which is at the *END* of + # the kpsewhich variables OPENTYPEFONTS and TTFONTS, we put + # all these fonts at the front of them # push current value of OSFONTDIR push @extradirs, $ENV{'OSFONTDIR'} if $ENV{'OSFONTDIR'}; - # compose OSFONTDIR - my $osfontdir = join ':', @extradirs; - $ENV{'OSFONTDIR'} = $osfontdir; - } - if ($ENV{'OSFONTDIR'}) { - print_debug("final setting of OSFONTDIR: $ENV{'OSFONTDIR'}\n"); + # update OPENTYPEFONTS and TTFONTS + if (@extradirs) { + my $newotf = join(':', @extradirs) . ':'; + my $newttf = $newotf; + $newotf .= $ENV{'OPENTYPEFONTS'} if ($ENV{'OPENTYPEFONTS'}); + $newttf .= $ENV{'TTFONTS'} if ($ENV{'TTFONTS'}); + $ENV{'OPENTYPEFONTS'} = $newotf; + $ENV{'TTFONTS'} = $newttf; + } } # prepare for kpsewhich call, we need to do quoting my $cmdl = 'kpsewhich '; @@ -766,8 +830,13 @@ sub check_for_files { # map basenames to filenames my %bntofn; for my $f (@foundfiles) { + my $realf = abs_path($f); + if (!$realf) { + print_warning("dead link or strange file found: $f - ignored!\n"); + next; + } my $bn = basename($f); - $bntofn{$bn} = $f; + $bntofn{$bn} = $realf; } if ($opt_debug > 0) { print_debug("dumping font database before file check:\n"); @@ -814,7 +883,7 @@ sub check_for_files { $fontdb{$k}{'subfont'} = $sf if ($fontdb{$k}{'type'} eq 'TTF'); } # not needed anymore - delete $fontdb{$k}{'files'}; + # delete $fontdb{$k}{'files'}; } if ($opt_debug > 0) { print_debug("dumping font database:\n"); @@ -973,7 +1042,7 @@ sub read_font_database { sub find_gs_resource { # we assume that gs is in the path # on Windows we probably have to try something else - my @ret = `gs --help 2>$nul`; + chomp( my @ret = `gs --help 2>$nul` ); my $foundres = ''; if ($?) { print_error("Cannot find gs ...\n"); @@ -982,9 +1051,9 @@ sub find_gs_resource { for (@ret) { if (m!Resource/Font!) { $foundres = $_; - $foundres =~ s/^\s*//; - $foundres =~ s/\s*:\s*$//; - $foundres =~ s!/Font!!; + # extract the first substring of non-space chars + # up to Resource/Font and drop the /Font part + $foundres =~ s!^.*\s(\S*Resource)/Font.*$!$1!; last; } } @@ -1018,9 +1087,9 @@ sub Usage { --filelist FILE read list of available font files from FILE instead of searching with kpathsea --link-texmf [DIR] link fonts into - DIR/fonts/opentype/cjk-gs-integrate + DIR/$otf_pathpart and - DIR/fonts/truetype/cjk-gs-integrate + DIR/$ttf_pathpart where DIR defaults to TEXMFLOCAL --machine-readable output of --list-aliases is machine readable --force do not bail out if linked fonts already exist |