Added LGPL standard comment, and copyright notices where necessary.
[wine/multimedia.git] / dlls / wineps / graphics.c
blob0b3509fbc9963ca05c5050cc21821cf4bb12f3b1
1 /*
2 * PostScript driver graphics functions
4 * Copyright 1998 Huw D M Davies
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include "config.h"
23 #include <string.h>
24 #include <math.h>
25 #if defined(HAVE_FLOAT_H)
26 #include <float.h>
27 #endif
28 #if !defined(PI)
29 #define PI M_PI
30 #endif
31 #include "psdrv.h"
32 #include "wine/debug.h"
33 #include "winspool.h"
35 WINE_DEFAULT_DEBUG_CHANNEL(psdrv);
38 /***********************************************************************
39 * PSDRV_LineTo
41 BOOL PSDRV_LineTo(DC *dc, INT x, INT y)
43 TRACE("%d %d\n", x, y);
45 PSDRV_SetPen(dc);
46 PSDRV_WriteMoveTo(dc, INTERNAL_XWPTODP(dc, dc->CursPosX, dc->CursPosY),
47 INTERNAL_YWPTODP(dc, dc->CursPosX, dc->CursPosY));
48 PSDRV_WriteLineTo(dc, INTERNAL_XWPTODP(dc, x, y),
49 INTERNAL_YWPTODP(dc, x, y));
50 PSDRV_DrawLine(dc);
52 return TRUE;
56 /***********************************************************************
57 * PSDRV_Rectangle
59 BOOL PSDRV_Rectangle( DC *dc, INT left, INT top, INT right,
60 INT bottom )
62 INT width;
63 INT height;
65 TRACE("%d %d - %d %d\n", left, top, right, bottom);
66 width = INTERNAL_XWSTODS(dc, right - left);
67 height = INTERNAL_YWSTODS(dc, bottom - top);
68 PSDRV_WriteRectangle(dc, INTERNAL_XWPTODP(dc, left, top),
69 INTERNAL_YWPTODP(dc, left, top),
70 width, height);
71 PSDRV_Brush(dc,0);
72 PSDRV_SetPen(dc);
73 PSDRV_DrawLine(dc);
74 return TRUE;
78 /***********************************************************************
79 * PSDRV_RoundRect
81 BOOL PSDRV_RoundRect( DC *dc, INT left, INT top, INT right,
82 INT bottom, INT ell_width, INT ell_height )
84 left = XLPTODP( dc, left );
85 right = XLPTODP( dc, right );
86 top = YLPTODP( dc, top );
87 bottom = YLPTODP( dc, bottom );
88 ell_width = XLSTODS( dc, ell_width );
89 ell_height = YLSTODS( dc, ell_height );
91 if( left > right ) { INT tmp = left; left = right; right = tmp; }
92 if( top > bottom ) { INT tmp = top; top = bottom; bottom = tmp; }
94 if(ell_width > right - left) ell_width = right - left;
95 if(ell_height > bottom - top) ell_height = bottom - top;
97 PSDRV_WriteMoveTo( dc, left, top + ell_height/2 );
98 PSDRV_WriteArc( dc, left + ell_width/2, top + ell_height/2, ell_width,
99 ell_height, 90.0, 180.0);
100 PSDRV_WriteLineTo( dc, right - ell_width/2, top );
101 PSDRV_WriteArc( dc, right - ell_width/2, top + ell_height/2, ell_width,
102 ell_height, 0.0, 90.0);
103 PSDRV_WriteLineTo( dc, right, bottom - ell_height/2 );
104 PSDRV_WriteArc( dc, right - ell_width/2, bottom - ell_height/2, ell_width,
105 ell_height, -90.0, 0.0);
106 PSDRV_WriteLineTo( dc, right - ell_width/2, bottom);
107 PSDRV_WriteArc( dc, left + ell_width/2, bottom - ell_height/2, ell_width,
108 ell_height, 180.0, -90.0);
109 PSDRV_WriteClosePath( dc );
111 PSDRV_Brush(dc,0);
112 PSDRV_SetPen(dc);
113 PSDRV_DrawLine(dc);
114 return TRUE;
117 /***********************************************************************
118 * PSDRV_DrawArc
120 * Does the work of Arc, Chord and Pie. lines is 0, 1 or 2 respectively.
122 static BOOL PSDRV_DrawArc( DC *dc, INT left, INT top,
123 INT right, INT bottom,
124 INT xstart, INT ystart,
125 INT xend, INT yend,
126 int lines )
128 INT x, y, h, w;
129 double start_angle, end_angle, ratio;
131 x = XLPTODP(dc, (left + right)/2);
132 y = YLPTODP(dc, (top + bottom)/2);
134 w = XLSTODS(dc, (right - left));
135 h = YLSTODS(dc, (bottom - top));
137 if(w < 0) w = -w;
138 if(h < 0) h = -h;
139 ratio = ((double)w)/h;
141 /* angle is the angle after the rectangle is transformed to a square and is
142 measured anticlockwise from the +ve x-axis */
144 start_angle = atan2((double)(y - ystart) * ratio, (double)(xstart - x));
145 end_angle = atan2((double)(y - yend) * ratio, (double)(xend - x));
147 start_angle *= 180.0 / PI;
148 end_angle *= 180.0 / PI;
150 if(lines == 2) /* pie */
151 PSDRV_WriteMoveTo(dc, x, y);
152 else
153 PSDRV_WriteNewPath( dc );
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);
158 PSDRV_Brush(dc,0);
160 PSDRV_SetPen(dc);
161 PSDRV_DrawLine(dc);
162 return TRUE;
166 /***********************************************************************
167 * PSDRV_Arc
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,
173 xend, yend, 0 );
176 /***********************************************************************
177 * PSDRV_Chord
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,
183 xend, yend, 1 );
187 /***********************************************************************
188 * PSDRV_Pie
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,
194 xend, yend, 2 );
198 /***********************************************************************
199 * PSDRV_Ellipse
201 BOOL PSDRV_Ellipse( DC *dc, INT left, INT top, INT right, INT bottom)
203 INT x, y, w, h;
205 TRACE("%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_WriteNewPath(dc);
214 PSDRV_WriteArc(dc, x, y, w, h, 0.0, 360.0);
215 PSDRV_WriteClosePath(dc);
216 PSDRV_Brush(dc,0);
217 PSDRV_SetPen(dc);
218 PSDRV_DrawLine(dc);
219 return TRUE;
223 /***********************************************************************
224 * PSDRV_PolyPolyline
226 BOOL PSDRV_PolyPolyline( DC *dc, const POINT* pts, const DWORD* counts,
227 DWORD polylines )
229 DWORD polyline, line;
230 const POINT* pt;
231 TRACE("\n");
233 pt = pts;
234 for(polyline = 0; polyline < polylines; polyline++) {
235 PSDRV_WriteMoveTo(dc, INTERNAL_XWPTODP(dc, pt->x, pt->y), INTERNAL_YWPTODP(dc, pt->x, pt->y));
236 pt++;
237 for(line = 1; line < counts[polyline]; line++) {
238 PSDRV_WriteLineTo(dc, INTERNAL_XWPTODP(dc, pt->x, pt->y), INTERNAL_YWPTODP(dc, pt->x, pt->y));
239 pt++;
242 PSDRV_SetPen(dc);
243 PSDRV_DrawLine(dc);
244 return TRUE;
248 /***********************************************************************
249 * PSDRV_Polyline
251 BOOL PSDRV_Polyline( DC *dc, const POINT* pt, INT count )
253 return PSDRV_PolyPolyline( dc, pt, (LPDWORD) &count, 1 );
257 /***********************************************************************
258 * PSDRV_PolyPolygon
260 BOOL PSDRV_PolyPolygon( DC *dc, const POINT* pts, const INT* counts,
261 UINT polygons )
263 DWORD polygon, line;
264 const POINT* pt;
265 TRACE("\n");
267 pt = pts;
268 for(polygon = 0; polygon < polygons; polygon++) {
269 PSDRV_WriteMoveTo(dc, INTERNAL_XWPTODP(dc, pt->x, pt->y), INTERNAL_YWPTODP(dc, pt->x, pt->y));
270 pt++;
271 for(line = 1; line < counts[polygon]; line++) {
272 PSDRV_WriteLineTo(dc, INTERNAL_XWPTODP(dc, pt->x, pt->y), INTERNAL_YWPTODP(dc, pt->x, pt->y));
273 pt++;
275 PSDRV_WriteClosePath(dc);
278 if(dc->polyFillMode == ALTERNATE)
279 PSDRV_Brush(dc, 1);
280 else /* WINDING */
281 PSDRV_Brush(dc, 0);
282 PSDRV_SetPen(dc);
283 PSDRV_DrawLine(dc);
284 return TRUE;
288 /***********************************************************************
289 * PSDRV_Polygon
291 BOOL PSDRV_Polygon( DC *dc, const POINT* pt, INT count )
293 return PSDRV_PolyPolygon( dc, pt, &count, 1 );
297 /***********************************************************************
298 * PSDRV_SetPixel
300 COLORREF PSDRV_SetPixel( DC *dc, INT x, INT y, COLORREF color )
302 PSDRV_PDEVICE *physDev = (PSDRV_PDEVICE *)dc->physDev;
303 PSCOLOR pscolor;
305 x = INTERNAL_XWPTODP(dc, x, y);
306 y = INTERNAL_YWPTODP(dc, x, y);
308 PSDRV_WriteRectangle( dc, x, y, 0, 0 );
309 PSDRV_CreateColor( physDev, &pscolor, color );
310 PSDRV_WriteSetColor( dc, &pscolor );
311 PSDRV_WriteFill( dc );
312 return color;
316 /***********************************************************************
317 * PSDRV_DrawLine
319 VOID PSDRV_DrawLine( DC *dc )
321 PSDRV_PDEVICE *physDev = (PSDRV_PDEVICE *)dc->physDev;
323 if (physDev->pen.style == PS_NULL)
324 PSDRV_WriteNewPath(dc);
325 else
326 PSDRV_WriteStroke(dc);