- Minor API files fixes
[wine/multimedia.git] / dlls / wineps / graphics.c
blob3e8ea03283df5fed933406be7f691bf315b995c3
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);
23 /***********************************************************************
24 * PSDRV_LineTo
26 BOOL PSDRV_LineTo(DC *dc, INT x, INT y)
28 TRACE("%d %d\n", x, y);
30 PSDRV_SetPen(dc);
31 PSDRV_WriteMoveTo(dc, INTERNAL_XWPTODP(dc, dc->CursPosX, dc->CursPosY),
32 INTERNAL_YWPTODP(dc, dc->CursPosX, dc->CursPosY));
33 PSDRV_WriteLineTo(dc, INTERNAL_XWPTODP(dc, x, y),
34 INTERNAL_YWPTODP(dc, x, y));
35 PSDRV_DrawLine(dc);
37 return TRUE;
41 /***********************************************************************
42 * PSDRV_Rectangle
44 BOOL PSDRV_Rectangle( DC *dc, INT left, INT top, INT right,
45 INT bottom )
47 INT width;
48 INT height;
50 TRACE("%d %d - %d %d\n", left, top, right, bottom);
51 width = INTERNAL_XWSTODS(dc, right - left);
52 height = INTERNAL_YWSTODS(dc, bottom - top);
53 PSDRV_WriteRectangle(dc, INTERNAL_XWPTODP(dc, left, top),
54 INTERNAL_YWPTODP(dc, left, top),
55 width, height);
56 PSDRV_Brush(dc,0);
57 PSDRV_SetPen(dc);
58 PSDRV_DrawLine(dc);
59 return TRUE;
63 /***********************************************************************
64 * PSDRV_RoundRect
66 BOOL PSDRV_RoundRect( DC *dc, INT left, INT top, INT right,
67 INT bottom, INT ell_width, INT ell_height )
69 left = XLPTODP( dc, left );
70 right = XLPTODP( dc, right );
71 top = YLPTODP( dc, top );
72 bottom = YLPTODP( dc, bottom );
73 ell_width = XLSTODS( dc, ell_width );
74 ell_height = YLSTODS( dc, ell_height );
76 if( left > right ) { INT tmp = left; left = right; right = tmp; }
77 if( top > bottom ) { INT tmp = top; top = bottom; bottom = tmp; }
79 if(ell_width > right - left) ell_width = right - left;
80 if(ell_height > bottom - top) ell_height = bottom - top;
82 PSDRV_WriteMoveTo( dc, left, top + ell_height/2 );
83 PSDRV_WriteArc( dc, left + ell_width/2, top + ell_height/2, ell_width,
84 ell_height, 90.0, 180.0);
85 PSDRV_WriteLineTo( dc, right - ell_width/2, top );
86 PSDRV_WriteArc( dc, right - ell_width/2, top + ell_height/2, ell_width,
87 ell_height, 0.0, 90.0);
88 PSDRV_WriteLineTo( dc, right, bottom - ell_height/2 );
89 PSDRV_WriteArc( dc, right - ell_width/2, bottom - ell_height/2, ell_width,
90 ell_height, -90.0, 0.0);
91 PSDRV_WriteLineTo( dc, right - ell_width/2, bottom);
92 PSDRV_WriteArc( dc, left + ell_width/2, bottom - ell_height/2, ell_width,
93 ell_height, 180.0, -90.0);
94 PSDRV_WriteClosePath( dc );
96 PSDRV_Brush(dc,0);
97 PSDRV_SetPen(dc);
98 PSDRV_DrawLine(dc);
99 return TRUE;
102 /***********************************************************************
103 * PSDRV_DrawArc
105 * Does the work of Arc, Chord and Pie. lines is 0, 1 or 2 respectively.
107 static BOOL PSDRV_DrawArc( DC *dc, INT left, INT top,
108 INT right, INT bottom,
109 INT xstart, INT ystart,
110 INT xend, INT yend,
111 int lines )
113 INT x, y, h, w;
114 double start_angle, end_angle, ratio;
116 x = XLPTODP(dc, (left + right)/2);
117 y = YLPTODP(dc, (top + bottom)/2);
119 w = XLSTODS(dc, (right - left));
120 h = YLSTODS(dc, (bottom - top));
122 if(w < 0) w = -w;
123 if(h < 0) h = -h;
124 ratio = ((double)w)/h;
126 /* angle is the angle after the rectangle is transformed to a square and is
127 measured anticlockwise from the +ve x-axis */
129 start_angle = atan2((double)(y - ystart) * ratio, (double)(xstart - x));
130 end_angle = atan2((double)(y - yend) * ratio, (double)(xend - x));
132 start_angle *= 180.0 / PI;
133 end_angle *= 180.0 / PI;
135 if(lines == 2) /* pie */
136 PSDRV_WriteMoveTo(dc, x, y);
137 else
138 PSDRV_WriteNewPath( dc );
140 PSDRV_WriteArc(dc, x, y, w, h, start_angle, end_angle);
141 if(lines == 1 || lines == 2) { /* chord or pie */
142 PSDRV_WriteClosePath(dc);
143 PSDRV_Brush(dc,0);
145 PSDRV_SetPen(dc);
146 PSDRV_DrawLine(dc);
147 return TRUE;
151 /***********************************************************************
152 * PSDRV_Arc
154 BOOL PSDRV_Arc( DC *dc, INT left, INT top, INT right, INT bottom,
155 INT xstart, INT ystart, INT xend, INT yend )
157 return PSDRV_DrawArc( dc, left, top, right, bottom, xstart, ystart,
158 xend, yend, 0 );
161 /***********************************************************************
162 * PSDRV_Chord
164 BOOL PSDRV_Chord( DC *dc, INT left, INT top, INT right, INT bottom,
165 INT xstart, INT ystart, INT xend, INT yend )
167 return PSDRV_DrawArc( dc, left, top, right, bottom, xstart, ystart,
168 xend, yend, 1 );
172 /***********************************************************************
173 * PSDRV_Pie
175 BOOL PSDRV_Pie( DC *dc, INT left, INT top, INT right, INT bottom,
176 INT xstart, INT ystart, INT xend, INT yend )
178 return PSDRV_DrawArc( dc, left, top, right, bottom, xstart, ystart,
179 xend, yend, 2 );
183 /***********************************************************************
184 * PSDRV_Ellipse
186 BOOL PSDRV_Ellipse( DC *dc, INT left, INT top, INT right, INT bottom)
188 INT x, y, w, h;
190 TRACE("%d %d - %d %d\n", left, top, right, bottom);
192 x = XLPTODP(dc, (left + right)/2);
193 y = YLPTODP(dc, (top + bottom)/2);
195 w = XLSTODS(dc, (right - left));
196 h = YLSTODS(dc, (bottom - top));
198 PSDRV_WriteNewPath(dc);
199 PSDRV_WriteArc(dc, x, y, w, h, 0.0, 360.0);
200 PSDRV_WriteClosePath(dc);
201 PSDRV_Brush(dc,0);
202 PSDRV_SetPen(dc);
203 PSDRV_DrawLine(dc);
204 return TRUE;
208 /***********************************************************************
209 * PSDRV_PolyPolyline
211 BOOL PSDRV_PolyPolyline( DC *dc, const POINT* pts, const DWORD* counts,
212 DWORD polylines )
214 DWORD polyline, line;
215 const POINT* pt;
216 TRACE("\n");
218 pt = pts;
219 for(polyline = 0; polyline < polylines; polyline++) {
220 PSDRV_WriteMoveTo(dc, INTERNAL_XWPTODP(dc, pt->x, pt->y), INTERNAL_YWPTODP(dc, pt->x, pt->y));
221 pt++;
222 for(line = 1; line < counts[polyline]; line++) {
223 PSDRV_WriteLineTo(dc, INTERNAL_XWPTODP(dc, pt->x, pt->y), INTERNAL_YWPTODP(dc, pt->x, pt->y));
224 pt++;
227 PSDRV_SetPen(dc);
228 PSDRV_DrawLine(dc);
229 return TRUE;
233 /***********************************************************************
234 * PSDRV_Polyline
236 BOOL PSDRV_Polyline( DC *dc, const POINT* pt, INT count )
238 return PSDRV_PolyPolyline( dc, pt, (LPDWORD) &count, 1 );
242 /***********************************************************************
243 * PSDRV_PolyPolygon
245 BOOL PSDRV_PolyPolygon( DC *dc, const POINT* pts, const INT* counts,
246 UINT polygons )
248 DWORD polygon, line;
249 const POINT* pt;
250 TRACE("\n");
252 pt = pts;
253 for(polygon = 0; polygon < polygons; polygon++) {
254 PSDRV_WriteMoveTo(dc, INTERNAL_XWPTODP(dc, pt->x, pt->y), INTERNAL_YWPTODP(dc, pt->x, pt->y));
255 pt++;
256 for(line = 1; line < counts[polygon]; line++) {
257 PSDRV_WriteLineTo(dc, INTERNAL_XWPTODP(dc, pt->x, pt->y), INTERNAL_YWPTODP(dc, pt->x, pt->y));
258 pt++;
260 PSDRV_WriteClosePath(dc);
263 if(dc->polyFillMode == ALTERNATE)
264 PSDRV_Brush(dc, 1);
265 else /* WINDING */
266 PSDRV_Brush(dc, 0);
267 PSDRV_SetPen(dc);
268 PSDRV_DrawLine(dc);
269 return TRUE;
273 /***********************************************************************
274 * PSDRV_Polygon
276 BOOL PSDRV_Polygon( DC *dc, const POINT* pt, INT count )
278 return PSDRV_PolyPolygon( dc, pt, &count, 1 );
282 /***********************************************************************
283 * PSDRV_SetPixel
285 COLORREF PSDRV_SetPixel( DC *dc, INT x, INT y, COLORREF color )
287 PSDRV_PDEVICE *physDev = (PSDRV_PDEVICE *)dc->physDev;
288 PSCOLOR pscolor;
290 x = INTERNAL_XWPTODP(dc, x, y);
291 y = INTERNAL_YWPTODP(dc, x, y);
293 PSDRV_WriteRectangle( dc, x, y, 0, 0 );
294 PSDRV_CreateColor( physDev, &pscolor, color );
295 PSDRV_WriteSetColor( dc, &pscolor );
296 PSDRV_WriteFill( dc );
297 return color;
301 /***********************************************************************
302 * PSDRV_DrawLine
304 VOID PSDRV_DrawLine( DC *dc )
306 PSDRV_PDEVICE *physDev = (PSDRV_PDEVICE *)dc->physDev;
308 if (physDev->pen.style == PS_NULL)
309 PSDRV_WriteNewPath(dc);
310 else
311 PSDRV_WriteStroke(dc);