home *** CD-ROM | disk | FTP | other *** search
- %BEGIN Regions
-
- % Copyright (C) 1993 David John Burrowes
- % Distributed under terms of GNU General Public License.
- % See COPYING.text in Convert PICT's CommentedPSCode for a copy
-
- %%%%%%%%%%%%%
- % Note:
- % regionBounds and regionPath is defined in the common file
- % regionInfo is top, left, bot, right coords of bounding rect, followed by the number
- % of shapes. Each spape is the number of vertices, followed by that many x,y pairs
- % that represent the corners of the shape.
- %%%%%%%%%%%%%
-
- %%%%%%%%%%%%%
- % Name: frameRgn [0080]
- % Syntax: regionInfo frameRgn -
- % About: Set up bounds. If pen sizes > 0 draw two paths. The outer goes from passed
- % vertex to passed vertex, drawing the outer edge. The second is inset by the
- % sizes of penWidth and penHeight. Fill between these to get a frame of right size.
- % Note: regions w/ holes (e.g. 'doughnuts') may not have the holes framed precisely
- % correctly. This will inset the frame of the hole, but perhaps the mac does not.
- %%%%%%%%%%%%%
- /frameRgn
- {
- gsave
- penPattern usePattern
- /tempRight exch def
- /tempBottom exch def
- /tempLeft exch def
- /tempTop exch def
- /numShapes exch def
- numShapes 0 eq
- {
- %
- % No shapes, frame the bounding rect. (do this by building a
- % 'fake' region shape for following routines to consume
- %
- tempLeft tempTop tempRight tempTop
- tempRight tempBottom tempLeft tempBottom
- 4
- /numShapes 1 def
- }
- {
- tempTop tempLeft tempBottom tempRight regionBounds
- clip
- }
- ifelse
-
- penWidth 0 le
- penHeight 0 le
- or
- {
- %
- % Consume & discard coordinates, using the passed counts for the repeat
- %
- numShapes
- {
- { pop pop }
- repeat
- }
- repeat
- }
- {
- %
- % For each of the shapes, read in verticees and draw lines between
- % then, make a second pass over points, drawing inner path
- %
- newpath
- numShapes
- {
- /numCoords exch 2 mul def
- /ptArray numCoords array def
- /firsty exch def
- /firstx exch def
- %
- % Form the outer edge of shape, storing points in array
- %
- firstx firsty moveto
- 0 2 numCoords 3 sub % 3 is for: zero origin, and skipped first coords
- {
- /arrayIndex exch def
- /y1 exch def
- /x1 exch def
- ptArray arrayIndex x1 put
- ptArray arrayIndex 1 add y1 put
- x1 y1 lineto
- }
- for
- closepath
- %
- % Compute inner edge. While inset by pen size, we must put vertices
- % in non straightforward position. lastx was the x coord of last vertex
- % we saw. thisx is the x of the current vertex. pendx is the x coordinate
- % that is proposed for the vertex to be drawn that cooresponds to the lastx
- % This is because we can not definitely figure out where point N's inset
- % coords are without knowing where point N+1 is. Do a couple examples.
- % NOTE: We trap for case where only 1 line segment (4 coords) in region.
- /pendx firstx penWidth add def
- numCoords 4 gt
- {
- ptArray 2 get pendx lt
- { /pendy firsty penHeight add def }
- { /pendy firsty penHeight sub def }
- ifelse
- }
- { /pendy firsty penHeight sub def }
- ifelse
- /lastx ptArray 0 get def
- /lasty ptArray 1 get def
- pendx pendy moveto
- 2 4 numCoords 5 sub
- {
- /arrayIndex exch def
-
- /thisx ptArray arrayIndex get def
- /thisy ptArray arrayIndex 1 add get def
- %
- % If thisy - lasty > 0, pendx = lastx + penWidth
- %
- /pendx lastx penWidth
- thisy lasty sub 0 gt {add} {sub} ifelse
- def
- pendx pendy lineto
- /lastx thisx def
- /lasty thisy def
-
- /thisx ptArray arrayIndex 2 add get def
- /thisy ptArray arrayIndex 3 add get def
- /pendy lasty penHeight
- thisx lastx sub 0 gt {sub} {add } ifelse
- def
- pendx pendy lineto
- /lasty thisy def
- /lastx thisx def
-
- }
- for
- firstx penWidth add pendy lineto
- closepath
- }
- repeat
- eofill
- }
- ifelse
- grestore
- }
- def
-
- %%%%%%%%%%%%%
- % Name: paintRgn [0081]
- % Syntax: regionInfo paintRgn -
- % About: Fill the passed region with the pen pattern (use eofill because there
- % may be shapes within shapes all drawn in same direction). Note:
- % If there are no shapes, we just fill the 'bounding' rect.
- %%%%%%%%%%%%%
- /paintRgn
- {
- gsave
- penPattern usePattern
- regionBounds
- /numShapes exch def
- numShapes 0 eq
- { fill }
- {
- clip
- numShapes regionPath
- eofill
- }
- ifelse
- grestore
- }
- def
-
- %%%%%%%%%%%%%
- % Name: eraseRgn [0082]
- % Syntax: regionInfo eraseRgn -
- % About: Fill the passed region with the background pattern (use eofill because there
- % may be shapes within shapes all drawn in same direction). Note:
- % If there are no shapes, we just fill the 'bounding' rect.
- %%%%%%%%%%%%%
- /eraseRgn
- {
- gsave
- backPattern usePattern
- regionBounds
- /numShapes exch def
- numShapes 0 eq
- { fill }
- {
- clip
- numShapes regionPath
- eofill
- }
- ifelse
- grestore
- }
- def
-
-
- %%%%%%%%%%%%%
- % Name: invertRgn [0083]
- % Syntax: regionInfo invertRgn -
- % About: Consume the region data. No inversion because we can't easily.
- %%%%%%%%%%%%%
- /invertRgn
- {
- gsave
- regionBounds
- regionPath
- grestore
- } def
-
- %%%%%%%%%%%%%
- % Name: fillRgn [0084]
- % Syntax: regionInfo fillRgn -
- % About: Fill the passed region with the fill pattern (use eofill because there
- % may be shapes within shapes all drawn in same direction). Note:
- % If there are no shapes, we just fill the 'bounding' rect.
- %%%%%%%%%%%%%
- /fillRgn
- {
- gsave
- fillPattern usePattern
- regionBounds
- /numShapes exch def
- numShapes 0 eq
- { fill }
- {
- clip
- numShapes regionPath
- eofill
- }
- ifelse
- grestore
- }
- def
-
- %%%%%%%%%%%%%
- % Name: frameSameRgn [0088]
- % Syntax: - frameSameRgn -
- % About: Apple doesn't implement this, so nor do I
- %%%%%%%%%%%%%
- /frameSameRgn
- { }
- def
-
- %%%%%%%%%%%%%
- % Name: paintSameRgn [0089]
- % Syntax: - paintSameRgn -
- % About: Apple doesn't implement this, so nor do I
- %%%%%%%%%%%%%
- /paintSameRgn
- { }
- def
-
- %%%%%%%%%%%%%
- % Name: eraseSameRgn [008A]
- % Syntax: - eraseSameRgn -
- % About: Apple doesn't implement this, so nor do I
- %%%%%%%%%%%%%
- /eraseSameRgn
- { }
- def
-
- %%%%%%%%%%%%%
- % Name: invertSameRgn [008B]
- % Syntax: - invertSameRgn -
- % About: Apple doesn't implement this, so nor do I
- %%%%%%%%%%%%%
- /invertSameRgn
- { }
- def
-
- %%%%%%%%%%%%%
- % Name: fillSameRgn [008C]
- % Syntax: - fillSameRgn -
- % About: Apple doesn't implement this, so nor do I
- %%%%%%%%%%%%%
- /fillSameRgn
- { }
- def
-
- %END Regions
-