% This is the descriptions of the kinds of things that PSDraw can draw.
%

%%&startkind	SolidRectangle
%%&startparams
colorlevel	color	"0.0 0.0 0.0"		Color to paint
%%&endparams
%%&starttemplate
&colorlevel setrgbcolor clippath fill
%%&endtemplate
%%&startbutton
0.2 setgray
0.25 0.25 0.5 0.5 rectfill
%%&endbutton
%%&endkind


%%&startkind	HollowRectangle
%%&startparams
colorlevel	color	"0.0 0.0 1.0"		Color to paint
linewidth	double		1.0		Linewidth to paint.
linejoin	enum(Miter:0,Round:1,Bevel:2) 0	Line join type
%%&endparams
%%&startprologue
/DrawHollowRect {
    /height exch def
    /width exch def
    dup setlinewidth
    /halflinewidth exch 2 div def
    /width width halflinewidth sub def
    /height height halflinewidth sub def
    halflinewidth halflinewidth moveto
    width halflinewidth lineto
    width height lineto
    halflinewidth height lineto
    closepath
    stroke
} bind def
%%&endprologue
%%&starttemplate
&linejoin setlinejoin &colorlevel setrgbcolor
&linewidth &width &height DrawHollowRect
%%&endtemplate
%%&startbutton
.05 setlinewidth 0.25 0.25 0.5 0.5 rectstroke
%%&endbutton
%%&endkind



%%&startkind	Text
%%&startparams
font		fontname	Helvetica	Font for text
size		double		24		Size of text
displaytext	string		""		Text to display.
colorlevel	color	"0.0 0.75 0.0"		Color to paint
%%&endparams
%%&startprologue
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% The following is Program 12 from the Blue Book.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

/wordbreak ( ) def

/BreakIntoLines {
	/proc exch def
	/linewidth exch def
	/textstring exch def

	/breakwidth wordbreak stringwidth pop def

	/curwidth 0 def
	/lastwordbreak 0 def
	/startchar 0 def
	/restoftext textstring def

	{ 
		restoftext wordbreak search
		{
			/nextword exch def pop
			/restoftext exch def
			/wordwidth nextword stringwidth pop def

			curwidth wordwidth add linewidth ge
			{
				textstring startchar 
					lastwordbreak startchar sub
					getinterval proc
				/startchar lastwordbreak def
				/curwidth wordwidth breakwidth add def
			} {
				/curwidth curwidth wordwidth add
					breakwidth add def
			} ifelse
			/lastwordbreak lastwordbreak 
				nextword length add 1 add def
		}
		{ pop exit }
		ifelse
	} loop
	/lastchar textstring length def
	textstring startchar lastchar startchar sub getinterval proc
} bind def

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% End of Program 12.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%&endprologue
%%&starttemplate
/&font &size selectfont
/yline &height &size sub def
&colorlevel setrgbcolor
(&displaytext) &width {0 yline moveto show /yline yline &size sub def}
BreakIntoLines
%%&endtemplate
%%&startbutton
0.2 setgray
/Helvetica 1 selectfont 0 0 moveto (A) show
%%&endbutton
%%&endkind


%%&startkind	SolidEllipse
%%&startparams
colorlevel	color	"0.0 1.0 1.0"		Color to paint
%%&endparams
%%&startprologue
/ellipsedict 8 dict def
ellipsedict /mtrx matrix put
/ellipse
 { ellipsedict begin
   /endangle exch def
   /startangle exch def
   /yrad exch def
   /xrad exch def
   /y exch def
   /x exch def
   /savematrix mtrx currentmatrix def
   x y translate
   xrad yrad scale
   0 0 1 startangle endangle arc
   savematrix setmatrix
   end
 } def
%%&endprologue
%%&starttemplate
&colorlevel setrgbcolor &width 2.0 div &height 2.0 div 2 copy 0 360 ellipse fill
%%&endtemplate
%%&startbutton
0.2 setgray
0.5 0.5 0.4 0 360 arc fill
%%&endbutton
%%&endkind



