Corrected operand sizes for the "enter" instruction.
[wine.git] / graphics / psdrv / graphics.c
blobcfcd43e6775fb66d7e315e9555ab2979fdcf5653
1 /*
2 * PostScript driver graphics functions
4 * Copyright 1998 Huw D M Davies
6 */
7 #include <string.h>
8 #include <math.h>
9 #include "config.h"
10 #if defined(HAVE_FLOAT_H)
11 #include <float.h>
12 #endif
13 #if !defined(PI)
14 #define PI M_PI
15 #endif
16 #include "psdrv.h"
17 #include "debugtools.h"
18 #include "winspool.h"
20 DEFAULT_DEBUG_CHANNEL(psdrv)
22 /**********************************************************************
23 * PSDRV_MoveToEx
25 BOOL PSDRV_MoveToEx(DC *dc, INT x, INT y, LPPOINT pt)
27 TRACE("%d %d\n", x, y);
28 if (pt)
30 pt->x = dc->w.CursPosX;
31 pt->y = dc->w.CursPosY;
33 dc->w.CursPosX = x;
34 dc->w.CursPosY = y;
36 return TRUE;
40 /***********************************************************************
41 * PSDRV_LineTo
43 BOOL PSDRV_LineTo(DC *dc, INT x, INT y)
45 TRACE("%d %d\n", x, y);
47 PSDRV_SetPen(dc);
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_DrawLine(dc);
53 dc->w.CursPosX = x;
54 dc->w.CursPosY = y;
55 return TRUE;
59 /***********************************************************************
60 * PSDRV_Rectangle
62 BOOL PSDRV_Rectangle( DC *dc, INT left, INT top, INT right,
63 INT bottom )
65 INT width = XLSTODS(dc, right - left);
66 INT height = YLSTODS(dc, bottom - top);
69 TRACE("%d %d - %d %d\n", left, top, right, bottom);
71 PSDRV_WriteRectangle(dc, XLPTODP(dc, left), YLPTODP(dc, top),
72 width, height);
74 PSDRV_Brush(dc,0);
75 PSDRV_SetPen(dc);
76 PSDRV_DrawLine(dc);
77 return TRUE;
81 /***********************************************************************
82 * PSDRV_RoundRect
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 );
114 PSDRV_Brush(dc,0);
115 PSDRV_SetPen(dc);
116 PSDRV_DrawLine(dc);
117 return TRUE;
120 /***********************************************************************
121 * PSDRV_DrawArc
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,
128 INT xend, INT yend,
129 int lines )
131 INT x, y, h, w;
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));
140 if(w < 0) w = -w;
141 if(h < 0) h = -h;
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 else
156 PSDRV_WriteNewPath( dc );
158 PSDRV_WriteArc(dc, x, y, w, h, start_angle, end_angle);
159 if(lines == 1 || lines == 2) { /* chord or pie */
160 PSDRV_WriteClosePath(dc);
161 PSDRV_Brush(dc,0);
163 PSDRV_SetPen(dc);
164 PSDRV_DrawLine(dc);
165 return TRUE;
169 /***********************************************************************
170 * PSDRV_Arc
172 BOOL PSDRV_Arc( DC *dc, INT left, INT top, INT right, INT bottom,
173 INT xstart, INT ystart, INT xend, INT yend )
175 return PSDRV_DrawArc( dc, left, top, right, bottom, xstart, ystart,
176 xend, yend, 0 );
179 /***********************************************************************
180 * PSDRV_Chord
182 BOOL PSDRV_Chord( DC *dc, INT left, INT top, INT right, INT bottom,
183 INT xstart, INT ystart, INT xend, INT yend )
185 return PSDRV_DrawArc( dc, left, top, right, bottom, xstart, ystart,
186 xend, yend, 1 );
190 /***********************************************************************
191 * PSDRV_Pie
193 BOOL PSDRV_Pie( DC *dc, INT left, INT top, INT right, INT bottom,
194 INT xstart, INT ystart, INT xend, INT yend )
196 return PSDRV_DrawArc( dc, left, top, right, bottom, xstart, ystart,
197 xend, yend, 2 );
201 /***********************************************************************
202 * PSDRV_Ellipse
204 BOOL PSDRV_Ellipse( DC *dc, INT left, INT top, INT right, INT bottom)
206 INT x, y, w, h;
208 TRACE("%d %d - %d %d\n", left, top, right, bottom);
210 x = XLPTODP(dc, (left + right)/2);
211 y = YLPTODP(dc, (top + bottom)/2);
213 w = XLSTODS(dc, (right - left));
214 h = YLSTODS(dc, (bottom - top));
216 PSDRV_WriteNewPath(dc);
217 PSDRV_WriteArc(dc, x, y, w, h, 0.0, 360.0);
218 PSDRV_WriteClosePath(dc);
219 PSDRV_Brush(dc,0);
220 PSDRV_SetPen(dc);
221 PSDRV_DrawLine(dc);
222 return TRUE;
226 /***********************************************************************
227 * PSDRV_PolyPolyline
229 BOOL PSDRV_PolyPolyline( DC *dc, const POINT* pts, const DWORD* counts,
230 DWORD polylines )
232 DWORD polyline, line;
233 const POINT* pt;
234 TRACE("\n");
236 pt = pts;
237 for(polyline = 0; polyline < polylines; polyline++) {
238 PSDRV_WriteMoveTo(dc, XLPTODP(dc, pt->x), YLPTODP(dc, pt->y));
239 pt++;
240 for(line = 1; line < counts[polyline]; line++) {
241 PSDRV_WriteLineTo(dc, XLPTODP(dc, pt->x), YLPTODP(dc, pt->y));
242 pt++;
245 PSDRV_SetPen(dc);
246 PSDRV_DrawLine(dc);
247 return TRUE;
251 /***********************************************************************
252 * PSDRV_Polyline
254 BOOL PSDRV_Polyline( DC *dc, const POINT* pt, INT count )
256 return PSDRV_PolyPolyline( dc, pt, (LPDWORD) &count, 1 );
260 /***********************************************************************
261 * PSDRV_PolyPolygon
263 BOOL PSDRV_PolyPolygon( DC *dc, const POINT* pts, const INT* counts,
264 UINT polygons )
266 DWORD polygon, line;
267 const POINT* pt;
268 TRACE("\n");
270 pt = pts;
271 for(polygon = 0; polygon < polygons; polygon++) {
272 PSDRV_WriteMoveTo(dc, XLPTODP(dc, pt->x), YLPTODP(dc, pt->y));
273 pt++;
274 for(line = 1; line < counts[polygon]; line++) {
275 PSDRV_WriteLineTo(dc, XLPTODP(dc, pt->x), YLPTODP(dc, pt->y));
276 pt++;
278 PSDRV_WriteClosePath(dc);
281 if(dc->w.polyFillMode == ALTERNATE)
282 PSDRV_Brush(dc, 1);
283 else /* WINDING */
284 PSDRV_Brush(dc, 0);
285 PSDRV_SetPen(dc);
286 PSDRV_DrawLine(dc);
287 return TRUE;
291 /***********************************************************************
292 * PSDRV_Polygon
294 BOOL PSDRV_Polygon( DC *dc, const POINT* pt, INT count )
296 return PSDRV_PolyPolygon( dc, pt, &count, 1 );
300 /***********************************************************************
301 * PSDRV_SetPixel
303 COLORREF PSDRV_SetPixel( DC *dc, INT x, INT y, COLORREF color )
305 PSDRV_PDEVICE *physDev = (PSDRV_PDEVICE *)dc->physDev;
306 PSCOLOR pscolor;
308 x = XLPTODP(dc, x);
309 y = YLPTODP(dc, y);
311 PSDRV_WriteRectangle( dc, x, y, 0, 0 );
312 PSDRV_CreateColor( physDev, &pscolor, color );
313 PSDRV_WriteSetColor( dc, &pscolor );
314 PSDRV_WriteFill( dc );
315 return color;
319 /***********************************************************************
320 * PSDRV_DrawLine
322 VOID PSDRV_DrawLine( DC *dc )
324 PSDRV_PDEVICE *physDev = (PSDRV_PDEVICE *)dc->physDev;
326 if (physDev->pen.style == PS_NULL)
327 PSDRV_WriteNewPath(dc);
328 else
329 PSDRV_WriteStroke(dc);