Thread View: comp.lang.postscript
1 messages
1 total messages
Started by Brian Bartholomew
Wed, 30 Dec 1992 14:44
Here's some pre-debugged arithmetic in GAWK for centering eps
Author: Brian Bartholomew
Date: Wed, 30 Dec 1992 14:44
Date: Wed, 30 Dec 1992 14:44
88 lines
3205 bytes
3205 bytes
#!/usr/local/bin/gawk -f
#
# centerps - Created 12/31/92 by bb@math.ufl.edu
#
# Generates code to translate and scale a PostScript program to
# center it on a field such as a letter-sized page. May be used to
# "justify" code within any given rectangle, such as a large field as
# for tiling. Assumes a valid bounding box.
#
# Some typical uses. Field values default to letter size with 1/2"
# side and top margins if unspecified. When specifying use inches.
#
# centerps < in.ps > bb.ps
#
# centerps topmargin=2 sidemargin=1 < in.ps > bb.ps
#
# centerps pagewidth=4 pageheight=4 margin=0 < in.ps | \
# cat - in.ps > out.ps
#
# centerps pagewidth=37.5 pageheight=40 margin=1 < in.ps | \
# cat - in.ps > out.ps
#
/^%%BoundingBox: [-0-9][ -0-9]*/ {
llx = $2 ; lly = $3 ; urx = $4 ; ury = $5
if (pagewidth == "") pagewidth = 8.5
if (pageheight == "") pageheight = 11
if (margin != "") topmargin = sidemargin = margin
if (topmargin == "") topmargin = 0.5
if (sidemargin == "") sidemargin = 0.5
pagewidth = pagewidth * 72
pageheight = pageheight * 72
margin = margin * 72
topmargin = topmargin * 72
sidemargin = sidemargin * 72
desiredwidth = pagewidth - sidemargin - sidemargin
desiredheight = pageheight - topmargin - topmargin
currentwidth = urx - llx
currentheight = ury - lly
xscalefactor = desiredwidth / currentwidth
yscalefactor = desiredheight / currentheight
if (xscalefactor < yscalefactor) {
scalefactor = xscalefactor
} else {
scalefactor = yscalefactor
}
shifth = pagewidth/2 - (llx + currentwidth/2) * scalefactor
shiftv = pageheight/2 - (lly + currentheight/2) * scalefactor
print "%!"
print ""
print "% llx: " llx
print "% lly: " lly
print "% urx: " urx
print "% ury: " ury
print "% desiredwidth: " desiredwidth
print "% desiredheight: " desiredheight
print "% pagewidth: " pagewidth
print "% pageheight: " pageheight
print "% margin: " margin
print "% topmargin: " topmargin
print "% sidemargin: " sidemargin
print "% currentwidth: " currentwidth
print "% currentheight: " currentheight
print "% xscalefactor: " xscalefactor
print "% yscalefactor: " yscalefactor
print "% scalefactor: " scalefactor
print "% shifth: " shifth
print "% shiftv: " shiftv
print ""
print shifth " " shiftv " translate"
print scalefactor " " scalefactor " scale"
print ""
}
--
"Any sufficiently advanced technology is indistinguishable from a rigged demo."
-------------------------------------------------------------------------------
Brian Bartholomew UUCP: ...gatech!uflorida!beach.cis.ufl.edu!bb
University of Florida Internet: bb@math.ufl.edu
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads