Large-scale renaming of all Win32 functions and types to use the
[wine/hacks.git] / graphics / psdrv / graphics.c
blob97d3bc7ad28b4a1d87f09ccca6d37b05242a04b3
1 /*
2 * PostScript driver graphics functions
4 * Copyright 1998 Huw D M Davies
6 */
7 #include <string.h>
8 #include <math.h>
9 #include "psdrv.h"
10 #include "debug.h"
11 #include "winspool.h"
12 #ifndef PI
13 #define PI M_PI
14 #endif
16 /**********************************************************************
17 * PSDRV_MoveToEx
19 BOOL PSDRV_MoveToEx(DC *dc, INT x, INT y, LPPOINT pt)
21 TRACE(psdrv, "%d %d\n", x, y);
22 if (pt)
24 pt->x = dc->w.CursPosX;
25 pt->y = dc->w.CursPosY;
27 dc->w.CursPosX = x;
28 dc->w.CursPosY = y;
30 return TRUE;
34 /***********************************************************************
35 * PSDRV_LineTo
37 BOOL PSDRV_LineTo(DC *dc, INT x, INT y)
39 TRACE(psdrv, "%d %d\n", x, y);
41 PSDRV_SetPen(dc);
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);
47 dc->w.CursPosX = x;
48 dc->w.CursPosY = y;
49 return TRUE;
53 /***********************************************************************
54 * PSDRV_Rectangle
56 BOOL PSDRV_Rectangle( DC *dc, INT left, INT top, INT right,
57 INT bottom )
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),
66 width, height);
68 PSDRV_Brush(dc,0);
69 PSDRV_SetPen(dc);
70 PSDRV_WriteStroke(dc);
71 return TRUE;
75 /***********************************************************************
76 * PSDRV_RoundRect
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 );
108 PSDRV_Brush(dc,0);
109 PSDRV_SetPen(dc);
110 PSDRV_WriteStroke(dc);
111 return TRUE;
114 /***********************************************************************
115 * PSDRV_DrawArc
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,
122 INT xend, INT yend,
123 int lines )
125 INT x, y, h, w;
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));
134 if(w < 0) w = -w;
135 if(h < 0) h = -h;
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);
152 PSDRV_Brush(dc,0);
154 PSDRV_SetPen(dc);
155 PSDRV_WriteStroke(dc);
156 return TRUE;
160 /***********************************************************************
161 * PSDRV_Arc
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,
167 xend, yend, 0 );
170 /***********************************************************************
171 * PSDRV_Chord
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,
177 xend, yend, 1 );
181 /***********************************************************************
182 * PSDRV_Pie
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,
188 xend, yend, 2 );
192 /***********************************************************************
193 * PSDRV_Ellipse
195 BOOL PSDRV_Ellipse( DC *dc, INT left, INT top, INT right, INT bottom)
197 INT x, y, w, h;
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);
209 PSDRV_Brush(dc,0);
210 PSDRV_SetPen(dc);
211 PSDRV_WriteStroke(dc);
212 return TRUE;
216 /***********************************************************************
217 * PSDRV_PolyPolyline
219 BOOL PSDRV_PolyPolyline( DC *dc, const POINT* pts, const DWORD* counts,
220 DWORD polylines )
222 DWORD polyline, line;
223 const POINT* pt;
224 TRACE(psdrv, "\n");
226 pt = pts;
227 for(polyline = 0; polyline < polylines; polyline++) {
228 PSDRV_WriteMoveTo(dc, XLPTODP(dc, pt->x), YLPTODP(dc, pt->y));
229 pt++;
230 for(line = 1; line < counts[polyline]; line++) {
231 PSDRV_WriteLineTo(dc, XLPTODP(dc, pt->x), YLPTODP(dc, pt->y));
232 pt++;
235 PSDRV_SetPen(dc);
236 PSDRV_WriteStroke(dc);
237 return TRUE;
241 /***********************************************************************
242 * PSDRV_Polyline
244 BOOL PSDRV_Polyline( DC *dc, const POINT* pt, INT count )
246 return PSDRV_PolyPolyline( dc, pt, (LPDWORD) &count, 1 );
250 /***********************************************************************
251 * PSDRV_PolyPolygon
253 BOOL PSDRV_PolyPolygon( DC *dc, const POINT* pts, const INT* counts,
254 UINT polygons )
256 DWORD polygon, line;
257 const POINT* pt;
258 TRACE(psdrv, "\n");
260 pt = pts;
261 for(polygon = 0; polygon < polygons; polygon++) {
262 PSDRV_WriteMoveTo(dc, XLPTODP(dc, pt->x), YLPTODP(dc, pt->y));
263 pt++;
264 for(line = 1; line < counts[polygon]; line++) {
265 PSDRV_WriteLineTo(dc, XLPTODP(dc, pt->x), YLPTODP(dc, pt->y));
266 pt++;
268 PSDRV_WriteClosePath(dc);
271 if(dc->w.polyFillMode == ALTERNATE)
272 PSDRV_Brush(dc, 1);
273 else /* WINDING */
274 PSDRV_Brush(dc, 0);
275 PSDRV_SetPen(dc);
276 PSDRV_WriteStroke(dc);
277 return TRUE;
281 /***********************************************************************
282 * PSDRV_Polygon
284 BOOL PSDRV_Polygon( DC *dc, const POINT* pt, INT count )
286 return PSDRV_PolyPolygon( dc, pt, &count, 1 );
290 /***********************************************************************
291 * PSDRV_SetPixel
293 COLORREF PSDRV_SetPixel( DC *dc, INT x, INT y, COLORREF color )
295 PSDRV_PDEVICE *physDev = (PSDRV_PDEVICE *)dc->physDev;
296 PSCOLOR pscolor;
298 x = XLPTODP(dc, x);
299 y = YLPTODP(dc, y);
301 PSDRV_WriteRectangle( dc, x, y, 0, 0 );
302 PSDRV_CreateColor( physDev, &pscolor, color );
303 PSDRV_WriteSetColor( dc, &pscolor );
304 PSDRV_WriteFill( dc );
305 return color;