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
;
152 rect
.bottom
= bottom
;
153 LPtoDP( physDev
->hdc
, (POINT
*)&rect
, 2 );
158 LPtoDP( physDev
->hdc
, &start
, 1 );
159 LPtoDP( physDev
->hdc
, &end
, 1 );
161 x
= (rect
.left
+ rect
.right
) / 2;
162 y
= (rect
.top
+ rect
.bottom
) / 2;
163 w
= rect
.right
- rect
.left
;
164 h
= rect
.bottom
- rect
.top
;
168 ratio
= ((double)w
)/h
;
170 /* angle is the angle after the rectangle is transformed to a square and is
171 measured anticlockwise from the +ve x-axis */
173 start_angle
= atan2((double)(y
- start
.y
) * ratio
, (double)(start
.x
- x
));
174 end_angle
= atan2((double)(y
- end
.y
) * ratio
, (double)(end
.x
- x
));
176 start_angle
*= 180.0 / PI
;
177 end_angle
*= 180.0 / PI
;
179 if(lines
== 2) /* pie */
180 PSDRV_WriteMoveTo(physDev
, x
, y
);
182 PSDRV_WriteNewPath( physDev
);
184 PSDRV_WriteArc(physDev
, x
, y
, w
, h
, start_angle
, end_angle
);
185 if(lines
== 1 || lines
== 2) { /* chord or pie */
186 PSDRV_WriteClosePath(physDev
);
187 PSDRV_Brush(physDev
,0);
189 PSDRV_SetPen(physDev
);
190 PSDRV_DrawLine(physDev
);
195 /***********************************************************************
198 BOOL
PSDRV_Arc( PSDRV_PDEVICE
*physDev
, INT left
, INT top
, INT right
, INT bottom
,
199 INT xstart
, INT ystart
, INT xend
, INT yend
)
201 return PSDRV_DrawArc( physDev
, left
, top
, right
, bottom
, xstart
, ystart
, xend
, yend
, 0 );
204 /***********************************************************************
207 BOOL
PSDRV_Chord( PSDRV_PDEVICE
*physDev
, INT left
, INT top
, INT right
, INT bottom
,
208 INT xstart
, INT ystart
, INT xend
, INT yend
)
210 return PSDRV_DrawArc( physDev
, left
, top
, right
, bottom
, xstart
, ystart
, xend
, yend
, 1 );
214 /***********************************************************************
217 BOOL
PSDRV_Pie( PSDRV_PDEVICE
*physDev
, INT left
, INT top
, INT right
, INT bottom
,
218 INT xstart
, INT ystart
, INT xend
, INT yend
)
220 return PSDRV_DrawArc( physDev
, left
, top
, right
, bottom
, xstart
, ystart
, xend
, yend
, 2 );
224 /***********************************************************************
227 BOOL
PSDRV_Ellipse( PSDRV_PDEVICE
*physDev
, INT left
, INT top
, INT right
, INT bottom
)
232 TRACE("%d %d - %d %d\n", left
, top
, right
, bottom
);
237 rect
.bottom
= bottom
;
238 LPtoDP( physDev
->hdc
, (POINT
*)&rect
, 2 );
240 x
= (rect
.left
+ rect
.right
) / 2;
241 y
= (rect
.top
+ rect
.bottom
) / 2;
242 w
= rect
.right
- rect
.left
;
243 h
= rect
.bottom
- rect
.top
;
245 PSDRV_WriteNewPath(physDev
);
246 PSDRV_WriteArc(physDev
, x
, y
, w
, h
, 0.0, 360.0);
247 PSDRV_WriteClosePath(physDev
);
248 PSDRV_Brush(physDev
,0);
249 PSDRV_SetPen(physDev
);
250 PSDRV_DrawLine(physDev
);
255 /***********************************************************************
258 BOOL
PSDRV_PolyPolyline( PSDRV_PDEVICE
*physDev
, const POINT
* pts
, const DWORD
* counts
,
261 DWORD polyline
, line
, total
;
266 for (polyline
= total
= 0; polyline
< polylines
; polyline
++) total
+= counts
[polyline
];
267 if (!(dev_pts
= HeapAlloc( GetProcessHeap(), 0, total
* sizeof(*dev_pts
) ))) return FALSE
;
268 memcpy( dev_pts
, pts
, total
* sizeof(*dev_pts
) );
269 LPtoDP( physDev
->hdc
, dev_pts
, total
);
272 for(polyline
= 0; polyline
< polylines
; polyline
++) {
273 PSDRV_WriteMoveTo(physDev
, pt
->x
, pt
->y
);
275 for(line
= 1; line
< counts
[polyline
]; line
++, pt
++)
276 PSDRV_WriteLineTo(physDev
, pt
->x
, pt
->y
);
278 HeapFree( GetProcessHeap(), 0, dev_pts
);
279 PSDRV_SetPen(physDev
);
280 PSDRV_DrawLine(physDev
);
285 /***********************************************************************
288 BOOL
PSDRV_Polyline( PSDRV_PDEVICE
*physDev
, const POINT
* pt
, INT count
)
290 return PSDRV_PolyPolyline( physDev
, pt
, (LPDWORD
) &count
, 1 );
294 /***********************************************************************
297 BOOL
PSDRV_PolyPolygon( PSDRV_PDEVICE
*physDev
, const POINT
* pts
, const INT
* counts
,
300 DWORD polygon
, line
, total
;
305 for (polygon
= total
= 0; polygon
< polygons
; polygon
++) total
+= counts
[polygon
];
306 if (!(dev_pts
= HeapAlloc( GetProcessHeap(), 0, total
* sizeof(*dev_pts
) ))) return FALSE
;
307 memcpy( dev_pts
, pts
, total
* sizeof(*dev_pts
) );
308 LPtoDP( physDev
->hdc
, dev_pts
, total
);
311 for(polygon
= 0; polygon
< polygons
; polygon
++) {
312 PSDRV_WriteMoveTo(physDev
, pt
->x
, pt
->y
);
314 for(line
= 1; line
< counts
[polygon
]; line
++, pt
++)
315 PSDRV_WriteLineTo(physDev
, pt
->x
, pt
->y
);
316 PSDRV_WriteClosePath(physDev
);
318 HeapFree( GetProcessHeap(), 0, dev_pts
);
320 if(GetPolyFillMode( physDev
->hdc
) == ALTERNATE
)
321 PSDRV_Brush(physDev
, 1);
323 PSDRV_Brush(physDev
, 0);
324 PSDRV_SetPen(physDev
);
325 PSDRV_DrawLine(physDev
);
330 /***********************************************************************
333 BOOL
PSDRV_Polygon( PSDRV_PDEVICE
*physDev
, const POINT
* pt
, INT count
)
335 return PSDRV_PolyPolygon( physDev
, pt
, &count
, 1 );
339 /***********************************************************************
342 COLORREF
PSDRV_SetPixel( PSDRV_PDEVICE
*physDev
, INT x
, INT y
, COLORREF color
)
349 LPtoDP( physDev
->hdc
, &pt
, 1 );
351 PSDRV_WriteRectangle( physDev
, pt
.x
, pt
.y
, 0, 0 );
352 PSDRV_CreateColor( physDev
, &pscolor
, color
);
353 PSDRV_WriteSetColor( physDev
, &pscolor
);
354 PSDRV_WriteFill( physDev
);
359 /***********************************************************************
362 VOID
PSDRV_DrawLine( PSDRV_PDEVICE
*physDev
)
364 if(physDev
->pathdepth
)
367 if (physDev
->pen
.style
== PS_NULL
)
368 PSDRV_WriteNewPath(physDev
);
370 PSDRV_WriteStroke(physDev
);