Article View: comp.lang.postscript
Article #5862Here's some pre-debugged arithmetic in GAWK for centering eps
From: 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
Technical Details
Message-ID:
<38088@uflorida.cis.ufl.edu>Path:
arc1-ca.pugleaf.net!sparky!uunet!paladin.american.edu!gatech!uflorida!bbShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!paladin.american.edu!gatech!uflorida!bb From: bb@beach.cis.ufl.edu (Brian Bartholomew) Newsgroups: comp.lang.postscript Subject: Here's some pre-debugged arithmetic in GAWK for centering eps Message-ID: <38088@uflorida.cis.ufl.edu> Date: 30 Dec 92 14:44:25 GMT Sender: news@uflorida.cis.ufl.edu Organization: Univ. of Florida CIS Dept. Lines: 88 Nntp-Posting-Host: beach.cis.ufl.edu