2 * PostScript driver graphics functions
4 * Copyright 1998 Huw D M Davies
10 #if defined(HAVE_FLOAT_H)
20 DEFAULT_DEBUG_CHANNEL(psdrv)
22 /**********************************************************************
25 BOOL PSDRV_MoveToEx(DC *dc, INT x, INT y, LPPOINT pt)
27 TRACE(psdrv, "%d %d\n", x, y);
30 pt->x = dc->w.CursPosX;
31 pt->y = dc->w.CursPosY;
40 /***********************************************************************
43 BOOL PSDRV_LineTo(DC *dc, INT x, INT y)
45 TRACE(psdrv, "%d %d\n", x, y);
48 PSDRV_WriteMoveTo(dc, XLPTODP(dc, dc->w.CursPosX),
49 YLPTODP(dc, dc->w.CursPosY));
50 PSDRV_WriteLineTo(dc, XLPTODP(dc, x), YLPTODP(dc, y));
51 PSDRV_WriteStroke(dc);
59 /***********************************************************************
62 BOOL PSDRV_Rectangle( DC *dc, INT left, INT top, INT right,
65 INT width = XLSTODS(dc, right - left);
66 INT height = YLSTODS(dc, bottom - top);
69 TRACE(psdrv, "%d %d - %d %d\n", left, top, right, bottom);
71 PSDRV_WriteRectangle(dc, XLPTODP(dc, left), YLPTODP(dc, top),
76 PSDRV_WriteStroke(dc);
81 /***********************************************************************
84 BOOL PSDRV_RoundRect( DC *dc, INT left, INT top, INT right,
85 INT bottom, INT ell_width, INT ell_height )
87 left = XLPTODP( dc, left );
88 right = XLPTODP( dc, right );
89 top = YLPTODP( dc, top );
90 bottom = YLPTODP( dc, bottom );
91 ell_width = XLSTODS( dc, ell_width );
92 ell_height = YLSTODS( dc, ell_height );
94 if( left > right ) { INT tmp = left; left = right; right = tmp; }
95 if( top > bottom ) { INT tmp = top; top = bottom; bottom = tmp; }
97 if(ell_width > right - left) ell_width = right - left;
98 if(ell_height > bottom - top) ell_height = bottom - top;
100 PSDRV_WriteMoveTo( dc, left, top + ell_height/2 );
101 PSDRV_WriteArc( dc, left + ell_width/2, top + ell_height/2, ell_width,
102 ell_height, 90.0, 180.0);
103 PSDRV_WriteLineTo( dc, right - ell_width/2, top );
104 PSDRV_WriteArc( dc, right - ell_width/2, top + ell_height/2, ell_width,
105 ell_height, 0.0, 90.0);
106 PSDRV_WriteLineTo( dc, right, bottom - ell_height/2 );
107 PSDRV_WriteArc( dc, right - ell_width/2, bottom - ell_height/2, ell_width,
108 ell_height, -90.0, 0.0);
109 PSDRV_WriteLineTo( dc, right - ell_width/2, bottom);
110 PSDRV_WriteArc( dc, left + ell_width/2, bottom - ell_height/2, ell_width,
111 ell_height, 180.0, -90.0);
112 PSDRV_WriteClosePath( dc );
116 PSDRV_WriteStroke(dc);
120 /***********************************************************************
123 * Does the work of Arc, Chord and Pie. lines is 0, 1 or 2 respectively.
125 static BOOL PSDRV_DrawArc( DC *dc, INT left, INT top,
126 INT right, INT bottom,
127 INT xstart, INT ystart,
132 double start_angle, end_angle, ratio;
134 x = XLPTODP(dc, (left + right)/2);
135 y = YLPTODP(dc, (top + bottom)/2);
137 w = XLSTODS(dc, (right - left));
138 h = YLSTODS(dc, (bottom - top));
142 ratio = ((double)w)/h;
144 /* angle is the angle after the rectangle is transformed to a square and is
145 measured anticlockwise from the +ve x-axis */
147 start_angle = atan2((double)(y - ystart) * ratio, (double)(xstart - x));
148 end_angle = atan2((double)(y - yend) * ratio, (double)(xend - x));
150 start_angle *= 180.0 / PI;
151 end_angle *= 180.0 / PI;
153 if(lines == 2) /* pie */
154 PSDRV_WriteMoveTo(dc, x, y);
155 PSDRV_WriteArc(dc, x, y, w, h, start_angle, end_angle);
156 if(lines == 1 || lines == 2) { /* chord or pie */
157 PSDRV_WriteClosePath(dc);
161 PSDRV_WriteStroke(dc);
166 /***********************************************************************
169 BOOL PSDRV_Arc( DC *dc, INT left, INT top, INT right, INT bottom,
170 INT xstart, INT ystart, INT xend, INT yend )
172 return PSDRV_DrawArc( dc, left, top, right, bottom, xstart, ystart,
176 /***********************************************************************
179 BOOL PSDRV_Chord( DC *dc, INT left, INT top, INT right, INT bottom,
180 INT xstart, INT ystart, INT xend, INT yend )
182 return PSDRV_DrawArc( dc, left, top, right, bottom, xstart, ystart,
187 /***********************************************************************
190 BOOL PSDRV_Pie( DC *dc, INT left, INT top, INT right, INT bottom,
191 INT xstart, INT ystart, INT xend, INT yend )
193 return PSDRV_DrawArc( dc, left, top, right, bottom, xstart, ystart,
198 /***********************************************************************
201 BOOL PSDRV_Ellipse( DC *dc, INT left, INT top, INT right, INT bottom)
205 TRACE(psdrv, "%d %d - %d %d\n", left, top, right, bottom);
207 x = XLPTODP(dc, (left + right)/2);
208 y = YLPTODP(dc, (top + bottom)/2);
210 w = XLSTODS(dc, (right - left));
211 h = YLSTODS(dc, (bottom - top));
213 PSDRV_WriteArc(dc, x, y, w, h, 0.0, 360.0);
214 PSDRV_WriteClosePath(dc);
217 PSDRV_WriteStroke(dc);
222 /***********************************************************************
225 BOOL PSDRV_PolyPolyline( DC *dc, const POINT* pts, const DWORD* counts,
228 DWORD polyline, line;
233 for(polyline = 0; polyline < polylines; polyline++) {
234 PSDRV_WriteMoveTo(dc, XLPTODP(dc, pt->x), YLPTODP(dc, pt->y));
236 for(line = 1; line < counts[polyline]; line++) {
237 PSDRV_WriteLineTo(dc, XLPTODP(dc, pt->x), YLPTODP(dc, pt->y));
242 PSDRV_WriteStroke(dc);
247 /***********************************************************************
250 BOOL PSDRV_Polyline( DC *dc, const POINT* pt, INT count )
252 return PSDRV_PolyPolyline( dc, pt, (LPDWORD) &count, 1 );
256 /***********************************************************************
259 BOOL PSDRV_PolyPolygon( DC *dc, const POINT* pts, const INT* counts,
267 for(polygon = 0; polygon < polygons; polygon++) {
268 PSDRV_WriteMoveTo(dc, XLPTODP(dc, pt->x), YLPTODP(dc, pt->y));
270 for(line = 1; line < counts[polygon]; line++) {
271 PSDRV_WriteLineTo(dc, XLPTODP(dc, pt->x), YLPTODP(dc, pt->y));
274 PSDRV_WriteClosePath(dc);
277 if(dc->w.polyFillMode == ALTERNATE)
282 PSDRV_WriteStroke(dc);
287 /***********************************************************************
290 BOOL PSDRV_Polygon( DC *dc, const POINT* pt, INT count )
292 return PSDRV_PolyPolygon( dc, pt, &count, 1 );
296 /***********************************************************************
299 COLORREF PSDRV_SetPixel( DC *dc, INT x, INT y, COLORREF color )
301 PSDRV_PDEVICE *physDev = (PSDRV_PDEVICE *)dc->physDev;
307 PSDRV_WriteRectangle( dc, x, y, 0, 0 );
308 PSDRV_CreateColor( physDev, &pscolor, color );
309 PSDRV_WriteSetColor( dc, &pscolor );
310 PSDRV_WriteFill( dc );