% This next one depends on the prologue from the previous one.  Probably not a
% very good thing to do, but it works.
%%&startkind	HollowEllipse
%%&startparams
colorlevel	color	"1.0 0.0 0.0"		Color to paint
linewidth	double		1.0		Linewidth to paint.
%%&endparams
%%&startprologue
/DrawHollowEllipse {
	/height exch def
	/width exch def
	/lw exch def
	setrgbcolor
	lw setlinewidth
	width 2.0 div height 2.0 div
	width lw sub 2.0 div height lw sub 2.0 div
	0 360 ellipse stroke
} bind def

%%&endprologue
%%&starttemplate
&colorlevel &linewidth &width &height DrawHollowEllipse
%%&endtemplate
%%&startbutton
0.05 setlinewidth 0.5 0.5 0.4 0 360 arc stroke
%%&endbutton
%%&endkind



%%&startkind	SolidPolygon
%%&startparams
points
colorlevel	color	"1.0 0.0 1.0"		Color to paint
filltype	enum(WindingRule:fill,ExclusiveOr:eofill) fill Fill method
%%&endparams
%%&startprologue
/DrawPolygon {
	3 1 roll
	moveto
	1 sub
	{lineto} repeat
	closepath
} bind def
%%&endprologue
%%&starttemplate
&colorlevel setrgbcolor &points DrawPolygon &filltype
%%&endtemplate
%%&startbutton
0.2 setgray
.4 .2 .8 .2 .9 .6 .5 .9 .1 .5 moveto lineto lineto lineto lineto closepath fill
%%&endbutton
%%&endkind



% Depends on Polygon, above.
%%&startkind	HollowPolygon
%%&startparams
points
colorlevel	color	"0.5 0.2 0.25"		Color to paint
linewidth	double		1.0		Linewidth to paint.
%%&endparams
%%&starttemplate
&colorlevel setrgbcolor &linewidth setlinewidth &points DrawPolygon stroke
%%&endtemplate
%%&startbutton
0.05 setlinewidth
.4 .2 .8 .2 .9 .6 .5 .9 .1 .5 moveto lineto lineto lineto lineto
closepath stroke
%%&endbutton
%%&endkind



%%&startkind SolidClosedBezier
%%&startparams
points
colorlevel	color	"0.75 0.5 0.25"		Color to paint
filltype	enum(WindingRule:fill,ExclusiveOr:eofill) fill Fill method
%%&endparams
%%&startprologue
/storexyn {
    /n exch def
    /y n array def
    /x n array def
    n 1 sub -1 0 {
	/i exch def
	y i 3 2 roll put
	x i 3 2 roll put
    } for
} def
/thirdpoint {
    /ty1 exch def
    /tx1 exch def
    /ty0 exch def
    /tx0 exch def
    tx0 2 mul tx1 add 3 div
    ty0 2 mul ty1 add 3 div
} bind def
/midpoint {
    /ty1 exch def
    /tx1 exch def
    /ty0 exch def
    /tx0 exch def
    tx0 tx1 add 2 div
    ty0 ty1 add 2 div
} bind def
/subspline {
    /movetoNeeded exch def
    y exch get /y3 exch def
    x exch get /x3 exch def
    y exch get /y2 exch def
    x exch get /x2 exch def
    y exch get /y1 exch def
    x exch get /x1 exch def
    y exch get /y0 exch def
    x exch get /x0 exch def
    x1 y1 x2 y2 thirdpoint
    /p1y exch def
    /p1x exch def
    x2 y2 x1 y1 thirdpoint
    /p2y exch def
    /p2x exch def
    x1 y1 x0 y0 thirdpoint
    p1x p1y midpoint
    /p0y exch def
    /p0x exch def
    x2 y2 x3 y3 thirdpoint
    p2x p2y midpoint
    /p3y exch def
    /p3x exch def
    movetoNeeded { p0x p0y moveto } if
    p1x p1y p2x p2y p3x p3y curveto
} bind def

