summaryrefslogtreecommitdiff
path: root/support/ps2eps
diff options
context:
space:
mode:
authorNorbert Preining <norbert@preining.info>2019-09-02 13:46:59 +0900
committerNorbert Preining <norbert@preining.info>2019-09-02 13:46:59 +0900
commite0c6872cf40896c7be36b11dcc744620f10adf1d (patch)
tree60335e10d2f4354b0674ec22d7b53f0f8abee672 /support/ps2eps
Initial commit
Diffstat (limited to 'support/ps2eps')
-rw-r--r--support/ps2eps/Changes.txt288
-rw-r--r--support/ps2eps/INSTALL.txt67
-rw-r--r--support/ps2eps/LICENSE.txt340
-rw-r--r--support/ps2eps/Latest_is_1.680
-rw-r--r--support/ps2eps/README43
-rw-r--r--support/ps2eps/bin/linux/i386/bboxbin0 -> 12003 bytes
-rwxr-xr-xsupport/ps2eps/bin/linux/x86_64/bboxbin0 -> 16386 bytes
-rw-r--r--support/ps2eps/bin/ps2eps946
-rw-r--r--support/ps2eps/doc/html/bbox.html226
-rw-r--r--support/ps2eps/doc/html/ps2eps.html1186
-rw-r--r--support/ps2eps/doc/man/man1/bbox.171
-rw-r--r--support/ps2eps/doc/man/man1/ps2eps.1366
-rw-r--r--support/ps2eps/doc/pdf/bbox.pdfbin0 -> 4949 bytes
-rw-r--r--support/ps2eps/doc/pdf/ps2eps.pdfbin0 -> 20821 bytes
-rw-r--r--support/ps2eps/src/C/bbox.c422
15 files changed, 3955 insertions, 0 deletions
diff --git a/support/ps2eps/Changes.txt b/support/ps2eps/Changes.txt
new file mode 100644
index 0000000000..ef0c46602c
--- /dev/null
+++ b/support/ps2eps/Changes.txt
@@ -0,0 +1,288 @@
+----------------------------
+Detailed Change Log:
+----------------------------
+revision 1.68
+date: 2010-05-07 21:42:35 +0200; author: bless; state: Exp; lines: +3 -3;
+- quoted translate command string
+----------------------------
+revision 1.67
+date: 2009-12-05 23:44:19 +0100; author: bless; state: Exp; lines: +39 -33;
+- quote of tmpfname for coping with spaces in filenames
+- added -a option
+- changed handling of hiresBB (now rounded to hiresprecision, by default 0.5pt)
+----------------------------
+revision 1.66
+date: 2007-10-30 12:04:24 +0100; author: bless; state: Exp; lines: +9 -5;
+- added %%BeginData %%EndData as indicators for Binary Section
+- added new option -b (treat as binary) to prevent filtering CR/LF stuff
+----------------------------
+revision 1.65
+date: 2007-01-24 14:19:42 +0100; author: bless; state: Exp; lines: +3 -3;
+- fixed help/usage formatting output
+----------------------------
+revision 1.64
+date: 2007-01-24 13:32:59 +0100; author: bless; state: Exp; lines: +4 -4;
+- Year (C) update
+----------------------------
+revision 1.63
+date: 2007-01-24 13:29:37 +0100; author: bless; state: Exp; lines: +3 -3;
+- Tried to make DSCfilter command more robust
+----------------------------
+revision 1.62 (not released)
+date: 2007-01-06 23:27:47 +0100; author: bless; state: Exp; lines: +11 -5;
+- better detection for files that have a binary heading stuff containing
+ even %! as character sequence
+----------------------------
+revision 1.61
+date: 2006-12-28 17:34:06 +0100; author: bless; state: Exp; lines: +5 -5;
+- changed year in comment and info printout only
+----------------------------
+revision 1.60 (not released)
+date: 2006-12-28 17:31:39 +0100; author: bless; state: Exp; lines: +9 -13;
+- incorporated changes for Windows/Cygwin detection by Karl Berry
+----------------------------
+revision 1.59 (not released)
+date: 2006-04-04 11:04:47 +0200; author: bless; state: Exp; lines: +4 -4;
+- removed surrounding ticks '' for -c $translation in $translatecmd
+ (hint by Thomas Riedle)
+- removed useless/unsupported 2>&1 in $bboxver for Windows
+----------------------------
+revision 1.58
+date: 2005/01/19 08:23:12; author: bless; state: Exp; lines: +8 -5
+- fix for two negative offsets in translation (reported by Hans Ecke)
+----------------------------
+revision 1.57
+date: 2005/01/19 07:59:52; author: bless; state: Exp; lines: +10 -3
+- more Windows friendly checking for bbox existence
+----------------------------
+revision 1.56
+date: 2005/01/17 12:32:54; author: bless; state: Exp; lines: +11 -3
+- added -r option to specify a resolution
+----------------------------
+revision 1.55
+date: 2005/01/14 15:28:09; author: bless; state: Exp; lines: +6 -4
+- minor fixes to the -g option (thanks to Koji Nakamaru):
+ * suppress info output if quiet option is active
+ * more robust parsing of gs call result
+----------------------------
+revision 1.54
+date: 2004/04/23 07:56:54; author: bless; state: Exp; lines: +4 -3
+- added ^pdfIm ^%-EOD- as indicator for binary section
+----------------------------
+revision 1.53
+date: 2004/04/01 19:28:02; author: bless; state: Exp; lines: +6 -2
+- Clipping code used always hiresBB, which gave wrong results when bbox returned no hiresBB
+----------------------------
+revision 1.52
+date: 2004/02/19 20:20:57; author: bless; state: Exp; lines: +90 -10
+- added rotate option -R
+- changed translate in order to avoid negative BB coordinates
+----------------------------
+revision 1.51
+date: 2004/01/25 22:02:04; author: bless; state: Exp; lines: +18 -9
+- removed ^ in parsing for %! heading, because Adobe Photoshop generated a
+ binary heading where ^%! did not work
+- added clipping along %%HiResBoundingBox +0.1 points
+- added option --nohires
+----------------------------
+revision 1.50
+date: 2004/01/25 10:04:56; author: bless; state: Exp; lines: +158 -41
+- ps2eps can now use the bbox device of ghostscript (either by option, environment variable or command line)
+- new environment variable PS2EPS_GSBBOX for specifying a default behavior
+- uses implicitly the ghostscript bbox device if external bbox command cannot be found
+- Added %%HiResBoundingBox output
+- now uses gswin32c as default for MSWin32 or cygwin platforms
+- added handling/passing of predefined paper sizes of ghostscript (including validity check and help)
+- added new environment variable PS2EPS_SIZE for default paper size
+- improved format checking for numerically given size
+- shows used page size if given while processing
+- shows whether it uses the bbox device of ghostscript
+- added use POSIX and check for OS
+- moved ps2eps header comment now after %%EndComments
+- removed looseBB option from call of bbox
+----------------------------
+revision 1.49
+date: 2003/11/19 15:08:52; author: bless; state: Exp; lines: +83 -47
+- Added -t|--translate <x,y> option which allows to specify an offset for drawings
+- Existing Bounding Box will now be detected even if negative and fractional values are contained
+- Translation will happen automatically if a Bounding Box comment exists with negative offsets
+- Warning(s) are printed if Bounding Boxes with negative coordinates are detected
+- Built-in wildcard processing is only effective for non-Unix platforms
+----------------------------
+revision 1.48
+date: 2003/11/09 17:47:47; author: bless; state: Exp; lines: +5 -5
+- print help, license and version to stdout instead of stderr (incorporated patch from Rafael Laboissiere <rafael at debian.org>)
+----------------------------
+revision 1.47
+date: 2003/07/09
+- different informational message for -F flag
+----------------------------
+revision 1.46
+date: 2003/07/09
+- now using Getopt::Long::Configure(), because the other way caused problems with module exports
+- fixsearchpat/fixreplacepat now filters initmatrix initclip initgraphics which is more generic
+ and will hopefully fix more bad postscript code
+- binary section detection had missing CRLFs
+- binary section detection now includes PScript 4 doNimage end marker
+- improved pattern for ADO detection
+----------------------------
+revision 1.45
+date: 2003/07/04
+- improved processing of images for Pscript_Win_Dib_L2: comment filtering
+ will not occur within doNimage,doclutimage,beginjpeg etc.
+----------------------------
+revision 1.44
+date: 2003/07/03
+- looseBB was not initialized
+- disabled use warnings since it may confuse users
+----------------------------
+revision 1.43 (not released)
+date: 2003/07/02
+- deactivated triggered filter and replaced it with search/replace filter
+- new $filtersearchpat,$filterreplacepat combo to filter "initclip"
+ for PScript5.dll Version 5.2
+- sanity check never worked, fixed it
+- new option -W --warnings to allow optional sanity check
+- added various comments and reformatted source a little bit
+- changed output within option processing, --help, --version, etc.
+- added use warnings;
+- refined filter expression in $rangefilter_begin
+- added $exclude_rangefilter_begin and $..._end pair to preserve non PPD
+ feature code (although DSCs are possibly removed)
+ (this feature was integrated from my filterfeatures script)
+----------------------------
+revision 1.42 (not released)
+date: 2003/04/14
+- provided more robustness if Postscript headerline is malformed
+----------------------------
+revision 1.41 (not released)
+date: 2003/03/21
+- converted option processing to Getopt::Long package (based on code from Christophe Druet)
+- rudimentary internal wildcard support (based on code from Christophe Druet)
+ (currently only within current directory)
+----------------------------
+revision 1.40 (not released)
+date: 2003/01/30
+- added filter for Orientation: comment in header, see new option -O
+----------------------------
+revision 1.39
+date: 2002/07/10
+- changed new XP filter to triggered filter
+- improved processing of binary files with beginimage endimage
+----------------------------
+revision 1.38 (not released)
+date: 2002/07/09
+- changed comment filtering in order to prevent image distortion
+- new filter for Windows XP PScript5.dll Version 5.2:
+ Bad lines are:
+ 0 GpPBeg
+ NP
+ 129 400 m 4629 400 l 4629 6400 l 129 6400 l CP
+ eoclip
+ 1 1 1 SC
+ NP
+ 128 400 m 4629 400 l 4629 6400 l 128 6400 l CP
+ AF
+ GSE
+ To avoid the white rectangle deleting all the text above,
+ it is sufficient to delete
+ "1 1 1 SC" to "AF", however, I used eoclip as indicator
+ for the whole sequence.
+----------------------------
+revision 1.37 (not released)
+date: 2001/10/10
+- added "/setpagedevice {pop} def" to prolog in order to fix
+ problems with pdf creation, pstricks and nested dvips output
+ (thanks to Hans Fredrik Nordhaug <hansfn at mi.uib.no> for
+ suggesting this addition)
+----------------------------
+revision 1.36 (not released)
+date: 2001/08/30
+Added filter for Staroffice 5.2 Linux
+revision 1.35
+-------------
+date: 2001/08/20 13:32:36
+- Improved removeADO (tolerates more spaces)
+----------------------------
+revision 1.34 (not released)
+-------------
+date: 2001/08/20 12:38:22
+- Improved processing of files with leading or trailing binary code
+- Improved processing of files with embedded binary coded images
+- Removes gabby diagnostic output from Adobe Printer Driver (see variable removeADO)
+----------------------------
+revision 1.33 (not released)
+-------------
+date: 2001/04/25 22:42:10
+- Corrected %%EOF handling (regex) once again, because of braindead Win-files with _CR_LF
+- Corrected handling of existing %%BoundingBox comments. Now it takes the last one seen.
+ Should esp. work with %%BoundingBox: (atend) usage...
+----------------------------
+revision 1.32 (not released)
+-------------
+date: 2001/04/06 22:31:27
+- Fixed case sensitiveness when checking for suffix replacement
+ (thanks to Erik Jørgensen)
+----------------------------
+revision 1.31
+-------------
+date: 2001/02/27 19:45:19
+- Heuristic added for finding end of file by counting %%EOF comments.
+ Now correctly treats already embedded EPS, too.
+ Usually only trailing garbage (e.g., PCL control sequences) follows
+ last %%EOF. However, sometimes the last %%EOF may be missing.
+ Therefore, the behavior is switchable by new -E option.
+----------------------------
+revision 1.30 (not released)
+-------------
+date: 2001/02/09 16:55:32
+Just forgot the new options in usage line, corrected year in copyright
+----------------------------
+revision 1.29
+-------------
+date: 2001/02/09 15:43:28
+- New first line of code for getting rid of the #! comment
+- EOF handling corrected, allowing better handling of already embedded eps files
+- New -P option to allow selective removal of embedded preview images
+ (was previously default)
+- Preview images were not filtered in the prolog section (now corrected with -P)
+- New -N option to prevent inclusion of any surrounding postscript code
+----------------------------
+revision 1.28
+-------------
+date: 2000/10/13 09:51:55
+\n was missing at altered clipping bounding box
+----------------------------
+revision 1.27 (not released)
+date: 2000/10/13 09:39:07
+Clip option should now also print the enlarged BoundingBox in the
+Postscript header, so it is not cut off if it gets clipped again.
+----------------------------
+revision 1.26
+- just fixed the E-Mail address, because it will not change so often
+ in the future
+----------------------------
+revision 1.25 (not released)
+- new -C option clipping added
+- fixed page bounding box search message
+- bbox 1.10 now fixed scanf() which might cause crashes
+----------------------------
+revision 1.24
+date: 2000/07/24 18:52:36;
+- just forgot the new options in usage txt, now fixed
+----------------------------
+revision 1.23
+date: 2000/07/24 18:34:52;
+- ps2eps now uses existing Bounding Box for GS rendering
+ (can be switched off with -B option)
+- Original Postscript version from first header line should now be retained
+ in output file
+- provide --help and --version with usual meaning for GNU programs
+----------------------------
+revision 1.22
+date: 2000/02/23 14:15:31; author: bless; state: Exp; lines: +12 -6
+ps2eps now draws in color (ppm) by default.
+Monochrome option added.
+Fixing message was not printed for each file.
+----------------------------
+not released before...
diff --git a/support/ps2eps/INSTALL.txt b/support/ps2eps/INSTALL.txt
new file mode 100644
index 0000000000..d3ca8d0926
--- /dev/null
+++ b/support/ps2eps/INSTALL.txt
@@ -0,0 +1,67 @@
+INSTALLATION
+------------
+
+* Prerequisites
+ you need:
+ - perl (an interpreter for the perl language, see http://www.perl.com)
+ - ghostscript (an interpreter/raster image processor
+ for the PostScript language,
+ see http://pages.cs.wisc.edu/~ghost/)
+ - maybe an ANSI-C compiler if the provided binaries for bbox do not work
+ for you. Sorry for the inconvenience, but I tried to write a bbox
+ equivalent in perl and it was terribly slow. Therefore I stick to C,
+ because of much better performance.
+ ALTERNATIVELY you can use ps2eps option -g, then no bbox binary is
+ required.
+
+* How to install
+
+ Please check that you have working
+ perl and ghostscript packages.
+
+ Linux/UNIX-based platform
+ =========================
+ 1.) install bbox
+
+ If a bbox binary is included for your platform you simply move it
+ into any directory of the system search path. Otherwise, you have
+ to compile bbox.c first by invoking
+ cc -o bbox bbox.c.
+ (sometimes "make bbox" also works).
+ Please make sure that bbox is executable (chmod a+x bbox).
+ If you already have a working perl and a working ghostscript, you're
+ finished here, else you have to install them first.
+
+ 2.) install ps2eps
+ On Unix platforms you simply move the perl script ps2eps into
+ a directory which is included in the system or personal search
+ path (e.g., /usr/local/bin, $home/bin). Please make sure that
+ ps2eps is executable (chmod a+x ps2eps).
+
+ Windows-based platform
+ ======================
+ Use the command line interpreter:
+ Copy bbox.exe from bin/win32/ directory into a directory that is
+ in your's or the system's search path for executables. Please try
+ to invoke bbox -h afterwards.
+
+ The best possibility is to use associated file types under
+ Windows NT/2000/XP:
+ 1.) rename ps2eps to ps2eps.pl and
+ 2.) SET PATHEXT=.pl;%PATHEXT% or use the
+ settings -> control panel -> system -> "advanced" tab -> environment variables
+ and edit the PATHEXT entry accordingly.
+ 3.) then simply typing ps2eps should invoke ps2eps correctly
+
+ Another option is to call perl directly:
+ perl ps2eps ...
+
+ The script assumes that you have "gswin32c" as
+ postscript interpreter in your path. Under Windows ps2eps
+ can perform wildcard expansion now on its own.
+
+UPDATES
+-------
+Possibly you can find the newest version at the
+following URL:
+http://tm.uka.de/~bless/ps2eps
diff --git a/support/ps2eps/LICENSE.txt b/support/ps2eps/LICENSE.txt
new file mode 100644
index 0000000000..60549be514
--- /dev/null
+++ b/support/ps2eps/LICENSE.txt
@@ -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) 19yy <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) 19yy 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/ps2eps/Latest_is_1.68 b/support/ps2eps/Latest_is_1.68
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/support/ps2eps/Latest_is_1.68
diff --git a/support/ps2eps/README b/support/ps2eps/README
new file mode 100644
index 0000000000..0f9784de35
--- /dev/null
+++ b/support/ps2eps/README
@@ -0,0 +1,43 @@
+DOCUMENTATION
+=============
+Please see documentation in the manpage or doc/ sub directory.
+Note that the manpage may have an older version number in it,
+which is nothing to worry about since there may have been minor changes
+incorporated into ps2eps not requiring any update of the
+documentation.
+
+INSTALLATION
+============
+Please see instructions in separate text file INSTALL.txt
+
+UPDATES
+=======
+Possibly you can find the newest version at the
+following URL:
+http://www.ipv6.tm.uka.de/~bless/ps2eps
+
+
+Contact information:
+ Roland Bless, roland <at> bless.de
+
+ If you have problems, please send a gzipped file of
+ relevant postscript code with your error description
+ and ps2eps version number.
+
+License:
+ 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
+---------------------------------------------------------------------------
+End of README.txt
+---------------------------------------------------------------------------
diff --git a/support/ps2eps/bin/linux/i386/bbox b/support/ps2eps/bin/linux/i386/bbox
new file mode 100644
index 0000000000..c1d388036f
--- /dev/null
+++ b/support/ps2eps/bin/linux/i386/bbox
Binary files differ
diff --git a/support/ps2eps/bin/linux/x86_64/bbox b/support/ps2eps/bin/linux/x86_64/bbox
new file mode 100755
index 0000000000..42052fe2e2
--- /dev/null
+++ b/support/ps2eps/bin/linux/x86_64/bbox
Binary files differ
diff --git a/support/ps2eps/bin/ps2eps b/support/ps2eps/bin/ps2eps
new file mode 100644
index 0000000000..f02e5a29cd
--- /dev/null
+++ b/support/ps2eps/bin/ps2eps
@@ -0,0 +1,946 @@
+eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}' && eval 'exec perl -S $0 $argv:q' # -*-perl-*-
+ if 0;
+# The expression in the previous line replaces the unix specific line
+# {#!/usr/bin/perl}.
+# ps2eps - convert PostScript to EPS (Encapsulated PostScript) files
+# -------------------------------------------------------------------
+# $Id: ps2eps,v 1.68 2010-05-07 19:42:35 bless Exp $
+# -------------------------------------------------------
+# (C)opyright 1999-2009 Roland Bless
+#
+# 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
+#
+# Author: Roland Bless
+# Send bug reports to roland <at> bless.de
+# -------------------------------------------------------------------
+# Additional filtering is performed when Windows generated PostScript files
+# are processed. Some instructions will otherwise lead to bad output
+# if EPS-file gets embedded into other PostScript files.
+#
+# Requirements:
+# + perl
+# + gs (ghostscript supporting pbm output)
+# + bbox (a little C program [ANSI-C - should work on every platform]
+# for calculation of the actual BoundingBox)
+
+use POSIX;
+
+#use warnings;
+
+#use Getopt package
+use Getopt::Long;
+Getopt::Long::Configure("no_ignore_case");
+
+$prgname= "ps2eps";
+
+if (! -d "/usr/bin")
+{ # we assume that we are running under native windows
+ $ghostscriptname = "gswin32c";
+ $NULLDEV = "nul";
+}
+else
+{ # Unix or cygwin
+ $ghostscriptname = "gs";
+ $NULLDEV = "/dev/null 2>&1";
+}
+
+$bboxver=`bbox >$NULLDEV -V`;
+$bboxname= ($?== -1) ? "" : "bbox";
+$version= '$Id: ps2eps,v 1.68 2010-05-07 19:42:35 bless Exp $'; #'
+$insertPScode= 1; # Insert surrounding Postscript code
+$infhandle = STDIN; # Standard input is the default input file
+$outfhandle = STDOUT; # Standard output is default output if STDIN is input
+$infname= '-';
+$outfname= '-';
+$forceoverwrite=0; # do not overwrite existing files
+$ignoreBB= 0; # ignore existing Bounding Box comment
+$removeDSC= 1; # remove Adobe document structure comments
+$removeADO= 1; # remove Adobe printer Driver console Output [Page: ...]
+$ignoreEOFDSC= 0; # ignore %%EOF DSC hint
+$removePreview= 0; # remove preview
+$quiet= 0; # write progress to stdout
+$resolution= 144; # resolution for bounding box calculation is 2x72 dpi
+$trytofixps= 1; # try to fix postscript code
+$forcefixps= 0; # fix postscript code unconditionally if eq 1
+$filterorientation= 1;# filter Orientation line
+$looseBB=''; # default: tight bounding box
+$clip=0; # do not clip
+$warnings=0; # do not print warnings concerning postscript sanity
+$debuggs=0; # no debugging of ghostscript call, turn this on if you want to see the gs call
+$inch=2.54; # one inch is 2.54cm
+$fullcolors= 1; # use ppm format (24-bit full color)
+$trailerseen= 0; # Trailer comment seen?
+$PSversion="2.0"; # default Postscript Version
+$PSDSCversion="2.0"; # default Postscript DSC Version
+$translate_x= 0; # translate by x postscript points
+$translate_y= 0; # translate by y postscript points
+$allbinary= 0; # treat postscript as binary do not filter or change stuff
+$alphaopt=""; # rendering option for ghostscript "-dTextAlphaBits=4 -dGraphicsAlphaBits=4"
+$hiresprecision=0.5; # amount that is changed of HiresBB in case that looseBB was requested
+
+$defaultext = '(ps|prn)'; # default extension
+$defaultoutext = '.eps'; # default output extension
+$envname_size = 'PS2EPS_SIZE';
+$envname_gsbbox = 'PS2EPS_GSBBOX';
+
+$gpar="";
+$known_papersizes="11x17|ledger|legal|letter(small)?|arch[A-E]|a([0-9]|10)|isob[0-6]|b[0-5]|c[0-6]|jisb[0-6]|fls(a|e)|halfletter";
+$papersize_help="11x17,ledger,legal,letter,lettersmall,archA,archB,archC,archD,archE\
+a0,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,isob0,isob1,isob2,isob3,isob4,isob5,isob6,\
+b0,b1,b2,b3,b4,b5,c0,c1,c2,c3,c4,c5,c6,\
+jisb0,jisb1,jisb2,jisb3,jisb4,jisb5,jisb6,flsa,flse,halfletter\n";
+$trigger= 0;
+$notsane= 0;
+$dummy="";
+
+@ver= split(/ /,$version);
+
+# filename for temporary files
+if ($^O =~ /MSWin32/i or $^O =~ /cygwin/i)
+{
+ # it is less trouble to use the current directory if working on
+ # cygwin and nevertheless using gswin32c.
+ $tmpfname= "$prgname.$$";
+ $win=1;
+}
+elsif (defined($ENV{'TMP'}))
+{
+ $tmpdir= $ENV{'TMP'};
+ $filesep= ($tmpdir =~ /^?\:\\/) ? '\\' : '/';
+ if ($tmpdir =~ /$filesep$/)
+ { $tmpfname= $tmpdir . "$prgname.$$"; }
+ else
+ { $tmpfname= $tmpdir . "$filesep$prgname.$$"; }
+ $win=1;
+}
+else #assume we're on a UNIXBOX
+{
+ $tmpfname= "/tmp/" . "$prgname.$$";
+ $win=0;
+}
+
+
+$licensetxt= "\
+ 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\n";
+
+@prgidtxt= ( "$prgname - convert PostScript to EPS (Encapsulated PostScript) files\n",
+ "(C)opyright 1998-2009 Roland Bless\n\n" );
+
+@helptxt= ("Version: $ver[2]\n",
+ "Operation:\n",
+ " Without any argument, $prgname reads from standard input\n",
+ " and writes to standard output.\n",
+ " If filenames are given as arguments they are processed\n",
+ " one by one and output files are written to filenames\n",
+ " with extension '$defaultoutext'. If input filenames have the extension\n",
+ " '.ps' or '.prn', this extension is replaced with '$defaultoutext'.\n",
+ " In all other cases '$defaultoutext' is appended to the input filename.\n",
+ " Please note that PostScript files for input should contain\n",
+ " only one single page.\n\n",
+ " If BoundingBox in output seems to be wrong, please try options --size or --ignoreBB.\n\n" );
+
+@usagetxt= ("Syntax:\n",
+ " $prgname [-f] [-q] [-N] [-O] [-n] [-P] [-c] [-b] [-C] [-m] [-B] [-E] [-s <pagedim>] [-R +|-|^] [-t <x,y>] [-l] [-g] [-d] [-H] [-h|--help] [-g] [-a] [-W] [-L] [-V|--version] [--] [psfile1] [psfile2] [...]\n",
+ "Options:\n",
+ " -f, --force force overwriting existing files\n",
+ " -q, --quiet quiet operation (no output while processing files)\n",
+ " -N, --noinsert do not insert any postscript code\n",
+ " -O, --preserveorientation do not filter Orientation: header comment\n",
+ " -n, --nofix do not try to fix postscript code\n",
+ " -P, --removepreview remove preview image (smaller file, but no preview)\n",
+ " -F, --fixps fix postscript code unconditionally\n",
+ " -c, --comments preserve document structure comments\n",
+ " -b, --binary treat postscript as binary, do not modify characters\n",
+ " -C, --clip insert postscript code for clipping\n",
+ " -m, --mono use black/white bitmap as base for calculation\n",
+ " -s, --size=<pagedim> page size (a0-a10,letter,...) or in format XxY[cm|in] (default:cm), where X and Y are numbers\n",
+ " use --size=list to list pre-defined page sizes\n",
+ " -R, --rotate=<direction> rotate resulting EPS. <direction>: +=+90 (clockw.),-=-90 (counter-clockw.) ^=180 degrees\n",
+ " -t, --translate specify x,y offset (may be negative) in postscript points (1/72 dpi)\n",
+ " -r, --resolution specify dpi resolution to render with ghostscript (default 144)\n",
+ " -l, --loose expand the original bounding box by one point in each direction\n",
+ " -B, --ignoreBB do not use existing bounding box as page size for rendering\n",
+ " -E, --ignoreEOF do not use %%EOF as hint for end of file\n",
+ " -g, --gsbbox use internal bbox device of ghostscript\n",
+ " -H, --no-hires do not use a HiResBoundingBox\n",
+ " -h, --help help information\n",
+ " -L, --license show licensing information\n",
+ " -V, --version show version information\n",
+ " -d, --debuggs show ghostscript call\n",
+ " -a, --accuracy improve accuracy during rendering (maybe slower)\n",
+ " -W, --warnings show warnings about sanity of generated eps file\n",
+ " -- all following arguments are treated as files\n",
+ " (allows filenames starting with -)\n",
+ "\n",
+ "Arguments:\n",
+ " One or more names of PostScript files for input\n");
+
+## %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+## -- argument checking --
+## %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+#environment variable for papersize
+if (defined($ENV{"$envname_size"}))
+{
+ $opt_s= $ENV{"$envname_size"};
+}
+else
+{
+ $opt_s = ''; # for s-option
+}
+
+if (defined($ENV{"$envname_gsbbox"}))
+{
+ $bboxname="";
+}
+
+$opt_t = ''; # for t-option
+$opt_R = ''; # for R-option
+$opt_r = ''; # for r-option
+$stopnow = 0;
+die "Wrong option(s), please check usage with $prgname --help\n" unless
+GetOptions('f|force' => \$forceoverwrite,
+ 'q|quiet' => \$quiet,
+ 'm|mono' => sub { $fullcolors = 0 },
+ 'n|nofix' => sub { $trytofixps = 0 },
+ 'F|fixps' => \$forcefixps,
+ 'N|noinsert' => sub { $insertPScode = 0 },
+ 'O|preserveorientation' => sub { $filterorientation= 0 },
+ 'P|removepreview' => \$removePreview,
+ 'c|comments' => sub { $removeDSC = 0 },
+ 'b|binary' => sub { $allbinary = 1 },
+ 'C|clip' => \$clip,
+ 'l|loose' => sub { $looseBB = '-l' },
+ 'B|ignoreBB' => \$ignoreBB,
+ 'E|ignoreEOF'=> \$ignoreEOFDSC,
+ 's|size=s' => \$opt_s,
+ 't|translate=s' => \$opt_t,
+ 'r|resolution=s' => \$opt_r,
+ 'R|rotate=s' => \$opt_R,
+ 'g|gsbbox' => sub { $bboxname=""; },
+ 'H|nohires' => \$nohires,
+ 'h|help' => sub { $stopnow = 1; print @prgidtxt,@helptxt,@usagetxt,"\nAuthor: Roland Bless (roland\@bless.de)\n\n"; },
+ 'L|license' => sub { $stopnow = 1; print @prgidtxt,$licensetxt,"\nAuthor: Roland Bless (roland\@bless.de)\n\n"; },
+ 'a|accuracy' => sub { $alphaopt = '-dTextAlphaBits=4 -dGraphicsAlphaBits=4' },
+ 'd|debuggs' => \$debuggs,
+ 'W|warnings' => \$warnings,
+ 'V|version' => sub { $stopnow = 1; print @prgidtxt,"Version: $ver[2]\n"; });exit if ($stopnow);
+
+## %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+## -- wildcard processing --
+## %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+## internal wildcard processing for current directory,
+## only used for non UNIX-based OSs (which may lack shell wildcard expansion)
+@filenames = ();
+foreach $object (@ARGV) {
+ if ($win && $object =~ m/\*/o) # asterisk is present in filename
+ {
+ $wildcard = $object;
+ $wildcard =~ s/\./\\\./g; # replace . in pattern with \.
+ $wildcard =~ s/\*/\(\.\*\)/g; # replace * in pattern with (.*)
+ opendir(DIR,'.') || die 'Unable to open current directory, stopped'; # open current directory
+ print STDERR $wildcard;
+ @fid = grep { /$wildcard(\.$defaultext)?/i } readdir(DIR);
+ foreach (@fid) { push @filenames, $_; }
+ closedir DIR;
+ }
+ else { push @filenames, $object; }
+} # end foreach
+$filenames[0]= '-' if (scalar(@filenames) == 0); # no file arguments, use STDIN as input
+
+print STDERR "Input files: @filenames\n" if (!$quiet);
+
+if ($opt_r ne '')
+{
+ $resolution=$opt_r;
+}
+
+# papersize stuff
+if ($opt_s ne '')
+{
+ # if explicit size is given, ignore existing BoundingBox always
+ $ignoreBB = 1;
+ $pagedimension = $opt_s;
+ if ($opt_s eq "list")
+ {
+ print STDERR "Available paper sizes: $papersize_help";
+ exit 0;
+ }
+
+ #explicit format XxY[cm|in]
+ if ($pagedimension =~ /(\d*\.?\d+)x(\d*\.?\d+)/)
+ {
+ ($x_dim, $dummy, $y_dim, $unit)= split(/(x|cm|in)/,$pagedimension);
+ if ( $x_dim !~ /^\d*\.?\d+$/ )
+ { die "$x_dim in $arg is not a valid number, stopped"; }
+ if ( $y_dim !~ /^\d*\.?\d+$/ )
+ { die "$y_dim in $arg is not a valid number, stopped"; }
+
+ #print STDERR "xdim: $x_dim ydim: $y_dim unit:$unit\n" ;
+ if (!defined($unit) )
+ {
+ $unit='cm';
+ $opt_s=$opt_s . $unit;
+ }
+ if ( $unit ne 'in' ) # assume centimeters
+ { # calculate dimension in pixels (remember: resolution is in dpi)
+ $xpixels= int(($x_dim * $resolution) / $inch)+1;
+ $ypixels= int(($y_dim * $resolution) / $inch)+1;
+ $gpar= "-g${xpixels}x${ypixels}";
+ }
+ else
+ {
+ $xpixels= int($x_dim * $resolution)+1;
+ $ypixels= int($y_dim * $resolution)+1;
+ $gpar= "-g${xpixels}x${ypixels}";
+ }
+ } #endif XxY in opt_s
+ else
+ {
+ if ($opt_s =~ /$known_papersizes/)
+ {
+ $gpar="-sPAPERSIZE=$opt_s";
+ }
+ else
+ {
+ print STDERR "Error: Unknown paper size: $opt_s\n Acceptable papersizes are:$papersize_help\n";
+ exit 1;
+ }
+ }
+}
+
+#translate option
+if ($opt_t ne '')
+{
+ ($translate_x,$translate_y)= split(/\,/,$opt_t);
+}
+
+#rotate
+$rotright='-90 rotate';
+$rotleft='90 rotate';
+$rotupsidedown='180 rotate';
+$rotate='';
+if ($opt_R ne '')
+{
+ if ($opt_R eq '+') { $rotate=$rotright; }
+ elsif ($opt_R eq '-') { $rotate=$rotleft; }
+ elsif ($opt_R eq '^') { $rotate=$rotupsidedown; }
+ else { die "Wrong parameter for option -R: Valid are only +,-,^\n"; };
+}
+
+$device= $fullcolors ? "ppmraw" : "pbmraw";
+
+## %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+## -- iterate over different input files --
+## %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+PROCESSFILE:
+while ($infname= (shift @filenames))
+{
+ # reset filter definitions for each file
+ undef $linefilter;
+ undef $rangefilter_begin;
+ undef $rangefilter_end;
+ $fixthisps= $trytofixps;
+ $fixmsgprinted= 0;
+
+ if (!$quiet) { print STDERR "Processing: $infname\n"; }
+ unless (open($infhandle,"<$infname"))
+ { # skip over this file
+ print STDERR "$prgname: Can't open $infname: $!\n";
+ next PROCESSFILE;
+ }
+
+ # buffer input from stdin into temporary file, because it has to be read twice
+ # one time for ghostscript processing, the second time for generating output
+ if ($infname eq '-') # input is stdin
+ {
+ $tmpfhandle='';
+ open($tmpfhandle,">$tmpfname") or
+ die "Cannot open temporary file $tmpfname for writing: $!\n";
+ }
+ else # input is not stdin
+ {
+ undef $tmpfhandle;
+ #if filename ends with $defaultext usually .ps or .prn, replace the extension with $defaultoutext
+ if ($infname =~ /\.$defaultext$/i)
+ {
+ $outfname= $infname; $outfname =~ s/\.$defaultext$/$defaultoutext/i;
+ }
+ else # otherwise simply append the extension $defaultoutext
+ {
+ $outfname= $infname . "$defaultoutext";
+ }
+ } #end else input is not stdin
+
+ ## %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+ ## -- process input file --
+ ## %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+ $linefilter= '^$'; #'# filter empty lines by default
+ while (<$infhandle>)
+ {
+ # get postscript and DSC version
+ if (/%!PS-Adobe-(\S+).*EPSF-(\S+)/)
+ {
+ $PSversion=$1;
+ $PSDSCversion=$2;
+ if (! ($PSversion =~ /\d+\.\d+/))
+ {
+ $PSDSCversion="2.0";
+ }
+ if (! ($PSDSCversion =~ /\d+\.\d+/))
+ {
+ $PSDSCversion="2.0";
+ }
+ }
+
+ # check for existing BoundingBox parameters
+ if ( /^%%\s*BoundingBox:\s*(.*)/ && !defined($eBBllx) )
+ {
+ $BBarg= $1;
+ # accept even negative and fractional BBs
+ if ( $BBarg =~ /(\-?\d+\.?\d*\s+){3,}\d+/ ) # ignore %% BoundingBox: (atend) comments
+ {
+ ($eBBllx,$eBBlly,$eBBurx,$eBBury,$dummy)= split /\s/,$BBarg;
+ #print STDERR "Existing BB: $eBBllx,$eBBlly,$eBBurx,$eBBury\n";
+ if (int($eBBllx) < 0) { $translate_x= - int($eBBllx-0.5); }
+ if (int($eBBlly) < 0) { $translate_y= - int($eBBlly-0.5); }
+
+ $xpixels= int((($eBBurx-$eBBllx) * $resolution)/72 + 0.5);
+ $ypixels= int((($eBBury-$eBBlly) * $resolution)/72 + 0.5);
+ if (!$ignoreBB)
+ {
+ $gpar= "-g${xpixels}x${ypixels}";
+ # check for meaningful values
+ if (($xpixels <= 1) || ($ypixels <= 1))
+ {
+ $gpar=""; undef $eBBllx; undef $eBBlly;
+ }
+ else
+ {
+ if (!$quiet)
+ {
+ print STDERR "Rendering with existing $_";
+ if (int($eBBllx) < 0 || int($eBBlly) < 0)
+ {
+ print STDERR "WARNING: existing Bounding Box shows negative values - shifting\n";
+ }
+ }
+ }
+ } #endif !$ignoreBB
+ } #endif $BBarg =~
+ }
+
+
+ if ($fixthisps) # try to fix bad postscript code
+ {
+ # check for Windows 3.x output
+ if ( /^Win.*Dict/ )
+ {
+ if (!$quiet && !$fixmsgprinted)
+ { print STDERR "Windows 3.5 generated Postscript file detected, fixing\n"; }
+ $linefilter= '^(EJ|RS)';
+ $rangefilter_begin= '^statusdict';
+ $rangefilter_end= 'cvx\ settransfer$'; #'
+ $fixmsgprinted= 1; # stop printing message
+ }
+ else
+ {
+ if ( /^%%Creator:\s*Wind.U\s*Xprinter/ )
+ {
+ if (!$quiet && !$fixmsgprinted)
+ { print STDERR "Star/OpenOffice generated Postscript file detected, fixing\n"; }
+ $linefilter= '^rs';
+ $fixmsgprinted= 1; # stop printing message
+ }
+ else
+ {
+ if ( $forcefixps ||
+ /^\/NTPS/ ||
+ /Creator:\s*(AdobePS|Pscript|.*Windows)/i ) #check for NT generated output
+ {
+ if (!$quiet && !$fixmsgprinted)
+ {
+ if ($forcefixps)
+ {
+ print STDERR "Postscript filtering requested, fixing\n";
+ }
+ else
+ {
+ print STDERR "Windows generated Postscript file detected, fixing\n";
+ }
+ }
+ $rangefilter_begin= '^((\[\{)|(featurebegin\{))$'; #'
+ $rangefilter_end= '^(\} stopped cleartomark|\}featurecleanup)';
+ $exclude_rangefilter_begin= '^(?i)%%BeginNonPPDFeature'; #'
+ $exclude_rangefilter_end= '^(?i)%%EndNonPPDFeature';
+ #$triggered_rangefilter_begin= ''; #'
+ #$triggered_rangefilter_end= ''; #'
+ $fixsearchpat='(^|\s)(initmatrix|initclip|initgraphics)(\s|$)';
+ $fixreplacepat=' ';
+ $fixmsgprinted= 1; # stop printing message
+ } # end if NTPS
+ } #end else
+ }
+ } #end if trytofixps
+
+ if (defined($tmpfhandle))
+ {
+ print $tmpfhandle $_ or die "$prgname: Failure during writing to temporary file $tmpfname";
+ }
+
+ if (/^%%EOF\s*$/)
+ {
+ $totalEOFDSC++
+ }
+ } #end while <$infhandle>
+
+ if (defined($tmpfhandle))
+ {
+ close($tmpfhandle);
+ }
+ else
+ {
+ $tmpfhandle= $infhandle;
+ $tmpfname= $infname;
+ }
+
+ ## %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+ ## -- calculate the bounding box --
+ ## %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+ if ($translate_x!=0 || $translate_y!=0)
+ {
+ $translation="$translate_x $translate_y translate";
+ $translatecmd="-c \'$translation\'";
+ }
+ else
+ {
+ $translation="";
+ $translatecmd="";
+ }
+
+ if (!$quiet)
+ {
+ print STDERR "Calculating Bounding Box...";
+ if ($opt_s)
+ {
+ print STDERR "using page size $opt_s...";
+ }
+ }
+
+ $rotatecmd='';
+ if ($rotate ne '')
+ {
+ $rotatecmd="-c \"$rotate\""
+ }
+ if ($bboxname ne '')
+ {
+ $cmdline="$ghostscriptname -dSAFER -dNOPAUSE $alphaopt -q $gpar -r$resolution -sDEVICE=$device -sOutputFile=- $translatecmd -f \"$tmpfname\" -c showpage -c quit | $bboxname -r $resolution";
+ }
+ else
+ {
+ if (!$quiet) {
+ print STDERR "...using bbox device of $ghostscriptname...";
+ }
+ $cmdline = "$ghostscriptname -dSAFER -dBATCH -dNOPAUSE -q $gpar -r$resolution -sDEVICE=bbox -sOutputFile=- -c \"/setpagedevice {pop} def\" $translatecmd -f \"$tmpfname\" -c quit 2>&1";
+ }
+
+ if ($debuggs) { print STDERR "\nCalling: $cmdline\n"; }
+
+ # actual ghostscript call
+ $boundingbox=`$cmdline`;
+ if ($debuggs) { print STDERR "Call result: $boundingbox"; }
+
+ # check result of gs call
+ if ($boundingbox !~ /^%%BoundingBox/m)
+ {
+ die "Error: Could not determine bounding box!\n",
+ "I suppose $ghostscriptname had some trouble interpreting the postscript-file $infname. Exiting now.\n";
+ }
+
+ $boundingbox =~ /^%%HiResBoundingBox:\s*(.*)/m;
+ if (defined($1)) # HiResBoundingBox given
+ {
+ ($hcBBllx,$hcBBlly,$hcBBurx,$hcBBury,$dummy)= split(/\s/,$1);
+ $hiresboundingbox="%%HiResBoundingBox: $hcBBllx $hcBBlly $hcBBurx $hcBBury\n";
+ $cBBllx = floor($hcBBllx);
+ $cBBlly = floor($hcBBlly);
+ $cBBurx = ceil($hcBBurx);
+ $cBBury = ceil($hcBBury);
+ }
+ else
+ { #use normal BoundingBox
+ $boundingbox =~ /^%%.*BoundingBox:\s*(.*)/;
+ ($cBBllx,$cBBlly,$cBBurx,$cBBury,$dummy)= split(/\s/,$1);
+ }
+ # if loose BB is requested
+ # apply changes to resulting bounding box if needed
+ if ($looseBB ne '')
+ {
+ if ($cBBllx > 0) { $cBBllx--; }
+ if ($cBBlly > 0) { $cBBlly--; }
+ $cBBurx++;
+ $cBBury++;
+
+ if ($hcBBllx-$hiresprecision >= 0.0) { $hcBBllx-= $hiresprecision; }
+ if ($hcBBlly-$hiresprecision >= 0.0) { $hcBBlly-= $hiresprecision; }
+ $hcBBurx+= $hiresprecision;
+ $hcBBury+= $hiresprecision;
+ $hiresboundingbox="%%HiResBoundingBox: $hcBBllx $hcBBlly $hcBBurx $hcBBury\n";
+
+ }
+ if ($cBBllx < 0 || $cBBlly < 0)
+ {
+ if (!$quiet)
+ {
+ print STDERR "WARNING! Your drawing had a negative Bounding Box which is deprecated and may cause problems!. I'll shift it.\n";
+ }
+ $translate_x= -int($cBBllx);
+ $translate_y= -int($cBBlly);
+ $cBBllx=0;
+ $cBBurx= $cBBurx + $translate_x;
+ $cBBlly=0;
+ $cBBury= $cBBury + $translate_y;
+
+ $hcBBurx= $hcBBurx + $hcBBllx;
+ $hcBBury= $hcBBury + $hcBBlly;
+ $hcBBllx= 0;
+ $hcBBlly= 0;
+
+ $hiresboundingbox="%%HiResBoundingBox: $hcBBllx $hcBBlly $hcBBurx $hcBBury\n";
+
+ $translation="$translate_x $translate_y translate";
+ $translatecmd="-c \'$translation\'";
+ }
+ $boundingbox = "%%BoundingBox: $cBBllx $cBBlly $cBBurx $cBBury\n";
+
+ if (!$quiet) { print STDERR "ready. $boundingbox" };
+
+ $before_startps= 1;
+ $inserted_prolog= 0;
+ $prolog_passed= 0;
+
+ ## %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+ ## -- Create output file --
+ ## %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+ if (!$quiet) { print STDERR "Creating output file $outfname ... "; }
+ if (!$forceoverwrite and -s "$outfname")
+ {
+ die "$prgname: Sorry, file named $outfname already exists,",
+ " will not overwrite it.\n",
+ " You will have to use the -f option, delete it or rename it",
+ " before running $prgname again.\n";
+ }
+ else
+ {
+ open($outfhandle,">$outfname") or die "Can't open file $outfname for writing: $!\n";
+ }
+
+
+ open($tmpfhandle,"<$tmpfname") or die "Cannot open file $tmpfname for reading";
+ CREATEOUTPUT:
+ while (<$tmpfhandle>)
+ {
+ # check whether we are in a binary section
+
+ $binarysection=$allbinary ||
+ (/^(%%Begin(Binary|Data))|(beginimage)\r?\n?$/ ... /^(%%End(Binary|Data))|^(endimage)/) ||
+ (/^(doNimage)|(doclutimage)\r?\n?$/ ... /(^|~> )Z\r?\n?$/) || # Pscript_Win_Dib_L2 5.0 0
+ (/^beginjpeg / ... /~> endjpeg\r?\n?$/) || # Pscript_Win_Dib_L2 5.0 0
+ (/^pdfIm/ ... /^%-EOD-/);
+
+ if ( !$binarysection )
+ {
+ s/\r?\n?$//; # remove CR and/or LF at end of line if not in binary section
+ }
+
+ # check where magic Postscript header starts - skip leading binary stuff, e.g., HP PCL/PJL code
+ if ($before_startps)
+ {
+ if ( /%!/ ) # This is usually the smallest magic sequence
+ { # Note: Adobe Photoshop generated a binary heading, so ^ is not applicable
+ # %! may be part of a binary sequence, but then control characters follow
+ # so skip %! if non alphanumeric characters follow
+ if ( ! /%!.*[^\w]{2,}/ )
+ {
+ # some heading without two control characters found
+ $before_startps= 0;
+ if (! /%!PS-Adobe.*/i) # some strange programs use other magics
+ {
+ print STDERR "** Warning **: Weird heading line -- ",$_," -- ";
+ }
+ }
+ }
+ next CREATEOUTPUT;
+ }
+ else # we are hopefully in regular postscript code now
+ {
+ # count %%EOFs as we want to know when we got the last EOF
+ if ( /^%%EOF\s*$/ )
+ {
+ $seenEOF++;
+ }
+
+ # We should insert our own prologue including the newly calculated BoundingBox
+ if (! $inserted_prolog)
+ {
+ print $outfhandle "%!PS-Adobe-$PSversion EPSF-$PSDSCversion\n";
+ # check if we need to rotate
+ $transrotcmd='';
+ if ($rotatecmd)
+ {
+ if ($rotate eq $rotright)
+ {
+ $transrotcmd="-$cBBlly $cBBurx translate";
+ $boundingbox='%%BoundingBox: 0 0 ' . ($cBBury-$cBBlly) . ' ' . ($cBBurx-$cBBllx) . "\n";
+ if ($hiresboundingbox ne "")
+ {
+ $hiresboundingbox='%%HiResBoundingBox: 0 0 ' . ($hcBBury-$hcBBlly) . ' ' . ($hcBBurx-$hcBBllx) . "\n";
+ }
+
+ }
+ elsif ($rotate eq $rotleft)
+ {
+ $transrotcmd="$cBBury -$cBBllx translate";
+ $boundingbox='%%BoundingBox: 0 0 ' . ($cBBury-$cBBlly) . ' ' . ($cBBurx-$cBBllx) . "\n";
+ if ($hiresboundingbox ne "")
+ {
+ $hiresboundingbox= '%%HiResBoundingBox: 0 0 ' . ($hcBBury-$hcBBlly) . ' ' . ($hcBBurx-$hcBBllx) . "\n";
+ }
+ }
+ elsif ($rotate eq $rotupsidedown)
+ {
+ $transrotcmd="$cBBurx $cBBury translate";
+ $boundingbox='%%BoundingBox: 0 0 ' . ($cBBurx-$cBBllx) . ' ' . ($cBBury-$cBBlly) . "\n";
+ if ($hiresboundingbox ne "")
+ {
+ $hiresboundingbox='%%HiResBoundingBox: 0 0 ' . ($hcBBurx-$hcBBllx) . ' ' . ($hcBBury-$hcBBlly) . "\n";
+ }
+ }
+ }
+ print $outfhandle $boundingbox;
+ if (!defined($hiresboundingbox))
+ {
+ $nohires=1;
+ }
+ if (defined($hiresboundingbox) && !defined($nohires)) { print $outfhandle $hiresboundingbox; }
+ $inserted_prolog= 1;
+ redo CREATEOUTPUT;
+ }
+ else # already inserted_prolog
+ {
+ if (! $prolog_passed)
+ {
+ #ignore the following lines in the prologue
+ if ( /^%%(HiRes)?BoundingBox/ ||
+ /^%%Pages/ ||
+ /^%%BeginProlog/ ||
+ /^%%EndProlog/ ||
+ ($filterorientation && /^%%Orientation/) ||
+ ($removeDSC && /^%%.*: \(atend\)/) ||
+ ($removePreview && (/^%%BeginPreview/ ... /^%%EndPreview/)) )
+ {
+ next CREATEOUTPUT;
+ }
+ else
+ {
+ if ( /^[^%].*/ ||
+ /^%%EndComments/ ) # line is not a comment
+ {
+ #output postscript code for proper EPS file
+ if ($insertPScode)
+ {
+ print $outfhandle "%%EndComments\n",
+ "% EPSF created by ps2eps $ver[2]\n",
+ "%%BeginProlog\n";
+ }
+ # Insert own postscript code for clipping
+ if ($clip)
+ {
+ if (!defined($nohires))
+ {
+ printf $outfhandle "newpath %f %f moveto %f %f lineto %f %f lineto %f %f lineto closepath clip\n",$hcBBllx,$hcBBlly,$hcBBurx,$hcBBlly,$hcBBurx,$hcBBury,$hcBBllx,$hcBBury;
+ }
+ else
+ {
+ printf $outfhandle "newpath %d %d moveto %d %d lineto %d %d lineto %d %d lineto closepath clip\n",$cBBllx,$cBBlly,$cBBurx,$cBBlly,$cBBurx,$cBBury,$cBBllx,$cBBury;
+ }
+ } #endif clip
+
+ if ($rotate ne '')
+ {
+ print $outfhandle "$transrotcmd\n";
+ print $outfhandle "$rotate\n";
+ }
+ if ($translation ne '')
+ {
+ print $outfhandle "$translation\n";
+ }
+
+ #insert surrounding postscript code
+ if ($insertPScode)
+ {
+ print $outfhandle "save\n",
+ "countdictstack\n",
+ "mark\n",
+ "newpath\n",
+ "/showpage {} def\n",
+ "/setpagedevice {pop} def\n",
+ "%%EndProlog\n",
+ "%%Page 1 1\n";
+ }
+ $prolog_passed= 1;
+ if (/^%%EndComments/) { next CREATEOUTPUT; }
+ } #endif line is not a comment
+ } #end else
+ } #endif (we are in the prologue section)
+ else #we are in the main part of postscript file
+ {
+ #end of postscript file reached?
+ #Usually the DSC %%EOF signifies the end
+ if ( eof($tmpfhandle) ||
+ ($ignoreEOFDSC == 0 && /^%%EOF\s*$/ && $seenEOF == $totalEOFDSC)
+ || ( $trailerseen && /^II\*\000.*/ )
+ )
+ {
+ #do not forget to print last line if not terminated by LF
+ if ( eof($tmpfhandle) && !/^$/ && !/^%%EOF\s*$/ ) # do not insert %%EOF twice
+ {
+ print $outfhandle $_,"\n";
+ }
+ #add appropriate trailer
+ if ($insertPScode)
+ {
+ print $outfhandle "%%Trailer\n",
+ "cleartomark\n",
+ "countdictstack\n",
+ "exch sub { end } repeat\n",
+ "restore\n",
+ "%%EOF\n";
+ }
+ last CREATEOUTPUT;
+ } # stop output
+
+ # Trailer comment seen?
+ if ( /^%%Trailer\s*$/ )
+ {
+ $trailerseen=1;
+ }
+ else
+ {
+ if (!/^\s*$/) #non empty lines follow
+ {
+ $trailerseen=0;
+ }
+ }
+
+ # check for trigger
+ if (defined($triggerstring) && /^$triggerstring$/)
+ {
+ $trigger= 1;
+ };
+
+ # remove complete lines if one of the expression matches
+ if ( !$binarysection # only when not in binary section
+ &&
+ (
+ ($removePreview && (/^%%BeginPreview/ ... /^%%EndPreview/))
+ || # no preview
+ (defined($rangefilter_begin) &&
+ (/$rangefilter_begin/ ... /$rangefilter_end/) &&
+ (!(/$exclude_rangefilter_begin/ ... /$exclude_rangefilter_end/))
+ )
+ ||
+ (defined($triggered_rangefilter_begin) && defined($triggered_rangefilter_end) &&
+ $trigger &&
+ (/$triggered_rangefilter_begin/ ... /$triggered_rangefilter_end/)
+ )
+ ||
+ /$linefilter/ # lines by linefilter
+ ||
+ ($removeDSC && (/^%( |!)(\w )+/ || /^%%([A-Za-z]+\s)/)) # any type of structured comment
+ ||
+ ($removeADO &&
+ (/^statusdict begin.*ProductName.*print product print.*flush end\r?\n?$/ ||
+ /^\(%%\[\s*(Page:.*|LastPage)\s*\]%%\)\s*=\s*\w*\s*\r?\n?/ ))
+ ||
+ /^$/ # empty lines
+ )
+ )
+ {
+ next CREATEOUTPUT;
+ }
+
+ # replacement
+ if ( defined($fixsearchpat) )
+ {
+ #if (/$fixsearchpat/) { print STDERR "**filter** before:",$_,"\n"; }
+ #if (s/$fixsearchpat/$fixreplacepat/) { print STDERR "**filter** after:",$_,"\n";}
+ s/$fixsearchpat/$fixreplacepat/;
+ }
+
+ # sanity check for potential dangerous commands
+ if ( /(^|\s)(clear|erasepage|initmatrix|initclip|initgraphics|startjob|cleardictstack|setmatrix|setpagedevice|copypage|grestoreall|exitserver|quit)(\s|$)/ )
+ {
+ $notsane= 1;
+ #print STDERR "Warning: dangerous command in line: ",$_,"\n";
+ }
+ } # end else (this is main part)
+
+ # Output the postscript line to result file
+ print $outfhandle $_;
+
+ if (!$binarysection)
+ {
+ print $outfhandle "\n"; # terminate line with LF
+ }
+ } # end else prolog_passed
+ } # end else inserted_prolog
+ } # end while CREATEOUTPUT
+
+ close($tmpfhandle);
+
+ if ($tmpfname ne $infname) { unlink "$tmpfname"; } #remove temporary file
+
+ close ($outfhandle);
+
+ # print warning if magic sequence not found
+ if ( $before_startps )
+ {
+ print STDERR "\n ** Error!! **: could not identify begin of postscript code in file $infname, please check header line!\n First line should start with %!. No output generated.\n";
+ }
+
+ if (!$quiet) { print STDERR "ready.\n"; }
+ if ($warnings and $notsane and !$quiet)
+ {
+ print STDERR "** Warning **: EPS-output for $infname is not sane, at least one\n",
+ "of the following commands was still present:\n",
+ "clear erasepage initmatrix initclip initgraphics startjob\n",
+ "cleardictstack setmatrix setpagedevice copypage grestoreall\n",
+ "exitserver quit\n";
+ }
+} #end while PROCESSFILE
+
+# ---- end of perl-script -------
diff --git a/support/ps2eps/doc/html/bbox.html b/support/ps2eps/doc/html/bbox.html
new file mode 100644
index 0000000000..581d13f7bc
--- /dev/null
+++ b/support/ps2eps/doc/html/bbox.html
@@ -0,0 +1,226 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN""http://www.w3.org/TR/html4/loose.dtd">
+<HTML
+><HEAD
+><TITLE
+>bbox</TITLE
+><META
+NAME="GENERATOR"
+CONTENT="Modular DocBook HTML Stylesheet Version 1.79"></HEAD
+><BODY
+CLASS="REFENTRY"
+BGCOLOR="#FFFFFF"
+TEXT="#000000"
+LINK="#0000FF"
+VLINK="#840084"
+ALINK="#0000FF"
+><H1
+><A
+NAME="AEN1"
+></A
+>bbox</H1
+><DIV
+CLASS="REFNAMEDIV"
+><A
+NAME="AEN15"
+></A
+><H2
+>Name</H2
+>bbox&nbsp;--&nbsp; prints out the bounding box of a rawppm or rawpbm image
+ </DIV
+><DIV
+CLASS="REFSYNOPSISDIV"
+><A
+NAME="AEN18"
+></A
+><H2
+>Synopsis</H2
+><P
+><B
+CLASS="COMMAND"
+>bbox</B
+> [<CODE
+CLASS="OPTION"
+>-l</CODE
+>] [<CODE
+CLASS="OPTION"
+>-r</CODE
+>] [<CODE
+CLASS="OPTION"
+>-h</CODE
+>] [<CODE
+CLASS="OPTION"
+>-V</CODE
+>] [<TT
+CLASS="REPLACEABLE"
+><I
+>rawpbmfile</I
+></TT
+>]</P
+></DIV
+><DIV
+CLASS="REFSECT1"
+><A
+NAME="AEN31"
+></A
+><H2
+>DESCRIPTION</H2
+><P
+><B
+CLASS="COMMAND"
+>bbox</B
+> reads a rawppm or rawpbm file
+ and prints out the bounding box of the image (as postscript comment and
+ in postscript points, i.e. 1/72dpi) as well as the high resolution
+ bounding box. Input is read from standard input if no filename is
+ specified.
+ Example output:
+ <PRE
+CLASS="SCREEN"
+> %%BoundingBox: 12 253 829 837
+ %%HiResBoundingBox: 12.500000 253.000000 828.500000 837.00000
+ </PRE
+>
+ </P
+><P
+><B
+CLASS="COMMAND"
+>bbox</B
+> has only very limited memory requirements
+ as it reads the input line by line and thus needs to store only one picture
+ line in memory.
+ </P
+></DIV
+><DIV
+CLASS="REFSECT1"
+><A
+NAME="AEN38"
+></A
+><H2
+>OPTIONS</H2
+><P
+></P
+><DIV
+CLASS="VARIABLELIST"
+><DL
+><DT
+><CODE
+CLASS="OPTION"
+>-h | --help</CODE
+></DT
+><DD
+><P
+>Show summary of options.</P
+></DD
+><DT
+><CODE
+CLASS="OPTION"
+>-V</CODE
+></DT
+><DD
+><P
+>Show version of program.</P
+></DD
+><DT
+><CODE
+CLASS="OPTION"
+>-r</CODE
+></DT
+><DD
+><P
+>resolution of picture in dpi</P
+></DD
+><DT
+><CODE
+CLASS="OPTION"
+>-l</CODE
+></DT
+><DD
+><P
+>loose bounding box (integer bounding box is expanded by 1
+ point, hires bounding box is expanded by 0.5 points)</P
+></DD
+></DL
+></DIV
+></DIV
+><DIV
+CLASS="REFSECT1"
+><A
+NAME="AEN61"
+></A
+><H2
+>SEE ALSO</H2
+><P
+>ps2eps (1)</P
+></DIV
+><DIV
+CLASS="REFSECT1"
+><A
+NAME="AEN64"
+></A
+><H2
+>AUTHOR</H2
+><P
+><B
+CLASS="COMMAND"
+>bbox</B
+> was written by Roland Bless. </P
+><DIV
+CLASS="REFSECT2"
+><A
+NAME="AEN68"
+></A
+><H3
+>ACKNOWLEDGMENTS</H3
+><P
+>Special thanks goes to Michael Sharpe from UCSD who suggested a lot of improvements for
+ bbox to become more precise and robust, especially for small drawings.</P
+><P
+>An earlier version of this manual page was originally written by
+ Rafael Laboissiere <CODE
+CLASS="EMAIL"
+>&#60;<A
+HREF="mailto:rafael@debian.org"
+>rafael@debian.org</A
+>&#62;</CODE
+> for
+ the <SPAN
+CLASS="PRODUCTNAME"
+>Debian</SPAN
+> system. Thank you Rafael! Permission is
+ granted to copy, distribute and/or modify this document under
+ the terms of the <ACRONYM
+CLASS="ACRONYM"
+>GNU</ACRONYM
+> Free Documentation
+ License, Version 1.1 or any later version published by the Free
+ Software Foundation; with no Invariant Sections, no Front-Cover
+ Texts and no Back-Cover Texts.</P
+></DIV
+></DIV
+><DIV
+CLASS="REFSECT1"
+><A
+NAME="BUGS"
+></A
+><H2
+>BUGS</H2
+><P
+> Though the code is quite small and the probability for bugs
+ is now small, there may be some left somewhere between the lines.
+ In case you find one, please send a short description with
+ <B
+CLASS="COMMAND"
+>bbox</B
+> version number to <CODE
+CLASS="EMAIL"
+>&#60;<A
+HREF="mailto:roland@bless.de"
+>roland@bless.de</A
+>&#62;</CODE
+> (please allow some time
+ to reply).
+ </P
+></DIV
+></BODY
+></HTML
+> \ No newline at end of file
diff --git a/support/ps2eps/doc/html/ps2eps.html b/support/ps2eps/doc/html/ps2eps.html
new file mode 100644
index 0000000000..505ed26db7
--- /dev/null
+++ b/support/ps2eps/doc/html/ps2eps.html
@@ -0,0 +1,1186 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN""http://www.w3.org/TR/html4/loose.dtd">
+<HTML
+><HEAD
+><TITLE
+>ps2eps</TITLE
+><META
+NAME="GENERATOR"
+CONTENT="Modular DocBook HTML Stylesheet Version 1.79"></HEAD
+><BODY
+CLASS="REFENTRY"
+BGCOLOR="#FFFFFF"
+TEXT="#000000"
+LINK="#0000FF"
+VLINK="#840084"
+ALINK="#0000FF"
+><H1
+><A
+NAME="AEN1"
+></A
+>ps2eps</H1
+><DIV
+CLASS="REFNAMEDIV"
+><A
+NAME="AEN15"
+></A
+><H2
+>Name</H2
+>ps2eps&nbsp;--&nbsp; convert PostScript to EPS (Encapsulated PostScript) files
+ </DIV
+><DIV
+CLASS="REFSYNOPSISDIV"
+><A
+NAME="AEN18"
+></A
+><H2
+>Synopsis</H2
+><P
+><B
+CLASS="COMMAND"
+>ps2eps</B
+> [<CODE
+CLASS="OPTION"
+>-f</CODE
+>] [<CODE
+CLASS="OPTION"
+>-q</CODE
+>] [<CODE
+CLASS="OPTION"
+>-N</CODE
+>] [<CODE
+CLASS="OPTION"
+>-O</CODE
+>] [<CODE
+CLASS="OPTION"
+>-n</CODE
+>] [<CODE
+CLASS="OPTION"
+>-P</CODE
+>] [<CODE
+CLASS="OPTION"
+>-c</CODE
+>] [<CODE
+CLASS="OPTION"
+>-C</CODE
+>] [<CODE
+CLASS="OPTION"
+>-m</CODE
+>] [<CODE
+CLASS="OPTION"
+>-B</CODE
+>] [<CODE
+CLASS="OPTION"
+>-E</CODE
+>] [<CODE
+CLASS="OPTION"
+>-s <TT
+CLASS="REPLACEABLE"
+><I
+>pagedim</I
+></TT
+></CODE
+>] [<CODE
+CLASS="OPTION"
+>-t <TT
+CLASS="REPLACEABLE"
+><I
+>offset</I
+></TT
+></CODE
+>] [<CODE
+CLASS="OPTION"
+>-r <TT
+CLASS="REPLACEABLE"
+><I
+>resolution</I
+></TT
+></CODE
+>] [<CODE
+CLASS="OPTION"
+>-R <TT
+CLASS="REPLACEABLE"
+><I
+>+|-|^</I
+></TT
+></CODE
+>] [<CODE
+CLASS="OPTION"
+>-l</CODE
+>] [<CODE
+CLASS="OPTION"
+>-g</CODE
+>] [<CODE
+CLASS="OPTION"
+>-H</CODE
+>] [<CODE
+CLASS="OPTION"
+>-d</CODE
+>] [<CODE
+CLASS="OPTION"
+>-h|--help</CODE
+>] [<CODE
+CLASS="OPTION"
+>-a</CODE
+>] [<CODE
+CLASS="OPTION"
+>-W</CODE
+>] [<CODE
+CLASS="OPTION"
+>-L</CODE
+>] [<CODE
+CLASS="OPTION"
+>-V|--version</CODE
+>] [<CODE
+CLASS="OPTION"
+>--</CODE
+>] [<TT
+CLASS="REPLACEABLE"
+><I
+>psfile1</I
+></TT
+>] [<TT
+CLASS="REPLACEABLE"
+><I
+>psfile2</I
+></TT
+>] [<TT
+CLASS="REPLACEABLE"
+><I
+>...</I
+></TT
+>]</P
+></DIV
+><DIV
+CLASS="REFSECT1"
+><A
+NAME="AEN81"
+></A
+><H2
+>DESCRIPTION</H2
+><P
+>This manual page documents <B
+CLASS="COMMAND"
+>ps2eps</B
+> version 1.68.</P
+><P
+><B
+CLASS="COMMAND"
+>ps2eps</B
+> is a tool (written in Perl) to produce
+ Encapsulated PostScript Files (EPS/EPSF) from usual one-paged Postscript
+ documents. It calculates correct Bounding Boxes for those EPS files and
+ filters some special postscript command sequences that can produce
+ erroneous results on printers. EPS files are often needed for including
+ (scalable) graphics of high quality into TeX/LaTeX (or even Word) documents.
+ </P
+><P
+>Without any argument, ps2eps reads from standard input
+ and writes to standard output.
+ If filenames are given as arguments they are processed
+ one by one and output files are written to filenames
+ with extension <TT
+CLASS="FILENAME"
+>.eps</TT
+>. If input filenames have the
+ extension <TT
+CLASS="FILENAME"
+>.ps</TT
+> or <TT
+CLASS="FILENAME"
+>.prn</TT
+>, this extension is replaced with <TT
+CLASS="FILENAME"
+>.eps</TT
+>.
+ In all other cases <TT
+CLASS="FILENAME"
+>.eps</TT
+> is appended to the input filename.
+ Please note that PostScript files for input should contain
+ only one single page (you can possibly use the <B
+CLASS="COMMAND"
+>psselect</B
+> from the
+ psutils package to extract a single page from a document that
+ contains multiple pages).</P
+><P
+> If BoundingBox in output seems to be wrong, please try options <CODE
+CLASS="OPTION"
+>--size</CODE
+> or
+ <CODE
+CLASS="OPTION"
+>--ignoreBB</CODE
+>. See also section TROUBLESHOOTING.
+
+ </P
+></DIV
+><DIV
+CLASS="REFSECT1"
+><A
+NAME="AEN97"
+></A
+><H2
+>OPTIONS</H2
+><P
+> <B
+CLASS="COMMAND"
+>ps2eps</B
+> follows the usual <ACRONYM
+CLASS="ACRONYM"
+>GNU</ACRONYM
+> command line syntax,
+ with long options starting with two dashes (`-'). A summary of
+ options is included below.
+ </P
+><P
+></P
+><DIV
+CLASS="VARIABLELIST"
+><DL
+><DT
+><CODE
+CLASS="OPTION"
+>-h</CODE
+>, <CODE
+CLASS="OPTION"
+>--help</CODE
+></DT
+><DD
+><P
+>Show summary of options.</P
+></DD
+><DT
+><CODE
+CLASS="OPTION"
+>-V</CODE
+>, <CODE
+CLASS="OPTION"
+>--version</CODE
+></DT
+><DD
+><P
+>Show version of program.</P
+></DD
+><DT
+><CODE
+CLASS="OPTION"
+>-f</CODE
+>, <CODE
+CLASS="OPTION"
+>--force</CODE
+></DT
+><DD
+><P
+>Force overwriting existing files. <B
+CLASS="COMMAND"
+>ps2eps</B
+>
+ will not overwrite files by default to avoid deleting original EPS
+ files accidently.
+ </P
+></DD
+><DT
+><CODE
+CLASS="OPTION"
+>-q</CODE
+>, <CODE
+CLASS="OPTION"
+>--quiet</CODE
+></DT
+><DD
+><P
+>quiet operation (no output while processing files, except errors).</P
+></DD
+><DT
+><CODE
+CLASS="OPTION"
+>-N</CODE
+>, <CODE
+CLASS="OPTION"
+>--noinsert</CODE
+></DT
+><DD
+><P
+>do not insert any postscript code. Normally a few postscript
+ instructions are added around the original postscript code by
+ <B
+CLASS="COMMAND"
+>ps2eps</B
+> which can be turned off by this option.
+ </P
+></DD
+><DT
+><CODE
+CLASS="OPTION"
+>-O</CODE
+>, <CODE
+CLASS="OPTION"
+>--preserveorientation</CODE
+></DT
+><DD
+><P
+>do not filter %%Orientation: header comment.</P
+></DD
+><DT
+><CODE
+CLASS="OPTION"
+>-n</CODE
+>, <CODE
+CLASS="OPTION"
+>--nofix</CODE
+></DT
+><DD
+><P
+>do not try to fix postscript code by filtering some instructions.</P
+></DD
+><DT
+><CODE
+CLASS="OPTION"
+>-P</CODE
+>, <CODE
+CLASS="OPTION"
+>--removepreview</CODE
+></DT
+><DD
+><P
+>remove preview image (smaller file, but no preview anymore).</P
+></DD
+><DT
+><CODE
+CLASS="OPTION"
+>-F</CODE
+>, <CODE
+CLASS="OPTION"
+>--fixps</CODE
+></DT
+><DD
+><P
+>fix postscript code unconditionally. Otherwise, filtering is
+ usually triggered by detection of certain drivers only.
+ </P
+></DD
+><DT
+><CODE
+CLASS="OPTION"
+>-c</CODE
+>, <CODE
+CLASS="OPTION"
+>--comments</CODE
+></DT
+><DD
+><P
+>preserve document structure comments.</P
+></DD
+><DT
+><CODE
+CLASS="OPTION"
+>-C</CODE
+>, <CODE
+CLASS="OPTION"
+>--clip</CODE
+></DT
+><DD
+><P
+>insert postscript code for clipping. Unless
+ <CODE
+CLASS="OPTION"
+>--nohires</CODE
+> is specified, the HiResBoundingBox
+ (enlarged by 0.1 points) is used for clipping. </P
+></DD
+><DT
+><CODE
+CLASS="OPTION"
+>-m</CODE
+>, <CODE
+CLASS="OPTION"
+>--mono</CODE
+></DT
+><DD
+><P
+>use black/white bitmap as base for calculation (default: off).</P
+></DD
+><DT
+><CODE
+CLASS="OPTION"
+>-s</CODE
+>, <CODE
+CLASS="OPTION"
+>--size</CODE
+>=<CODE
+CLASS="VARNAME"
+>pagedim</CODE
+></DT
+><DD
+><P
+>where <CODE
+CLASS="VARNAME"
+>pagedim</CODE
+> is a pre-defined standard page size
+ (e.g., a4,a0,b0,letter,...) or explicitly specified in a
+ format <CODE
+CLASS="VARNAME"
+>pagedim</CODE
+>:=<TT
+CLASS="REPLACEABLE"
+><I
+>X</I
+></TT
+>x<TT
+CLASS="REPLACEABLE"
+><I
+>Y</I
+></TT
+>[cm|in],
+ where <TT
+CLASS="REPLACEABLE"
+><I
+>X</I
+></TT
+> and <TT
+CLASS="REPLACEABLE"
+><I
+>Y</I
+></TT
+> are numbers (floating points are accepted) followed by
+ units centimeter (cm) or inch (in), (default: cm).
+ Use <CODE
+CLASS="OPTION"
+>--size=list</CODE
+> to list pre-defined pagesizes.
+ See also environment variable <CODE
+CLASS="VARNAME"
+>PS2EPS_SIZE</CODE
+>.</P
+></DD
+><DT
+><CODE
+CLASS="OPTION"
+>-t</CODE
+>, <CODE
+CLASS="OPTION"
+>--translate=x,y</CODE
+></DT
+><DD
+><P
+>specify an x,y offset (may be negative) in postscript points
+ (1/72 dpi) for drawing. This option may be required
+ if your drawing has negative coordinates which usually lets ghostscript
+ cut the negative part of your picture, because it starts to render
+ at positive coordinates. The resulting output will
+ also be shifted.
+ </P
+></DD
+><DT
+><CODE
+CLASS="OPTION"
+>-r</CODE
+>, <CODE
+CLASS="OPTION"
+>--resolution=dpi</CODE
+></DT
+><DD
+><P
+>specify a resolution in dpi (dots per inch) for drawing under
+ ghostscript. Default
+ resolution is 144 dpi which is the double of the typical 72 dpi.
+ This option may help if there is a hardware dependent resolution
+ encoded in the postscript, e.g., 600dpi. Example:
+ <KBD
+CLASS="USERINPUT"
+>ps2eps -l -r 600 test.ps</KBD
+>
+ </P
+></DD
+><DT
+><CODE
+CLASS="OPTION"
+>-R</CODE
+>, <CODE
+CLASS="OPTION"
+>--rotate=direction</CODE
+></DT
+><DD
+><P
+> This option rotates the resulting EPS output.
+ The parameter <CODE
+CLASS="VARNAME"
+>direction</CODE
+> determines the direction of
+ rotation: + means +90 degrees (clockwise),- means -90 degrees
+ (counter-clockwise), and ^ means 180 degrees (up-side down).
+ </P
+></DD
+><DT
+><CODE
+CLASS="OPTION"
+>-l</CODE
+>, <CODE
+CLASS="OPTION"
+>--loose</CODE
+></DT
+><DD
+><P
+>expand the original tight bounding box by one point in each
+ direction.</P
+></DD
+><DT
+><CODE
+CLASS="OPTION"
+>-B</CODE
+>, <CODE
+CLASS="OPTION"
+>--ignoreBB</CODE
+></DT
+><DD
+><P
+>do not use existing bounding box as page size for
+ rendering.</P
+></DD
+><DT
+><CODE
+CLASS="OPTION"
+>-E</CODE
+>, <CODE
+CLASS="OPTION"
+>--ignoreEOF</CODE
+></DT
+><DD
+><P
+>do not use %%EOF as hint for end of file. Otherwise, <B
+CLASS="COMMAND"
+>ps2eps</B
+> assumes
+ that postscript code ends after the last %%EOF comment, because
+ some drivers add trailing binary <SPAN
+CLASS="QUOTE"
+>"garbage"</SPAN
+> code which gets deleted
+ by <B
+CLASS="COMMAND"
+>ps2eps</B
+> by default.
+ </P
+></DD
+><DT
+><CODE
+CLASS="OPTION"
+>-g</CODE
+>, <CODE
+CLASS="OPTION"
+>--gsbbox</CODE
+></DT
+><DD
+><P
+>use internal bbox device of ghostscript instead of the external C
+ program <B
+CLASS="COMMAND"
+>bbox</B
+>. The internal bbox device of ghostscript
+ generates different values (sometimes even incorrect),
+ so using the provided <B
+CLASS="COMMAND"
+>bbox</B
+> should be more robust.
+ See also environment variable <CODE
+CLASS="VARNAME"
+>PS2EPS_GSBBOX</CODE
+>.
+ </P
+></DD
+><DT
+><CODE
+CLASS="OPTION"
+>-H</CODE
+>, <CODE
+CLASS="OPTION"
+>--nohires</CODE
+></DT
+><DD
+><P
+> do not generate a %%HiResBoundingBox comment for output.
+ </P
+></DD
+><DT
+><CODE
+CLASS="OPTION"
+>-a</CODE
+>, <CODE
+CLASS="OPTION"
+>--accuracy</CODE
+></DT
+><DD
+><P
+> increase the accuracy by turning subsample antialiasing on (may be slower)
+ </P
+></DD
+><DT
+><CODE
+CLASS="OPTION"
+>-L</CODE
+>, <CODE
+CLASS="OPTION"
+>--license</CODE
+></DT
+><DD
+><P
+>show licensing information.</P
+></DD
+><DT
+><CODE
+CLASS="OPTION"
+>-d</CODE
+>, <CODE
+CLASS="OPTION"
+>--debuggs</CODE
+></DT
+><DD
+><P
+>show ghostscript call. This may be helpful for solving problems that
+ occur during a ghostscript call.</P
+></DD
+><DT
+><CODE
+CLASS="OPTION"
+>-W</CODE
+>, <CODE
+CLASS="OPTION"
+>--warnings</CODE
+></DT
+><DD
+><P
+>show warnings about sanity of generated EPS file. Certain
+ postscript commands should not be contained in an EPS file.
+ With this option set <B
+CLASS="COMMAND"
+>ps2eps</B
+> will issue a warning if it
+ detects at least one of them.
+ </P
+></DD
+></DL
+></DIV
+></DIV
+><DIV
+CLASS="REFSECT1"
+><A
+NAME="TROUBLESHOOTING"
+></A
+><H2
+>TROUBLESHOOTING</H2
+><P
+>Based on the given postscript source code (in most cases generated by
+ some postscript printer driver) there are many potential obstacles or
+ problems that may occur when trying to create proper EPS files. Please
+ read this section carefully to be aware of common pitfalls.</P
+><DIV
+CLASS="REFSECT2"
+><A
+NAME="AEN277"
+></A
+><H3
+>Incomplete/Clipped Images</H3
+><P
+>or how to determine the right size for ghostscript.</P
+><P
+>If you have documents that are larger than your
+ ghostscript default (usually A4 or US letter), you have to
+ specify the page dimensions explicitly using the
+ <CODE
+CLASS="OPTION"
+>-s</CODE
+> option. Otherwise your EPS
+ might be cut off during rasterizing by ghostscript resulting
+ in a wrongly calculated bounding box. You can pass
+ all pre-defined page sizes to <CODE
+CLASS="OPTION"
+>-s</CODE
+> that ghostscript understands. These are
+ currently: 11x17, ledger, legal, letter, lettersmall, archA, archB, archC, archD, archE
+ a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, isob0, isob1, isob2, isob3, isob4, isob5, isob6,
+ b0, b1, b2, b3, b4, b5, c0, c1, c2, c3, c4, c5, c6, jisb0, jisb1,
+ jisb2, jisb3, jisb4, jisb5, jisb6, flsa, flse, halfletter.
+ Unfortunately, all sizes are currently only available in portrait
+ orientation (not landscape).
+ </P
+><P
+> By default, <B
+CLASS="COMMAND"
+>ps2eps</B
+> uses an already given %%BoundingBox
+ from the source file, which often corresponds to the size of
+ the physical page format for which the document was
+ printed. However, you should be aware that this already
+ specified bounding box may be not correct, thus resulting in a
+ wrongly cropped (or even no usable) <TT
+CLASS="FILENAME"
+>.eps</TT
+>-file.
+ <B
+CLASS="COMMAND"
+>ps2eps</B
+> can only do as good as ghostscript does in rendering the original
+ postscript file (though <B
+CLASS="COMMAND"
+>ps2eps</B
+> even works with negative and
+ fractional values are contained in the original bounding box by using
+ automatic translation). Therefore, if the given bounding box is to
+ small or incorrect anyway, you can ignore the existing bounding box with the <CODE
+CLASS="OPTION"
+>-B</CODE
+>
+ option, which will cause ghostscript to use its internal
+ default size (or use <CODE
+CLASS="OPTION"
+>-s</CODE
+>). However, if the
+ BoundingBox has negative coordinates, which is not allowed by
+ the specification, <B
+CLASS="COMMAND"
+>ps2eps</B
+> will shift the output to positive values.
+ </P
+><P
+>Hint: to avoid rotating the picture
+ if you have the original drawing in landscape format, you may
+ use the <SPAN
+CLASS="QUOTE"
+>"Encapsulated Postscript"</SPAN
+> option in the printer driver
+ which should generate an EPS file (but with a bounding box of
+ the sheet size!). But some Windows printer drivers are drawing
+ the image with an offset from the bottom of the portrait page,
+ so that a part of it is drawn outside the landscape oriented
+ page. In this case, you'll have to specify a square size of
+ the page using the maximum length, e.g., 29.7cm x 29.7cm for
+ an A4 page.</P
+></DIV
+><DIV
+CLASS="REFSECT2"
+><A
+NAME="AEN293"
+></A
+><H3
+>Clipping</H3
+><P
+>or why gets some of my text deleted above the included <TT
+CLASS="FILENAME"
+>.eps</TT
+> file?</P
+><P
+> Some postscript drivers draw a white rectangle from the top left
+ corner of the page to the right lower corner of the object. This may
+ erase some or even all text above your imported/included EPS file,
+ which is very annoying. In order to prevent this, most programs have a
+ clipping option for imported <TT
+CLASS="FILENAME"
+>.eps</TT
+> files (within LaTeX you can use
+ \includegraphics*{}) for this purpose. If this is unfortunately not
+ the case, you can use the <CODE
+CLASS="OPTION"
+>-C</CODE
+> option of <B
+CLASS="COMMAND"
+>ps2eps</B
+> which will (hopefully)
+ do it for you. Unfortunately, PScript.dll 5.2 (Windows XP) introduced
+ new very badly behaving Postscript code (initclip) which will even
+ override the outer clipping! Thus, a new filter had to be installed
+ in <B
+CLASS="COMMAND"
+>ps2eps</B
+> which will fix it.
+ </P
+><P
+> However, because most programs clip directly on the bounding box,
+ you still may loose some pixels of your image, because the bounding
+ box is described in the coarse resolution of postscript points,
+ i.e. 72 dpi. In order to prevent this, you can use the <CODE
+CLASS="OPTION"
+>-l</CODE
+>
+ option or <CODE
+CLASS="OPTION"
+>-C</CODE
+> option (for the latter, clipping by the importing program
+ should be disabled then) to allow for a 1 point larger bounding box.
+ <CODE
+CLASS="OPTION"
+>-C</CODE
+> clips around a 1 point enlarged bounding box and <CODE
+CLASS="OPTION"
+>-l</CODE
+> enlarges the
+ bounding box values by 1 point (you can also combine both options).
+ </P
+></DIV
+><DIV
+CLASS="REFSECT2"
+><A
+NAME="AEN307"
+></A
+><H3
+>Included Filters</H3
+><P
+> Some postscript sequences, e.g., for using specific printer
+ features (featurebegin ...), are not working well within an <TT
+CLASS="FILENAME"
+>.eps</TT
+>
+ file, so <B
+CLASS="COMMAND"
+>ps2eps</B
+> tries to filter them out. But please note that
+ filters for postscript code may not work properly for your printer
+ driver (<B
+CLASS="COMMAND"
+>ps2eps</B
+> was mainly tested with HP and Adobe printer
+ drivers, although it may work for all printers using the
+ PScript.dll). In this case you can try to turn of filtering by
+ using option <CODE
+CLASS="OPTION"
+>-n</CODE
+>, or try to find the bad sequence in the postscript
+ code and adapt the filter rule in the <B
+CLASS="COMMAND"
+>ps2eps</B
+> script (variables
+ $linefilter, $rangefilter_begin, $rangefilter_end; linefilter is
+ an expression for filtering single lines, rangefilter_... are
+ expressions that filter all lines between a pattern matching
+ $rangefilter_begin and $rangefilter_end; drop me an e-mail with
+ your modifications). However, things may change as the printer
+ drivers (e.g., PScript.dll) or postscript language evolve.
+ </P
+><P
+> Some applications or drivers generate postscript code with leading
+ or trailing binary code, which often confuses older postscript
+ interpreters. <B
+CLASS="COMMAND"
+>ps2eps</B
+> tries to remove such code, but it may
+ sometimes make a wrong guess about start and end of the real
+ postscript code (drop me an e-mail with a zipped postscript
+ source, see section BUGS).
+ </P
+><P
+>Comment lines or even blank lines are removed
+ (which is the default to make .eps files smaller), which may corrupt your
+ output. Please check the next section how to fix this.
+ <B
+CLASS="COMMAND"
+>ps2eps</B
+> removes blank lines and also &lt;CR&gt; (carriage ceturn
+ <SPAN
+CLASS="QUOTE"
+>"\r"</SPAN
+>) at the end of lines. However, nicely formatted postscript code
+ gives a hint by using <SPAN
+CLASS="QUOTE"
+>"%%BeginBinary"</SPAN
+> <SPAN
+CLASS="QUOTE"
+>"%%EndBinary"</SPAN
+> comments. When
+ <B
+CLASS="COMMAND"
+>ps2eps</B
+> detects these comments it will refrain from any filtering
+ action within the marked binary sections.
+ </P
+><P
+> <B
+CLASS="COMMAND"
+>ps2eps</B
+> filters also %%Orientation: comments by
+ default (you can use option <CODE
+CLASS="OPTION"
+>-O</CODE
+> to turn off filtering),
+ because ghostscript may <SPAN
+CLASS="QUOTE"
+>"automagically"</SPAN
+> rotate images when generating PDF
+ images, which is not desired in most cases. Hint: you can turn off that
+ feature in ghostscript unconditionally by specifying -dAutoRotatePages=/None.
+ </P
+></DIV
+><DIV
+CLASS="REFSECT2"
+><A
+NAME="AEN327"
+></A
+><H3
+>Corrupted Output</H3
+><P
+> Some postscript code may get corrupted when comment lines or even blank
+ lines are removed (which is the default to make .eps files smaller),
+ because those files may contain encoded images
+ which also have a % as first character in a line or use a special
+ comment as end of image delimiter. If this is the case, use the <CODE
+CLASS="OPTION"
+>-c</CODE
+>
+ option to prevent filtering comments.
+ </P
+></DIV
+><DIV
+CLASS="REFSECT2"
+><A
+NAME="AEN331"
+></A
+><H3
+>Color and memory</H3
+><P
+><B
+CLASS="COMMAND"
+>ps2eps</B
+> supports colored postscript, consequently
+ letting ghostscript consume more resources for drawing its bitmap
+ (roughly 6MBytes for an A4 page). <B
+CLASS="COMMAND"
+>bbox</B
+> is reading
+ the bitmap line by line so it consumes only minimal memory. If you experience problems
+ with memory consumption of ghostscript, you may use the <CODE
+CLASS="OPTION"
+>-m</CODE
+> option
+ for using a monochrome image. But this will probably result in wrongly
+ determined bounding boxes with colored
+ images, because ghostscript has to do black/white dithering and may thus suppress
+ objects drawn in light colors.</P
+><P
+>Another option in case of memory problems and too long run times
+ is to use the much more memory efficient internal ghostscript bbox by using the
+ <CODE
+CLASS="OPTION"
+>-g</CODE
+> option.
+ </P
+></DIV
+></DIV
+><DIV
+CLASS="REFSECT1"
+><A
+NAME="AEN339"
+></A
+><H2
+>ENVIRONMENT VARIABLES</H2
+><P
+>Please note that a command line option always takes precedence over
+ the related environment variable.</P
+><P
+>The environment variable <CODE
+CLASS="VARNAME"
+>PS2EPS_SIZE</CODE
+> can be used
+ to specify a default page size and take any argument that
+ <CODE
+CLASS="OPTION"
+>--size</CODE
+> accepts. Examples: <KBD
+CLASS="USERINPUT"
+>export PS2EPS_SIZE=a0</KBD
+> (bash-like syntax)
+ or <KBD
+CLASS="USERINPUT"
+>setenv PS2EPS_SIZE letter</KBD
+> (csh syntax). </P
+><P
+>If the environment variable <CODE
+CLASS="VARNAME"
+>PS2EPS_GSBBOX</CODE
+> is set
+ the internal bbox device of ghostscript will be used instead of the external
+ command <B
+CLASS="COMMAND"
+>bbox</B
+>. Examples: <KBD
+CLASS="USERINPUT"
+>export PS2EPS_GSBBOX=true</KBD
+> (bash-like syntax)
+ or <KBD
+CLASS="USERINPUT"
+>setenv PS2EPS_GSBBOX 1</KBD
+> (csh syntax).</P
+></DIV
+><DIV
+CLASS="REFSECT1"
+><A
+NAME="AEN352"
+></A
+><H2
+>EXAMPLES</H2
+><P
+>The usual call is simply:
+ <KBD
+CLASS="USERINPUT"
+>ps2eps -l <TT
+CLASS="REPLACEABLE"
+><I
+>file</I
+></TT
+></KBD
+></P
+><P
+>A relatively failsafe call would be (if your postscript is smaller
+ than iso b0 [100cm x 141.4cm] and you have a fast computer with enough memory):
+ <KBD
+CLASS="USERINPUT"
+>ps2eps -l -B -s b0 -c -n <TT
+CLASS="REPLACEABLE"
+><I
+>file</I
+></TT
+></KBD
+></P
+><P
+>If output is not correct try:
+ <KBD
+CLASS="USERINPUT"
+>ps2eps -l -B -s b0 -F <TT
+CLASS="REPLACEABLE"
+><I
+>file</I
+></TT
+></KBD
+> </P
+></DIV
+><DIV
+CLASS="REFSECT1"
+><A
+NAME="AEN363"
+></A
+><H2
+>AUTHOR</H2
+><P
+><B
+CLASS="COMMAND"
+>ps2eps</B
+> was written by Roland Bless. </P
+><DIV
+CLASS="REFSECT2"
+><A
+NAME="AEN367"
+></A
+><H3
+>WHY?</H3
+><P
+> Other programs like <B
+CLASS="COMMAND"
+>ps2epsi</B
+> do not calculate the
+ bounding box always correctly (because the values are put on the
+ postscript stack which may get corrupted by bad postscript code) or
+ rounded it off so that clipping the EPS cut off some part of the
+ image. <B
+CLASS="COMMAND"
+>ps2eps</B
+> uses a double precision resolution
+ of 144 dpi and appropriate rounding to get a proper bounding
+ box. The internal bbox device of ghostscript generates different values
+ (sometimes even incorrect), so using the provided <B
+CLASS="COMMAND"
+>bbox</B
+>
+ should be more robust.
+ However, because normal clipping has only a resolution of 1/72dpi
+ (postscript point), the clipping process may still erase parts of your
+ EPS image. In this case please use the <CODE
+CLASS="OPTION"
+>-l</CODE
+> option to add
+ an additional point of white space around the tight bounding box.
+ </P
+></DIV
+><DIV
+CLASS="REFSECT2"
+><A
+NAME="AEN374"
+></A
+><H3
+>ACKNOWLEDGMENTS</H3
+><P
+>Some people contributed code or suggestions to improve <B
+CLASS="COMMAND"
+>ps2eps</B
+>. Here
+ are at least some names (sorry if I forgot your name):
+ Christophe Druet, Hans Ecke, Berend Hasselman, Erik Joergensen, Koji Nakamaru, Hans Fredrik Nordhaug, Michael Sharpe.
+ Special thanks goes to Michael Sharpe from UCSD who suggested a lot of useful features for ps2eps and
+ who fixed bbox to become more precise and robust.
+ </P
+><P
+>An earlier version of this manual page was originally written by
+ Rafael Laboissiere <CODE
+CLASS="EMAIL"
+>&#60;<A
+HREF="mailto:rafael at debian.org"
+>rafael at debian.org</A
+>&#62;</CODE
+> for
+ the <SPAN
+CLASS="PRODUCTNAME"
+>Debian</SPAN
+> system. Thank you Rafael! </P
+><P
+> Permission is granted to copy, distribute and/or modify this document under
+ the terms of the <ACRONYM
+CLASS="ACRONYM"
+>GNU</ACRONYM
+> Free Documentation
+ License, Version 1.1 or any later version published by the Free
+ Software Foundation; with no Invariant Sections, no Front-Cover
+ Texts and no Back-Cover Texts.</P
+></DIV
+></DIV
+><DIV
+CLASS="REFSECT1"
+><A
+NAME="BUGS"
+></A
+><H2
+>BUGS</H2
+><P
+> If you experience problems, please check carefully all hints in the section
+ TROUBLESHOOTING
+
+ first. Otherwise, check for an updated
+ version at <A
+HREF="http://www.tm.uka.de/~bless/ps2eps"
+TARGET="_top"
+>http://www.tm.uka.de/~bless/ps2eps</A
+>
+ or send a gzipped file of
+ relevant postscript source code with your error description
+ and <B
+CLASS="COMMAND"
+>ps2eps</B
+> version number to <CODE
+CLASS="EMAIL"
+>&#60;<A
+HREF="mailto:roland at bless.de"
+>roland at bless.de</A
+>&#62;</CODE
+> (please allow some time
+ to reply).
+ </P
+></DIV
+><DIV
+CLASS="REFSECT1"
+><A
+NAME="AEN389"
+></A
+><H2
+>SEE ALSO</H2
+><P
+>bbox (1), gs (1), ps2epsi (1)</P
+></DIV
+></BODY
+></HTML
+> \ No newline at end of file
diff --git a/support/ps2eps/doc/man/man1/bbox.1 b/support/ps2eps/doc/man/man1/bbox.1
new file mode 100644
index 0000000000..64696f3264
--- /dev/null
+++ b/support/ps2eps/doc/man/man1/bbox.1
@@ -0,0 +1,71 @@
+.\" This manpage has been automatically generated by docbook2man
+.\" from a DocBook document. This tool can be found at:
+.\" <http://shell.ipoline.com/~elmert/comp/docbook2X/>
+.\" Please send any bug reports, improvements, comments, patches,
+.\" etc. to Steve Cheng <steve@ggi-project.org>.
+.TH "BBOX" "1" "31 August 2010" "" ""
+
+.SH NAME
+bbox \- prints out the bounding box of a rawppm or rawpbm image
+.SH SYNOPSIS
+
+\fBbbox\fR [ \fB-l\fR ] [ \fB-r\fR ] [ \fB-h\fR ] [ \fB-V\fR ] [ \fB\fIrawpbmfile\fB\fR ]
+
+.SH "DESCRIPTION"
+.PP
+\fBbbox\fR reads a rawppm or rawpbm file
+and prints out the bounding box of the image (as postscript comment and
+in postscript points, i.e. 1/72dpi) as well as the high resolution
+bounding box. Input is read from standard input if no filename is
+specified.
+Example output:
+
+.nf
+ %%BoundingBox: 12 253 829 837
+ %%HiResBoundingBox: 12.500000 253.000000 828.500000 837.00000
+
+.fi
+.PP
+\fBbbox\fR has only very limited memory requirements
+as it reads the input line by line and thus needs to store only one picture
+line in memory.
+.SH "OPTIONS"
+.TP
+\fB-h | --help \fR
+Show summary of options.
+.TP
+\fB-V \fR
+Show version of program.
+.TP
+\fB-r \fR
+resolution of picture in dpi
+.TP
+\fB-l \fR
+loose bounding box (integer bounding box is expanded by 1
+point, hires bounding box is expanded by 0.5 points)
+.SH "SEE ALSO"
+.PP
+ps2eps (1)
+.SH "AUTHOR"
+.PP
+\fBbbox\fR was written by Roland Bless.
+.SS "ACKNOWLEDGMENTS"
+.PP
+Special thanks goes to Michael Sharpe from UCSD who suggested a lot of improvements for
+bbox to become more precise and robust, especially for small drawings.
+.PP
+An earlier version of this manual page was originally written by
+Rafael Laboissiere <rafael@debian.org> for
+the Debian system. Thank you Rafael! Permission is
+granted to copy, distribute and/or modify this document under
+the terms of the GNU Free Documentation
+License, Version 1.1 or any later version published by the Free
+Software Foundation; with no Invariant Sections, no Front-Cover
+Texts and no Back-Cover Texts.
+.SH "BUGS"
+.PP
+Though the code is quite small and the probability for bugs
+is now small, there may be some left somewhere between the lines.
+In case you find one, please send a short description with
+\fBbbox\fR version number to <roland@bless.de> (please allow some time
+to reply).
diff --git a/support/ps2eps/doc/man/man1/ps2eps.1 b/support/ps2eps/doc/man/man1/ps2eps.1
new file mode 100644
index 0000000000..d74e88ca34
--- /dev/null
+++ b/support/ps2eps/doc/man/man1/ps2eps.1
@@ -0,0 +1,366 @@
+.\" This manpage has been automatically generated by docbook2man
+.\" from a DocBook document. This tool can be found at:
+.\" <http://shell.ipoline.com/~elmert/comp/docbook2X/>
+.\" Please send any bug reports, improvements, comments, patches,
+.\" etc. to Steve Cheng <steve@ggi-project.org>.
+.TH "PS2EPS" "1" "31 August 2010" "" ""
+
+.SH NAME
+ps2eps \- convert PostScript to EPS (Encapsulated PostScript) files
+.SH SYNOPSIS
+
+\fBps2eps\fR [ \fB-f\fR ] [ \fB-q\fR ] [ \fB-N\fR ] [ \fB-O\fR ] [ \fB-n\fR ] [ \fB-P\fR ] [ \fB-c\fR ] [ \fB-C\fR ] [ \fB-m\fR ] [ \fB-B\fR ] [ \fB-E\fR ] [ \fB-s \fIpagedim\fB\fR ] [ \fB-t \fIoffset\fB\fR ] [ \fB-r \fIresolution\fB\fR ] [ \fB-R \fI+|-|^\fB\fR ] [ \fB-l\fR ] [ \fB-g\fR ] [ \fB-H\fR ] [ \fB-d\fR ] [ \fB-h|--help\fR ] [ \fB-a\fR ] [ \fB-W\fR ] [ \fB-L\fR ] [ \fB-V|--version\fR ] [ \fB--\fR ] [ \fB\fIpsfile1\fB\fR ] [ \fB\fIpsfile2\fB\fR ] [ \fB\fI\&...\fB\fR ]
+
+.SH "DESCRIPTION"
+.PP
+This manual page documents \fBps2eps\fR version 1.68.
+.PP
+\fBps2eps\fR is a tool (written in Perl) to produce
+Encapsulated PostScript Files (EPS/EPSF) from usual one-paged Postscript
+documents. It calculates correct Bounding Boxes for those EPS files and
+filters some special postscript command sequences that can produce
+erroneous results on printers. EPS files are often needed for including
+(scalable) graphics of high quality into TeX/LaTeX (or even Word) documents.
+.PP
+Without any argument, ps2eps reads from standard input
+and writes to standard output.
+If filenames are given as arguments they are processed
+one by one and output files are written to filenames
+with extension \fI\&.eps\fR\&. If input filenames have the
+extension \fI\&.ps\fR or \fI\&.prn\fR, this extension is replaced with \fI\&.eps\fR\&.
+In all other cases \fI\&.eps\fR is appended to the input filename.
+Please note that PostScript files for input should contain
+only one single page (you can possibly use the \fBpsselect\fR from the
+psutils package to extract a single page from a document that
+contains multiple pages).
+.PP
+If BoundingBox in output seems to be wrong, please try options \fB--size\fR or
+\fB--ignoreBB\fR\&. See also section TROUBLESHOOTING.
+.SH "OPTIONS"
+.PP
+\fBps2eps\fR follows the usual GNU command line syntax,
+with long options starting with two dashes (`-'). A summary of
+options is included below.
+.TP
+\fB-h, --help \fR
+Show summary of options.
+.TP
+\fB-V, --version \fR
+Show version of program.
+.TP
+\fB-f, --force \fR
+Force overwriting existing files. \fBps2eps\fR
+will not overwrite files by default to avoid deleting original EPS
+files accidently.
+.TP
+\fB-q, --quiet \fR
+quiet operation (no output while processing files, except errors).
+.TP
+\fB-N, --noinsert \fR
+do not insert any postscript code. Normally a few postscript
+instructions are added around the original postscript code by
+\fBps2eps\fR which can be turned off by this option.
+.TP
+\fB-O, --preserveorientation \fR
+do not filter %%Orientation: header comment.
+.TP
+\fB-n, --nofix \fR
+do not try to fix postscript code by filtering some instructions.
+.TP
+\fB-P, --removepreview \fR
+remove preview image (smaller file, but no preview anymore).
+.TP
+\fB-F, --fixps \fR
+fix postscript code unconditionally. Otherwise, filtering is
+usually triggered by detection of certain drivers only.
+.TP
+\fB-c, --comments \fR
+preserve document structure comments.
+.TP
+\fB-C, --clip \fR
+insert postscript code for clipping. Unless
+\fB--nohires\fR is specified, the HiResBoundingBox
+(enlarged by 0.1 points) is used for clipping.
+.TP
+\fB-m, --mono \fR
+use black/white bitmap as base for calculation (default: off).
+.TP
+\fB-s, --size=pagedim \fR
+where pagedim is a pre-defined standard page size
+(e.g., a4,a0,b0,letter,...) or explicitly specified in a
+format pagedim:=\fIX\fRx\fIY\fR[cm|in],
+where \fIX\fR and \fIY\fR are numbers (floating points are accepted) followed by
+units centimeter (cm) or inch (in), (default: cm).
+Use \fB--size=list\fR to list pre-defined pagesizes.
+See also environment variable PS2EPS_SIZE\&.
+.TP
+\fB-t, --translate=x,y \fR
+specify an x,y offset (may be negative) in postscript points
+(1/72 dpi) for drawing. This option may be required
+if your drawing has negative coordinates which usually lets ghostscript
+cut the negative part of your picture, because it starts to render
+at positive coordinates. The resulting output will
+also be shifted.
+.TP
+\fB-r, --resolution=dpi \fR
+specify a resolution in dpi (dots per inch) for drawing under
+ghostscript. Default
+resolution is 144 dpi which is the double of the typical 72 dpi.
+This option may help if there is a hardware dependent resolution
+encoded in the postscript, e.g., 600dpi. Example:
+\fBps2eps -l -r 600 test.ps\fR
+.TP
+\fB-R, --rotate=direction \fR
+This option rotates the resulting EPS output.
+The parameter direction determines the direction of
+rotation: + means +90 degrees (clockwise),- means -90 degrees
+(counter-clockwise), and ^ means 180 degrees (up-side down).
+.TP
+\fB-l, --loose \fR
+expand the original tight bounding box by one point in each
+direction.
+.TP
+\fB-B, --ignoreBB \fR
+do not use existing bounding box as page size for
+rendering.
+.TP
+\fB-E, --ignoreEOF \fR
+do not use %%EOF as hint for end of file. Otherwise, \fBps2eps\fR assumes
+that postscript code ends after the last %%EOF comment, because
+some drivers add trailing binary ``garbage'' code which gets deleted
+by \fBps2eps\fR by default.
+.TP
+\fB-g, --gsbbox \fR
+use internal bbox device of ghostscript instead of the external C
+program \fBbbox\fR\&. The internal bbox device of ghostscript
+generates different values (sometimes even incorrect),
+so using the provided \fBbbox\fR should be more robust.
+See also environment variable PS2EPS_GSBBOX\&.
+.TP
+\fB-H, --nohires \fR
+do not generate a %%HiResBoundingBox comment for output.
+.TP
+\fB-a, --accuracy \fR
+increase the accuracy by turning subsample antialiasing on (may be slower)
+.TP
+\fB-L, --license \fR
+show licensing information.
+.TP
+\fB-d, --debuggs \fR
+show ghostscript call. This may be helpful for solving problems that
+occur during a ghostscript call.
+.TP
+\fB-W, --warnings \fR
+show warnings about sanity of generated EPS file. Certain
+postscript commands should not be contained in an EPS file.
+With this option set \fBps2eps\fR will issue a warning if it
+detects at least one of them.
+.SH "TROUBLESHOOTING"
+.PP
+Based on the given postscript source code (in most cases generated by
+some postscript printer driver) there are many potential obstacles or
+problems that may occur when trying to create proper EPS files. Please
+read this section carefully to be aware of common pitfalls.
+.SS "INCOMPLETE/CLIPPED IMAGES"
+.PP
+or how to determine the right size for ghostscript.
+.PP
+If you have documents that are larger than your
+ghostscript default (usually A4 or US letter), you have to
+specify the page dimensions explicitly using the
+\fB-s\fR option. Otherwise your EPS
+might be cut off during rasterizing by ghostscript resulting
+in a wrongly calculated bounding box. You can pass
+all pre-defined page sizes to \fB-s\fR that ghostscript understands. These are
+currently: 11x17, ledger, legal, letter, lettersmall, archA, archB, archC, archD, archE
+a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, isob0, isob1, isob2, isob3, isob4, isob5, isob6,
+b0, b1, b2, b3, b4, b5, c0, c1, c2, c3, c4, c5, c6, jisb0, jisb1,
+jisb2, jisb3, jisb4, jisb5, jisb6, flsa, flse, halfletter.
+Unfortunately, all sizes are currently only available in portrait
+orientation (not landscape).
+.PP
+By default, \fBps2eps\fR uses an already given %%BoundingBox
+from the source file, which often corresponds to the size of
+the physical page format for which the document was
+printed. However, you should be aware that this already
+specified bounding box may be not correct, thus resulting in a
+wrongly cropped (or even no usable) \fI\&.eps\fR-file.
+\fBps2eps\fR can only do as good as ghostscript does in rendering the original
+postscript file (though \fBps2eps\fR even works with negative and
+fractional values are contained in the original bounding box by using
+automatic translation). Therefore, if the given bounding box is to
+small or incorrect anyway, you can ignore the existing bounding box with the \fB-B\fR
+option, which will cause ghostscript to use its internal
+default size (or use \fB-s\fR). However, if the
+BoundingBox has negative coordinates, which is not allowed by
+the specification, \fBps2eps\fR will shift the output to positive values.
+.PP
+Hint: to avoid rotating the picture
+if you have the original drawing in landscape format, you may
+use the ``Encapsulated Postscript'' option in the printer driver
+which should generate an EPS file (but with a bounding box of
+the sheet size!). But some Windows printer drivers are drawing
+the image with an offset from the bottom of the portrait page,
+so that a part of it is drawn outside the landscape oriented
+page. In this case, you'll have to specify a square size of
+the page using the maximum length, e.g., 29.7cm x 29.7cm for
+an A4 page.
+.SS "CLIPPING"
+.PP
+or why gets some of my text deleted above the included \fI\&.eps\fR file?
+.PP
+Some postscript drivers draw a white rectangle from the top left
+corner of the page to the right lower corner of the object. This may
+erase some or even all text above your imported/included EPS file,
+which is very annoying. In order to prevent this, most programs have a
+clipping option for imported \fI\&.eps\fR files (within LaTeX you can use
+\\includegraphics*{}) for this purpose. If this is unfortunately not
+the case, you can use the \fB-C\fR option of \fBps2eps\fR which will (hopefully)
+do it for you. Unfortunately, PScript.dll 5.2 (Windows XP) introduced
+new very badly behaving Postscript code (initclip) which will even
+override the outer clipping! Thus, a new filter had to be installed
+in \fBps2eps\fR which will fix it.
+.PP
+However, because most programs clip directly on the bounding box,
+you still may loose some pixels of your image, because the bounding
+box is described in the coarse resolution of postscript points,
+i.e. 72 dpi. In order to prevent this, you can use the \fB-l\fR
+option or \fB-C\fR option (for the latter, clipping by the importing program
+should be disabled then) to allow for a 1 point larger bounding box.
+\fB-C\fR clips around a 1 point enlarged bounding box and \fB-l\fR enlarges the
+bounding box values by 1 point (you can also combine both options).
+.SS "INCLUDED FILTERS"
+.PP
+Some postscript sequences, e.g., for using specific printer
+features (featurebegin ...), are not working well within an \fI\&.eps\fR
+file, so \fBps2eps\fR tries to filter them out. But please note that
+filters for postscript code may not work properly for your printer
+driver (\fBps2eps\fR was mainly tested with HP and Adobe printer
+drivers, although it may work for all printers using the
+PScript.dll). In this case you can try to turn of filtering by
+using option \fB-n\fR, or try to find the bad sequence in the postscript
+code and adapt the filter rule in the \fBps2eps\fR script (variables
+$linefilter, $rangefilter_begin, $rangefilter_end; linefilter is
+an expression for filtering single lines, rangefilter_... are
+expressions that filter all lines between a pattern matching
+$rangefilter_begin and $rangefilter_end; drop me an e-mail with
+your modifications). However, things may change as the printer
+drivers (e.g., PScript.dll) or postscript language evolve.
+.PP
+Some applications or drivers generate postscript code with leading
+or trailing binary code, which often confuses older postscript
+interpreters. \fBps2eps\fR tries to remove such code, but it may
+sometimes make a wrong guess about start and end of the real
+postscript code (drop me an e-mail with a zipped postscript
+source, see section BUGS).
+.PP
+Comment lines or even blank lines are removed
+(which is the default to make .eps files smaller), which may corrupt your
+output. Please check the next section how to fix this.
+\fBps2eps\fR removes blank lines and also <CR> (carriage ceturn
+``\\r'') at the end of lines. However, nicely formatted postscript code
+gives a hint by using ``%%BeginBinary'' ``%%EndBinary'' comments. When
+\fBps2eps\fR detects these comments it will refrain from any filtering
+action within the marked binary sections.
+.PP
+\fBps2eps\fR filters also %%Orientation: comments by
+default (you can use option \fB-O\fR to turn off filtering),
+because ghostscript may ``automagically'' rotate images when generating PDF
+images, which is not desired in most cases. Hint: you can turn off that
+feature in ghostscript unconditionally by specifying -dAutoRotatePages=/None.
+.SS "CORRUPTED OUTPUT"
+.PP
+Some postscript code may get corrupted when comment lines or even blank
+lines are removed (which is the default to make .eps files smaller),
+because those files may contain encoded images
+which also have a % as first character in a line or use a special
+comment as end of image delimiter. If this is the case, use the \fB-c\fR
+option to prevent filtering comments.
+.SS "COLOR AND MEMORY"
+.PP
+\fBps2eps\fR supports colored postscript, consequently
+letting ghostscript consume more resources for drawing its bitmap
+(roughly 6MBytes for an A4 page). \fBbbox\fR is reading
+the bitmap line by line so it consumes only minimal memory. If you experience problems
+with memory consumption of ghostscript, you may use the \fB-m\fR option
+for using a monochrome image. But this will probably result in wrongly
+determined bounding boxes with colored
+images, because ghostscript has to do black/white dithering and may thus suppress
+objects drawn in light colors.
+.PP
+Another option in case of memory problems and too long run times
+is to use the much more memory efficient internal ghostscript bbox by using the
+\fB-g\fR option.
+.SH "ENVIRONMENT VARIABLES"
+.PP
+Please note that a command line option always takes precedence over
+the related environment variable.
+.PP
+The environment variable PS2EPS_SIZE can be used
+to specify a default page size and take any argument that
+\fB--size\fR accepts. Examples: \fBexport PS2EPS_SIZE=a0\fR (bash-like syntax)
+or \fBsetenv PS2EPS_SIZE letter\fR (csh syntax).
+.PP
+If the environment variable PS2EPS_GSBBOX is set
+the internal bbox device of ghostscript will be used instead of the external
+command \fBbbox\fR\&. Examples: \fBexport PS2EPS_GSBBOX=true\fR (bash-like syntax)
+or \fBsetenv PS2EPS_GSBBOX 1\fR (csh syntax).
+.SH "EXAMPLES"
+.PP
+The usual call is simply:
+\fBps2eps -l \fIfile\fB\fR
+.PP
+A relatively failsafe call would be (if your postscript is smaller
+than iso b0 [100cm x 141.4cm] and you have a fast computer with enough memory):
+\fBps2eps -l -B -s b0 -c -n \fIfile\fB\fR
+.PP
+If output is not correct try:
+\fBps2eps -l -B -s b0 -F \fIfile\fB\fR
+.SH "AUTHOR"
+.PP
+\fBps2eps\fR was written by Roland Bless.
+.SS "WHY?"
+.PP
+Other programs like \fBps2epsi\fR do not calculate the
+bounding box always correctly (because the values are put on the
+postscript stack which may get corrupted by bad postscript code) or
+rounded it off so that clipping the EPS cut off some part of the
+image. \fBps2eps\fR uses a double precision resolution
+of 144 dpi and appropriate rounding to get a proper bounding
+box. The internal bbox device of ghostscript generates different values
+(sometimes even incorrect), so using the provided \fBbbox\fR
+should be more robust.
+However, because normal clipping has only a resolution of 1/72dpi
+(postscript point), the clipping process may still erase parts of your
+EPS image. In this case please use the \fB-l\fR option to add
+an additional point of white space around the tight bounding box.
+.SS "ACKNOWLEDGMENTS"
+.PP
+Some people contributed code or suggestions to improve \fBps2eps\fR\&. Here
+are at least some names (sorry if I forgot your name):
+Christophe Druet, Hans Ecke, Berend Hasselman, Erik Joergensen, Koji Nakamaru, Hans Fredrik Nordhaug, Michael Sharpe.
+Special thanks goes to Michael Sharpe from UCSD who suggested a lot of useful features for ps2eps and
+who fixed bbox to become more precise and robust.
+.PP
+An earlier version of this manual page was originally written by
+Rafael Laboissiere <rafael at debian.org> for
+the Debian system. Thank you Rafael!
+.PP
+Permission is granted to copy, distribute and/or modify this document under
+the terms of the GNU Free Documentation
+License, Version 1.1 or any later version published by the Free
+Software Foundation; with no Invariant Sections, no Front-Cover
+Texts and no Back-Cover Texts.
+.SH "BUGS"
+.PP
+If you experience problems, please check carefully all hints in the section
+TROUBLESHOOTING
+first. Otherwise, check for an updated
+version at <URL:http://www.tm.uka.de/~bless/ps2eps>
+or send a gzipped file of
+relevant postscript source code with your error description
+and \fBps2eps\fR version number to <roland at bless.de> (please allow some time
+to reply).
+.SH "SEE ALSO"
+.PP
+bbox (1), gs (1), ps2epsi (1)
diff --git a/support/ps2eps/doc/pdf/bbox.pdf b/support/ps2eps/doc/pdf/bbox.pdf
new file mode 100644
index 0000000000..bff1372088
--- /dev/null
+++ b/support/ps2eps/doc/pdf/bbox.pdf
Binary files differ
diff --git a/support/ps2eps/doc/pdf/ps2eps.pdf b/support/ps2eps/doc/pdf/ps2eps.pdf
new file mode 100644
index 0000000000..65b36d2183
--- /dev/null
+++ b/support/ps2eps/doc/pdf/ps2eps.pdf
Binary files differ
diff --git a/support/ps2eps/src/C/bbox.c b/support/ps2eps/src/C/bbox.c
new file mode 100644
index 0000000000..a11a393b9b
--- /dev/null
+++ b/support/ps2eps/src/C/bbox.c
@@ -0,0 +1,422 @@
+/********************************************************************/
+/** bbox -- calculates Bounding Box of a pbmraw/ppmraw-picture **/
+/** Created: Nov. 1997, revised Feb. 1998, Dec. 1999, June 2009 **/
+/** Author: Roland Bless <roland -at- bless.de> **/
+/** Copyright (C) 1998-2009 Roland Bless **/
+/** To compile simply use: **/
+/** "cc bbox.c -o bbox" or "make bbox" **/
+/********************************************************************/
+/*
+ * $Id: bbox.c,v 1.18 2009-10-13 15:03:49 bless Exp $
+ */
+
+/**
+* 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
+*
+**/
+
+/* Quoting EPSF Spec:
+ http://partners.adobe.com/public/developer/en/ps/5002.EPSF_Spec.pdf
+
+ %!PS-Adobe-3.0 EPSF-3.0
+ %%BoundingBox: llx lly urx ury
+
+ The four arguments of the bounding box comment correspond to the
+ lower-left (llx, lly) and upper-right (urx, ury) corners of the
+ bounding box. They are expressed in the default PostScript
+ coordinate system. For an EPS file, the bounding box is the smallest
+ rectangle that encloses all the marks painted on the single page of
+ the EPS file.
+*/
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#if defined(_WIN32) && !defined(__CYGWIN__)
+#include <io.h> /* needed for _setmode() */
+#include <fcntl.h>
+#endif
+
+/**********************
+* global variables *
+**********************/
+const char *const version= "$Revision: 1.18 $ $Date: 2009-10-13 15:03:49 $";
+const char *const prgname= "bbox";
+
+const double round_precision= 1e-6;
+
+unsigned char bitval[8]=
+{
+ 1 << 7,
+ 1 << 6,
+ 1 << 5,
+ 1 << 4,
+ 1 << 3,
+ 1 << 2,
+ 1 << 1,
+ 1
+};
+
+unsigned int minus_one(const unsigned x)
+{
+ return (x == 0) ? x : x-1;
+}
+
+unsigned int plus_one(const unsigned x)
+{
+ return (x == (unsigned int) ~0U) ? x : x+1;
+}
+
+/***************************** readppm_and_calcbb ***********************
+* input: name, resolution, tight *
+* output: - (stdout) *
+* *
+* Reads a RAWPPM or RAWPBM picture file (name or STDIN) and *
+* calculates its Bounding Box on-the-fly (line-by-line). *
+* *
+* Parameters: *
+* name: name of the PBMRAW file or NULL (input from stdin) *
+* resolution: Pixel per Inch (DPI) *
+* tight: boolean value, if false 1 Postscript Point is added to *
+ each Bounding Box parameter, otherwise the BB is tight *
+* The Bounding Box is given in Postscript Points (72 dots/inch) *
+* and printed to stdout *
+************************************************************************/
+/* calculate the bounding box in postscript points, given a resolution in dpi */
+void readppm_and_calcbb(const char *name,
+ const unsigned int resolution,
+ const unsigned char tight)
+{
+ FILE *inputfile;
+ char inputline[1024];
+ unsigned char magic_found= 0;
+ int x,y,byte_x,i;
+ const double pt_dpi_dbl= 72.0;
+ unsigned int x_min, x_max, y_min, y_max;
+ unsigned int llx, lly, urx, ury; /* bounding box */
+ double hllx, hlly, hurx, hury; /* hires bounding box */
+ unsigned char *image_row, /* ImageRow */
+ *tmpcolumnbytep;
+ unsigned int width,height; /* Image Size */
+ unsigned int byte_width;
+ unsigned char stepsize;
+ unsigned char colormax= 0; /* max color value */
+ unsigned int ui_colormax= 0; /* max color value */
+
+ if ( name == NULL )
+ {
+ inputfile = stdin;
+ name = "- STDIN -";
+ }
+ else
+ {
+ inputfile = fopen(name,"r");
+ if ( inputfile == NULL )
+ {
+ fprintf(stderr,"%s: ERROR -- could not open file %s\n",
+ prgname, name);
+ return;
+ }
+ }
+ /** check for magic number **/
+ do
+ {
+ fgets(inputline, 1024, inputfile);
+#ifdef DEBUG
+ fprintf(stderr,"read:[%s]\n",inputline);
+#endif
+ if ( strcmp(inputline,"P4\n") == 0 )
+ {
+ stepsize= 1;
+ magic_found= 4;
+ }
+ else
+ if ( strcmp(inputline,"P6\n") == 0 )
+ {
+ stepsize= 3;
+ magic_found= 6;
+ }
+ }
+ while ( !feof(inputfile) && !magic_found );
+
+ if ( !magic_found )
+ {
+ fprintf(stderr,"%s: ERROR -- %s is not in ppmraw or pbmraw format\n",
+ prgname, name);
+ return;
+ }
+ /** skip comments **/
+ do
+ {
+ fgets(inputline, 1024, inputfile);
+#ifdef DEBUG
+ fprintf(stderr,"read:[%s]\n",inputline);
+#endif
+ if (*inputline == '#')
+ continue;
+ else
+ break;
+ }
+ while ( !feof(inputfile) );
+ /** read picture size: width, height **/
+ sscanf(inputline,"%u %u",&width,&height);
+ if ( magic_found == 6 ) /* PPM file has maximum color-component value */
+ {
+ fgets(inputline, 1024, inputfile);
+ sscanf(inputline,"%u",&ui_colormax);
+ colormax = (unsigned char) ui_colormax; /* this is safer */
+ }
+#ifdef DEBUG
+ fprintf(stderr,"\nreading picture: %s size X: %u Y: %u\n",name,width,height);
+#endif
+ x_min= width>0 ? width-1 : 0;
+ x_max= 0;
+ y_min= height>0 ? height-1 : 0;
+ y_max= 0;
+ if ( magic_found == 4 ) /* PBMRAW = Bitmap */
+ { /** read raw pbmfile **/
+ byte_width= width / 8;
+ if (width % 8 != 0)
+ byte_width++;
+ }
+ else /** assume ppm raw **/
+ {
+ byte_width= width * 3; /* we have RGB, i.e. three bytes for each pixel */
+ }
+ /*
+ * Now read a raster of Width * Height pixels, proceeding through the image in normal English reading order,
+ * i.e., starting from top left then moving right
+ */
+ /* we allocate only one line */
+ image_row= malloc(byte_width);
+ if ( image_row )
+ {
+#if defined(_WIN32) && !defined(__CYGWIN__) /* this is really braindead stuff for MSVC */
+ i= _setmode( _fileno(stdin), _O_BINARY);
+ if (i == -1)
+ fprintf(stderr,"%s: ERROR - Cannot set binary mode for STDIN\n");
+#endif
+ for (y= 0; y<height; y++) /* for every image row 0..height-1 */
+ {
+ if (fread(image_row, byte_width, 1, inputfile) != 1)
+ {
+ fprintf(stderr,"%s: WARNING -- fread incomplete - file %s seems to be corrupt\n", prgname, name);
+ break;
+ }
+ tmpcolumnbytep= image_row;
+ /* inspect this line from left to right */
+ for (byte_x= 0; byte_x<byte_width; byte_x++,tmpcolumnbytep++)
+ {
+ if (*tmpcolumnbytep != colormax) /* there are pixels not white */
+ {
+ if (magic_found == 4)
+ {
+ for (i= 0; i<8 ; i++)
+ {
+ if (*tmpcolumnbytep & bitval[i])
+ {
+ x= byte_x*8+i;
+ if ( x >= width ) break;
+#ifdef DEBUG
+ printf("(row %04d, %04d): <not white>\n",y,x);
+#endif
+ }
+ } /* end for */
+ } /* end if magic_found 4 */
+ else
+ { /* assume PPM */
+ x= byte_x/3; /* we have 3 bytes per pixel */
+#ifdef DEBUG
+ printf("(row %04d, col %04d) byte %04d: <not %d>\n",y,x,byte_x,colormax);
+#endif
+ }
+ /* update bounding box */
+ if ( x < x_min ) x_min= x;
+ if ( x > x_max ) x_max= x;
+ if ( y < y_min ) y_min= y;
+ if ( y > y_max ) y_max= y;
+#ifdef DEBUG
+ printf("ymin,height:(%04d,%04d) xmin,width:(%04d,%04d)\n",
+ y_min,y_max,x_min,x_max);
+#endif
+ break;
+ } /* if there are pixels not white */
+ } /* end for byte_x */
+ if ( byte_x != byte_width )
+ { /* there was a pixel with no background color */
+ tmpcolumnbytep= image_row+byte_width-1;
+ /* inspect this line from the right */
+ for (byte_x= byte_width-1;
+ byte_x >= 0;
+ byte_x--,tmpcolumnbytep--)
+ {
+ if ( *tmpcolumnbytep != colormax ) /* there are pixels not white */
+ {
+ if ( magic_found == 4 )
+ {
+ for (i= 0; i<8 ; i++)
+ {
+ if ( *tmpcolumnbytep & bitval[i] )
+ {
+ x= byte_x*8+i;
+ if (x >= width) break;
+#ifdef DEBUG
+ printf("(%04d,%04d): <not white>\n",y,x);
+#endif
+ }
+ } /* end for */
+ } /* end if magic_found 4 */
+ else
+ { /* assume PPM */
+ x= byte_x/3; /* we have 3 bytes per pixel */
+ }
+ /* update bounding box */
+ if ( x < x_min ) x_min= x;
+ if ( x > x_max ) x_max= x;
+ if ( y < y_min ) y_min= y;
+ if ( y > y_max ) y_max= y;
+#ifdef DEBUG
+ printf("ymin,height:(%04d,%04d) xmin,width:(%04d,%04d)\n",
+ y_min,y_max,x_min,x_max);
+#endif
+ break;
+ } /* if there are pixels not white */
+ } /* end for byte_x */
+ } /* if line contained not only background color */
+ } /* end for y */
+#ifdef DEBUG_BOX
+ fprintf(stderr,"(%04d,%04d), (%04d,%04d)\n", x_min,height-y_max,x_max,height-y_min);
+#endif
+ /* distance from the left edge to the leftmost point */
+ hllx= (x_min*pt_dpi_dbl)/resolution;
+ /* distance from the bottom edge to the bottommost point */
+ hlly= ((minus_one(height)-y_max)*pt_dpi_dbl)/resolution;
+ /* distance from the left edge to the righmost point */
+ hurx= (plus_one(x_max)*pt_dpi_dbl)/resolution;
+ /* distance from the bottom edge to the uppermost point */
+ hury= ((height-y_min)*pt_dpi_dbl)/resolution;
+
+
+ if ( !tight )
+ {
+ /* distance from the left edge to the leftmost point */
+ llx= minus_one((unsigned int) ((unsigned long) x_min*72UL)/resolution);
+ /* distance from the bottom edge to the bottommost point */
+ lly= minus_one((unsigned int) ((unsigned long) (minus_one(height)-y_max)*72UL)/resolution);
+ /* distance from the left edge to the righmost point */
+ urx= plus_one((unsigned int) ((unsigned long) plus_one(x_max)*72UL)/resolution);
+ /* distance from the bottom edge to the uppermost point */
+ ury= plus_one((unsigned int) ((unsigned long) (height-y_min)*72UL)/resolution);
+
+ /* also loosen hires BBox by default precision */
+ if (hllx-round_precision >= 0.0)
+ hllx-= round_precision;
+ if (hlly-round_precision >= 0.0)
+ hlly-= round_precision;
+
+ hurx+= round_precision;
+ hury+= round_precision;
+ }
+ else /* tight bounding box */
+ {
+ /* distance from the left edge to the leftmost point */
+ llx= (unsigned int) ((unsigned long) x_min*72UL)/resolution;
+ /* distance from the bottom edge to the bottommost point */
+ lly= (unsigned int) ((unsigned long) (minus_one(height)-y_max)*72UL)/resolution;
+ /* distance from the left edge to the righmost point */
+ urx= (unsigned int) ((unsigned long) plus_one(x_max)*72UL)/resolution;
+ /* round up if we got a remainder */
+ if ( (((unsigned long) plus_one(x_max)*72UL) % resolution) != 0 )
+ urx= plus_one(urx);
+ /* distance from the bottom edge to the uppermost point */
+ ury= (unsigned int) ((unsigned long) (height-y_min)*72UL)/resolution;
+ if ( (((unsigned long) (height-y_min)*72UL) % resolution) != 0 )
+ ury= plus_one(ury);
+ }
+ /* skip the rest of the file if any data is still present */
+ while ( !feof(inputfile) )
+ {
+ fgets(inputline, 1024, inputfile);
+ }
+
+ /* give out Bounding Box */
+ printf("%%%%BoundingBox: %d %d %d %d\n", llx, lly, urx, ury);
+ printf("%%%%HiResBoundingBox: %f %f %f %f\n", hllx, hlly, hurx, hury);
+ }
+ else
+ fprintf(stderr,"%s: ERROR -- not enough memory to read in one row of the picture\n",prgname);
+
+ fclose(inputfile);
+ free(image_row);
+}
+
+
+int
+main(int argc, char **argv)
+{
+ int i;
+ char *filename= NULL;
+ unsigned int resolution= 72; /* use 72 dpi as default resolution */
+ unsigned char tight= 1;
+
+ for (i= 1; i<argc; i++)
+ {
+ if ( strcmp(argv[i],"-r") == 0 )
+ {
+ if (++i<argc)
+ resolution= atol(argv[i]);
+ else
+ fprintf(stderr,"%s: ERROR -- Missing resolution after -r\n",prgname);
+ }
+ else
+ if ( strcmp(argv[i],"-l") == 0 )
+ {
+ tight= 0;
+ }
+ else
+ if ( strcmp(argv[i],"-V") == 0 || strcmp(argv[i],"--version")==0 )
+ {
+ printf("%s: bbox Version %s\n",prgname,version);
+ return 0;
+ }
+ else
+ if ( strcmp(argv[i],"-h")==0 || strcmp(argv[i],"--help")==0 )
+ {
+ printf("%s: Version %s\n",prgname,version);
+ printf(" usage: %s [-l] [-r resolution] [-V] [filename]\n",prgname);
+ printf(" -l: loose bounding box (bbox is expanded by 1 point)\n");
+ printf(" -r: resolution of picture in dpi\n");
+ printf(" -V: version information\n");
+ printf(" -h: this help\n");
+ printf(" bbox reads a rawppm or rawpbm file and prints out the\n");
+ printf(" bounding box of the image. If no filename is specified\n");
+ printf(" input is read from standard input.\n");
+ return 0;
+ }
+ else
+ if ( argv[i][0] == '-' ) /* unkown option */
+ {
+ fprintf(stderr,"%s: ERROR -- unknown option %s\n call %s -h for help on usage\n",
+ prgname, argv[i], prgname);
+ return 1;
+ }
+ else /* filename argument */
+ filename= argv[i];
+ }
+
+ readppm_and_calcbb(filename, resolution, tight);
+
+ return 0;
+}