Update shell xxxAW wrapper prototypes for fixed SHLWAPI functions.
[wine] / dlls / wineps / graphics.c
1 /*
2  *      PostScript driver graphics functions
3  *
4  *      Copyright 1998  Huw D M Davies
5  *
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.
10  *
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.
15  *
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
19  */
20
21 #include "config.h"
22
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"
34
35 WINE_DEFAULT_DEBUG_CHANNEL(psdrv);
36
37
38 /***********************************************************************
39  *           PSDRV_LineTo
40  */
41 BOOL PSDRV_LineTo(DC *dc, INT x, INT y)
42 {
43     TRACE("%d %d\n", x, y);
44
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);
51
52     return TRUE;
53 }
54
55
56 /***********************************************************************
57  *           PSDRV_Rectangle
58  */
59 BOOL PSDRV_Rectangle( DC *dc, INT left, INT top, INT right,
60                        INT bottom )
61 {
62     INT width;
63     INT height;
64
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;
75 }
76
77
78 /***********************************************************************
79  *           PSDRV_RoundRect
80  */
81 BOOL PSDRV_RoundRect( DC *dc, INT left, INT top, INT right,
82                         INT bottom, INT ell_width, INT ell_height )
83 {
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 );
90
91     if( left > right ) { INT tmp = left; left = right; right = tmp; }
92     if( top > bottom ) { INT tmp = top; top = bottom; bottom = tmp; }
93
94     if(ell_width > right - left) ell_width = right - left;
95     if(ell_height > bottom - top) ell_height = bottom - top;
96
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 );
110
111     PSDRV_Brush(dc,0);
112     PSDRV_SetPen(dc);
113     PSDRV_DrawLine(dc);
114     return TRUE;
115 }
116
117 /***********************************************************************
118  *           PSDRV_DrawArc
119  *
120  * Does the work of Arc, Chord and Pie. lines is 0, 1 or 2 respectively.
121  */
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 )
127 {
128     INT x, y, h, w;
129     double start_angle, end_angle, ratio;
130
131     x = XLPTODP(dc, (left + right)/2);
132     y = YLPTODP(dc, (top + bottom)/2);
133
134     w = XLSTODS(dc, (right - left));
135     h = YLSTODS(dc, (bottom - top));
136
137     if(w < 0) w = -w;
138     if(h < 0) h = -h;
139     ratio = ((double)w)/h;
140
141     /* angle is the angle after the rectangle is transformed to a square and is
142        measured anticlockwise from the +ve x-axis */
143
144     start_angle = atan2((double)(y - ystart) * ratio, (double)(xstart - x));
145     end_angle = atan2((double)(y - yend) * ratio, (double)(xend - x));
146
147     start_angle *= 180.0 / PI;
148     end_angle *= 180.0 / PI;
149
150     if(lines == 2) /* pie */
151         PSDRV_WriteMoveTo(dc, x, y);
152     else
153         PSDRV_WriteNewPath( dc );
154
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);
159     }
160     PSDRV_SetPen(dc);
161     PSDRV_DrawLine(dc);
162     return TRUE;
163 }
164
165
166 /***********************************************************************
167  *           PSDRV_Arc
168  */
169 BOOL PSDRV_Arc( DC *dc, INT left, INT top, INT right, INT bottom,
170                   INT xstart, INT ystart, INT xend, INT yend )
171 {
172     return PSDRV_DrawArc( dc, left, top, right, bottom, xstart, ystart,
173                          xend, yend, 0 );
174 }
175
176 /***********************************************************************
177  *           PSDRV_Chord
178  */
179 BOOL PSDRV_Chord( DC *dc, INT left, INT top, INT right, INT bottom,
180                   INT xstart, INT ystart, INT xend, INT yend )
181 {
182     return PSDRV_DrawArc( dc, left, top, right, bottom, xstart, ystart,
183                          xend, yend, 1 );
184 }
185
186
187 /***********************************************************************
188  *           PSDRV_Pie
189  */
190 BOOL PSDRV_Pie( DC *dc, INT left, INT top, INT right, INT bottom,
191                   INT xstart, INT ystart, INT xend, INT yend )
192 {
193     return PSDRV_DrawArc( dc, left, top, right, bottom, xstart, ystart,
194                          xend, yend, 2 );
195 }
196
197
198 /***********************************************************************
199  *           PSDRV_Ellipse
200  */
201 BOOL PSDRV_Ellipse( DC *dc, INT left, INT top, INT right, INT bottom)
202 {
203     INT x, y, w, h;
204
205     TRACE("%d %d - %d %d\n", left, top, right, bottom);
206
207     x = XLPTODP(dc, (left + right)/2);
208     y = YLPTODP(dc, (top + bottom)/2);
209
210     w = XLSTODS(dc, (right - left));
211     h = YLSTODS(dc, (bottom - top));
212
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;
220 }
221
222
223 /***********************************************************************
224  *           PSDRV_PolyPolyline
225  */
226 BOOL PSDRV_PolyPolyline( DC *dc, const POINT* pts, const DWORD* counts,
227                            DWORD polylines )
228 {
229     DWORD polyline, line;
230     const POINT* pt;
231     TRACE("\n");
232
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++;
240         }
241     }
242     PSDRV_SetPen(dc);
243     PSDRV_DrawLine(dc);
244     return TRUE;
245 }   
246
247
248 /***********************************************************************
249  *           PSDRV_Polyline
250  */
251 BOOL PSDRV_Polyline( DC *dc, const POINT* pt, INT count )
252 {
253     return PSDRV_PolyPolyline( dc, pt, (LPDWORD) &count, 1 );
254 }
255
256
257 /***********************************************************************
258  *           PSDRV_PolyPolygon
259  */
260 BOOL PSDRV_PolyPolygon( DC *dc, const POINT* pts, const INT* counts,
261                           UINT polygons )
262 {
263     DWORD polygon, line;
264     const POINT* pt;
265     TRACE("\n");
266
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++;
274         }
275         PSDRV_WriteClosePath(dc);
276     }
277
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;
285 }
286
287
288 /***********************************************************************
289  *           PSDRV_Polygon
290  */
291 BOOL PSDRV_Polygon( DC *dc, const POINT* pt, INT count )
292 {
293      return PSDRV_PolyPolygon( dc, pt, &count, 1 );
294 }
295
296
297 /***********************************************************************
298  *           PSDRV_SetPixel
299  */
300 COLORREF PSDRV_SetPixel( DC *dc, INT x, INT y, COLORREF color )
301 {
302     PSDRV_PDEVICE *physDev = (PSDRV_PDEVICE *)dc->physDev;
303     PSCOLOR pscolor;
304
305     x = INTERNAL_XWPTODP(dc, x, y);
306     y = INTERNAL_YWPTODP(dc, x, y);
307
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;
313 }
314
315
316 /***********************************************************************
317  *           PSDRV_DrawLine
318  */
319 VOID PSDRV_DrawLine( DC *dc )
320 {
321     PSDRV_PDEVICE *physDev = (PSDRV_PDEVICE *)dc->physDev;
322
323     if (physDev->pen.style == PS_NULL)
324         PSDRV_WriteNewPath(dc);
325     else
326         PSDRV_WriteStroke(dc);
327 }