home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / lang / postscri / 6127 < prev    next >
Encoding:
Internet Message Format  |  1992-12-30  |  3.0 KB

  1. Path: sparky!uunet!paladin.american.edu!gatech!uflorida!bb
  2. From: bb@beach.cis.ufl.edu (Brian Bartholomew)
  3. Newsgroups: comp.lang.postscript
  4. Subject: Here's some pre-debugged arithmetic in GAWK for centering eps
  5. Message-ID: <38088@uflorida.cis.ufl.edu>
  6. Date: 30 Dec 92 14:44:25 GMT
  7. Sender: news@uflorida.cis.ufl.edu
  8. Organization: Univ. of Florida CIS Dept.
  9. Lines: 88
  10. Nntp-Posting-Host: beach.cis.ufl.edu
  11.  
  12. #!/usr/local/bin/gawk -f
  13.  
  14. #
  15. #  centerps - Created 12/31/92 by bb@math.ufl.edu
  16. #
  17. #  Generates code to translate and scale a PostScript program to
  18. #  center it on a field such as a letter-sized page.  May be used to
  19. #  "justify" code within any given rectangle, such as a large field as
  20. #  for tiling.  Assumes a valid bounding box.
  21. #
  22. #  Some typical uses.  Field values default to letter size with 1/2"
  23. #  side and top margins if unspecified.  When specifying use inches.
  24. #
  25. #    centerps < in.ps > bb.ps
  26. #
  27. #    centerps topmargin=2 sidemargin=1 < in.ps > bb.ps
  28. #
  29. #    centerps pagewidth=4 pageheight=4 margin=0 < in.ps | \
  30. #        cat - in.ps > out.ps
  31. #
  32. #    centerps pagewidth=37.5 pageheight=40 margin=1 < in.ps | \
  33. #        cat - in.ps > out.ps
  34. #
  35.  
  36. /^%%BoundingBox: [-0-9][ -0-9]*/ {
  37.  
  38.     llx = $2 ; lly = $3 ; urx = $4 ; ury = $5
  39.  
  40.     if (pagewidth == "") pagewidth = 8.5
  41.     if (pageheight == "") pageheight = 11
  42.     if (margin != "") topmargin = sidemargin = margin
  43.     if (topmargin == "") topmargin = 0.5
  44.     if (sidemargin == "") sidemargin = 0.5
  45.  
  46.     pagewidth = pagewidth * 72
  47.     pageheight = pageheight * 72
  48.     margin = margin * 72
  49.     topmargin = topmargin * 72
  50.     sidemargin = sidemargin * 72
  51.  
  52.     desiredwidth = pagewidth - sidemargin - sidemargin
  53.     desiredheight = pageheight - topmargin - topmargin
  54.  
  55.     currentwidth = urx - llx
  56.     currentheight = ury - lly
  57.  
  58.     xscalefactor = desiredwidth / currentwidth
  59.     yscalefactor = desiredheight / currentheight
  60.  
  61.     if (xscalefactor < yscalefactor) {
  62.         scalefactor = xscalefactor
  63.     } else {
  64.         scalefactor = yscalefactor
  65.     }
  66.  
  67.     shifth = pagewidth/2 - (llx + currentwidth/2) * scalefactor
  68.     shiftv = pageheight/2 - (lly + currentheight/2) * scalefactor
  69.  
  70.     print "%!"
  71.     print ""
  72.     print "%              llx: " llx
  73.     print "%              lly: " lly
  74.     print "%              urx: " urx
  75.     print "%              ury: " ury
  76.     print "%     desiredwidth: " desiredwidth
  77.     print "%    desiredheight: " desiredheight
  78.     print "%        pagewidth: " pagewidth
  79.     print "%       pageheight: " pageheight
  80.     print "%           margin: " margin
  81.     print "%        topmargin: " topmargin
  82.     print "%       sidemargin: " sidemargin
  83.     print "%     currentwidth: " currentwidth
  84.     print "%    currentheight: " currentheight
  85.     print "%     xscalefactor: " xscalefactor
  86.     print "%     yscalefactor: " yscalefactor
  87.     print "%      scalefactor: " scalefactor
  88.     print "%           shifth: " shifth
  89.     print "%           shiftv: " shiftv
  90.     print ""
  91.     print shifth " " shiftv " translate"
  92.     print scalefactor " " scalefactor " scale"
  93.     print ""
  94. }
  95. -- 
  96. "Any sufficiently advanced technology is indistinguishable from a rigged demo."
  97. -------------------------------------------------------------------------------
  98. Brian Bartholomew    UUCP:       ...gatech!uflorida!beach.cis.ufl.edu!bb
  99. University of Florida    Internet:   bb@math.ufl.edu
  100.