diff options
author | Norbert Preining <norbert@preining.info> | 2019-09-02 13:46:59 +0900 |
---|---|---|
committer | Norbert Preining <norbert@preining.info> | 2019-09-02 13:46:59 +0900 |
commit | e0c6872cf40896c7be36b11dcc744620f10adf1d (patch) | |
tree | 60335e10d2f4354b0674ec22d7b53f0f8abee672 /support/impose |
Initial commit
Diffstat (limited to 'support/impose')
-rw-r--r-- | support/impose/AUTHORS | 1 | ||||
-rw-r--r-- | support/impose/COPYING | 340 | ||||
-rw-r--r-- | support/impose/INSTALL | 7 | ||||
-rw-r--r-- | support/impose/Makefile | 19 | ||||
-rw-r--r-- | support/impose/README | 36 | ||||
-rw-r--r-- | support/impose/TODO | 3 | ||||
-rwxr-xr-x | support/impose/bboxx | 242 | ||||
-rwxr-xr-x | support/impose/fixtd | 100 | ||||
-rw-r--r-- | support/impose/html/impose-ex.png | bin | 0 -> 34173 bytes | |||
-rw-r--r-- | support/impose/html/index.html | 76 | ||||
-rw-r--r-- | support/impose/html/psnup-ex.png | bin | 0 -> 26793 bytes | |||
-rwxr-xr-x | support/impose/impose | 244 | ||||
-rwxr-xr-x | support/impose/psbl | 103 |
13 files changed, 1171 insertions, 0 deletions
diff --git a/support/impose/AUTHORS b/support/impose/AUTHORS new file mode 100644 index 0000000000..885a1826e3 --- /dev/null +++ b/support/impose/AUTHORS @@ -0,0 +1 @@ +* Dov Grobgeld <dov@imagic.weizmann.ac.il> diff --git a/support/impose/COPYING b/support/impose/COPYING new file mode 100644 index 0000000000..d60c31a97a --- /dev/null +++ b/support/impose/COPYING @@ -0,0 +1,340 @@ + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc. + 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Library General Public License instead.) You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + <one line to give the program's name and a brief idea of what it does.> + Copyright (C) <year> <name of author> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) year name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + <signature of Ty Coon>, 1 April 1989 + Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Library General +Public License instead of this License. diff --git a/support/impose/INSTALL b/support/impose/INSTALL new file mode 100644 index 0000000000..fedbe72879 --- /dev/null +++ b/support/impose/INSTALL @@ -0,0 +1,7 @@ +To install the programs copy them to a place in your path and +make sure that they are executable and have their perl statements +pointing to your perl executable. + +I will be happy to receive a real installation environment for these +scripts. + diff --git a/support/impose/Makefile b/support/impose/Makefile new file mode 100644 index 0000000000..621f3b0e5a --- /dev/null +++ b/support/impose/Makefile @@ -0,0 +1,19 @@ +DIST = AUTHORS \ + COPYING \ + INSTALL \ + README \ + TODO \ + Makefile \ + bboxx \ + fixtd \ + impose \ + psbl \ + html/index.html \ + html/impose-ex.png \ + html/psnup-ex.png + +VER = 0.1 + +dist: + tar cvf impose+-$(VER).tar $(DIST) + gzip impose+-$(VER).tar diff --git a/support/impose/README b/support/impose/README new file mode 100644 index 0000000000..1e197e7fa7 --- /dev/null +++ b/support/impose/README @@ -0,0 +1,36 @@ + impose+ + version 0.1 + A set of PostScript utilities + Dov Grobgeld + +impose+ is a set of postscript utilities. The main program of impose+ +is impose which is used for two-up printing of DSC complient postscript. +This includes postscript from e.g. netscape, dvips, and FrameMaker. It +makes an effort to remove white space from the printout by probing the +original postscript for the bounding box of the printed area. This makes +the output much more esthetic than does a simplistic layout of non-cropped +original papers. + +impose may also be used as a print filter, e.g. for automatically +printing two-up files from netscape. + +The utilities are all written in perl and are released under the GNU +public licence as described in the file COPYING. They depend on the +installation of the psutils package by Angus J.C. Duggan. + +Here is some additional descriptions of the different scripts in the +program. + +impose - A preprocessor to pstops by Angus J.C. Duggan, for creating + 2-up printouts. It uses bboxx to extract the bounding box + of the original postscript file and creates the 2-up copy, + considering only the text body and the margin parameters + entered by the user. + +bboxx - Extract the bounding box of a postscript file, with the + option of entering the bounding box into the file. + +fixtd - Set tumble and duplex options for the printout. + +psbl - A preprocessor to impose and psbl for creating + booklets. diff --git a/support/impose/TODO b/support/impose/TODO new file mode 100644 index 0000000000..7a8f4b4ad8 --- /dev/null +++ b/support/impose/TODO @@ -0,0 +1,3 @@ +* Make a proper installation. +* Write more documentation. +* Support 4-up printing. diff --git a/support/impose/bboxx b/support/impose/bboxx new file mode 100755 index 0000000000..4ff276a3ec --- /dev/null +++ b/support/impose/bboxx @@ -0,0 +1,242 @@ +#!/usr/local/bin/perl +######################################################################## +# This program uses ghostscript and its pbm driver to extract absolute +# bounding box information for any postscript file. +# +# The output of the program is the bounding box for every page in the +# document. +# +# This program could certainly be made faster if written in a compiled +# language, but the time spent within it is probably neglible compared +# to the time spent by ghostscript. +# +# Bugs: +# The program may be confused by files that directly set the page +# size. +# +# Copyright (C) 1999 Dov Grobgeld <dov@imagic.weizmann.ac.il> +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# For more details see the file COPYING. +######################################################################## + +$GSPATH = "gs"; # Your path to gs + +while( $_ = $ARGV[0], /^-/) { + shift; + /-res/ && do { $baseres = shift; next }; + /-letter/ && do { $pagesize = 'letter'; next }; + /-a4/ && do { $pagesize = 'a4'; next; }; + /-pages/ && do { $maxpages = shift; next; }; + /-evenodd/ && do { $evenodd++; next; }; + /-insert/ && do { $insert++; next; }; + /-pad/ && do { $pad = shift; next; }; + /-help/ && do { print <<EOHELP; exit; }; +$0 - Calculate the bounding boxes of all pages in a PostScript file + +Syntax: + $0 [-res r] [-letter|-a4] filename + +Description: + The program outputs the page number and the Bounding Box parameters + for every page in the file filename . + $0 accomplishes this by calling ghostscript, which must be in + the path, at the resolution given by res, with output device pbm . + The bounding box information is then extracted by scanning the pbm + file. + +Options: + -res res Choose a resolution for ghostscript other than the default + 72 lpi. + -letter -a4 Choose paper size. Default is a4. + -evenodd Report separate document bounding boxes for odd and even pages + -pages n Set max number of pages to analyze to n. + -insert Edit the postscript file and change/insert a EPSF directive + and a BoundingBox statement. + -pad p Padd bounding box on all sides with p postscript points. + +Requirements: + Ghostscript in path with pbmraw support compiled in. + +Author: + Dov Grobgeld, Rehovot, Israel, 1997 +EOHELP + die "Unknown option $_!\n"; +} + +# defaults +$pagesize = 'a4' unless $pagesize; +$baseres = 72 unless $baseres; +$maxpages = 1_000_000 unless $maxpages; + +# table of known paper sizes. +# perl5 +# %papersizes = ( 'a4'=> [595,842], 'letter', [612,792]); +# ($pw,$ph) = @{$papersize{$pagesize}}; + +%paperwidth = ( 'a4', 595, 'letter', 612 ); +%paperheight = ( 'a4', 842, 'letter', 792 ); + +$pw = $paperwidth{$pagesize}; $ph = $paperheight{$pagesize}; + +# Calculate a resolution of about $baseres that gives the pixelwidth +# divisible by 8. +$w8 = int($pw / 72 * $baseres /8 + 0.5) * 8; +$res = 72.0*$w8/$pw; + +# create an empty row for optimization +$emptyrow = "\0" x ($w8/8); + +# document bounding box initialization +$docllx=$pw; $doclly=$ph; $docurx=0; $docury=0; +$odddocllx=$pw; $odddoclly=$ph; $odddocurx=0; $odddocury=0; +$evendocllx=$pw; $evendoclly=$ph; $evendocurx=0; $evendocury=0; + +# get filename +$fn = shift || die "Expected postscript file name!\n"; +-f $fn || die "No such file $fn!\n"; + +# Print header +print " Page: llx lly urx ury\n"; + +$gsopt = "-q -dNOPAUSE -sPAPERSIZE=$pagesize -sDEVICE=pbmraw -sOutputFile=-"; +open(GS, "$GSPATH -r$res $gsopt -- $fn|"); + +$|++; +$page=0; +while(!eof(GS)) { + chop($_=<GS>); + die "Expected P4 but got '$_'. \nProbably a PostScript error...\n" unless /P4/; + while(<GS>) { last unless /^#/; } + ($w,$h)=split(" ", $_); + unless ($w8 == $w) { + warn "Warning! Expected bitmap width $w8 but got $w. Adjusting resolution...\n"; + $res *= $w8 / $w; + close(GS); + open(GS, "$GSPATH -r$res $gsopt -- $fn|"); + next; + } + $page++; + printf " %4d ", $page; + $topmarg = 0; + $botmarg = 0; + $leftmarg = $w; + $rightmarg = $w; + $top=1; + for $i (1..$h) { + read(GS, $_, $w/8 ); + + # Check for an empty row + #if ($_ eq $emptyrow) + if ($_=~ /^\00*$/) { + if ($top) { # Still scanning top margin? + $topmarg++; + } + else { + $botmarg = 0 unless $bot; # reset the bottom margin + $bot=1; + $botmarg++; + } + } + # Otherwise get the left and right margins of the row + else { + $bot=0; $top=0; # Not counting top and bottom margins anymore + + # Get left margin of line + /^(\00*)([^\00])/; + $lmcand=length($1)*8; + if ($lmcand < $leftmarg) { + ($b=unpack('B*',$2))=~ /^0*/; + $lmcand+= length($&); + $leftmarg = $lmcand if $lmcand < $leftmarg; + } + + # Get right margin of line + /([^\00])(\00*)$/; + $rmcand=length($2)*8; + if ($rmcand < $rightmarg) { + ($b = unpack('B*', $1))=~ /0*$/; + $rmcand+= length($&); + $rightmarg = $rmcand if ($rmcand < $rightmarg); + } + } + } + + # scale and translate to postscript points + $scale = 72/$res; + $ury= ($h-$topmarg)*$scale; + $lly= $botmarg*$scale; + $llx= $leftmarg*$scale; + $urx= ($w-$rightmarg)*$scale; + $lly= $h*$scale if $lly==$ury && $lly==0; + printf "%5.f %5.f %5.f %5.f\n", $llx, $lly, $urx, $ury; + + if ($pad) { + $llx-=$pad; + $lly-=$pad; + $urx+=$pad; + $ury+=$pad; + } + + if ($evenodd) { + if ($page % 2) { # odd + $odddocllx=$llx if $llx<$odddocllx; + $odddoclly=$lly if $lly<$odddoclly; + $odddocurx=$urx if $urx>$odddocurx; + $odddocury=$ury if $ury>$odddocury; + } + else { + $evendocllx=$llx if $llx<$evendocllx; + $evendoclly=$lly if $lly<$evendoclly; + $evendocurx=$urx if $urx>$evendocurx; + $evendocury=$ury if $ury>$evendocury; + } + } + + $docllx=$llx if $llx<$docllx; + $doclly=$lly if $lly<$doclly; + $docurx=$urx if $urx>$docurx; + $docury=$ury if $ury>$docury; + + if ($page >= $maxpages) { + print "skipping rest of file...\n"; + last; + } +} +print "Document: "; +printf "%5.f %5.f %5.f %5.f\n", $docllx, $doclly, $docurx, $docury; +if ($evenodd) { + print "Odd: "; + printf "%5.f %5.f %5.f %5.f\n", $odddocllx, $odddoclly, $odddocurx, $odddocury; + print "Even: "; + printf "%5.f %5.f %5.f %5.f\n", $evendocllx, $evendoclly, $evendocurx, $evendocury; +} + +if ($insert) { + rename($fn, "$fn~"); + open(PSIN, "$fn~"); open(PSOUT, ">$fn"); + print PSOUT "%!PS-Adobe-1.0 EPSF-1.0\n"; + print PSOUT "%%BoundingBox: "; + printf PSOUT "%5.f %5.f %5.f %5.f\n", $docllx, $doclly, $docurx, $docury; + print PSOUT "%%Comment: Bounding box extracted by bboxx\n"; + print PSOUT "%%+: A program by Dov Grobgeld 1994\n"; + + while(<PSIN>) { + next if $.==1 && /^%!/; + next if /^%%BoundingBox: /; + print PSOUT; + } +} diff --git a/support/impose/fixtd b/support/impose/fixtd new file mode 100755 index 0000000000..2fc05e2075 --- /dev/null +++ b/support/impose/fixtd @@ -0,0 +1,100 @@ +#!/usr/local/bin/perl +############################################################################# +# This scripts changes a postscript with twoup so that every other page +# will no longer be printed upside down. +# +# The postscript code was copied from the 'parr' program that came together +# with the perl-reference guide by Johan Vromans. +# +# Copyright (C) 1999 Dov Grobgeld <dov@imagic.weizmann.ac.il> +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +############################################################################# + +while ($ARGV[0] =~ /^-/) { + $_ = shift; + + if (/^-mode/) { + $mode = shift; + } + elsif (/^-tumble/) { + $tumble++; + } + elsif (/^-simplex/) { + $simplex++; + } + elsif (/-h(elp)?/) { + print<<EOH +fixdt - insert tumble and duplex directives in a PostScript file + +Syntax: + fixtumble [-simplex] [-tumble] filename + +Options: + + -simplex Simplex printing. (Default is duplex) + -tumble Tumble pages. +EOH +; exit; + } +} + +while(<>) { + unless ($mode) { + if (/dvips/) { $mode='dvips'; } + elsif (/mpage/) { $mode='mpage'; } + elsif (/Start of enscript\.pro/) { $mode='enscript'; } + elsif (/pstops/) { $mode='pstops'; } + elsif (/ditroff/) { $mode='reenc'; } + elsif (($.==1000) || eof) { $mode='giveup'; last; } + } + else { + if ($mode eq 'dvips') { + last if /%%EndSetup/; + } + elsif ($mode eq 'mpage') { + last if /^statusdict/; + } + elsif ($mode eq 'enscript') { + last if /^%%EndProlog/; + } + elsif ($mode eq 'reenc') { + last if /^\/reencsmalldict/; + } + } + push(@P,$_); +} +die "Unable to determine format!\n" unless $mode; + +if ($mode eq 'giveup') { + # Insert in first noncomment place + $i=0; + $p=shift(@P); + (print $p), ($p=shift(@P)) until $p!~ /^%/; + $_= $p.join("",@P) . $_; +} +else { print @P; } +print 'statusdict /setduplexmode known ' . + '{ statusdict begin true setduplexmode end } if',"\n" unless $simplex; +print 'statusdict /settumble known ' . + '{ statusdict begin true settumble end } if',"\n" if $tumble; +print $_; + +# Copy the rest of it +while (<>) { + print; +} + diff --git a/support/impose/html/impose-ex.png b/support/impose/html/impose-ex.png Binary files differnew file mode 100644 index 0000000000..5c868277b0 --- /dev/null +++ b/support/impose/html/impose-ex.png diff --git a/support/impose/html/index.html b/support/impose/html/index.html new file mode 100644 index 0000000000..a2e01c637b --- /dev/null +++ b/support/impose/html/index.html @@ -0,0 +1,76 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"> +<HTML> + <HEAD> + <TITLE>impose+ (13-Dec-1999)</TITLE> + <!-- Created by: Dov Grobgeld, 12-Dec-1999 --> + <!-- Changed by: Dov Grobgeld, 13-Dec-1999 --> + + + </HEAD> + <BODY> + <H1 align=center>impose+</H1> +<h2 align=center>version 0.1<br> + A set of PostScript utilities<br> +by Dov Grobgeld</h2> +<b>Latest version:</b> <a href="impose+-0.1.tar.gz">impose+-0.1.tar.gz</a> + +<h2>Description</h2> +impose+ is a set of postscript utilities. The main program of impose+ +is impose which is used for two-up printing of DSC complient postscript. +This includes postscript from e.g. netscape, dvips, and FrameMaker. It +makes an effort to remove white space from the printout by probing the +original postscript for the bounding box of the printed area. This makes +the output much more esthetic than does a simplistic layout of non-cropped +original papers. +<p> +impose may also be used as a print filter, e.g. for automatically +printing two-up files from netscape. +<p> +The utilities are all written in perl and are released under the GNU +public licence as described in the file COPYING. They depend on the +installation of the psutils package by Angus J.C. Duggan. + +<h2>Example</h2> +The following example shows the same pages treated by both psnup +and by impose. +<p> +<center> +<table border> + <tr><td align=center><img src="psnup-ex.png"> + <td align=center><img src="impose-ex.png"> + <tr><th>psnup -2 + <th>impose +</table> +</center> +<p> +The left image is the simplistic tiling done by "psnup -2" +where the whole page has been tiled. On the right is the postscript +output of impose. As can be seen, a postscript file created by impose +has more text and less white space on it. + +<h2>Contents</h2> + +Here is some additional descriptions of the different scripts in the +program. +<p> +<dl> + +<dt>impose <dd> - A preprocessor to pstops by Angus J.C. Duggan, for creating + 2-up printouts. It uses bboxx to extract the bounding box + of the original postscript file and creates the 2-up copy, + considering only the text body and the margin parameters + entered by the user. + +<dt>bboxx<dd> - Extract the bounding box of a postscript file, with the + option of entering the bounding box into the file. + +<dt>fixtd<dd> - Set tumble and duplex options for the printout. + +<dt>psbl<dd> - A preprocessor to impose and psbl for creating + booklets. + +</dl> +<hr> +Please send your questions and comments to: <a href="mailto:dov@imagic.weizmann.ac.il">dov@imagic.weizmann.ac.il</a> + </BODY> +</HTML>
\ No newline at end of file diff --git a/support/impose/html/psnup-ex.png b/support/impose/html/psnup-ex.png Binary files differnew file mode 100644 index 0000000000..b4780b77fb --- /dev/null +++ b/support/impose/html/psnup-ex.png diff --git a/support/impose/impose b/support/impose/impose new file mode 100755 index 0000000000..c1860a423a --- /dev/null +++ b/support/impose/impose @@ -0,0 +1,244 @@ +#!/usr/local/bin/perl +###################################################################### +# An imposition program for doing automatic balanced twoup +# imposition. +# +# Copyright (C) 1999 Dov Grobgeld <dov@imagic.weizmann.ac.il> +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# For more details see the file COPYING. +###################################################################### + + +while($_=$ARGV[0],/^-/) { + shift; + + /^-help/ && do { print <<EOHELP; exit; }; +impose - create 2-up files + +Syntax: + impose {options} filename + +Description: + Produces a new file filename.imposed that is a 2-up version of the + file filename. + +Options: + -letter Use letter size paper (sets width and height). + -height h Set paper height h. + -width w Set paper width w. + -scale s Force scale of imposed pages to be s. + -noscale Equal to -scale 1.0 + -pages p How many pages bboxx should probe to find document bbox. + -xm Left and right margins along the long side of the page. + Default 30. + -xrm Separate right x-margin. + -xlm Separate left x-margin. + -ym Margin at the top of the page. Default is 40. + -gutter Gutter space between the two columns. + -noglue Don\'t rubber band extra white space. + -bbox Manually set bbox so bboxx won\'t be run. + -noevenodd Don\'t use different bounding boxes for even and odd pages. + -evenbbox Set even page bbox. + -oddbbox Set odd page bbox. + -lastbbox Use bbox information of last run of $0. + -stdout Print output to stdout. + -rtl Do RTL layout of pages + +Author: + Dov Grobgeld +EOHELP + + /^-letter/ && do { $height = 792; $width=612; next; }; + /^-height/ && do { $height = shift; next; }; + /^-rtl/ && do { $rtl++; next; }; + /^-width/ && do { $width = shift; next; }; + /^-scale/ && do { $scaling = shift; next; }; + /^-noscal/ && do { $scaling=1.0; next; }; + /^-pages/ && do { $pages = shift; next; }; + /^-ud/ && do { $rotdir='R'; next; }; + /^-xm/ && do { $xright = $xleft = shift; next; }; + /^-xrm/ && do { $xright = shift; next; }; + /^-xlm/ && do { $xleft = shift; next; }; + /^-ym/ && do { $ytop = $ybot = shift; next; }; + /^-tmarg/ && do { $ytop = shift; next; }; + /^-bmarg/ && do { $ybot = shift; next; }; + /^-notumble/ && do { $no_tumble++; next; }; + /^-ybot/ && do { $ybot = shift; next; }; + /^-gutter/ && do { $gutter = shift; next; }; + /^-stdout/ && do { $do_stdout++; next; }; + /^-noglue/ && do { $noglue++; next; }; + /^-noevenodd/ && do { $noevenodd++; next }; + /^-bboxfile/ && do { $bboxfile=shift; next; }; + /^-bbox/ && do { $bbox[0]=shift; $bbox[1]=shift; $bbox[2]=shift; $bbox[3]=shift; next; }; + /^-evenbbox/ && do { $evenbbox[0]=shift; $evenbbox[1]=shift; $evenbbox[2]=shift; $evenbbox[3]=shift; next; }; + /^-oddbbox/ && do { $oddbbox[0]=shift; $oddbbox[1]=shift; $oddbbox[2]=shift; $oddbbox[3]=shift; next; }; + /^-lastbbox/ && do { $lastbbox++; next }; + die "Unknown option $_!\n"; +} + +# defaults +$height=842 unless $height; +$width=595 unless $width; +$xright=30 unless $xright; +$xleft=30 unless $xleft; +$gutter=40 unless $gutter; +$ytop=30 unless $ytop; +$ybot=30 unless $ybot; +$pages=6 unless defined $pages; +$rotdir="L" unless $rotdir; + +$filename = shift or do { + $filename = "/tmp/$ENV{USER}-tmp.ps"; + open(TMP, ">$filename"); + while(<>) { print TMP; } + close(TMP); + $do_stdout++; + $do_erase_tmp++; +}; +#die "Couldn't get filename!\n"; +-f $filename || die "No such file $filename!\n"; + +if ($filename =~ m|/([^/]*)$|) { + $filename = $1; + $path = $`; +} +else { + $path = "."; +} + +# get the bounding box +if ($bboxfile) { + open(BB,"$bboxfile"); + $_=<BB>; @oddbbox=split; + $_=<BB>; @evenbbox=split; + @oddbbox = @evenbbox unless @evenbbox; + close(BB); +} +elsif ($lastbbox && -e "/tmp/bboxx-$ENV{USER}") { + open(BB,"/tmp/bboxx-$ENV{USER}"); + $_=<BB>; @oddbbox=split; + $_=<BB>; @evenbbox=split; + close(BB); + # print "oddbbox = @oddbbox\n"; + # print "evenbbox = @evenbbox\n"; +} +elsif (@bbox) { + @oddbbox=@bbox; + @evenbbox=@bbox; +} +elsif (!@oddbbox || !@evenbbox) { + @oddbbox=(0,0,0,0); + @evenbbox=(0,0,0,0); + &getboundingboxes("$path/$filename", @oddbbox, @evenbbox); +} + +@evenbbox = @oddbbox if $noevenodd; + +# record the bboxx information +open(BB, ">/tmp/bboxx-$ENV{USER}"); +print BB "@oddbbox\n@evenbbox\n"; +close(BB); + +# Do page calculations +$oddwidth = $oddbbox[2]-$oddbbox[0]; +$oddheight = $oddbbox[3]-$oddbbox[1]; +$evenwidth = $evenbbox[2]-$evenbbox[0]; +$evenheight = $evenbbox[3]-$evenbbox[1]; + +# Check for lone page... +if ($evenwidth <= 0) { + $evenwidth = $oddwidth; + $evenheight = $oddheight; +} + +unless ($scaling) { + $scaling = ($height/2 - $gutter/2 - $xleft) / $oddwidth; + if ($oddheight*$scaling > $width - $ytop - $ybot) { + $scaling = ($width - $ytop - $ybot) / $oddheight; + } +} + +# for ($oddheight,$oddweight,$evenheight, $evenwidth) { $_*= $scaling } # perl5 + +$oddheight *= $scaling; +$oddwidth *= $scaling; +$evenheight *= $scaling; +$evenwidth *= $scaling; + +# scale bboxes +foreach (@oddbbox) { $_ = sprintf("%.1f",$_*$scaling); } +foreach (@evenbbox) { $_ = sprintf("%.1f",$_*$scaling); } + +# readjust xleft, ytop, and gutter in a TeX glue like manner +unless ($noglue) { + $mpg = $height - $oddwidth - $evenwidth; # xmargins + gutter + $r = $xleft/($gutter+$xleft+$xright); + $r1= $xright/($gutter+$xleft+$xright); + $xleft= $mpg*$r; + $xright= $mpg*$r1; + $gutter= $mpg*(1-$r-$r1); + $ym = $width - $oddheight; # ymargins + $s = $ytop / ($ytop + $ybot); + $ytop = $ym * $s; + $ybot = $ym * (1-$s); +} + +$shifty = sprintf("%.1f", $ytop+$oddbbox[3]); +$shiftoddx = sprintf("%.1f",$xleft-$oddbbox[0]); +$shiftevenx = sprintf("%.1f", $height-$xright-$evenwidth - $evenbbox[0]); +$scaling= sprintf("%.4f", $scaling); + +if ($rtl) { + $pstops_prm = "2:1${rotdir}\@${scaling}($shifty,$shiftoddx)+0${rotdir}\@${scaling}($shifty,$shiftevenx)"; +} +else { + $pstops_prm = "2:0${rotdir}\@${scaling}($shifty,$shiftoddx)+1${rotdir}\@${scaling}($shifty,$shiftevenx)"; +} + +$out = "|fixtd -tumble" unless $no_tumble; +$out .= "> $filename.imposed" unless $do_stdout; +$cmd="pstops '$pstops_prm' $path/$filename $out"; +print STDERR $cmd,"\n"; +system $cmd; +unlink "$path/$filename" if $do_erase_tmp; + +sub getboundingboxes { + local ($filename) = $_[0]; + local($bboxinfo); + + # This should really only look for some reasonable amount of pages... + $pages = "-pages $pages" if $pages; + $cmd= "bboxx -evenodd $pages $filename"; + print "$cmd\n"; + $_ = `$cmd`; + print; + + # Get the odd pages bounding box + ($llx,$lly,$urx,$ury) = /Odd: \s*(\d+)\s+(\d+)\s+(\d+)\s+(\d+)/; + + $_[1] = $llx; + $_[2] = $lly; + $_[3] = $urx; + $_[4] = $ury; + + # Get the even pages bounding box + ($llx,$lly,$urx,$ury) = /Even: \s*(\d+)\s+(\d+)\s+(\d+)\s+(\d+)/; + $_[5] = $llx; + $_[6] = $lly; + $_[7] = $urx; + $_[8] = $ury; +} diff --git a/support/impose/psbl b/support/impose/psbl new file mode 100755 index 0000000000..239b350fca --- /dev/null +++ b/support/impose/psbl @@ -0,0 +1,103 @@ +#!/usr/local/bin/perl + +###################################################################### +# Perl font split impose +# +# Copyright (C) 1999 Dov Grobgeld <dov@imagic.weizmann.ac.il> +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# For more details see the file COPYING. +###################################################################### + +# Get options +while($_ = $ARGV[0], /^-/) { + shift; + /^-lastbbox/ and do { $lastbbox="-lastbbox"; next; }; + /^-lpi/ and do { $lpi = shift; next; }; + /^-impose_options/ and do { $impose_options = shift; next; }; + /^-max(_pages)?/ and do { $max_pages_per_signature = shift; next; }; + /^-help/ and print<<HELP and exit; +psbl -- A program for automatic booklet formatting of postscript files + +SYNTAX: + psbl [-lastbbox] [-lpi] [-impose_options io] [-max_pages mp] + postscript.file + +SEEALSO: + impose +HELP + die "Unknown option $_!\n"; +} + +$lpi = 80 unless $lpi; + +# Defaults +$max_pages_per_signature = 60 unless $max_pages_per_signature; + +# Get the name of the orginial file +$psname = shift || die "Need name of ps file!\n"; + +# Get number of pages in file +$pages = get_num_pages($psname); + +# Split it nicely +$num_signatures = int($pages/$max_pages_per_signature + 0.9999999); + +$q_per_signature = int($pages/4/$num_signatures+0.999); +print "num_signatures = $num_signatures\n"; +print "q_per_signature = $q_per_signature\n"; + +for $i (0..$num_signatures-1) { + my $start = $i * $q_per_signature * 4 + 1; + my $end = ($i+1) * $q_per_signature * 4; + if ($end > $pages) { + $end = $pages; + } + $cmd = "psselect $start-$end $psname | fixtd -tumble | psbook > $psname.$start-$end"; + print "$cmd\n"; + system $cmd; + + $lastbbox = "-lastbbox" if $i > 0; + $cmd = "impose $impose_options $lastbbox $psname.$start-$end"; + print "$cmd\n"; + system $cmd; + + unlink "$psname.$start-$end"; +} +print "Done!\n"; + +sub get_num_pages { + my $fn = shift; + my $pages; + open(PS, $fn) || die "Couldn't open $fn: $!\n"; + while(<PS>) { + if ($. == 1) { + die "Not a Postscript file!\n" unless /^%!/; + } + $pages = $_ and last if /^%%Pages:/; + } + die "Couldn't find %%Pages!\n" unless $pages; + + if ($pages =~ /atend/) { + seek(PS, -2000, 2); + read(PS, $_, 2000); + /^%%Pages:.*$/m or die "Couldn't find %%Pages at end of file!\n"; + $pages = $&; + } + + $pages=~ /(\d+)\S*(\d*)/; + return $1; +} |