summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/scripts
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2010-01-10 01:05:40 +0000
committerKarl Berry <karl@freefriends.org>2010-01-10 01:05:40 +0000
commit0257641352e7f3139f754e7af6e99b0b95b9059f (patch)
tree071f2cd614038785084e278cf8c0d6b5dcc153cd /Master/texmf-dist/scripts
parentedb3f0e6434fdd9b9ba2f6abaef04d9a3ada23d7 (diff)
pdfcrop update (9jan10)
git-svn-id: svn://tug.org/texlive/trunk@16655 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/scripts')
-rwxr-xr-xMaster/texmf-dist/scripts/pdfcrop/pdfcrop.pl76
1 files changed, 70 insertions, 6 deletions
diff --git a/Master/texmf-dist/scripts/pdfcrop/pdfcrop.pl b/Master/texmf-dist/scripts/pdfcrop/pdfcrop.pl
index 16ff326b71d..5855eb0849e 100755
--- a/Master/texmf-dist/scripts/pdfcrop/pdfcrop.pl
+++ b/Master/texmf-dist/scripts/pdfcrop/pdfcrop.pl
@@ -5,7 +5,7 @@ $^W=1; # turn warning on
#
# pdfcrop.pl
#
-# Copyright (C) 2002, 2004, 2005, 2008, 2009 Heiko Oberdiek.
+# Copyright (C) 2002, 2004, 2005, 2008-2010 Heiko Oberdiek.
#
# This program may be distributed and/or modified under the
# conditions of the LaTeX Project Public License, either version 1.2
@@ -22,10 +22,10 @@ $^W=1; # turn warning on
#
my $file = "pdfcrop.pl";
my $program = uc($&) if $file =~ /^\w+/;
-my $version = "1.22";
-my $date = "2009/12/29";
+my $version = "1.23";
+my $date = "2010/01/09";
my $author = "Heiko Oberdiek";
-my $copyright = "Copyright (c) 2002-2009 by $author.";
+my $copyright = "Copyright (c) 2002-2010 by $author.";
#
# Reqirements: Perl5, Ghostscript
# History:
@@ -68,6 +68,7 @@ my $copyright = "Copyright (c) 2002-2009 by $author.";
# * Option --luatex and --luatexcmd added for LuaTeX.
# 2009/12/29 v1.22: * Syntax description for option --bbox fixed
# (Lukas Prochazka).
+# 2010/01/09 v1.23: * Options --bbox-odd and -bbox-even added.
### program identification
my $title = "$program $version, $date - $copyright\n";
@@ -187,6 +188,8 @@ $::opt_hires = 0;
$::opt_papersize = "";
$::opt_resolution = "";
$::opt_bbox = "";
+$::opt_bbox_odd = "";
+$::opt_bbox_even = "";
$::opt_initex = 0;
sub usage ($) {
@@ -225,6 +228,8 @@ Expert options:
--bbox "<left> <bottom> <right> <top>" ()
override bounding box found by ghostscript
with origin at the lower left corner
+ --bbox-odd, --bbox-even ()
+ Same as --bbox, but for odd, even pages only
Examples:
\L$program\E --margins 10 input.pdf output.pdf
\L$program\E --margins '5 10 5 20' --clip input.pdf output.pdf
@@ -264,6 +269,8 @@ GetOptions(
"papersize=s",
"resolution=s",
"bbox=s",
+ "bbox-odd=s" => \$::opt_bbox_odd,
+ "bbox-even=s" => \$::opt_bbox_even,
"restricted" => sub { $restricted = 1; },
) or usage(1);
!$::opt_help or usage(0);
@@ -292,6 +299,30 @@ if ($::opt_bbox) {
die "$Error Parse error (option --bbox \"$::opt_bbox\")!\n";
}
}
+if ($::opt_bbox_odd) {
+ $::opt_bbox_odd =~ s/^\s+//;
+ $::opt_bbox_odd =~ s/\s+$//;
+ $::opt_bbox_odd =~ s/\s+/ /;
+ if ($::opt_bbox_odd =~ /^-?\d*\.?\d+ -?\d*\.?\d+ -?\d*\.?\d+ -?\d*\.?\d+$/) {
+ print "* Explicite Bounding Box for odd pages: $::opt_bbox_odd\n"
+ if $::opt_debug;
+ }
+ else {
+ die "$Error Parse error (option --bbox-odd \"$::opt_bbox_odd\")!\n";
+ }
+}
+if ($::opt_bbox_even) {
+ $::opt_bbox_even =~ s/^\s+//;
+ $::opt_bbox_even =~ s/\s+$//;
+ $::opt_bbox_even =~ s/\s+/ /;
+ if ($::opt_bbox_even =~ /^-?\d*\.?\d+ -?\d*\.?\d+ -?\d*\.?\d+ -?\d*\.?\d+$/) {
+ print "* Explicite Bounding Box for even pages: $::opt_bbox_even\n"
+ if $::opt_debug;
+ }
+ else {
+ die "$Error Parse error (option --bbox-even \"$::opt_bbox_even\")!\n";
+ }
+}
@ARGV <= 2 or die "$Error Too many files!\n";
@@ -620,9 +651,42 @@ print "* Running ghostscript for BoundingBox calculation ...\n"
print "* Ghostscript call: $::opt_gscmd @gsargs\n" if $::opt_debug;
my @bbox;
+my @bbox_all;
+my @bbox_odd;
+my @bbox_even;
if ($::opt_bbox) {
$::opt_bbox =~ /([-\d\.]+) ([-\d\.]+) ([-\d\.]+) ([-\d\.]+)/;
- @bbox = ($1, $2, $3, $4);
+ @bbox_all = ($1, $2, $3, $4);
+}
+if ($::opt_bbox_odd) {
+ $::opt_bbox_odd =~ /([-\d\.]+) ([-\d\.]+) ([-\d\.]+) ([-\d\.]+)/;
+ @bbox_odd = ($1, $2, $3, $4);
+}
+if ($::opt_bbox_even) {
+ $::opt_bbox_even =~ /([-\d\.]+) ([-\d\.]+) ([-\d\.]+) ([-\d\.]+)/;
+ @bbox_even = ($1, $2, $3, $4);
+}
+
+sub getbbox ($$$$$) {
+ my $page = shift;
+ my $a = shift;
+ my $b = shift;
+ my $c = shift;
+ my $d = shift;
+ if ($page % 2 == 1) {
+ if ($::opt_bbox_odd) {
+ return @bbox_odd;
+ }
+ }
+ else {
+ if ($::opt_bbox_even) {
+ return @bbox_even;
+ }
+ }
+ if ($::opt_bbox) {
+ return @bbox_all;
+ }
+ return ($a, $b, $c, $d);
}
my $page = 0;
my $gs_pipe = "$::opt_gscmd -dSAFER @gsargs 2>&1";
@@ -636,8 +700,8 @@ while (<GS>) {
print $_ if $::opt_verbose;
next unless
/^$bb:\s*(-?[\.\d]+) (-?[\.\d]+) (-?[\.\d]+) (-?[\.\d]+)/o;
- @bbox = ($1, $2, $3, $4) unless $::opt_bbox;
$page++;
+ @bbox = getbbox($page, $1, $2, $3, $4);
my $empty = 0;
$empty = 1 if $bbox[0] >= $bbox[2];