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_SetPen(physDev);
103 PSDRV_SetClip(physDev);
104 PSDRV_WriteRectangle(physDev, rect.left, rect.top, rect.right - rect.left,
105 rect.bottom - rect.top );
106 PSDRV_Brush(physDev,0);
107 PSDRV_DrawLine(physDev);
108 PSDRV_ResetClip(physDev);
113 /***********************************************************************
116 BOOL PSDRV_RoundRect( PSDRV_PDEVICE *physDev, INT left, INT top, INT right,
117 INT bottom, INT ell_width, INT ell_height )
123 rect[0].right = right;
124 rect[0].bottom = bottom;
127 rect[1].right = ell_width;
128 rect[1].bottom = ell_height;
129 LPtoDP( physDev->hdc, (POINT *)rect, 4 );
133 right = rect[0].right;
134 bottom = rect[0].bottom;
135 if (left > right) { INT tmp = left; left = right; right = tmp; }
136 if (top > bottom) { INT tmp = top; top = bottom; bottom = tmp; }
138 ell_width = rect[1].right - rect[1].left;
139 ell_height = rect[1].bottom - rect[1].top;
140 if (ell_width > right - left) ell_width = right - left;
141 if (ell_height > bottom - top) ell_height = bottom - top;
143 PSDRV_WriteSpool(physDev, "%RoundRect\n",11);
144 PSDRV_SetPen(physDev);
146 PSDRV_SetClip(physDev);
147 PSDRV_WriteMoveTo( physDev, left, top + ell_height/2 );
148 PSDRV_WriteArc( physDev, left + ell_width/2, top + ell_height/2, ell_width,
149 ell_height, 90.0, 180.0);
150 PSDRV_WriteLineTo( physDev, right - ell_width/2, top );
151 PSDRV_WriteArc( physDev, right - ell_width/2, top + ell_height/2, ell_width,
152 ell_height, 0.0, 90.0);
153 PSDRV_WriteLineTo( physDev, right, bottom - ell_height/2 );
154 PSDRV_WriteArc( physDev, right - ell_width/2, bottom - ell_height/2, ell_width,
155 ell_height, -90.0, 0.0);
156 PSDRV_WriteLineTo( physDev, right - ell_width/2, bottom);
157 PSDRV_WriteArc( physDev, left + ell_width/2, bottom - ell_height/2, ell_width,
158 ell_height, 180.0, -90.0);
159 PSDRV_WriteClosePath( physDev );
161 PSDRV_Brush(physDev,0);
162 PSDRV_DrawLine(physDev);
163 PSDRV_ResetClip(physDev);
167 /***********************************************************************
170 * Does the work of Arc, Chord and Pie. lines is 0, 1 or 2 respectively.
172 static BOOL PSDRV_DrawArc( PSDRV_PDEVICE *physDev, INT left, INT top,
173 INT right, INT bottom, INT xstart, INT ystart,
174 INT xend, INT yend, int lines )
177 double start_angle, end_angle, ratio;
184 rect.bottom = bottom;
185 LPtoDP( physDev->hdc, (POINT *)&rect, 2 );
190 LPtoDP( physDev->hdc, &start, 1 );
191 LPtoDP( physDev->hdc, &end, 1 );
193 x = (rect.left + rect.right) / 2;
194 y = (rect.top + rect.bottom) / 2;
195 w = rect.right - rect.left;
196 h = rect.bottom - rect.top;
200 ratio = ((double)w)/h;
202 /* angle is the angle after the rectangle is transformed to a square and is
203 measured anticlockwise from the +ve x-axis */
205 start_angle = atan2((double)(y - start.y) * ratio, (double)(start.x - x));
206 end_angle = atan2((double)(y - end.y) * ratio, (double)(end.x - x));
208 start_angle *= 180.0 / PI;
209 end_angle *= 180.0 / PI;
211 PSDRV_WriteSpool(physDev,"%DrawArc\n", 9);
212 PSDRV_SetPen(physDev);
214 PSDRV_SetClip(physDev);
215 if(lines == 2) /* pie */
216 PSDRV_WriteMoveTo(physDev, x, y);
218 PSDRV_WriteNewPath( physDev );
220 PSDRV_WriteArc(physDev, x, y, w, h, start_angle, end_angle);
221 if(lines == 1 || lines == 2) { /* chord or pie */
222 PSDRV_WriteClosePath(physDev);
223 PSDRV_Brush(physDev,0);
225 PSDRV_DrawLine(physDev);
226 PSDRV_ResetClip(physDev);
232 /***********************************************************************
235 BOOL PSDRV_Arc( PSDRV_PDEVICE *physDev, INT left, INT top, INT right, INT bottom,
236 INT xstart, INT ystart, INT xend, INT yend )
238 return PSDRV_DrawArc( physDev, left, top, right, bottom, xstart, ystart, xend, yend, 0 );
241 /***********************************************************************
244 BOOL PSDRV_Chord( PSDRV_PDEVICE *physDev, INT left, INT top, INT right, INT bottom,
245 INT xstart, INT ystart, INT xend, INT yend )
247 return PSDRV_DrawArc( physDev, left, top, right, bottom, xstart, ystart, xend, yend, 1 );
251 /***********************************************************************
254 BOOL PSDRV_Pie( PSDRV_PDEVICE *physDev, INT left, INT top, INT right, INT bottom,
255 INT xstart, INT ystart, INT xend, INT yend )
257 return PSDRV_DrawArc( physDev, left, top, right, bottom, xstart, ystart, xend, yend, 2 );
261 /***********************************************************************
264 BOOL PSDRV_Ellipse( PSDRV_PDEVICE *physDev, INT left, INT top, INT right, INT bottom)
269 TRACE("%d %d - %d %d\n", left, top, right, bottom);
274 rect.bottom = bottom;
275 LPtoDP( physDev->hdc, (POINT *)&rect, 2 );
277 x = (rect.left + rect.right) / 2;
278 y = (rect.top + rect.bottom) / 2;
279 w = rect.right - rect.left;
280 h = rect.bottom - rect.top;
282 PSDRV_WriteSpool(physDev, "%Ellipse\n", 9);
283 PSDRV_SetPen(physDev);
285 PSDRV_SetClip(physDev);
286 PSDRV_WriteNewPath(physDev);
287 PSDRV_WriteArc(physDev, x, y, w, h, 0.0, 360.0);
288 PSDRV_WriteClosePath(physDev);
289 PSDRV_Brush(physDev,0);
290 PSDRV_DrawLine(physDev);
291 PSDRV_ResetClip(physDev);
296 /***********************************************************************
299 BOOL PSDRV_PolyPolyline( PSDRV_PDEVICE *physDev, const POINT* pts, const DWORD* counts,
302 DWORD polyline, line, total;
307 for (polyline = total = 0; polyline < polylines; polyline++) total += counts[polyline];
308 if (!(dev_pts = HeapAlloc( GetProcessHeap(), 0, total * sizeof(*dev_pts) ))) return FALSE;
309 memcpy( dev_pts, pts, total * sizeof(*dev_pts) );
310 LPtoDP( physDev->hdc, dev_pts, total );
314 PSDRV_WriteSpool(physDev, "%PolyPolyline\n",14);
315 PSDRV_SetPen(physDev);
316 PSDRV_SetClip(physDev);
318 for(polyline = 0; polyline < polylines; polyline++) {
319 PSDRV_WriteMoveTo(physDev, pt->x, pt->y);
321 for(line = 1; line < counts[polyline]; line++, pt++)
322 PSDRV_WriteLineTo(physDev, pt->x, pt->y);
324 HeapFree( GetProcessHeap(), 0, dev_pts );
326 PSDRV_DrawLine(physDev);
327 PSDRV_ResetClip(physDev);
332 /***********************************************************************
335 BOOL PSDRV_Polyline( PSDRV_PDEVICE *physDev, const POINT* pt, INT count )
337 return PSDRV_PolyPolyline( physDev, pt, (LPDWORD) &count, 1 );
341 /***********************************************************************
344 BOOL PSDRV_PolyPolygon( PSDRV_PDEVICE *physDev, const POINT* pts, const INT* counts,
347 DWORD polygon, line, total;
352 for (polygon = total = 0; polygon < polygons; polygon++) total += counts[polygon];
353 if (!(dev_pts = HeapAlloc( GetProcessHeap(), 0, total * sizeof(*dev_pts) ))) return FALSE;
354 memcpy( dev_pts, pts, total * sizeof(*dev_pts) );
355 LPtoDP( physDev->hdc, dev_pts, total );
359 PSDRV_WriteSpool(physDev, "%PolyPolygon\n",13);
360 PSDRV_SetPen(physDev);
361 PSDRV_SetClip(physDev);
363 for(polygon = 0; polygon < polygons; polygon++) {
364 PSDRV_WriteMoveTo(physDev, pt->x, pt->y);
366 for(line = 1; line < counts[polygon]; line++, pt++)
367 PSDRV_WriteLineTo(physDev, pt->x, pt->y);
368 PSDRV_WriteClosePath(physDev);
370 HeapFree( GetProcessHeap(), 0, dev_pts );
372 if(GetPolyFillMode( physDev->hdc ) == ALTERNATE)
373 PSDRV_Brush(physDev, 1);
375 PSDRV_Brush(physDev, 0);
377 PSDRV_DrawLine(physDev);
378 PSDRV_ResetClip(physDev);
383 /***********************************************************************
386 BOOL PSDRV_Polygon( PSDRV_PDEVICE *physDev, const POINT* pt, INT count )
388 return PSDRV_PolyPolygon( physDev, pt, &count, 1 );
392 /***********************************************************************
395 COLORREF PSDRV_SetPixel( PSDRV_PDEVICE *physDev, INT x, INT y, COLORREF color )
402 LPtoDP( physDev->hdc, &pt, 1 );
404 PSDRV_SetClip(physDev);
405 /* we bracket the setcolor in gsave/grestore so that we don't trash
406 the current pen colour */
407 PSDRV_WriteGSave(physDev);
408 PSDRV_WriteRectangle( physDev, pt.x, pt.y, 0, 0 );
409 PSDRV_CreateColor( physDev, &pscolor, color );
410 PSDRV_WriteSetColor( physDev, &pscolor );
411 PSDRV_WriteFill( physDev );
412 PSDRV_WriteGRestore(physDev);
413 PSDRV_ResetClip(physDev);
417 /***********************************************************************
420 BOOL PSDRV_PaintRgn( PSDRV_PDEVICE *physDev, HRGN hrgn )
423 RGNDATA *rgndata = NULL;
427 TRACE("hdc=%p\n", physDev->hdc);
429 size = GetRegionData(hrgn, 0, NULL);
430 rgndata = HeapAlloc( GetProcessHeap(), 0, size );
432 ERR("Can't allocate buffer\n");
436 GetRegionData(hrgn, size, rgndata);
437 if (rgndata->rdh.nCount == 0)
440 LPtoDP(physDev->hdc, (POINT*)rgndata->Buffer, rgndata->rdh.nCount * 2);
442 PSDRV_SetClip(physDev);
443 PSDRV_WriteNewPath(physDev);
444 for(i = 0, pRect = (RECT*)rgndata->Buffer; i < rgndata->rdh.nCount; i++, pRect++)
445 PSDRV_WriteRectangle(physDev, pRect->left, pRect->top, pRect->right - pRect->left, pRect->bottom - pRect->top);
447 PSDRV_Brush(physDev, 0);
448 PSDRV_ResetClip(physDev);
451 HeapFree(GetProcessHeap(), 0, rgndata);