2 * PostScript driver graphics functions
4 * Copyright 1998 Huw D M Davies
12 #if defined(HAVE_FLOAT_H)
19 #include "debugtools.h"
22 DEFAULT_DEBUG_CHANNEL(psdrv);
25 /***********************************************************************
28 BOOL PSDRV_LineTo(DC *dc, INT x, INT y)
30 TRACE("%d %d\n", x, y);
33 PSDRV_WriteMoveTo(dc, INTERNAL_XWPTODP(dc, dc->CursPosX, dc->CursPosY),
34 INTERNAL_YWPTODP(dc, dc->CursPosX, dc->CursPosY));
35 PSDRV_WriteLineTo(dc, INTERNAL_XWPTODP(dc, x, y),
36 INTERNAL_YWPTODP(dc, x, y));
43 /***********************************************************************
46 BOOL PSDRV_Rectangle( DC *dc, INT left, INT top, INT right,
52 TRACE("%d %d - %d %d\n", left, top, right, bottom);
53 width = INTERNAL_XWSTODS(dc, right - left);
54 height = INTERNAL_YWSTODS(dc, bottom - top);
55 PSDRV_WriteRectangle(dc, INTERNAL_XWPTODP(dc, left, top),
56 INTERNAL_YWPTODP(dc, left, top),
65 /***********************************************************************
68 BOOL PSDRV_RoundRect( DC *dc, INT left, INT top, INT right,
69 INT bottom, INT ell_width, INT ell_height )
71 left = XLPTODP( dc, left );
72 right = XLPTODP( dc, right );
73 top = YLPTODP( dc, top );
74 bottom = YLPTODP( dc, bottom );
75 ell_width = XLSTODS( dc, ell_width );
76 ell_height = YLSTODS( dc, ell_height );
78 if( left > right ) { INT tmp = left; left = right; right = tmp; }
79 if( top > bottom ) { INT tmp = top; top = bottom; bottom = tmp; }
81 if(ell_width > right - left) ell_width = right - left;
82 if(ell_height > bottom - top) ell_height = bottom - top;
84 PSDRV_WriteMoveTo( dc, left, top + ell_height/2 );
85 PSDRV_WriteArc( dc, left + ell_width/2, top + ell_height/2, ell_width,
86 ell_height, 90.0, 180.0);
87 PSDRV_WriteLineTo( dc, right - ell_width/2, top );
88 PSDRV_WriteArc( dc, right - ell_width/2, top + ell_height/2, ell_width,
89 ell_height, 0.0, 90.0);
90 PSDRV_WriteLineTo( dc, right, bottom - ell_height/2 );
91 PSDRV_WriteArc( dc, right - ell_width/2, bottom - ell_height/2, ell_width,
92 ell_height, -90.0, 0.0);
93 PSDRV_WriteLineTo( dc, right - ell_width/2, bottom);
94 PSDRV_WriteArc( dc, left + ell_width/2, bottom - ell_height/2, ell_width,
95 ell_height, 180.0, -90.0);
96 PSDRV_WriteClosePath( dc );
104 /***********************************************************************
107 * Does the work of Arc, Chord and Pie. lines is 0, 1 or 2 respectively.
109 static BOOL PSDRV_DrawArc( DC *dc, INT left, INT top,
110 INT right, INT bottom,
111 INT xstart, INT ystart,
116 double start_angle, end_angle, ratio;
118 x = XLPTODP(dc, (left + right)/2);
119 y = YLPTODP(dc, (top + bottom)/2);
121 w = XLSTODS(dc, (right - left));
122 h = YLSTODS(dc, (bottom - top));
126 ratio = ((double)w)/h;
128 /* angle is the angle after the rectangle is transformed to a square and is
129 measured anticlockwise from the +ve x-axis */
131 start_angle = atan2((double)(y - ystart) * ratio, (double)(xstart - x));
132 end_angle = atan2((double)(y - yend) * ratio, (double)(xend - x));
134 start_angle *= 180.0 / PI;
135 end_angle *= 180.0 / PI;
137 if(lines == 2) /* pie */
138 PSDRV_WriteMoveTo(dc, x, y);
140 PSDRV_WriteNewPath( dc );
142 PSDRV_WriteArc(dc, x, y, w, h, start_angle, end_angle);
143 if(lines == 1 || lines == 2) { /* chord or pie */
144 PSDRV_WriteClosePath(dc);
153 /***********************************************************************
156 BOOL PSDRV_Arc( DC *dc, INT left, INT top, INT right, INT bottom,
157 INT xstart, INT ystart, INT xend, INT yend )
159 return PSDRV_DrawArc( dc, left, top, right, bottom, xstart, ystart,
163 /***********************************************************************
166 BOOL PSDRV_Chord( DC *dc, INT left, INT top, INT right, INT bottom,
167 INT xstart, INT ystart, INT xend, INT yend )
169 return PSDRV_DrawArc( dc, left, top, right, bottom, xstart, ystart,
174 /***********************************************************************
177 BOOL PSDRV_Pie( DC *dc, INT left, INT top, INT right, INT bottom,
178 INT xstart, INT ystart, INT xend, INT yend )
180 return PSDRV_DrawArc( dc, left, top, right, bottom, xstart, ystart,
185 /***********************************************************************
188 BOOL PSDRV_Ellipse( DC *dc, INT left, INT top, INT right, INT bottom)
192 TRACE("%d %d - %d %d\n", left, top, right, bottom);
194 x = XLPTODP(dc, (left + right)/2);
195 y = YLPTODP(dc, (top + bottom)/2);
197 w = XLSTODS(dc, (right - left));
198 h = YLSTODS(dc, (bottom - top));
200 PSDRV_WriteNewPath(dc);
201 PSDRV_WriteArc(dc, x, y, w, h, 0.0, 360.0);
202 PSDRV_WriteClosePath(dc);
210 /***********************************************************************
213 BOOL PSDRV_PolyPolyline( DC *dc, const POINT* pts, const DWORD* counts,
216 DWORD polyline, line;
221 for(polyline = 0; polyline < polylines; polyline++) {
222 PSDRV_WriteMoveTo(dc, INTERNAL_XWPTODP(dc, pt->x, pt->y), INTERNAL_YWPTODP(dc, pt->x, pt->y));
224 for(line = 1; line < counts[polyline]; line++) {
225 PSDRV_WriteLineTo(dc, INTERNAL_XWPTODP(dc, pt->x, pt->y), INTERNAL_YWPTODP(dc, pt->x, pt->y));
235 /***********************************************************************
238 BOOL PSDRV_Polyline( DC *dc, const POINT* pt, INT count )
240 return PSDRV_PolyPolyline( dc, pt, (LPDWORD) &count, 1 );
244 /***********************************************************************
247 BOOL PSDRV_PolyPolygon( DC *dc, const POINT* pts, const INT* counts,
255 for(polygon = 0; polygon < polygons; polygon++) {
256 PSDRV_WriteMoveTo(dc, INTERNAL_XWPTODP(dc, pt->x, pt->y), INTERNAL_YWPTODP(dc, pt->x, pt->y));
258 for(line = 1; line < counts[polygon]; line++) {
259 PSDRV_WriteLineTo(dc, INTERNAL_XWPTODP(dc, pt->x, pt->y), INTERNAL_YWPTODP(dc, pt->x, pt->y));
262 PSDRV_WriteClosePath(dc);
265 if(dc->polyFillMode == ALTERNATE)
275 /***********************************************************************
278 BOOL PSDRV_Polygon( DC *dc, const POINT* pt, INT count )
280 return PSDRV_PolyPolygon( dc, pt, &count, 1 );
284 /***********************************************************************
287 COLORREF PSDRV_SetPixel( DC *dc, INT x, INT y, COLORREF color )
289 PSDRV_PDEVICE *physDev = (PSDRV_PDEVICE *)dc->physDev;
292 x = INTERNAL_XWPTODP(dc, x, y);
293 y = INTERNAL_YWPTODP(dc, x, y);
295 PSDRV_WriteRectangle( dc, x, y, 0, 0 );
296 PSDRV_CreateColor( physDev, &pscolor, color );
297 PSDRV_WriteSetColor( dc, &pscolor );
298 PSDRV_WriteFill( dc );
303 /***********************************************************************
306 VOID PSDRV_DrawLine( DC *dc )
308 PSDRV_PDEVICE *physDev = (PSDRV_PDEVICE *)dc->physDev;
310 if (physDev->pen.style == PS_NULL)
311 PSDRV_WriteNewPath(dc);
313 PSDRV_WriteStroke(dc);