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(DC
*dc
, INT x
, INT y
)
43 TRACE("%d %d\n", x
, y
);
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
));
56 /***********************************************************************
59 BOOL
PSDRV_Rectangle( DC
*dc
, INT left
, INT top
, INT right
,
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
),
78 /***********************************************************************
81 BOOL
PSDRV_RoundRect( DC
*dc
, INT left
, INT top
, INT right
,
82 INT bottom
, INT ell_width
, INT ell_height
)
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
);
91 if( left
> right
) { INT tmp
= left
; left
= right
; right
= tmp
; }
92 if( top
> bottom
) { INT tmp
= top
; top
= bottom
; bottom
= tmp
; }
94 if(ell_width
> right
- left
) ell_width
= right
- left
;
95 if(ell_height
> bottom
- top
) ell_height
= bottom
- top
;
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
);
117 /***********************************************************************
120 * Does the work of Arc, Chord and Pie. lines is 0, 1 or 2 respectively.
122 static BOOL
PSDRV_DrawArc( DC
*dc
, INT left
, INT top
,
123 INT right
, INT bottom
,
124 INT xstart
, INT ystart
,
129 double start_angle
, end_angle
, ratio
;
131 x
= XLPTODP(dc
, (left
+ right
)/2);
132 y
= YLPTODP(dc
, (top
+ bottom
)/2);
134 w
= XLSTODS(dc
, (right
- left
));
135 h
= YLSTODS(dc
, (bottom
- top
));
139 ratio
= ((double)w
)/h
;
141 /* angle is the angle after the rectangle is transformed to a square and is
142 measured anticlockwise from the +ve x-axis */
144 start_angle
= atan2((double)(y
- ystart
) * ratio
, (double)(xstart
- x
));
145 end_angle
= atan2((double)(y
- yend
) * ratio
, (double)(xend
- x
));
147 start_angle
*= 180.0 / PI
;
148 end_angle
*= 180.0 / PI
;
150 if(lines
== 2) /* pie */
151 PSDRV_WriteMoveTo(dc
, x
, y
);
153 PSDRV_WriteNewPath( dc
);
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
);
166 /***********************************************************************
169 BOOL
PSDRV_Arc( DC
*dc
, INT left
, INT top
, INT right
, INT bottom
,
170 INT xstart
, INT ystart
, INT xend
, INT yend
)
172 return PSDRV_DrawArc( dc
, left
, top
, right
, bottom
, xstart
, ystart
,
176 /***********************************************************************
179 BOOL
PSDRV_Chord( DC
*dc
, INT left
, INT top
, INT right
, INT bottom
,
180 INT xstart
, INT ystart
, INT xend
, INT yend
)
182 return PSDRV_DrawArc( dc
, left
, top
, right
, bottom
, xstart
, ystart
,
187 /***********************************************************************
190 BOOL
PSDRV_Pie( DC
*dc
, INT left
, INT top
, INT right
, INT bottom
,
191 INT xstart
, INT ystart
, INT xend
, INT yend
)
193 return PSDRV_DrawArc( dc
, left
, top
, right
, bottom
, xstart
, ystart
,
198 /***********************************************************************
201 BOOL
PSDRV_Ellipse( DC
*dc
, INT left
, INT top
, INT right
, INT bottom
)
205 TRACE("%d %d - %d %d\n", left
, top
, right
, bottom
);
207 x
= XLPTODP(dc
, (left
+ right
)/2);
208 y
= YLPTODP(dc
, (top
+ bottom
)/2);
210 w
= XLSTODS(dc
, (right
- left
));
211 h
= YLSTODS(dc
, (bottom
- top
));
213 PSDRV_WriteNewPath(dc
);
214 PSDRV_WriteArc(dc
, x
, y
, w
, h
, 0.0, 360.0);
215 PSDRV_WriteClosePath(dc
);
223 /***********************************************************************
226 BOOL
PSDRV_PolyPolyline( DC
*dc
, const POINT
* pts
, const DWORD
* counts
,
229 DWORD polyline
, line
;
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
));
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
));
248 /***********************************************************************
251 BOOL
PSDRV_Polyline( DC
*dc
, const POINT
* pt
, INT count
)
253 return PSDRV_PolyPolyline( dc
, pt
, (LPDWORD
) &count
, 1 );
257 /***********************************************************************
260 BOOL
PSDRV_PolyPolygon( DC
*dc
, const POINT
* pts
, const INT
* counts
,
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
));
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
));
275 PSDRV_WriteClosePath(dc
);
278 if(dc
->polyFillMode
== ALTERNATE
)
288 /***********************************************************************
291 BOOL
PSDRV_Polygon( DC
*dc
, const POINT
* pt
, INT count
)
293 return PSDRV_PolyPolygon( dc
, pt
, &count
, 1 );
297 /***********************************************************************
300 COLORREF
PSDRV_SetPixel( DC
*dc
, INT x
, INT y
, COLORREF color
)
302 PSDRV_PDEVICE
*physDev
= (PSDRV_PDEVICE
*)dc
->physDev
;
305 x
= INTERNAL_XWPTODP(dc
, x
, y
);
306 y
= INTERNAL_YWPTODP(dc
, x
, y
);
308 PSDRV_WriteRectangle( dc
, x
, y
, 0, 0 );
309 PSDRV_CreateColor( physDev
, &pscolor
, color
);
310 PSDRV_WriteSetColor( dc
, &pscolor
);
311 PSDRV_WriteFill( dc
);
316 /***********************************************************************
319 VOID
PSDRV_DrawLine( DC
*dc
)
321 PSDRV_PDEVICE
*physDev
= (PSDRV_PDEVICE
*)dc
->physDev
;
323 if (physDev
->pen
.style
== PS_NULL
)
324 PSDRV_WriteNewPath(dc
);
326 PSDRV_WriteStroke(dc
);