home *** CD-ROM | disk | FTP | other *** search
- %BEGIN ReoundRectangles
-
- % 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
-
- %%%%%%%%%%%%%
- % Define the default values to be used for the width and height of the
- % cuves on the corners of the round rectangles.
- %%%%%%%%%%%%%
- /ovWidth 0 def
- /ovHeight 0 def
-
- %%%%%%%%%%%%%
- % Name: ovSize [000B]
- % Syntax: width height ovSize -
- % About: Sets the width and height of curves on round-rectangle corners
- %%%%%%%%%%%%%
- /ovSize
- {
- /ovHeight exch def
- /ovWidth exch def
- }
- def
-
- %%%%%%%%%%%%%
- % Name: buildRRpath
- % Syntax: t l b r buildRRpath -
- % About: Given a rectangle, build a round-rect path in that rect
- % using the values of ovWidth and ovHeight. This necessarily
- % distorts userspace to get the ovaled corners.
- % Note: This assumes there is a current path. It does not
- % create a new one because it is called 2ce by frameRRect
- % Remove trapping for big oval sizes for pretty results
- %%%%%%%%%%%%%
- /buildRRpath
- {
- /rightCoord exch def
- /bottomCoord exch def
- /leftCoord exch def
- /topCoord exch def
-
- /startmatrix matrix currentmatrix def
- %
- % Compute half ovheight and half ovwith, trapping for (a) case when
- % width or height larger than corresponding rect dimension, and
- % (b) cases when ovwidth or ovheight is 0. In case of (b), we make
- % the half value non-zero, but very small. We divide by this value
- % later, so a 0 value would be bad.
- %
- ovHeight 0 le
- { /halfheight .0001 def }
- {
- ovHeight bottomCoord topCoord sub gt
- {/halfheight bottomCoord topCoord sub 2 div def}
- {/halfheight ovHeight 2 div def}
- ifelse
- }
- ifelse
-
- ovWidth 0 le
- { /halfwidth .0001 def }
- {
- ovWidth rightCoord leftCoord sub gt
- {/halfwidth rightCoord leftCoord sub 2 div def}
- {/halfwidth ovWidth 2 div def}
- ifelse
- }
- ifelse
- %
- % Distort space properly for ovals, and compute where the
- % rectangle edges should be in this distorted space (so they
- % lie on the same screen locations despite distortion)
- %
- halfwidth halfheight gt
- {
- /unscale halfwidth halfheight div def
- 1 halfheight halfwidth div scale
- /radius halfwidth def
- /newleft leftCoord def
- /newright rightCoord def
- /newtop topCoord unscale mul def
- /newbottom bottomCoord unscale mul def
- }
- {
- /unscale halfheight halfwidth div def
- halfwidth halfheight div 1 scale
- /radius halfheight def
- /newleft leftCoord unscale mul def
- /newright rightCoord unscale mul def
- /newtop topCoord def
- /newbottom bottomCoord def
- }
- ifelse
- %
- % Finally, draw the round rect using arct which draws both an
- % arced corner, as well as the edge to it.
- %
- newleft halfwidth add newtop moveto
- newright newtop newright newbottom radius arct
- newright newbottom newleft newbottom radius arct
- newleft newbottom newleft newtop radius arct
- newleft newtop newright newtop radius arct
- closepath
- startmatrix setmatrix
- }
- def
-
-
- %%%%%%%%%%%%%
- % Name: roundrectpath
- % Syntax: t l b r roundrectpath -
- % About: Provides a wrapper around buildRRpath so we can declare
- % a newpath first. Note that we define last* values here for
- % all the routines below that call this.
- %%%%%%%%%%%%%
- /roundrectpath
- {
- /lastright exch def
- /lastbottom exch def
- /lastleft exch def
- /lasttop exch def
-
- newpath
- lasttop lastleft lastbottom lastright buildRRpath
- }
- def
-
- %%%%%%%%%%%%%
- % Name: frameRRect [0040]
- % Syntax: t l b r frameRRect -
- % About: Frames the specified round rect. If the pen sizes are 1,
- % stroke the path. Otherwise, build an inner path, and
- % fill between them.
- %%%%%%%%%%%%%
- /frameRRect
- {
- /lastright exch def
- /lastbottom exch def
- /lastleft exch def
- /lasttop exch def
- %
- % Do something if pen sizes > 0
- %
- penWidth 0 gt
- penHeight 0 gt
- and
- {
- gsave
- penPattern usePattern
- newpath
- penWidth 1 eq
- penHeight 1 eq
- and
- {
- lasttop lastleft lastbottom 1 sub lastright 1 sub buildRRpath
- stroke
- }
- {
- lasttop lastleft lastbottom lastright buildRRpath
- %
- % Compute parameters for inner edge of rrect frame.
- % Note: we temporarily change ovWidth & ovHeight to
- % produce aesthetically pleasing inner curves.
- %
- save
- /ovHeight ovHeight penHeight 2 mul sub def
- /ovWidth ovWidth penWidth 2 mul sub def
- lasttop penHeight add
- lastleft penWidth add
- lastbottom penHeight sub
- lastright penWidth sub
- buildRRpath
- eofill
- restore
- }
- ifelse
- grestore
- }
- if
- } def
-
- %%%%%%%%%%%%%
- % Name: paintRRect [0041]
- % Syntax: t l b r paintRRect -
- % About: Fills the path of a round rectangle with the pen pattern
- %%%%%%%%%%%%%
- /paintRRect
- {
- gsave
- penPattern usePattern
- roundrectpath
- fill
- grestore
- }
- def
-
- %%%%%%%%%%%%%
- % Name: eraseRRect [0042]
- % Syntax: t l b r eraseRRect -
- % About: Fills the path of a round rectangle with the background pattern
- %%%%%%%%%%%%%
- /eraseRRect
- {
- gsave
- backPattern usePattern
- roundrectpath
- fill
- grestore
- }
- def
-
- %%%%%%%%%%%%%
- % Name: invertRRect [0043]
- % Syntax: t l b r invertRRect -
- % About: Calls roundrectpath to properly consume parameters.
- % We don't know how to invert it, though, so don't.
- %%%%%%%%%%%%%
- /invertRRect
- {
- gsave
- roundrectpath
- grestore
- } def
-
- %%%%%%%%%%%%%
- % Name: fillRRect [0044]
- % Syntax: t l b r fillRRect -
- % About: Fills the path of a round rectangle with the fill pattern
- %%%%%%%%%%%%%
- /fillRRect
- {
- gsave
- fillPattern usePattern
- roundrectpath
- fill
- grestore
- } def
-
- %%%%%%%%%%%%%
- % Name: frameSameRRect [0048]
- % Syntax: - frameSameRRect -
- % About: Frames the last roundrectangle used
- %%%%%%%%%%%%%
- /frameSameRRect
- { lasttop lastleft lastbottom lastright frameRRect }
- def
-
- %%%%%%%%%%%%%
- % Name: paintSameRRect [0049]
- % Syntax: - paintSameRRect -
- % About: Paints the last roundrectangle used
- %%%%%%%%%%%%%
- /paintSameRRect
- { lasttop lastleft lastbottom lastright paintRRect }
- def
-
- %%%%%%%%%%%%%
- % Name: eraseSameRRect [004A]
- % Syntax: - eraseSameRRect -
- % About: Erases the last roundrectangle used
- %%%%%%%%%%%%%
- /eraseSameRRect
- { lasttop lastleft lastbottom lastright eraseRRect }
- def
-
- %%%%%%%%%%%%%
- % Name: invertSameRRect [004B]
- % Syntax: - invertSameRRect -
- % About: Inverts the last roundrectangle used
- %%%%%%%%%%%%%
- /invertSameRRect
- { lasttop lastleft lastbottom lastright invertRRect }
- def
-
- %%%%%%%%%%%%%
- % Name: fillSameRRect [004C]
- % Syntax: - fillSameRRect -
- % About: Fills the last roundrectangle used
- %%%%%%%%%%%%%
- /fillSameRRect
- { lasttop lastleft lastbottom lastright fillRRect }
- def
-
- %END RoundRectangles
-