Debian Codegraph @

psbl

raw ◀ ▶
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
1 Debian patch touch this file
1 #!/usr/local/bin/perl
2
3 ######################################################################
4 # Perl font split impose
5 #
6 # Copyright (C) 2003 Dov Grobgeld <[email protected]>
7 #
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 2 of the License, or
11 # (at your option) any later version.
12 #
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
17 #
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, write to the Free Software
20 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #
22 # For more details see the file COPYING.
23 ######################################################################
24
25 my $VERSION = "0.2";
26
27 # Get options
28 while($_ = $ARGV[0], /^-/) {
29 shift;
30 /^-lastbbox/ and do { $lastbbox="-lastbbox"; next; };
31 /^-lpi/ and do { $lpi = shift; next; };
32 /^-impose_options/ and do { $impose_options = shift; next; };
33 /^-max(_pages)?/ and do { $max_pages_per_signature = shift; next; };
34 /^-help/ and print<<HELP and exit;
35 psbl -- A program for automatic booklet formatting of postscript files
36
37 SYNTAX:
38 psbl [-lastbbox] [-lpi] [-impose_options io] [-max_pages mp]
39 postscript.file
40
41 SEEALSO:
42 impose
43 HELP
44 die "Unknown option $_!\n";
45 }
46
47 $lpi = 80 unless $lpi;
48
49 # Defaults
50 $max_pages_per_signature = 60 unless $max_pages_per_signature;
51
52 # Get the name of the orginial file
53 $psname = shift || die "Need name of ps file!\n";
54
55 # Get number of pages in file
56 $pages = get_num_pages($psname);
57
58 # Split it nicely
59 $num_signatures = int($pages/$max_pages_per_signature + 0.9999999);
60
61 $q_per_signature = int($pages/4/$num_signatures+0.999);
62 print "num_signatures = $num_signatures\n";
63 print "q_per_signature = $q_per_signature\n";
64
65 for $i (0..$num_signatures-1) {
66 my $start = $i * $q_per_signature * 4 + 1;
67 my $end = ($i+1) * $q_per_signature * 4;
68 if ($end > $pages) {
69 $end = $pages;
70 }
71 $cmd = "psselect $start-$end $psname | fixtd -tumble | psbook > $psname.$start-$end";
72 print "$cmd\n";
73 system $cmd;
74
75 $lastbbox = "-lastbbox" if $i > 0;
76 $cmd = "impose $impose_options $lastbbox $psname.$start-$end";
77 print "$cmd\n";
78 system $cmd;
79
80 unlink "$psname.$start-$end";
81 }
82 print "Done!\n";
83
84 sub get_num_pages {
85 my $fn = shift;
86 my $pages;
87 open(PS, $fn) || die "Couldn't open $fn: $!\n";
88 while(<PS>) {
89 if ($. == 1) {
90 die "Not a Postscript file!\n" unless /^%!/;
91 }
92 $pages = $_ and last if /^%%Pages:/;
93 }
94 die "Couldn't find %%Pages!\n" unless $pages;
95
96 if ($pages =~ /atend/) {
97 seek(PS, -2000, 2);
98 read(PS, $_, 2000);
99 /^%%Pages:.*$/m or die "Couldn't find %%Pages at end of file!\n";
100 $pages = $&;
101 }
102
103 $pages=~ /(\d+)\S*(\d*)/;
104 return $1;
105 }