#!/bin/csh -f # # Uses ghostscript to translate an Encapsulated PostScript file to # Portable Anymap format file(s). # pstopnm will create as many files as the number of pages in # the Postscript document. The name of the files will be # psfile001.ppm, psfile002.ppm, etc. # The ouput files will contain the area inside the BoundingBox. # If BoundingBox parameters are not found in the PostScript # document, default values are used. # # # Usage: epstopnm [-forceplain] [-help] # [-llx s] [-lly s] [-urx s] [-ury s] (printers points) # [-pbm|-pgm|-ppm] # [-xsize n] [-ysize n] (size in pixels) # [-rot] # [-verbose] # psfile[.ps] # # Written by Graham Freeman, 1997, based on "pstopnm" which contains the # following copyright notice: # Copyright (C) 1992 by Alberto Accomazzi, Smithsonian Astrophysical # Observatory (alberto@cfa.harvard.edu). # # Permission to use, copy, modify, and distribute this software and its # documentation for any purpose and without fee is hereby granted, # provided that the above copyright notice appear in all copies and # that both that copyright notice and this permission notice appear # in supporting documentation. This software is provided "as is" # without express or implied warranty. # set noglob set progname = $0 set progname = $progname:t set filtertail = "raw" set filterhead = "ppm" set xsize = 0 set ysize = 0 set res = 72 # default value: orientation is unknown set orient = 0 set psfile = "" set USAGE = "Usage: epstopnm [-forceplain] [-help] \n\ [-llx s] [-lly s] [-urx s] [-ury s] (bounds in printers points) \n\ [-pbm|-pgm|-ppm] \n\ [-xsize n] [-ysize n] (size in pixels) \n\ [-rot] \n\ [-verbose] \n\ psfile[.ps]" alias usage 'echo $USAGE; exit 1' while ($#argv > 0) switch ($argv[1]) case -h*: # -help usage breaksw case -pbm: case -pgm: case -ppm: set filterhead = `echo "$argv[1]" | sed "s/-//1"` breaksw case -llx: shift argv if ($#argv == 0) eval usage set llx = `(echo "scale=4";echo "$argv[1]")|bc -l` set nobb breaksw case -lly: shift argv if ($#argv == 0) eval usage set lly = `(echo "scale=4";echo "$argv[1]")|bc -l` set nobb breaksw case -urx: shift argv if ($#argv == 0) eval usage set urx = `(echo "scale=4";echo "$argv[1]")|bc -l` set nobb breaksw case -ury: shift argv if ($#argv == 0) eval usage set ury = `(echo "scale=4";echo "$argv[1]")|bc -l` set nobb breaksw case -xs*: # -xsize shift argv if ($#argv == 0) eval usage @ xsize = $argv[1] breaksw case -ys*: # -ysize shift argv if ($#argv == 0) eval usage @ ysize = $argv[1] breaksw case -f*: # -forceplain set filtertail = "" breaksw case -v*: # -verbose set verb breaksw case -ro*: # -rotate set orient = 2 breaksw case -*: echo "${progname}: Unknown option $argv[1]" usage breaksw default: # input file set psfile = $argv[1] set ppmfile = `basename $argv[1] .ps` set ppmfile = `basename $ppmfile .eps` set ppmfile = `basename $ppmfile .epsi` breaksw endsw shift argv end if ($psfile =~ "") eval usage if (! -f $psfile) then echo "${progname}: file '${psfile}' not found" usage endif set bb = `grep "%%BoundingBox" $psfile` if ($#bb == 5) then if ($?nobb == 0) then set llx = $bb[2] set lly = $bb[3] set urx = $bb[4] set ury = $bb[5] endif # add a 4-pixel margin set llx = `(echo "scale=4";echo "$llx - 4")|bc -l` set lly = `(echo "scale=4";echo "$lly - 4")|bc -l` set urx = `(echo "scale=4";echo "$urx + 4")|bc -l` set ury = `(echo "scale=4";echo "$ury + 4")|bc -l` set sx = `(echo "scale=4";echo "$urx - $llx")|bc -l` set sy = `(echo "scale=4";echo "$ury - $lly")|bc -l` # see if rotation was specified if ($orient == 0) then set orient = 1 endif if ($orient != 1) then # rotation set tmpsx = $sx set sx = $sy set sy = $tmpsx endif # if xsize or ysize was specified, compute resolution from them if ($xsize == 0) then if ($ysize == 0) then set xres = 100 set yres = 100 # set xsize = $sx # set ysize = $sy set xsize = `(echo "scale=4";echo "$sx * $xres / $res + .5")|bc -l` set ysize = `(echo "scale=4";echo "$sy * $yres / $res + .5")|bc -l` else set yres = `(echo "scale=4";echo "$res * $ysize / $sy")|bc -l` set xres = $yres set xsize = `(echo "scale=4";echo "$sx * $xres / $res + .5")|bc -l` endif else if ($ysize == 0) then set xres = `(echo "scale=4";echo "$res * $xsize / $sx")|bc -l` set yres = $xres set ysize = `(echo "scale=4";echo "$sy * $yres / $res + .5")|bc -l` else set xres = `(echo "scale=4";echo "$res * $xsize / $sx")|bc -l` set yres = `(echo "scale=4";echo "$res * $ysize / $sy")|bc -l` endif endif set xsize = $xsize:r set ysize = $ysize:r # translate + rotate image, if necessary if ($orient == 1) then # no rotation set pstrans = "$llx neg $lly neg translate" else # rotate set pstrans = "90 rotate $llx neg $ury neg translate" endif if ($?verb) then echo "sx = $sx" echo "sy = $sy" echo "xres = $xres" echo "yres = $yres" echo "xsize = $xsize" echo "ysize = $ysize" if ($orient != 1) then echo "rotate" else echo "no rotate" endif echo "PS header: $pstrans" endif echo "${progname}: writing $filterhead file(s)" echo "showpage" >/tmp/pspnm.showp echo $pstrans | \ gs -sDEVICE=${filterhead}${filtertail} \ -sOutputFile=$ppmfile%03d.$filterhead \ -g${xsize}x${ysize} \ -r${xres}x${yres} \ -q - $psfile /tmp/pspnm.showp rm /tmp/pspnm.showp # echo "File(s) `ls ${ppmfile}*.$filterhead` created" # ls $ppmfile*.$filterhead else echo "${progname}: BoundingBox not found in file '${psfile}'" endif