diff options
Diffstat (limited to 'Build')
-rwxr-xr-x | Build/source/texk/texlive/linked_scripts/pdfcrop/pdfcrop.pl | 206 |
1 files changed, 128 insertions, 78 deletions
diff --git a/Build/source/texk/texlive/linked_scripts/pdfcrop/pdfcrop.pl b/Build/source/texk/texlive/linked_scripts/pdfcrop/pdfcrop.pl index b7662c15f26..c459e5c41e1 100755 --- a/Build/source/texk/texlive/linked_scripts/pdfcrop/pdfcrop.pl +++ b/Build/source/texk/texlive/linked_scripts/pdfcrop/pdfcrop.pl @@ -5,16 +5,12 @@ $^W=1; # turn warning on # pdfcrop.pl # # Copyright (C) 2002, 2004, 2005, 2008-2012 Heiko Oberdiek. +# 2020 Oberdiek Package Support Group # # This program may be distributed and/or modified under the -# conditions of the LaTeX Project Public License, either version 1.2 -# of this license or (at your option) any later version. -# The latest version of this license is in -# http://www.latex-project.org/lppl.txt -# and version 1.2 or later is part of all distributions of LaTeX -# version 1999/12/01 or later. +# conditions of the LaTeX Project Public License, version 1.3c or later. # -# See file "README" for a list of files that belong to this project. +# See file "README.md" for a list of files that belong to this project. # # This file "pdfcrop.pl" may be renamed to "pdfcrop" # for installation purposes. @@ -22,10 +18,10 @@ $^W=1; # turn warning on my $prj = 'pdfcrop'; my $file = "$prj.pl"; my $program = uc($&) if $file =~ /^\w+/; -my $version = "1.38"; -my $date = "2012/11/02"; -my $author = "Heiko Oberdiek"; -my $copyright = "Copyright (c) 2002-2012 by $author."; +my $version = "1.40"; +my $date = "2020/06/06"; +my $author = "Heiko Oberdiek, Oberdiek Package Support Group"; +my $copyright = "Copyright (c) 2002-2020 by $author."; # # Reqirements: Perl5, Ghostscript # History: @@ -107,6 +103,12 @@ my $copyright = "Copyright (c) 2002-2012 by $author."; # * Fix for broken v1.36. # 2012/11/02 v1.38: * Fix for unsufficient cleanup, if function `cleanup' is # prematurely called in `eval' for `symlink' checking. +# 2020/05/24 v1.39: * adapted to pdfversion 2.0, corrected luatex support, +# corrected a problem with xetex. +# 2020/06/06 v1.40: * improved ghostscript detection on windows when a bash is used +# added direct pdf version support to xetex. + + ### program identification my $title = "$program $version, $date - $copyright\n"; @@ -171,7 +173,7 @@ sub find_ghostscript () { print "* Arch name: $archname\n" if $::opt_debug; print "* System: $system\n" if $::opt_debug; my %candidates = ( - 'unix' => [qw|gs gsc|], + 'unix' => [qw|gs gsc gswin64c gswin32c|], 'dos' => [qw|gs386 gs|], 'os2' => [qw|gsos2 gs|], 'win' => [qw|gswin32c gs|], @@ -362,6 +364,7 @@ $::opt_bbox_odd = ""; $::opt_bbox_even = ""; $::opt_initex = 0; $::opt_pdfversion = "auto"; +$::opt_uncompress = 0; sub usage ($) { my $ret = shift; @@ -401,13 +404,15 @@ Expert options: with origin at the lower left corner --bbox-odd Same as --bbox, but for odd pages only ($::opt_bbox_odd) --bbox-even Same as --bbox, but for even pages only ($::opt_bbox_even) - --pdfversion <1.x> | auto | none - Set the PDF version to 1.x, 1 < x < 8. + --pdfversion <x.y> | auto | none + Set the PDF version to x.y, x= 1 or 2, y=0-9. If `auto' is given as value, then the PDF version is taken from the header of the input PDF file. An empty value or `none' uses the default of the TeX engine. ($::opt_pdfversion) + --uncompress creates an uncompressed pdf, + useful for debugging ($bool[$::opt_uncompress]) Input file: If the name is `-', then the standard input is used and the output file name must be explicitly given. @@ -454,6 +459,7 @@ GetOptions( "bbox-even=s" => \$::opt_bbox_even, "restricted" => sub { $restricted = 1; }, "pdfversion=s" => \$::opt_pdfversion, + "uncompress!", ) or usage(1); !$::opt_help or usage(0); @@ -471,10 +477,12 @@ print $title; print "* Restricted mode: ", ($restricted ? "enabled" : "disabled"), "\n" if $::opt_debug; -$::opt_pdfversion =~ /^(|none|auto|1\.([2-7]))$/ +$::opt_pdfversion =~ /^(|none|auto|(([1-2])\.(\d)))$/ or die "!!! Error: Invalid value `$::opt_pdfversion' for option `--pdfversion'!\n"; print "* Option `pdfversion': $::opt_pdfversion\n" if $::opt_debug; $::opt_pdfversion = $2 if $2; +$::opt_pdfmajorversion = $3 if $2; +$::opt_pdfminorversion = $4 if $2; $::opt_pdfversion = '' if $::opt_pdfversion eq 'none'; find_ghostscript(); @@ -721,16 +729,19 @@ if ($::opt_pdfversion eq 'auto') { or die sprintf "!!! Error: Cannot read the header of `%s' failed (%s)!\n", $inputfilesafe, exterr; close(IN); - if ($buf =~ /%PDF-1.([0-7])\s/) { + if ($buf =~ /%PDF-((\d).(\d))\s/) { $::opt_pdfversion = $1; - print "* PDF header: %PDF-1.$::opt_pdfversion\n" if $::opt_verbose; - $::opt_pdfversion = 2 if $::opt_pdfversion < 2; + $::opt_pdfmajorversion = $2; + $::opt_pdfminorversion = $3; + print "* PDF header: %PDF-$::opt_pdfversion\n" if $::opt_verbose; + $::opt_pdfminorversion = 2 if ($::opt_pdfmajorversion < 2 && $::opt_pdfminorversion < 2); + $::opt_pdfversion = $::opt_pdfmajorversion . '.' . $::opt_pdfminorversion; } else { die "!!! Error: Cannot find PDF header of `$inputfilesafe'!\n"; } } -print '* Using PDF minor version: ', +print '* Using PDF version: ', ($::opt_pdfversion ? $::opt_pdfversion : "engine's default"), "\n" if $::opt_debug; @@ -819,75 +830,37 @@ if ($::opt_tex eq 'luatex') { \expandafter\ifx\csname directlua\endcsname\relax \errmessage{LuaTeX not found!}% \else - \begingroup - \newlinechar=10 % - \endlinechar=\newlinechar % - \ifnum0% - \directlua{% - if tex.enableprimitives then - tex.enableprimitives('TEST', { - 'luatexversion', - 'pdfoutput', - 'pdfcompresslevel', - 'pdfhorigin', - 'pdfvorigin', - 'pdfpagewidth', - 'pdfpageheight', - 'pdfmapfile', - 'pdfximage', - 'pdflastximage', - 'pdfrefximage', - 'pdfminorversion', - 'pdfobjcompresslevel', - }) - tex.print('1') - end - }% - \ifx\TESTluatexversion\UnDeFiNeD\else 1\fi % - =11 % - \global\let\luatexversion\luatexversion % - \global\let\pdfoutput\TESTpdfoutput % - \global\let\pdfcompresslevel\TESTpdfcompresslevel % - \global\let\pdfhorigin\TESTpdfhorigin % - \global\let\pdfvorigin\TESTpdfvorigin % - \global\let\pdfpagewidth\TESTpdfpagewidth % - \global\let\pdfpageheight\TESTpdfpageheight % - \global\let\pdfmapfile\TESTpdfmapfile % - \global\let\pdfximage\TESTpdfximage % - \global\let\pdflastximage\TESTpdflastximage % - \global\let\pdfrefximage\TESTpdfrefximage % - \global\let\pdfminorversion\TESTpdfminorversion % - \global\let\pdfobjcompresslevel\TESTpdfobjcompresslevel % - \else % - \errmessage{% - Missing \string\luatexversion % - }% - \fi % - \endgroup % \fi END_TMP } -if ($::opt_tex eq 'pdftex' or $::opt_tex eq 'luatex') { + +my $uncompress = $::opt_uncompress ? '0 ' : '9 '; +if ($::opt_tex eq 'pdftex') { + print TMP "\\pdfcompresslevel=$uncompress "; print TMP <<'END_TMP_HEAD'; \pdfoutput=1 % -\pdfcompresslevel=9 % \csname pdfmapfile\endcsname{} -\def\setpdfversion#1{% +\def\setpdfversion#1#2{% \IfUndefined{pdfobjcompresslevel}{% }{% - \ifnum#1<5 % - \pdfobjcompresslevel=0 % - \else - \pdfobjcompresslevel=2 % - \fi + \ifnum#1=1 % + \ifnum#2<5 + \pdfobjcompresslevel=0 % + \else + \pdfobjcompresslevel=2 % + \fi + \fi }% \IfUndefined{pdfminorversion}{% \IfUndefined{pdfoptionpdfminorversion}{% }{% - \pdfoptionpdfminorversion=#1\relax + \pdfoptionpdfminorversion=#2\relax }% }{% - \pdfminorversion=#1\relax + \pdfminorversion=#2\relax + \IfUndefined{pdfmajorversion}{% + \ifnum#2=0 \pdfminorversion=5\fi} + {\pdfmajorversion=#1\relax}% }% } \def\page #1 [#2 #3 #4 #5]{% @@ -943,13 +916,89 @@ if ($::opt_tex eq 'pdftex' or $::opt_tex eq 'luatex') { }% } END_TMP_HEAD - print TMP "\\setpdfversion{$::opt_pdfversion}\n" if $::opt_pdfversion; + print TMP "\\setpdfversion{$::opt_pdfmajorversion}{$::opt_pdfminorversion}\n" if $::opt_pdfversion; +} +elsif ($::opt_tex eq 'luatex') + { + print TMP "\\pdfvariable compresslevel=$uncompress "; + print TMP <<'END_TMP_HEAD'; +\outputmode=1 % +\pdfextension mapfile {} +\def\setpdfversion#1#2{% + \ifnum#1=1 % + \ifnum#2<5 + \pdfvariable objcompresslevel=0 % + \else + \pdfvariable objcompresslevel=2 % + \fi + \fi + \pdfvariable minorversion= #2 + \pdfvariable majorversion= #1 } +\def\page #1 [#2 #3 #4 #5]{% + \count0=#1\relax + \setbox0=\hbox{% + \saveimageresource page #1 mediabox{\pdffile}% + \useimageresource\lastsavedimageresourceindex + }% + \pdfvariable horigin=-#2bp\relax + \pdfvariable vorigin=#3bp\relax + \pagewidth=#4bp\relax + \advance\pagewidth by -#2bp\relax + \pageheight=#5bp\relax + \advance\pageheight by -#3bp\relax + \ht0=\pageheight + \shipout\box0\relax +} +\def\pageclip #1 [#2 #3 #4 #5][#6 #7 #8 #9]{% + \count0=#1\relax + \dimen0=#4bp\relax \advance\dimen0 by -#2bp\relax + \edef\imagewidth{\the\dimen0}% + \dimen0=#5bp\relax \advance\dimen0 by -#3bp\relax + \edef\imageheight{\the\dimen0}% + \saveimageresource page #1 mediabox{\pdffile}% + \setbox0=\hbox{% + \kern -#2bp\relax + \lower #3bp\hbox{\useimageresource\lastsavedimageresourceindex}% + }% + \wd0=\imagewidth\relax + \ht0=\imageheight\relax + \dp0=0pt\relax + \pdfvariable horigin=#6pt\relax + \pdfvariable vorigin=#7bp\relax + \pagewidth=\imagewidth + \advance\pagewidth by #6bp\relax + \advance\pagewidth by #8bp\relax + \pageheight=\imageheight\relax + \advance\pageheight by #7bp\relax + \advance\pageheight by #9bp\relax + \saveboxresource0\relax + \shipout\hbox{\useboxresource\lastsavedboxresourceindex}% +}% +\def\pageinclude#1{% + \pdfvariable horigin=0pt\relax + \pdfvariable vorigin=0pt\relax + \saveimageresource page #1 mediabox{\pdffile}% + \setbox0=\hbox{\useimageresource\lastsavedimageresourceindex}% + \pagewidth=\wd0\relax + \pageheight=\ht0\relax + \advance\pageheight by \dp0\relax + \shipout\hbox{% + \raise\dp0\box0\relax + }% +} +END_TMP_HEAD + print TMP "\\setpdfversion{$::opt_pdfmajorversion}{$::opt_pdfminorversion}\n" if $::opt_pdfversion; +} else { # XeTeX print TMP <<'END_TMP_HEAD'; \expandafter\ifx\csname XeTeXpdffile\endcsname\relax \errmessage{XeTeX not found or too old!}% \fi +\def\setpdfversion#1#2{% + \special{pdf:majorversion #1}% + \special{pdf:minorversion #2}} + \def\page #1 [#2 #3 #4 #5]{% \count0=#1\relax \setbox0=\hbox{% @@ -990,6 +1039,7 @@ else { # XeTeX }% } END_TMP_HEAD +print TMP "\\setpdfversion{$::opt_pdfmajorversion}{$::opt_pdfminorversion}\n" if $::opt_pdfversion; } print "* Running ghostscript for BoundingBox calculation ...\n" @@ -1183,15 +1233,15 @@ if ($::opt_pdfversion) { read PDF, $header, 9 or die sprintf "!!! Error: Cannot read header of `%s' (%s)!\n", "$tmp.pdf", exterr; - $header =~ /^%PDF-1\.(\d)\s$/ or die "!!! Error: Cannot find header of `$tmp.pdf'!\n"; + $header =~ /^%PDF-(\d\.\d)\s$/ or die "!!! Error: Cannot find header of `$tmp.pdf'!\n"; if ($1 ne $::opt_pdfversion) { - seek PDF, 7, 0 + seek PDF, 5, 0 or die sprintf "!!! Error: Cannot seek in `%s' (%s)!\n", "$tmp.pdf", exterr; print PDF $::opt_pdfversion or die sprintf "!!! Error: Cannot write in `%s' (%s)!\n", "$tmp.pdf", exterr; - print "* PDF version correction in output file: 1.$::opt_pdfversion\n" + print "* PDF version correction in output file: $::opt_pdfversion\n" if $::opt_debug; } close(PDF); |