2 * PostScript driver graphics functions
4 * Copyright 1998 Huw D M Davies
16 /**********************************************************************
19 BOOL
PSDRV_MoveToEx(DC
*dc
, INT x
, INT y
, LPPOINT pt
)
21 TRACE(psdrv
, "%d %d\n", x
, y
);
24 pt
->x
= dc
->w
.CursPosX
;
25 pt
->y
= dc
->w
.CursPosY
;
34 /***********************************************************************
37 BOOL
PSDRV_LineTo(DC
*dc
, INT x
, INT y
)
39 TRACE(psdrv
, "%d %d\n", x
, y
);
42 PSDRV_WriteMoveTo(dc
, XLPTODP(dc
, dc
->w
.CursPosX
),
43 YLPTODP(dc
, dc
->w
.CursPosY
));
44 PSDRV_WriteLineTo(dc
, XLPTODP(dc
, x
), YLPTODP(dc
, y
));
45 PSDRV_WriteStroke(dc
);
53 /***********************************************************************
56 BOOL
PSDRV_Rectangle( DC
*dc
, INT left
, INT top
, INT right
,
59 INT width
= XLSTODS(dc
, right
- left
);
60 INT height
= YLSTODS(dc
, bottom
- top
);
63 TRACE(psdrv
, "%d %d - %d %d\n", left
, top
, right
, bottom
);
65 PSDRV_WriteRectangle(dc
, XLPTODP(dc
, left
), YLPTODP(dc
, top
),
70 PSDRV_WriteStroke(dc
);
75 /***********************************************************************
78 BOOL
PSDRV_RoundRect( DC
*dc
, INT left
, INT top
, INT right
,
79 INT bottom
, INT ell_width
, INT ell_height
)
81 left
= XLPTODP( dc
, left
);
82 right
= XLPTODP( dc
, right
);
83 top
= YLPTODP( dc
, top
);
84 bottom
= YLPTODP( dc
, bottom
);
85 ell_width
= XLSTODS( dc
, ell_width
);
86 ell_height
= YLSTODS( dc
, ell_height
);
88 if( left
> right
) { INT tmp
= left
; left
= right
; right
= tmp
; }
89 if( top
> bottom
) { INT tmp
= top
; top
= bottom
; bottom
= tmp
; }
91 if(ell_width
> right
- left
) ell_width
= right
- left
;
92 if(ell_height
> bottom
- top
) ell_height
= bottom
- top
;
94 PSDRV_WriteMoveTo( dc
, left
, top
+ ell_height
/2 );
95 PSDRV_WriteArc( dc
, left
+ ell_width
/2, top
+ ell_height
/2, ell_width
,
96 ell_height
, 90.0, 180.0);
97 PSDRV_WriteLineTo( dc
, right
- ell_width
/2, top
);
98 PSDRV_WriteArc( dc
, right
- ell_width
/2, top
+ ell_height
/2, ell_width
,
99 ell_height
, 0.0, 90.0);
100 PSDRV_WriteLineTo( dc
, right
, bottom
- ell_height
/2 );
101 PSDRV_WriteArc( dc
, right
- ell_width
/2, bottom
- ell_height
/2, ell_width
,
102 ell_height
, -90.0, 0.0);
103 PSDRV_WriteLineTo( dc
, right
- ell_width
/2, bottom
);
104 PSDRV_WriteArc( dc
, left
+ ell_width
/2, bottom
- ell_height
/2, ell_width
,
105 ell_height
, 180.0, -90.0);
106 PSDRV_WriteClosePath( dc
);
110 PSDRV_WriteStroke(dc
);
114 /***********************************************************************
117 * Does the work of Arc, Chord and Pie. lines is 0, 1 or 2 respectively.
119 static BOOL
PSDRV_DrawArc( DC
*dc
, INT left
, INT top
,
120 INT right
, INT bottom
,
121 INT xstart
, INT ystart
,
126 double start_angle
, end_angle
, ratio
;
128 x
= XLPTODP(dc
, (left
+ right
)/2);
129 y
= YLPTODP(dc
, (top
+ bottom
)/2);
131 w
= XLSTODS(dc
, (right
- left
));
132 h
= YLSTODS(dc
, (bottom
- top
));
136 ratio
= ((double)w
)/h
;
138 /* angle is the angle after the rectangle is transformed to a square and is
139 measured anticlockwise from the +ve x-axis */
141 start_angle
= atan2((double)(y
- ystart
) * ratio
, (double)(xstart
- x
));
142 end_angle
= atan2((double)(y
- yend
) * ratio
, (double)(xend
- x
));
144 start_angle
*= 180.0 / PI
;
145 end_angle
*= 180.0 / PI
;
147 if(lines
== 2) /* pie */
148 PSDRV_WriteMoveTo(dc
, x
, y
);
149 PSDRV_WriteArc(dc
, x
, y
, w
, h
, start_angle
, end_angle
);
150 if(lines
== 1 || lines
== 2) { /* chord or pie */
151 PSDRV_WriteClosePath(dc
);
155 PSDRV_WriteStroke(dc
);
160 /***********************************************************************
163 BOOL
PSDRV_Arc( DC
*dc
, INT left
, INT top
, INT right
, INT bottom
,
164 INT xstart
, INT ystart
, INT xend
, INT yend
)
166 return PSDRV_DrawArc( dc
, left
, top
, right
, bottom
, xstart
, ystart
,
170 /***********************************************************************
173 BOOL
PSDRV_Chord( DC
*dc
, INT left
, INT top
, INT right
, INT bottom
,
174 INT xstart
, INT ystart
, INT xend
, INT yend
)
176 return PSDRV_DrawArc( dc
, left
, top
, right
, bottom
, xstart
, ystart
,
181 /***********************************************************************
184 BOOL
PSDRV_Pie( DC
*dc
, INT left
, INT top
, INT right
, INT bottom
,
185 INT xstart
, INT ystart
, INT xend
, INT yend
)
187 return PSDRV_DrawArc( dc
, left
, top
, right
, bottom
, xstart
, ystart
,
192 /***********************************************************************
195 BOOL
PSDRV_Ellipse( DC
*dc
, INT left
, INT top
, INT right
, INT bottom
)
199 TRACE(psdrv
, "%d %d - %d %d\n", left
, top
, right
, bottom
);
201 x
= XLPTODP(dc
, (left
+ right
)/2);
202 y
= YLPTODP(dc
, (top
+ bottom
)/2);
204 w
= XLSTODS(dc
, (right
- left
));
205 h
= YLSTODS(dc
, (bottom
- top
));
207 PSDRV_WriteArc(dc
, x
, y
, w
, h
, 0.0, 360.0);
208 PSDRV_WriteClosePath(dc
);
211 PSDRV_WriteStroke(dc
);
216 /***********************************************************************
219 BOOL
PSDRV_PolyPolyline( DC
*dc
, const POINT
* pts
, const DWORD
* counts
,
222 DWORD polyline
, line
;
227 for(polyline
= 0; polyline
< polylines
; polyline
++) {
228 PSDRV_WriteMoveTo(dc
, XLPTODP(dc
, pt
->x
), YLPTODP(dc
, pt
->y
));
230 for(line
= 1; line
< counts
[polyline
]; line
++) {
231 PSDRV_WriteLineTo(dc
, XLPTODP(dc
, pt
->x
), YLPTODP(dc
, pt
->y
));
236 PSDRV_WriteStroke(dc
);
241 /***********************************************************************
244 BOOL
PSDRV_Polyline( DC
*dc
, const POINT
* pt
, INT count
)
246 return PSDRV_PolyPolyline( dc
, pt
, (LPDWORD
) &count
, 1 );
250 /***********************************************************************
253 BOOL
PSDRV_PolyPolygon( DC
*dc
, const POINT
* pts
, const INT
* counts
,
261 for(polygon
= 0; polygon
< polygons
; polygon
++) {
262 PSDRV_WriteMoveTo(dc
, XLPTODP(dc
, pt
->x
), YLPTODP(dc
, pt
->y
));
264 for(line
= 1; line
< counts
[polygon
]; line
++) {
265 PSDRV_WriteLineTo(dc
, XLPTODP(dc
, pt
->x
), YLPTODP(dc
, pt
->y
));
268 PSDRV_WriteClosePath(dc
);
271 if(dc
->w
.polyFillMode
== ALTERNATE
)
276 PSDRV_WriteStroke(dc
);
281 /***********************************************************************
284 BOOL
PSDRV_Polygon( DC
*dc
, const POINT
* pt
, INT count
)
286 return PSDRV_PolyPolygon( dc
, pt
, &count
, 1 );
290 /***********************************************************************
293 COLORREF
PSDRV_SetPixel( DC
*dc
, INT x
, INT y
, COLORREF color
)
295 PSDRV_PDEVICE
*physDev
= (PSDRV_PDEVICE
*)dc
->physDev
;
301 PSDRV_WriteRectangle( dc
, x
, y
, 0, 0 );
302 PSDRV_CreateColor( physDev
, &pscolor
, color
);
303 PSDRV_WriteSetColor( dc
, &pscolor
);
304 PSDRV_WriteFill( dc
);