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
25 #if defined(HAVE_FLOAT_H)
32 #include "wine/debug.h"
35 WINE_DEFAULT_DEBUG_CHANNEL(psdrv);
38 /***********************************************************************
41 BOOL PSDRV_LineTo(PSDRV_PDEVICE *physDev, INT x, INT y)
45 TRACE("%d %d\n", x, y);
47 GetCurrentPositionEx( physDev->hdc, pt );
50 LPtoDP( physDev->hdc, pt, 2 );
52 PSDRV_SetPen(physDev);
53 PSDRV_WriteMoveTo(physDev, pt[0].x, pt[0].y );
54 PSDRV_WriteLineTo(physDev, pt[1].x, pt[1].y );
55 PSDRV_DrawLine(physDev);
61 /***********************************************************************
64 BOOL PSDRV_Rectangle( PSDRV_PDEVICE *physDev, INT left, INT top, INT right, INT bottom )
68 TRACE("%d %d - %d %d\n", left, top, right, bottom);
74 LPtoDP( physDev->hdc, (POINT *)&rect, 2 );
76 PSDRV_WriteRectangle(physDev, rect.left, rect.top, rect.right - rect.left,
77 rect.bottom - rect.top );
78 PSDRV_Brush(physDev,0);
79 PSDRV_SetPen(physDev);
80 PSDRV_DrawLine(physDev);
85 /***********************************************************************
88 BOOL PSDRV_RoundRect( PSDRV_PDEVICE *physDev, INT left, INT top, INT right,
89 INT bottom, INT ell_width, INT ell_height )
95 rect[0].right = right;
96 rect[0].bottom = bottom;
99 rect[1].right = ell_width;
100 rect[1].bottom = ell_height;
101 LPtoDP( physDev->hdc, (POINT *)rect, 4 );
105 right = rect[0].right;
106 bottom = rect[0].bottom;
107 if (left > right) { INT tmp = left; left = right; right = tmp; }
108 if (top > bottom) { INT tmp = top; top = bottom; bottom = tmp; }
110 ell_width = rect[1].right - rect[1].left;
111 ell_height = rect[1].bottom - rect[1].top;
112 if (ell_width > right - left) ell_width = right - left;
113 if (ell_height > bottom - top) ell_height = bottom - top;
115 PSDRV_WriteMoveTo( physDev, left, top + ell_height/2 );
116 PSDRV_WriteArc( physDev, left + ell_width/2, top + ell_height/2, ell_width,
117 ell_height, 90.0, 180.0);
118 PSDRV_WriteLineTo( physDev, right - ell_width/2, top );
119 PSDRV_WriteArc( physDev, right - ell_width/2, top + ell_height/2, ell_width,
120 ell_height, 0.0, 90.0);
121 PSDRV_WriteLineTo( physDev, right, bottom - ell_height/2 );
122 PSDRV_WriteArc( physDev, right - ell_width/2, bottom - ell_height/2, ell_width,
123 ell_height, -90.0, 0.0);
124 PSDRV_WriteLineTo( physDev, right - ell_width/2, bottom);
125 PSDRV_WriteArc( physDev, left + ell_width/2, bottom - ell_height/2, ell_width,
126 ell_height, 180.0, -90.0);
127 PSDRV_WriteClosePath( physDev );
129 PSDRV_Brush(physDev,0);
130 PSDRV_SetPen(physDev);
131 PSDRV_DrawLine(physDev);
135 /***********************************************************************
138 * Does the work of Arc, Chord and Pie. lines is 0, 1 or 2 respectively.
140 static BOOL PSDRV_DrawArc( PSDRV_PDEVICE *physDev, INT left, INT top,
141 INT right, INT bottom, INT xstart, INT ystart,
142 INT xend, INT yend, int lines )
145 double start_angle, end_angle, ratio;
151 rect.bottom = bottom;
152 LPtoDP( physDev->hdc, (POINT *)&rect, 2 );
154 x = (rect.left + rect.right) / 2;
155 y = (rect.top + rect.bottom) / 2;
156 w = rect.right - rect.left;
157 h = rect.bottom - rect.top;
161 ratio = ((double)w)/h;
163 /* angle is the angle after the rectangle is transformed to a square and is
164 measured anticlockwise from the +ve x-axis */
166 start_angle = atan2((double)(y - ystart) * ratio, (double)(xstart - x));
167 end_angle = atan2((double)(y - yend) * ratio, (double)(xend - x));
169 start_angle *= 180.0 / PI;
170 end_angle *= 180.0 / PI;
172 if(lines == 2) /* pie */
173 PSDRV_WriteMoveTo(physDev, x, y);
175 PSDRV_WriteNewPath( physDev );
177 PSDRV_WriteArc(physDev, x, y, w, h, start_angle, end_angle);
178 if(lines == 1 || lines == 2) { /* chord or pie */
179 PSDRV_WriteClosePath(physDev);
180 PSDRV_Brush(physDev,0);
182 PSDRV_SetPen(physDev);
183 PSDRV_DrawLine(physDev);
188 /***********************************************************************
191 BOOL PSDRV_Arc( PSDRV_PDEVICE *physDev, INT left, INT top, INT right, INT bottom,
192 INT xstart, INT ystart, INT xend, INT yend )
194 return PSDRV_DrawArc( physDev, left, top, right, bottom, xstart, ystart, xend, yend, 0 );
197 /***********************************************************************
200 BOOL PSDRV_Chord( PSDRV_PDEVICE *physDev, INT left, INT top, INT right, INT bottom,
201 INT xstart, INT ystart, INT xend, INT yend )
203 return PSDRV_DrawArc( physDev, left, top, right, bottom, xstart, ystart, xend, yend, 1 );
207 /***********************************************************************
210 BOOL PSDRV_Pie( PSDRV_PDEVICE *physDev, INT left, INT top, INT right, INT bottom,
211 INT xstart, INT ystart, INT xend, INT yend )
213 return PSDRV_DrawArc( physDev, left, top, right, bottom, xstart, ystart, xend, yend, 2 );
217 /***********************************************************************
220 BOOL PSDRV_Ellipse( PSDRV_PDEVICE *physDev, INT left, INT top, INT right, INT bottom)
225 TRACE("%d %d - %d %d\n", left, top, right, bottom);
230 rect.bottom = bottom;
231 LPtoDP( physDev->hdc, (POINT *)&rect, 2 );
233 x = (rect.left + rect.right) / 2;
234 y = (rect.top + rect.bottom) / 2;
235 w = rect.right - rect.left;
236 h = rect.bottom - rect.top;
238 PSDRV_WriteNewPath(physDev);
239 PSDRV_WriteArc(physDev, x, y, w, h, 0.0, 360.0);
240 PSDRV_WriteClosePath(physDev);
241 PSDRV_Brush(physDev,0);
242 PSDRV_SetPen(physDev);
243 PSDRV_DrawLine(physDev);
248 /***********************************************************************
251 BOOL PSDRV_PolyPolyline( PSDRV_PDEVICE *physDev, const POINT* pts, const DWORD* counts,
254 DWORD polyline, line, total;
259 for (polyline = total = 0; polyline < polylines; polyline++) total += counts[polyline];
260 if (!(dev_pts = HeapAlloc( GetProcessHeap(), 0, total * sizeof(*dev_pts) ))) return FALSE;
261 memcpy( dev_pts, pts, total * sizeof(*dev_pts) );
262 LPtoDP( physDev->hdc, dev_pts, total );
265 for(polyline = 0; polyline < polylines; polyline++) {
266 PSDRV_WriteMoveTo(physDev, pt->x, pt->y);
268 for(line = 1; line < counts[polyline]; line++, pt++)
269 PSDRV_WriteLineTo(physDev, pt->x, pt->y);
271 HeapFree( GetProcessHeap(), 0, dev_pts );
272 PSDRV_SetPen(physDev);
273 PSDRV_DrawLine(physDev);
278 /***********************************************************************
281 BOOL PSDRV_Polyline( PSDRV_PDEVICE *physDev, const POINT* pt, INT count )
283 return PSDRV_PolyPolyline( physDev, pt, (LPDWORD) &count, 1 );
287 /***********************************************************************
290 BOOL PSDRV_PolyPolygon( PSDRV_PDEVICE *physDev, const POINT* pts, const INT* counts,
293 DWORD polygon, line, total;
298 for (polygon = total = 0; polygon < polygons; polygon++) total += counts[polygon];
299 if (!(dev_pts = HeapAlloc( GetProcessHeap(), 0, total * sizeof(*dev_pts) ))) return FALSE;
300 memcpy( dev_pts, pts, total * sizeof(*dev_pts) );
301 LPtoDP( physDev->hdc, dev_pts, total );
304 for(polygon = 0; polygon < polygons; polygon++) {
305 PSDRV_WriteMoveTo(physDev, pt->x, pt->y);
307 for(line = 1; line < counts[polygon]; line++, pt++)
308 PSDRV_WriteLineTo(physDev, pt->x, pt->y);
309 PSDRV_WriteClosePath(physDev);
311 HeapFree( GetProcessHeap(), 0, dev_pts );
313 if(GetPolyFillMode( physDev->hdc ) == ALTERNATE)
314 PSDRV_Brush(physDev, 1);
316 PSDRV_Brush(physDev, 0);
317 PSDRV_SetPen(physDev);
318 PSDRV_DrawLine(physDev);
323 /***********************************************************************
326 BOOL PSDRV_Polygon( PSDRV_PDEVICE *physDev, const POINT* pt, INT count )
328 return PSDRV_PolyPolygon( physDev, pt, &count, 1 );
332 /***********************************************************************
335 COLORREF PSDRV_SetPixel( PSDRV_PDEVICE *physDev, INT x, INT y, COLORREF color )
342 LPtoDP( physDev->hdc, &pt, 1 );
344 PSDRV_WriteRectangle( physDev, pt.x, pt.y, 0, 0 );
345 PSDRV_CreateColor( physDev, &pscolor, color );
346 PSDRV_WriteSetColor( physDev, &pscolor );
347 PSDRV_WriteFill( physDev );
352 /***********************************************************************
355 VOID PSDRV_DrawLine( PSDRV_PDEVICE *physDev )
357 if (physDev->pen.style == PS_NULL)
358 PSDRV_WriteNewPath(physDev);
360 PSDRV_WriteStroke(physDev);