/DrawClosedBezier {
    dup 2 gt {
	storexyn
	newpath
	n 1 sub dup 0 0 1 1 2 2 true subspline
	1 1 n 3 sub {
	    /i exch def
	    i 1 sub dup i dup i 1 add dup i 2 add dup false subspline
	} for
	n 3 sub dup n 2 sub dup n 1 sub dup 0 0 false subspline
	n 2 sub dup n 1 sub dup 0 0 1 1 false subspline
    } {
	DrawPolygon
    } ifelse
} bind def
%%&endprologue
%%&starttemplate
&colorlevel setrgbcolor &points DrawClosedBezier &filltype
%%&endtemplate
%%&startbutton
/storexyn {
    /n exch def
    /y n array def
    /x n array def
    n 1 sub -1 0 {
	/i exch def
	y i 3 2 roll put
	x i 3 2 roll put
    } for
} def
/thirdpoint {
    /ty1 exch def
    /tx1 exch def
    /ty0 exch def
    /tx0 exch def
    tx0 2 mul tx1 add 3 div
    ty0 2 mul ty1 add 3 div
} bind def
/midpoint {
    /ty1 exch def
    /tx1 exch def
    /ty0 exch def
    /tx0 exch def
    tx0 tx1 add 2 div
    ty0 ty1 add 2 div
} bind def
/subspline {
    /movetoNeeded exch def
    y exch get /y3 exch def
    x exch get /x3 exch def
    y exch get /y2 exch def
    x exch get /x2 exch def
    y exch get /y1 exch def
    x exch get /x1 exch def
    y exch get /y0 exch def
    x exch get /x0 exch def
    x1 y1 x2 y2 thirdpoint
    /p1y exch def
    /p1x exch def
    x2 y2 x1 y1 thirdpoint
    /p2y exch def
    /p2x exch def
    x1 y1 x0 y0 thirdpoint
    p1x p1y midpoint
    /p0y exch def
    /p0x exch def
    x2 y2 x3 y3 thirdpoint
    p2x p2y midpoint
    /p3y exch def
    /p3x exch def
    movetoNeeded { p0x p0y moveto } if
    p1x p1y p2x p2y p3x p3y curveto
} bind def

/DrawClosedBezier {
    dup 2 gt {
	storexyn
	newpath
	n 1 sub dup 0 0 1 1 2 2 true subspline
	1 1 n 3 sub {
	    /i exch def
	    i 1 sub dup i dup i 1 add dup i 2 add dup false subspline
	} for
	n 3 sub dup n 2 sub dup n 1 sub dup 0 0 false subspline
	n 2 sub dup n 1 sub dup 0 0 1 1 false subspline
    } {
    } ifelse
} bind def

.8 .05
.5 .5
1.1 .65
.5 1.1
.3 .7
.1 .3
6
0.2 setgray
DrawClosedBezier fill
%%&endbutton
%%&endkind

%%&startkind	CircleText
%%&startparams
font		fontname	Times-Roman 	Font for text
size		double		24.		Size of text
displaytext	string		"text"	        Text to display
colorlevel	color	"0.0 0.0 0.0"		Color to paint
radius		double		50.		Circle Radius
%%&endparams
%%&startprologue
%-----------------------------------------------------------

/circletext
{
 /radius exch def
 /text exch def
 /char 0 def
 /str 1 string def
 /pi 3.14159 def
 /circum radius 2 mul pi mul def
 /oshow
 {
  true charpath gsave
  rand
  fill grestore
  stroke
 } def
 text stringwidth pop
 2 div
 circum div 360 mul
 rotate
 text
 {
  /char exch def
  0 radius moveto
  str 0 char put
  str stringwidth pop
  circum div 360 mul
  /charot exch def
  gsave
  0 radius translate
  charot 2 div neg rotate

  str oshow
 grestore
  charot
  neg rotate
 } forall
} def

%%&endprologue
%%&starttemplate
/&font &size selectfont
/yline &height &size sub def
&colorlevel setrgbcolor
&width 2 div 0 translate
(&displaytext) &radius
circletext
%%&endtemplate
%%&startbutton
.5 setgray
/Helvetica 1 selectfont .17 .17 moveto (A) show
0.05 setlinewidth 0.5 0.5 0.45 0 360 arc stroke
%%&endbutton
%%&endkind
