2 * PostScript driver graphics functions
4 * Copyright 1998 Huw D M Davies
17 /**********************************************************************
20 BOOL32 PSDRV_MoveToEx(DC *dc, INT32 x, INT32 y, LPPOINT32 pt)
22 TRACE(psdrv, "%d %d\n", x, y);
25 pt->x = dc->w.CursPosX;
26 pt->y = dc->w.CursPosY;
35 /***********************************************************************
38 BOOL32 PSDRV_LineTo(DC *dc, INT32 x, INT32 y)
40 TRACE(psdrv, "%d %d\n", x, y);
43 PSDRV_WriteMoveTo(dc, XLPTODP(dc, dc->w.CursPosX),
44 YLPTODP(dc, dc->w.CursPosY));
45 PSDRV_WriteLineTo(dc, XLPTODP(dc, x), YLPTODP(dc, y));
46 PSDRV_WriteStroke(dc);
54 /***********************************************************************
57 BOOL32 PSDRV_Rectangle( DC *dc, INT32 left, INT32 top, INT32 right,
60 INT32 width = XLSTODS(dc, right - left);
61 INT32 height = YLSTODS(dc, bottom - top);
64 TRACE(psdrv, "%d %d - %d %d\n", left, top, right, bottom);
66 PSDRV_WriteRectangle(dc, XLPTODP(dc, left), YLPTODP(dc, top),
71 PSDRV_WriteStroke(dc);
76 /***********************************************************************
79 BOOL32 PSDRV_RoundRect( DC *dc, INT32 left, INT32 top, INT32 right,
80 INT32 bottom, INT32 ell_width, INT32 ell_height )
82 left = XLPTODP( dc, left );
83 right = XLPTODP( dc, right );
84 top = YLPTODP( dc, top );
85 bottom = YLPTODP( dc, bottom );
86 ell_width = XLSTODS( dc, ell_width );
87 ell_height = YLSTODS( dc, ell_height );
89 if( left > right ) { INT32 tmp = left; left = right; right = tmp; }
90 if( top > bottom ) { INT32 tmp = top; top = bottom; bottom = tmp; }
92 if(ell_width > right - left) ell_width = right - left;
93 if(ell_height > bottom - top) ell_height = bottom - top;
95 PSDRV_WriteMoveTo( dc, left, top + ell_height/2 );
96 PSDRV_WriteArc( dc, left + ell_width/2, top + ell_height/2, ell_width,
97 ell_height, 90.0, 180.0);
98 PSDRV_WriteLineTo( dc, right - ell_width/2, top );
99 PSDRV_WriteArc( dc, right - ell_width/2, top + ell_height/2, ell_width,
100 ell_height, 0.0, 90.0);
101 PSDRV_WriteLineTo( dc, right, bottom - ell_height/2 );
102 PSDRV_WriteArc( dc, right - ell_width/2, bottom - ell_height/2, ell_width,
103 ell_height, -90.0, 0.0);
104 PSDRV_WriteLineTo( dc, right - ell_width/2, bottom);
105 PSDRV_WriteArc( dc, left + ell_width/2, bottom - ell_height/2, ell_width,
106 ell_height, 180.0, -90.0);
107 PSDRV_WriteClosePath( dc );
111 PSDRV_WriteStroke(dc);
115 /***********************************************************************
118 * Does the work of Arc, Chord and Pie. lines is 0, 1 or 2 respectively.
120 static BOOL32 PSDRV_DrawArc( DC *dc, INT32 left, INT32 top,
121 INT32 right, INT32 bottom,
122 INT32 xstart, INT32 ystart,
123 INT32 xend, INT32 yend,
127 double start_angle, end_angle, ratio;
129 x = XLPTODP(dc, (left + right)/2);
130 y = YLPTODP(dc, (top + bottom)/2);
132 w = XLSTODS(dc, (right - left));
133 h = YLSTODS(dc, (bottom - top));
137 ratio = ((double)w)/h;
139 /* angle is the angle after the rectangle is transformed to a square and is
140 measured anticlockwise from the +ve x-axis */
142 start_angle = atan2((double)(y - ystart) * ratio, (double)(xstart - x));
143 end_angle = atan2((double)(y - yend) * ratio, (double)(xend - x));
145 start_angle *= 180.0 / PI;
146 end_angle *= 180.0 / PI;
148 if(lines == 2) /* pie */
149 PSDRV_WriteMoveTo(dc, x, y);
150 PSDRV_WriteArc(dc, x, y, w, h, start_angle, end_angle);
151 if(lines == 1 || lines == 2) { /* chord or pie */
152 PSDRV_WriteClosePath(dc);
156 PSDRV_WriteStroke(dc);
161 /***********************************************************************
164 BOOL32 PSDRV_Arc( DC *dc, INT32 left, INT32 top, INT32 right, INT32 bottom,
165 INT32 xstart, INT32 ystart, INT32 xend, INT32 yend )
167 return PSDRV_DrawArc( dc, left, top, right, bottom, xstart, ystart,
171 /***********************************************************************
174 BOOL32 PSDRV_Chord( DC *dc, INT32 left, INT32 top, INT32 right, INT32 bottom,
175 INT32 xstart, INT32 ystart, INT32 xend, INT32 yend )
177 return PSDRV_DrawArc( dc, left, top, right, bottom, xstart, ystart,
182 /***********************************************************************
185 BOOL32 PSDRV_Pie( DC *dc, INT32 left, INT32 top, INT32 right, INT32 bottom,
186 INT32 xstart, INT32 ystart, INT32 xend, INT32 yend )
188 return PSDRV_DrawArc( dc, left, top, right, bottom, xstart, ystart,
193 /***********************************************************************
196 BOOL32 PSDRV_Ellipse( DC *dc, INT32 left, INT32 top, INT32 right, INT32 bottom)
200 TRACE(psdrv, "%d %d - %d %d\n", left, top, right, bottom);
202 x = XLPTODP(dc, (left + right)/2);
203 y = YLPTODP(dc, (top + bottom)/2);
205 w = XLSTODS(dc, (right - left));
206 h = YLSTODS(dc, (bottom - top));
208 PSDRV_WriteArc(dc, x, y, w, h, 0.0, 360.0);
209 PSDRV_WriteClosePath(dc);
212 PSDRV_WriteStroke(dc);
217 /***********************************************************************
220 BOOL32 PSDRV_PolyPolyline( DC *dc, const POINT32* pts, const DWORD* counts,
223 DWORD polyline, line;
228 for(polyline = 0; polyline < polylines; polyline++) {
229 PSDRV_WriteMoveTo(dc, XLPTODP(dc, pt->x), YLPTODP(dc, pt->y));
231 for(line = 1; line < counts[polyline]; line++) {
232 PSDRV_WriteLineTo(dc, XLPTODP(dc, pt->x), YLPTODP(dc, pt->y));
237 PSDRV_WriteStroke(dc);
242 /***********************************************************************
245 BOOL32 PSDRV_Polyline( DC *dc, const POINT32* pt, INT32 count )
247 return PSDRV_PolyPolyline( dc, pt, (LPDWORD) &count, 1 );
251 /***********************************************************************
254 BOOL32 PSDRV_PolyPolygon( DC *dc, const POINT32* pts, const INT32* counts,
262 for(polygon = 0; polygon < polygons; polygon++) {
263 PSDRV_WriteMoveTo(dc, XLPTODP(dc, pt->x), YLPTODP(dc, pt->y));
265 for(line = 1; line < counts[polygon]; line++) {
266 PSDRV_WriteLineTo(dc, XLPTODP(dc, pt->x), YLPTODP(dc, pt->y));
269 PSDRV_WriteClosePath(dc);
272 if(dc->w.polyFillMode == ALTERNATE)
277 PSDRV_WriteStroke(dc);
282 /***********************************************************************
285 BOOL32 PSDRV_Polygon( DC *dc, const POINT32* pt, INT32 count )
287 return PSDRV_PolyPolygon( dc, pt, &count, 1 );
291 /***********************************************************************
294 COLORREF PSDRV_SetPixel( DC *dc, INT32 x, INT32 y, COLORREF color )
296 PSDRV_PDEVICE *physDev = (PSDRV_PDEVICE *)dc->physDev;
302 PSDRV_WriteRectangle( dc, x, y, 0, 0 );
303 PSDRV_CreateColor( physDev, &pscolor, color );
304 PSDRV_WriteSetColor( dc, &pscolor );
305 PSDRV_WriteFill( dc );