diff options
author | Karl Berry <karl@freefriends.org> | 2016-07-30 23:20:02 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2016-07-30 23:20:02 +0000 |
commit | 7a23af3027d0dbd92cf162ed368fd4542142cb37 (patch) | |
tree | 0750978acb8b700cc5be66e3c0eff3294e1a8604 | |
parent | e96ebef7fcb5a399544c72e789fda889859795c4 (diff) |
pdflatexpicscale (27jul16)
git-svn-id: svn://tug.org/texlive/trunk@41779 c570f23f-e606-0410-a88d-b1316a301751
29 files changed, 723 insertions, 2 deletions
diff --git a/Build/source/texk/texlive/linked_scripts/Makefile.am b/Build/source/texk/texlive/linked_scripts/Makefile.am index 2da60f80c44..29d1a67fd84 100644 --- a/Build/source/texk/texlive/linked_scripts/Makefile.am +++ b/Build/source/texk/texlive/linked_scripts/Makefile.am @@ -152,6 +152,7 @@ texmf_other_scripts = \ oberdiek/pdfatfi.pl \ pax/pdfannotextractor.pl \ pdfcrop/pdfcrop.pl \ + pdflatexpicscale/pdflatexpicscale.pl \ pedigree-perl/pedigree.pl \ perltex/perltex.pl \ petri-nets/pn2pdf \ diff --git a/Build/source/texk/texlive/linked_scripts/Makefile.in b/Build/source/texk/texlive/linked_scripts/Makefile.in index 57e7d5b152a..9b25c09673d 100644 --- a/Build/source/texk/texlive/linked_scripts/Makefile.in +++ b/Build/source/texk/texlive/linked_scripts/Makefile.in @@ -367,6 +367,7 @@ texmf_other_scripts = \ oberdiek/pdfatfi.pl \ pax/pdfannotextractor.pl \ pdfcrop/pdfcrop.pl \ + pdflatexpicscale/pdflatexpicscale.pl \ pedigree-perl/pedigree.pl \ perltex/perltex.pl \ petri-nets/pn2pdf \ diff --git a/Build/source/texk/texlive/linked_scripts/pdflatexpicscale/pdflatexpicscale.pl b/Build/source/texk/texlive/linked_scripts/pdflatexpicscale/pdflatexpicscale.pl new file mode 100755 index 00000000000..638f0bdd2a7 --- /dev/null +++ b/Build/source/texk/texlive/linked_scripts/pdflatexpicscale/pdflatexpicscale.pl @@ -0,0 +1,227 @@ +#!/usr/bin/perl -w +# Scale pictures to be included into a LaTeX generated PDF file. +# version 0.1 written by peter willadt +# contact willadt at t-online.de +# this software is subject to the LaTeX project public license. +# changes: +# 2016-08-01 first public release + +use strict; +use File::Basename; +use File::Spec; +use File::Copy; +use Getopt::Long; + +my $version = '0.1'; +my $versiondate = '2016-07-28'; +my $showversion; + +my $verbose; +my $TeXproject; + +# folders for scaled graphics, relative names +my $printfolderprefix = 'printimg'; +my $previewfolderprefix = 'previewimg'; +my $srcfolder = ''; + +# final resolution. special b/w handling not implemented yet +my $printdpi = 300; +my $printbwdpi = 4 * $printdpi; +my $previewdpi = 72; +my $tolerance = 20; + +# file formats +my %canhandle = +( JPG => '1', + PNG => '1', +); + +# bookkeeping +my %processedimages; +my $copied = 0; +my $scaled = 0; +my $skipped = 0; + +sub printInplaceError +{ + my $filename = shift; + print "I will not do inplace modification of graphics:\n" . + "($filename) will not be processed. (Missing path?)\n"; +} + +sub printMissingError +{ + my $filename = shift; + print "I can not find ($filename). (What have you done?)\n"; +} + +sub handleImage +{ + my $filename = shift; + my $dstwidth = shift; + my $dstheight = shift; + my ($srcwidth, $srcheight, $srcdepth); + my $dstfilename; + my $xfilename; + my @xsrcdirs; + my @dstdirs; + my @convertargs; + my $idstring; + + $dstdirs[0] = '.'; + $dstdirs[1] = $printfolderprefix; + $dstfilename = File::Spec->catfile(@dstdirs, basename($filename)); + if($filename eq $dstfilename){ + unless ($srcfolder > ' ') { + printInplaceError($filename); + $skipped++; + return; + } + $xsrcdirs[0] = $srcfolder; + $xfilename = File::Spec->catfile(@xsrcdirs, basename($filename)); + unless (-e $xfilename){ + printMissingError($xfilename); + $skipped++; + return; + } + $filename = $xfilename; + } + # check for image width and height + $idstring = `identify -format "%w x %h %[depth] " $filename`; + return unless $idstring =~ /(\d+) x (\d+) (\d+)/; + $srcwidth = $1; $srcheight = $2; $srcdepth = $3; + if($srcdepth == 1) { # hires for bw pix + $dstwidth = int($dstwidth * $printbwdpi / 72.27 + .5); + $dstheight = int($dstheight * $printbwdpi / 72.27 + .5); + }else { # moderate res for any other + $dstwidth = int($dstwidth * $printdpi / 72.27 + .5); + $dstheight = int($dstheight * $printdpi / 72.27 + .5); + } + if(-e $dstfilename){ + # if younger and requested size: skip + my ($mtime1, $mtime2, $size1, $size2, $idstring2, $existwidth); + my ($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size, + $atime, $ctime, $blksize, $blocks); + ($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size, + $atime, $mtime1, $ctime, $blksize, $blocks) + = stat($dstfilename); + ($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size, + $atime, $mtime2, $ctime, $blksize, $blocks) + = stat($filename); + if($mtime1 >= $mtime2){ + $idstring2 = `identify -format "%w x %h %[depth] " $dstfilename`; + if($idstring2 =~ /(\d+) x (\d+) (\d+)/){ + $existwidth = $1; + if($existwidth == $dstwidth){ + $processedimages{$filename} = $existwidth; + $skipped++; + return; + } + } + } + } + if(($dstwidth >= $srcwidth) || + ($dstwidth *(100 + $tolerance)/100 >= $srcwidth)) { + # we do no upscaling, but will probably copy the file. + if (defined $processedimages{$filename}){ + $skipped++; + }else { + $processedimages{$filename} = $srcwidth; + print "will copy $filename to $dstfilename\n" if $verbose; + copy($filename, $dstfilename); + $copied++; + return; + } + }else { + if((defined $processedimages{$filename}) && + ($processedimages{$filename} >= $dstwidth)) { + $skipped++; + return; + } + # we do some downscaling + $processedimages{$filename} = $dstwidth; + $convertargs[0] = 'convert'; + $convertargs[1] = ${filename}; + $convertargs[2] = '-resize'; +# $convertargs[3] = "${dstwidth}x${dstheight}!"; + $convertargs[3] = "${dstwidth}x${dstheight}"; + $convertargs[4] = "-density"; + $convertargs[5] = $printdpi; + $convertargs[6] = ${dstfilename}; + print "will @convertargs\n" if $verbose; + system(@convertargs); + $scaled++; + } +} + +sub readlog +{ + my $logfilename = shift; + $logfilename .= '.log'; + my ($picname, $picext, $picwidth, $picheight); + my ($picextu, $needsize); + open LOGFILE, "<$logfilename" or die "Cannot read $logfilename"; + $needsize = 0; + while (<LOGFILE>){ + if (/^Package pdftex\.def Info\: (\S*)\.(\w+) used /){ + $picname = $1; + $picext = $2; + ($picextu = $picext) =~ tr/a-z/A-Z/; + if( defined $canhandle{$picextu}){ + $needsize = 1; + next; + } + } + next unless ($needsize == 1); + next unless /Requested size: (\d+\.\d+)pt x (\d+\.\d+)pt/; + $picwidth = $1; + $picheight = $2; + handleImage("$picname.$picext", $picwidth, $picheight); + $needsize = 0; + } +} + +sub usage +{ + print <<'_endusage'; +pdflatexpicscale will downscale large raster images for your TeX project +to reasonable size. +Basic usage: + pdflatexpicscale myarticle +where your main LaTeX file is called 'myarticle.tex' and a log file exists. +Fine tuning: +--destdir=folder (relative path, must exist, + defaults to 'printimg' subfolder of current folder) +--srcdir=folder (folder to find original images, if this software + can't figure it out on it's own, because you already + used the target directory.) +--printdpi=XXX (default 300) +--tolerance=XX (default 20 Percents over printdpi to ignore scaling) +--verbose (if you want to know what the script attempts to do) +--version (show software version) +_endusage +} + +GetOptions('verbose' => \$verbose, + 'printdpi=i' => \$printdpi, + 'destdir=s' => \$printfolderprefix, + 'tolerance=i' => \$tolerance, + 'srcdir=s' => \$srcfolder, + 'version' => \$showversion); + +$TeXproject = shift; + +if($showversion){ + print "pdflatexpicscale Version $version $versiondate\n"; +} + +unless ($TeXproject gt ' '){ + usage(); + end(); +} + +readlog($TeXproject); +if($verbose) { + print "$copied file(s) copied, $scaled file(s) converted " . + "and $skipped occurence(s) skipped.\n"; +} diff --git a/Build/source/texk/texlive/linked_scripts/scripts.lst b/Build/source/texk/texlive/linked_scripts/scripts.lst index 05c92c4025d..5d55ed8dd35 100644 --- a/Build/source/texk/texlive/linked_scripts/scripts.lst +++ b/Build/source/texk/texlive/linked_scripts/scripts.lst @@ -97,6 +97,7 @@ musixtex/musixtex.lua oberdiek/pdfatfi.pl pax/pdfannotextractor.pl pdfcrop/pdfcrop.pl +pdflatexpicscale/pdflatexpicscale.pl pedigree-perl/pedigree.pl perltex/perltex.pl petri-nets/pn2pdf diff --git a/Master/bin/amd64-freebsd/pdflatexpicscale b/Master/bin/amd64-freebsd/pdflatexpicscale new file mode 120000 index 00000000000..029b2dd62a5 --- /dev/null +++ b/Master/bin/amd64-freebsd/pdflatexpicscale @@ -0,0 +1 @@ +../../texmf-dist/scripts/pdflatexpicscale/pdflatexpicscale.pl
\ No newline at end of file diff --git a/Master/bin/amd64-netbsd/pdflatexpicscale b/Master/bin/amd64-netbsd/pdflatexpicscale new file mode 120000 index 00000000000..029b2dd62a5 --- /dev/null +++ b/Master/bin/amd64-netbsd/pdflatexpicscale @@ -0,0 +1 @@ +../../texmf-dist/scripts/pdflatexpicscale/pdflatexpicscale.pl
\ No newline at end of file diff --git a/Master/bin/armel-linux/pdflatexpicscale b/Master/bin/armel-linux/pdflatexpicscale new file mode 120000 index 00000000000..029b2dd62a5 --- /dev/null +++ b/Master/bin/armel-linux/pdflatexpicscale @@ -0,0 +1 @@ +../../texmf-dist/scripts/pdflatexpicscale/pdflatexpicscale.pl
\ No newline at end of file diff --git a/Master/bin/armhf-linux/pdflatexpicscale b/Master/bin/armhf-linux/pdflatexpicscale new file mode 120000 index 00000000000..029b2dd62a5 --- /dev/null +++ b/Master/bin/armhf-linux/pdflatexpicscale @@ -0,0 +1 @@ +../../texmf-dist/scripts/pdflatexpicscale/pdflatexpicscale.pl
\ No newline at end of file diff --git a/Master/bin/i386-cygwin/pdflatexpicscale b/Master/bin/i386-cygwin/pdflatexpicscale new file mode 120000 index 00000000000..029b2dd62a5 --- /dev/null +++ b/Master/bin/i386-cygwin/pdflatexpicscale @@ -0,0 +1 @@ +../../texmf-dist/scripts/pdflatexpicscale/pdflatexpicscale.pl
\ No newline at end of file diff --git a/Master/bin/i386-freebsd/pdflatexpicscale b/Master/bin/i386-freebsd/pdflatexpicscale new file mode 120000 index 00000000000..029b2dd62a5 --- /dev/null +++ b/Master/bin/i386-freebsd/pdflatexpicscale @@ -0,0 +1 @@ +../../texmf-dist/scripts/pdflatexpicscale/pdflatexpicscale.pl
\ No newline at end of file diff --git a/Master/bin/i386-linux/pdflatexpicscale b/Master/bin/i386-linux/pdflatexpicscale new file mode 120000 index 00000000000..029b2dd62a5 --- /dev/null +++ b/Master/bin/i386-linux/pdflatexpicscale @@ -0,0 +1 @@ +../../texmf-dist/scripts/pdflatexpicscale/pdflatexpicscale.pl
\ No newline at end of file diff --git a/Master/bin/i386-netbsd/pdflatexpicscale b/Master/bin/i386-netbsd/pdflatexpicscale new file mode 120000 index 00000000000..029b2dd62a5 --- /dev/null +++ b/Master/bin/i386-netbsd/pdflatexpicscale @@ -0,0 +1 @@ +../../texmf-dist/scripts/pdflatexpicscale/pdflatexpicscale.pl
\ No newline at end of file diff --git a/Master/bin/i386-solaris/pdflatexpicscale b/Master/bin/i386-solaris/pdflatexpicscale new file mode 120000 index 00000000000..029b2dd62a5 --- /dev/null +++ b/Master/bin/i386-solaris/pdflatexpicscale @@ -0,0 +1 @@ +../../texmf-dist/scripts/pdflatexpicscale/pdflatexpicscale.pl
\ No newline at end of file diff --git a/Master/bin/powerpc-linux/pdflatexpicscale b/Master/bin/powerpc-linux/pdflatexpicscale new file mode 120000 index 00000000000..029b2dd62a5 --- /dev/null +++ b/Master/bin/powerpc-linux/pdflatexpicscale @@ -0,0 +1 @@ +../../texmf-dist/scripts/pdflatexpicscale/pdflatexpicscale.pl
\ No newline at end of file diff --git a/Master/bin/sparc-solaris/pdflatexpicscale b/Master/bin/sparc-solaris/pdflatexpicscale new file mode 120000 index 00000000000..029b2dd62a5 --- /dev/null +++ b/Master/bin/sparc-solaris/pdflatexpicscale @@ -0,0 +1 @@ +../../texmf-dist/scripts/pdflatexpicscale/pdflatexpicscale.pl
\ No newline at end of file diff --git a/Master/bin/universal-darwin/pdflatexpicscale b/Master/bin/universal-darwin/pdflatexpicscale new file mode 120000 index 00000000000..029b2dd62a5 --- /dev/null +++ b/Master/bin/universal-darwin/pdflatexpicscale @@ -0,0 +1 @@ +../../texmf-dist/scripts/pdflatexpicscale/pdflatexpicscale.pl
\ No newline at end of file diff --git a/Master/bin/win32/pdflatexpicscale.exe b/Master/bin/win32/pdflatexpicscale.exe Binary files differnew file mode 100755 index 00000000000..5777d90a17a --- /dev/null +++ b/Master/bin/win32/pdflatexpicscale.exe diff --git a/Master/bin/x86_64-cygwin/pdflatexpicscale b/Master/bin/x86_64-cygwin/pdflatexpicscale new file mode 120000 index 00000000000..029b2dd62a5 --- /dev/null +++ b/Master/bin/x86_64-cygwin/pdflatexpicscale @@ -0,0 +1 @@ +../../texmf-dist/scripts/pdflatexpicscale/pdflatexpicscale.pl
\ No newline at end of file diff --git a/Master/bin/x86_64-darwin/pdflatexpicscale b/Master/bin/x86_64-darwin/pdflatexpicscale new file mode 120000 index 00000000000..029b2dd62a5 --- /dev/null +++ b/Master/bin/x86_64-darwin/pdflatexpicscale @@ -0,0 +1 @@ +../../texmf-dist/scripts/pdflatexpicscale/pdflatexpicscale.pl
\ No newline at end of file diff --git a/Master/bin/x86_64-linux/pdflatexpicscale b/Master/bin/x86_64-linux/pdflatexpicscale new file mode 120000 index 00000000000..029b2dd62a5 --- /dev/null +++ b/Master/bin/x86_64-linux/pdflatexpicscale @@ -0,0 +1 @@ +../../texmf-dist/scripts/pdflatexpicscale/pdflatexpicscale.pl
\ No newline at end of file diff --git a/Master/bin/x86_64-solaris/pdflatexpicscale b/Master/bin/x86_64-solaris/pdflatexpicscale new file mode 120000 index 00000000000..029b2dd62a5 --- /dev/null +++ b/Master/bin/x86_64-solaris/pdflatexpicscale @@ -0,0 +1 @@ +../../texmf-dist/scripts/pdflatexpicscale/pdflatexpicscale.pl
\ No newline at end of file diff --git a/Master/texmf-dist/doc/support/pdflatexpicscale/README b/Master/texmf-dist/doc/support/pdflatexpicscale/README new file mode 100644 index 00000000000..97d31c5d27a --- /dev/null +++ b/Master/texmf-dist/doc/support/pdflatexpicscale/README @@ -0,0 +1,30 @@ +pdflatexpicscale is software to scale pictures down +to a target resolution before creating a PDF document +with PdfLaTeX. + +*Requirements* +Perl and ImageMagick have to be installed. + +*Basic usage* +pdflatex article +pdflatexpicscale.pl article +edit article.tex: insert \graphicspath{{printimg/}} +pdflatex article +and you're done. + +For more information, please consult pdflatexpicscale.pdf. + +*File list* +README This file +pdflatexpicscale.pl Tool, perl code +pdflatexpicscale.pdf Documentation (Installation and usage) +testprinter.ps Resolution test file for your PostScript printer + +*Licensing* +pdflatexpicscale and the accompanying files are +subject to the current version of the +LaTeX project public license (not included). + +*Author* +Peter Willadt +Email: willadt at t-online.de diff --git a/Master/texmf-dist/doc/support/pdflatexpicscale/pdflatexpicscale.pdf b/Master/texmf-dist/doc/support/pdflatexpicscale/pdflatexpicscale.pdf Binary files differnew file mode 100644 index 00000000000..1f8ab3029f0 --- /dev/null +++ b/Master/texmf-dist/doc/support/pdflatexpicscale/pdflatexpicscale.pdf diff --git a/Master/texmf-dist/doc/support/pdflatexpicscale/testprinter.ps b/Master/texmf-dist/doc/support/pdflatexpicscale/testprinter.ps new file mode 100644 index 00000000000..e6e17254a0b --- /dev/null +++ b/Master/texmf-dist/doc/support/pdflatexpicscale/testprinter.ps @@ -0,0 +1,206 @@ +%!PS +% Halftone testing inspired by PS by Example P. 544 ff +% Willadt 2016-07-27 +/prozente 20 string def + +/Palatino-Roman findfont +36 scalefont +setfont +72 60 moveto +(Gray scale test) show + +/Palatino-Roman findfont +10 scalefont +setfont + +444 60 moveto +(Version 2016-07-27) show +72 100 translate + +/raster +{ + 5 mul + dup + 0 60 moveto + 0 setgray + prozente cvs show + ( lpi) show + 0 {dup mul exch dup mul add 1 exch sub } setscreen + .45 setgray + 0 0 moveto + 0 50 lineto + 10 50 lineto + 10 0 lineto + closepath + fill + .5 setgray + 10 0 moveto + 10 50 lineto + 20 50 lineto + 20 0 lineto + closepath + fill + .55 setgray + 20 0 moveto + 20 50 lineto + 30 50 lineto + 30 0 lineto + closepath + fill + .6 setgray + 30 0 moveto + 30 50 lineto + 40 50 lineto + 40 0 lineto + closepath + fill + .65 setgray + 40 0 moveto + 40 50 lineto + 50 50 lineto + 50 0 lineto + closepath + fill + 60 0 translate +} def + +/rechteck +{ + 0 0 moveto + 0 50 lineto + 40 50 lineto + 40 0 lineto + closepath + dup +% gsave + setgray + fill +% grestore + 100 mul + 0 60 moveto + 0 setgray + prozente cvs show + ( %) show + 50 0 translate +} def + +0 rechteck +0.02 rechteck +0.04 rechteck +0.06 rechteck +0.08 rechteck +0.1 rechteck +0.12 rechteck +0.15 rechteck +0.2 rechteck +-450 80 translate +0.8 rechteck +0.85 rechteck +0.88 rechteck +0.9 rechteck +0.92 rechteck +0.94 rechteck +0.96 rechteck +0.98 rechteck +1 rechteck +-450 80 translate +/Palatino-Roman findfont +36 scalefont +setfont +0 0 moveto +(Raster test) show +0 0 moveto +0 50 translate +/Palatino-Roman findfont +10 scalefont +setfont + +0 setgray +5 raster +6 raster +7 raster +8 raster +9 raster +10 raster +11 raster +12 raster +-480 70 translate +13 raster +14 raster +15 raster +16 raster +17 raster +18 raster +19 raster +20 raster +-480 70 translate +21 raster +22 raster +23 raster +24 raster +25 raster +26 raster +27 raster +28 raster +-480 70 translate +0 setgray +/Palatino-Roman findfont +36 scalefont +setfont +0 0 moveto +(Line test) show +0 0 moveto +0 50 translate +/Palatino-Roman findfont +10 scalefont +setfont + +0 setlinewidth + +/linien +{ + 0 60 moveto + 5 mul + dup dup + prozente cvs show + ( lpi) show + 0 exch 72 exch div 50 { + dup + 0 moveto + 50 lineto + stroke + }for + 60 0 translate +} def + + + + 5 linien + 6 linien + 7 linien + 8 linien + 9 linien + 10 linien + 11 linien + 12 linien +-480 70 translate + 13 linien + 14 linien + 15 linien + 16 linien + 17 linien + 18 linien + 19 linien + 20 linien + -480 70 translate + 21 linien + 22 linien + 23 linien + 24 linien + 25 linien + 26 linien + 27 linien + 28 linien + + +showpage diff --git a/Master/texmf-dist/scripts/pdflatexpicscale/pdflatexpicscale.pl b/Master/texmf-dist/scripts/pdflatexpicscale/pdflatexpicscale.pl new file mode 100755 index 00000000000..638f0bdd2a7 --- /dev/null +++ b/Master/texmf-dist/scripts/pdflatexpicscale/pdflatexpicscale.pl @@ -0,0 +1,227 @@ +#!/usr/bin/perl -w +# Scale pictures to be included into a LaTeX generated PDF file. +# version 0.1 written by peter willadt +# contact willadt at t-online.de +# this software is subject to the LaTeX project public license. +# changes: +# 2016-08-01 first public release + +use strict; +use File::Basename; +use File::Spec; +use File::Copy; +use Getopt::Long; + +my $version = '0.1'; +my $versiondate = '2016-07-28'; +my $showversion; + +my $verbose; +my $TeXproject; + +# folders for scaled graphics, relative names +my $printfolderprefix = 'printimg'; +my $previewfolderprefix = 'previewimg'; +my $srcfolder = ''; + +# final resolution. special b/w handling not implemented yet +my $printdpi = 300; +my $printbwdpi = 4 * $printdpi; +my $previewdpi = 72; +my $tolerance = 20; + +# file formats +my %canhandle = +( JPG => '1', + PNG => '1', +); + +# bookkeeping +my %processedimages; +my $copied = 0; +my $scaled = 0; +my $skipped = 0; + +sub printInplaceError +{ + my $filename = shift; + print "I will not do inplace modification of graphics:\n" . + "($filename) will not be processed. (Missing path?)\n"; +} + +sub printMissingError +{ + my $filename = shift; + print "I can not find ($filename). (What have you done?)\n"; +} + +sub handleImage +{ + my $filename = shift; + my $dstwidth = shift; + my $dstheight = shift; + my ($srcwidth, $srcheight, $srcdepth); + my $dstfilename; + my $xfilename; + my @xsrcdirs; + my @dstdirs; + my @convertargs; + my $idstring; + + $dstdirs[0] = '.'; + $dstdirs[1] = $printfolderprefix; + $dstfilename = File::Spec->catfile(@dstdirs, basename($filename)); + if($filename eq $dstfilename){ + unless ($srcfolder > ' ') { + printInplaceError($filename); + $skipped++; + return; + } + $xsrcdirs[0] = $srcfolder; + $xfilename = File::Spec->catfile(@xsrcdirs, basename($filename)); + unless (-e $xfilename){ + printMissingError($xfilename); + $skipped++; + return; + } + $filename = $xfilename; + } + # check for image width and height + $idstring = `identify -format "%w x %h %[depth] " $filename`; + return unless $idstring =~ /(\d+) x (\d+) (\d+)/; + $srcwidth = $1; $srcheight = $2; $srcdepth = $3; + if($srcdepth == 1) { # hires for bw pix + $dstwidth = int($dstwidth * $printbwdpi / 72.27 + .5); + $dstheight = int($dstheight * $printbwdpi / 72.27 + .5); + }else { # moderate res for any other + $dstwidth = int($dstwidth * $printdpi / 72.27 + .5); + $dstheight = int($dstheight * $printdpi / 72.27 + .5); + } + if(-e $dstfilename){ + # if younger and requested size: skip + my ($mtime1, $mtime2, $size1, $size2, $idstring2, $existwidth); + my ($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size, + $atime, $ctime, $blksize, $blocks); + ($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size, + $atime, $mtime1, $ctime, $blksize, $blocks) + = stat($dstfilename); + ($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size, + $atime, $mtime2, $ctime, $blksize, $blocks) + = stat($filename); + if($mtime1 >= $mtime2){ + $idstring2 = `identify -format "%w x %h %[depth] " $dstfilename`; + if($idstring2 =~ /(\d+) x (\d+) (\d+)/){ + $existwidth = $1; + if($existwidth == $dstwidth){ + $processedimages{$filename} = $existwidth; + $skipped++; + return; + } + } + } + } + if(($dstwidth >= $srcwidth) || + ($dstwidth *(100 + $tolerance)/100 >= $srcwidth)) { + # we do no upscaling, but will probably copy the file. + if (defined $processedimages{$filename}){ + $skipped++; + }else { + $processedimages{$filename} = $srcwidth; + print "will copy $filename to $dstfilename\n" if $verbose; + copy($filename, $dstfilename); + $copied++; + return; + } + }else { + if((defined $processedimages{$filename}) && + ($processedimages{$filename} >= $dstwidth)) { + $skipped++; + return; + } + # we do some downscaling + $processedimages{$filename} = $dstwidth; + $convertargs[0] = 'convert'; + $convertargs[1] = ${filename}; + $convertargs[2] = '-resize'; +# $convertargs[3] = "${dstwidth}x${dstheight}!"; + $convertargs[3] = "${dstwidth}x${dstheight}"; + $convertargs[4] = "-density"; + $convertargs[5] = $printdpi; + $convertargs[6] = ${dstfilename}; + print "will @convertargs\n" if $verbose; + system(@convertargs); + $scaled++; + } +} + +sub readlog +{ + my $logfilename = shift; + $logfilename .= '.log'; + my ($picname, $picext, $picwidth, $picheight); + my ($picextu, $needsize); + open LOGFILE, "<$logfilename" or die "Cannot read $logfilename"; + $needsize = 0; + while (<LOGFILE>){ + if (/^Package pdftex\.def Info\: (\S*)\.(\w+) used /){ + $picname = $1; + $picext = $2; + ($picextu = $picext) =~ tr/a-z/A-Z/; + if( defined $canhandle{$picextu}){ + $needsize = 1; + next; + } + } + next unless ($needsize == 1); + next unless /Requested size: (\d+\.\d+)pt x (\d+\.\d+)pt/; + $picwidth = $1; + $picheight = $2; + handleImage("$picname.$picext", $picwidth, $picheight); + $needsize = 0; + } +} + +sub usage +{ + print <<'_endusage'; +pdflatexpicscale will downscale large raster images for your TeX project +to reasonable size. +Basic usage: + pdflatexpicscale myarticle +where your main LaTeX file is called 'myarticle.tex' and a log file exists. +Fine tuning: +--destdir=folder (relative path, must exist, + defaults to 'printimg' subfolder of current folder) +--srcdir=folder (folder to find original images, if this software + can't figure it out on it's own, because you already + used the target directory.) +--printdpi=XXX (default 300) +--tolerance=XX (default 20 Percents over printdpi to ignore scaling) +--verbose (if you want to know what the script attempts to do) +--version (show software version) +_endusage +} + +GetOptions('verbose' => \$verbose, + 'printdpi=i' => \$printdpi, + 'destdir=s' => \$printfolderprefix, + 'tolerance=i' => \$tolerance, + 'srcdir=s' => \$srcfolder, + 'version' => \$showversion); + +$TeXproject = shift; + +if($showversion){ + print "pdflatexpicscale Version $version $versiondate\n"; +} + +unless ($TeXproject gt ' '){ + usage(); + end(); +} + +readlog($TeXproject); +if($verbose) { + print "$copied file(s) copied, $scaled file(s) converted " . + "and $skipped occurence(s) skipped.\n"; +} diff --git a/Master/tlpkg/bin/tlpkg-ctan-check b/Master/tlpkg/bin/tlpkg-ctan-check index acbb1b2eb48..21667fe9b95 100755 --- a/Master/tlpkg/bin/tlpkg-ctan-check +++ b/Master/tlpkg/bin/tlpkg-ctan-check @@ -440,7 +440,8 @@ my @TLP_working = qw( patch patchcmd patgen2-tutorial path pauldoc pawpict pax pbibtex-base pbox pb-diagram pbsheet pdf14 - pdf-trans pdfbook2 pdfcomment pdfcprot pdfcrop pdfjam pdfmarginpar + pdf-trans pdfbook2 pdfcomment pdfcprot pdfcrop pdfjam + pdflatexpicscale pdfmarginpar pdfpagediff pdfpages pdfscreen pdfslide pdfsync pdftricks pdftricks2 pdfx pdfxup pecha pedigree-perl perception perfectcut perltex diff --git a/Master/tlpkg/libexec/ctan2tds b/Master/tlpkg/libexec/ctan2tds index 694cc386cc6..70389032b7a 100755 --- a/Master/tlpkg/libexec/ctan2tds +++ b/Master/tlpkg/libexec/ctan2tds @@ -2757,6 +2757,7 @@ $standardttf = '\.ttf|\.TTC'; 'pdfbook2' => 'pdfbook2$', 'pdfcrop' => '\.pl$', # doscripts() does r* 'pdfjam' => 'pdf[^.]*$', + 'pdflatexpicscale' => '\.pl$', 'pdfxup' => 'pdfxup$', 'pedigree-perl' => '\.pl$', 'perltex' => '\.pl$', @@ -5514,12 +5515,20 @@ sub build_scripts_copy { # (but not for mptopdf, since peb unified it.) return if $exec =~ /mptopdf/; (my $exec_basename = $exec) =~ s,^.*/,,; - my $scripts_Makefile = "$Build/$build_scriptsdir/Makefile.in"; my $pattern = "\\b$build_subdir/$exec_basename\\b"; + # + my $scripts_Makefile = "$Build/$build_scriptsdir/Makefile.in"; system ("grep '$pattern' $scripts_Makefile >/dev/null"); if ($? != 0) { print "*** $build_subdir/$exec_basename not in $scripts_Makefile\n"; } + # we'd should get rid of scripts.lst since it is nothing but + # redundancy; coordinate with debian, though. + my $scripts_lst = "$Build/$build_scriptsdir/scripts.lst"; + system ("grep '$pattern' $scripts_lst >/dev/null"); + if ($? != 0) { + print "*** $build_subdir/$exec_basename not in $scripts_lst\n"; + } } sub POSTcontext_games { diff --git a/Master/tlpkg/tlpsrc/collection-binextra.tlpsrc b/Master/tlpkg/tlpsrc/collection-binextra.tlpsrc index c154916dbdc..908704bb31b 100644 --- a/Master/tlpkg/tlpsrc/collection-binextra.tlpsrc +++ b/Master/tlpkg/tlpsrc/collection-binextra.tlpsrc @@ -56,6 +56,7 @@ depend patgen depend pdfbook2 depend pdfcrop depend pdfjam +depend pdflatexpicscale depend pdftools depend pdfxup depend pfarrei diff --git a/Master/tlpkg/tlpsrc/pdflatexpicscale.tlpsrc b/Master/tlpkg/tlpsrc/pdflatexpicscale.tlpsrc new file mode 100644 index 00000000000..dca338c719c --- /dev/null +++ b/Master/tlpkg/tlpsrc/pdflatexpicscale.tlpsrc @@ -0,0 +1 @@ +binpattern f bin/${ARCH}/${PKGNAME} |