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
26 #if defined(HAVE_FLOAT_H)
33 #include "wine/debug.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(psdrv);
38 /***********************************************************************
41 static void PSDRV_DrawLine( PSDRV_PDEVICE *physDev )
43 if(physDev->pathdepth)
46 if (physDev->pen.style == PS_NULL)
47 PSDRV_WriteNewPath(physDev);
49 PSDRV_WriteStroke(physDev);
52 /***********************************************************************
55 BOOL PSDRV_LineTo(PSDRV_PDEVICE *physDev, INT x, INT y)
59 TRACE("%d %d\n", x, y);
61 GetCurrentPositionEx( physDev->hdc, pt );
64 LPtoDP( physDev->hdc, pt, 2 );
66 PSDRV_SetPen(physDev);
68 PSDRV_SetClip(physDev);
69 PSDRV_WriteMoveTo(physDev, pt[0].x, pt[0].y );
70 PSDRV_WriteLineTo(physDev, pt[1].x, pt[1].y );
71 PSDRV_DrawLine(physDev);
72 PSDRV_ResetClip(physDev);
78 /***********************************************************************
81 BOOL PSDRV_Rectangle( PSDRV_PDEVICE *physDev, INT left, INT top, INT right, INT bottom )
85 TRACE("%d %d - %d %d\n", left, top, right, bottom);
91 LPtoDP( physDev->hdc, (POINT *)&rect, 2 );
93 /* HACK to get inserted eps files printing from Office 2k */
94 if(GetROP2(physDev->hdc) == R2_NOP) {
96 sprintf(buf, "%ld %ld %ld %ld B\n", rect.right - rect.left, rect.bottom - rect.top, rect.left, rect.top);
97 PSDRV_WriteSpool(physDev, buf, strlen(buf));
101 PSDRV_WriteSpool(physDev, "%Rectangle\n",11);
102 PSDRV_SetPen(physDev);
104 PSDRV_SetClip(physDev);
105 PSDRV_WriteRectangle(physDev, rect.left, rect.top, rect.right - rect.left,
106 rect.bottom - rect.top );
107 PSDRV_Brush(physDev,0);
108 PSDRV_DrawLine(physDev);
109 PSDRV_ResetClip(physDev);
114 /***********************************************************************
117 BOOL PSDRV_RoundRect( PSDRV_PDEVICE *physDev, INT left, INT top, INT right,
118 INT bottom, INT ell_width, INT ell_height )
124 rect[0].right = right;
125 rect[0].bottom = bottom;
128 rect[1].right = ell_width;
129 rect[1].bottom = ell_height;
130 LPtoDP( physDev->hdc, (POINT *)rect, 4 );
134 right = rect[0].right;
135 bottom = rect[0].bottom;
136 if (left > right) { INT tmp = left; left = right; right = tmp; }
137 if (top > bottom) { INT tmp = top; top = bottom; bottom = tmp; }
139 ell_width = rect[1].right - rect[1].left;
140 ell_height = rect[1].bottom - rect[1].top;
141 if (ell_width > right - left) ell_width = right - left;
142 if (ell_height > bottom - top) ell_height = bottom - top;
144 PSDRV_WriteSpool(physDev, "%RoundRect\n",11);
145 PSDRV_SetPen(physDev);
147 PSDRV_SetClip(physDev);
148 PSDRV_WriteMoveTo( physDev, left, top + ell_height/2 );
149 PSDRV_WriteArc( physDev, left + ell_width/2, top + ell_height/2, ell_width,
150 ell_height, 90.0, 180.0);
151 PSDRV_WriteLineTo( physDev, right - ell_width/2, top );
152 PSDRV_WriteArc( physDev, right - ell_width/2, top + ell_height/2, ell_width,
153 ell_height, 0.0, 90.0);
154 PSDRV_WriteLineTo( physDev, right, bottom - ell_height/2 );
155 PSDRV_WriteArc( physDev, right - ell_width/2, bottom - ell_height/2, ell_width,
156 ell_height, -90.0, 0.0);
157 PSDRV_WriteLineTo( physDev, right - ell_width/2, bottom);
158 PSDRV_WriteArc( physDev, left + ell_width/2, bottom - ell_height/2, ell_width,
159 ell_height, 180.0, -90.0);
160 PSDRV_WriteClosePath( physDev );
162 PSDRV_Brush(physDev,0);
163 PSDRV_DrawLine(physDev);
164 PSDRV_ResetClip(physDev);
168 /***********************************************************************
171 * Does the work of Arc, Chord and Pie. lines is 0, 1 or 2 respectively.
173 static BOOL PSDRV_DrawArc( PSDRV_PDEVICE *physDev, INT left, INT top,
174 INT right, INT bottom, INT xstart, INT ystart,
175 INT xend, INT yend, int lines )
178 double start_angle, end_angle, ratio;
185 rect.bottom = bottom;
186 LPtoDP( physDev->hdc, (POINT *)&rect, 2 );
191 LPtoDP( physDev->hdc, &start, 1 );
192 LPtoDP( physDev->hdc, &end, 1 );
194 x = (rect.left + rect.right) / 2;
195 y = (rect.top + rect.bottom) / 2;
196 w = rect.right - rect.left;
197 h = rect.bottom - rect.top;
201 ratio = ((double)w)/h;
203 /* angle is the angle after the rectangle is transformed to a square and is
204 measured anticlockwise from the +ve x-axis */
206 start_angle = atan2((double)(y - start.y) * ratio, (double)(start.x - x));
207 end_angle = atan2((double)(y - end.y) * ratio, (double)(end.x - x));
209 start_angle *= 180.0 / PI;
210 end_angle *= 180.0 / PI;
212 PSDRV_WriteSpool(physDev,"%DrawArc\n", 9);
213 PSDRV_SetPen(physDev);
215 PSDRV_SetClip(physDev);
216 if(lines == 2) /* pie */
217 PSDRV_WriteMoveTo(physDev, x, y);
219 PSDRV_WriteNewPath( physDev );
221 PSDRV_WriteArc(physDev, x, y, w, h, start_angle, end_angle);
222 if(lines == 1 || lines == 2) { /* chord or pie */
223 PSDRV_WriteClosePath(physDev);
224 PSDRV_Brush(physDev,0);
226 PSDRV_DrawLine(physDev);
227 PSDRV_ResetClip(physDev);
233 /***********************************************************************
236 BOOL PSDRV_Arc( PSDRV_PDEVICE *physDev, INT left, INT top, INT right, INT bottom,
237 INT xstart, INT ystart, INT xend, INT yend )
239 return PSDRV_DrawArc( physDev, left, top, right, bottom, xstart, ystart, xend, yend, 0 );
242 /***********************************************************************
245 BOOL PSDRV_Chord( PSDRV_PDEVICE *physDev, INT left, INT top, INT right, INT bottom,
246 INT xstart, INT ystart, INT xend, INT yend )
248 return PSDRV_DrawArc( physDev, left, top, right, bottom, xstart, ystart, xend, yend, 1 );
252 /***********************************************************************
255 BOOL PSDRV_Pie( PSDRV_PDEVICE *physDev, INT left, INT top, INT right, INT bottom,
256 INT xstart, INT ystart, INT xend, INT yend )
258 return PSDRV_DrawArc( physDev, left, top, right, bottom, xstart, ystart, xend, yend, 2 );
262 /***********************************************************************
265 BOOL PSDRV_Ellipse( PSDRV_PDEVICE *physDev, INT left, INT top, INT right, INT bottom)
270 TRACE("%d %d - %d %d\n", left, top, right, bottom);
275 rect.bottom = bottom;
276 LPtoDP( physDev->hdc, (POINT *)&rect, 2 );
278 x = (rect.left + rect.right) / 2;
279 y = (rect.top + rect.bottom) / 2;
280 w = rect.right - rect.left;
281 h = rect.bottom - rect.top;
283 PSDRV_WriteSpool(physDev, "%Ellipse\n", 9);
284 PSDRV_SetPen(physDev);
286 PSDRV_SetClip(physDev);
287 PSDRV_WriteNewPath(physDev);
288 PSDRV_WriteArc(physDev, x, y, w, h, 0.0, 360.0);
289 PSDRV_WriteClosePath(physDev);
290 PSDRV_Brush(physDev,0);
291 PSDRV_DrawLine(physDev);
292 PSDRV_ResetClip(physDev);
297 /***********************************************************************
300 BOOL PSDRV_PolyPolyline( PSDRV_PDEVICE *physDev, const POINT* pts, const DWORD* counts,
303 DWORD polyline, line, total;
308 for (polyline = total = 0; polyline < polylines; polyline++) total += counts[polyline];
309 if (!(dev_pts = HeapAlloc( GetProcessHeap(), 0, total * sizeof(*dev_pts) ))) return FALSE;
310 memcpy( dev_pts, pts, total * sizeof(*dev_pts) );
311 LPtoDP( physDev->hdc, dev_pts, total );
315 PSDRV_WriteSpool(physDev, "%PolyPolyline\n",14);
316 PSDRV_SetPen(physDev);
317 PSDRV_SetClip(physDev);
319 for(polyline = 0; polyline < polylines; polyline++) {
320 PSDRV_WriteMoveTo(physDev, pt->x, pt->y);
322 for(line = 1; line < counts[polyline]; line++, pt++)
323 PSDRV_WriteLineTo(physDev, pt->x, pt->y);
325 HeapFree( GetProcessHeap(), 0, dev_pts );
327 PSDRV_DrawLine(physDev);
328 PSDRV_ResetClip(physDev);
333 /***********************************************************************
336 BOOL PSDRV_Polyline( PSDRV_PDEVICE *physDev, const POINT* pt, INT count )
338 return PSDRV_PolyPolyline( physDev, pt, (LPDWORD) &count, 1 );
342 /***********************************************************************
345 BOOL PSDRV_PolyPolygon( PSDRV_PDEVICE *physDev, const POINT* pts, const INT* counts,
348 DWORD polygon, line, total;
353 for (polygon = total = 0; polygon < polygons; polygon++) total += counts[polygon];
354 if (!(dev_pts = HeapAlloc( GetProcessHeap(), 0, total * sizeof(*dev_pts) ))) return FALSE;
355 memcpy( dev_pts, pts, total * sizeof(*dev_pts) );
356 LPtoDP( physDev->hdc, dev_pts, total );
360 PSDRV_WriteSpool(physDev, "%PolyPolygon\n",13);
361 PSDRV_SetPen(physDev);
362 PSDRV_SetClip(physDev);
364 for(polygon = 0; polygon < polygons; polygon++) {
365 PSDRV_WriteMoveTo(physDev, pt->x, pt->y);
367 for(line = 1; line < counts[polygon]; line++, pt++)
368 PSDRV_WriteLineTo(physDev, pt->x, pt->y);
369 PSDRV_WriteClosePath(physDev);
371 HeapFree( GetProcessHeap(), 0, dev_pts );
373 if(GetPolyFillMode( physDev->hdc ) == ALTERNATE)
374 PSDRV_Brush(physDev, 1);
376 PSDRV_Brush(physDev, 0);
378 PSDRV_DrawLine(physDev);
379 PSDRV_ResetClip(physDev);
384 /***********************************************************************
387 BOOL PSDRV_Polygon( PSDRV_PDEVICE *physDev, const POINT* pt, INT count )
389 return PSDRV_PolyPolygon( physDev, pt, &count, 1 );
393 /***********************************************************************
396 COLORREF PSDRV_SetPixel( PSDRV_PDEVICE *physDev, INT x, INT y, COLORREF color )
403 LPtoDP( physDev->hdc, &pt, 1 );
405 PSDRV_SetClip(physDev);
406 /* we bracket the setcolor in gsave/grestore so that we don't trash
407 the current pen colour */
408 PSDRV_WriteGSave(physDev);
409 PSDRV_WriteRectangle( physDev, pt.x, pt.y, 0, 0 );
410 PSDRV_CreateColor( physDev, &pscolor, color );
411 PSDRV_WriteSetColor( physDev, &pscolor );
412 PSDRV_WriteFill( physDev );
413 PSDRV_WriteGRestore(physDev);
414 PSDRV_ResetClip(physDev);