]>
git.ipfire.org Git - thirdparty/cups.git/blob - filter/hpgl-polygon.c
2 * "$Id: hpgl-polygon.c 6649 2007-07-11 21:46:42Z mike $"
4 * HP-GL/2 polygon routines for the Common UNIX Printing System (CUPS).
6 * Copyright 2007 by Apple Inc.
7 * Copyright 1993-2005 by Easy Software Products.
9 * These coded instructions, statements, and computer programs are the
10 * property of Apple Inc. and are protected by Federal copyright
11 * law. Distribution and use rights are outlined in the file "LICENSE.txt"
12 * which should have been included with this file. If this file is
13 * file is missing or damaged, see the license at "http://www.cups.org/".
15 * This file is subject to the Apple OS-Developed Software exception.
19 * EA_edge_rect_absolute() - Draw a rectangle.
20 * EP_edge_polygon() - Stroke the edges of a polygon.
21 * ER_edge_rect_relative() - Draw a rectangle relative to the current
22 * EW_edge_wedge() - Draw a pie wedge.
23 * FP_fill_polygon() - Fill a polygon.
24 * PM_polygon_mode() - Set the polygon drawing mode.
25 * RA_fill_rect_absolute() - Fill a rectangle.
26 * RR_fill_rect_relative() - Fill a rectangle relative to the current
27 * WG_fill_wedge() - Fill a pie wedge.
31 * Include necessary headers...
38 * 'EA_edge_rect_absolute()' - Draw a rectangle.
42 EA_edge_rect_absolute(int num_params
, /* I - Number of parameters */
43 param_t
*params
) /* I - Parameters */
45 float x
, y
; /* Transformed coordinates */
51 x
= Transform
[0][0] * params
[0].value
.number
+
52 Transform
[0][1] * params
[1].value
.number
+
54 y
= Transform
[1][0] * params
[0].value
.number
+
55 Transform
[1][1] * params
[1].value
.number
+
63 Outputf("%.3f %.3f MO\n", PenPosition
[0], PenPosition
[1]);
64 Outputf("%.3f %.3f LI\n", PenPosition
[0], y
);
65 Outputf("%.3f %.3f LI\n", x
, y
);
66 Outputf("%.3f %.3f LI\n", x
, PenPosition
[1]);
75 * 'EP_edge_polygon()' - Stroke the edges of a polygon.
79 EP_edge_polygon(int num_params
, /* I - Number of parameters */
80 param_t
*params
) /* I - Parameters */
90 * 'ER_edge_rect_relative()' - Draw a rectangle relative to the current
95 ER_edge_rect_relative(int num_params
, /* I - Number of parameters */
96 param_t
*params
) /* I - Parameters */
98 float x
, y
; /* Transformed coordinates */
104 x
= Transform
[0][0] * params
[0].value
.number
+
105 Transform
[0][1] * params
[1].value
.number
+
107 y
= Transform
[1][0] * params
[0].value
.number
+
108 Transform
[1][1] * params
[1].value
.number
+
116 Outputf("%.3f %.3f MO\n", PenPosition
[0], PenPosition
[1]);
117 Outputf("%.3f %.3f LI\n", PenPosition
[0], y
);
118 Outputf("%.3f %.3f LI\n", x
, y
);
119 Outputf("%.3f %.3f LI\n", x
, PenPosition
[1]);
128 * 'EW_edge_wedge()' - Draw a pie wedge.
132 EW_edge_wedge(int num_params
, /* I - Number of parameters */
133 param_t
*params
) /* I - Parameters */
135 float x
, y
; /* Transformed coordinates */
136 float start
, end
, /* Start and end of arc */
137 theta
, /* Current angle */
138 dt
, /* Step between points */
139 radius
; /* Radius of arc */
145 radius
= params
[0].value
.number
;
146 start
= params
[1].value
.number
;
147 end
= start
+ params
[2].value
.number
;
150 dt
= (float)fabs(params
[3].value
.number
);
159 Outputf("%.3f %.3f MO\n", PenPosition
[0], PenPosition
[1]);
162 for (theta
= start
+ dt
; theta
< end
; theta
+= dt
)
164 x
= (float)(PenPosition
[0] +
165 radius
* cos(M_PI
* theta
/ 180.0) * Transform
[0][0] +
166 radius
* sin(M_PI
* theta
/ 180.0) * Transform
[0][1]);
167 y
= (float)(PenPosition
[1] +
168 radius
* cos(M_PI
* theta
/ 180.0) * Transform
[1][0] +
169 radius
* sin(M_PI
* theta
/ 180.0) * Transform
[1][1]);
171 Outputf("%.3f %.3f LI\n", x
, y
);
174 for (theta
= start
- dt
; theta
> end
; theta
-= dt
)
176 x
= (float)(PenPosition
[0] +
177 radius
* cos(M_PI
* theta
/ 180.0) * Transform
[0][0] +
178 radius
* sin(M_PI
* theta
/ 180.0) * Transform
[0][1]);
179 y
= (float)(PenPosition
[1] +
180 radius
* cos(M_PI
* theta
/ 180.0) * Transform
[1][0] +
181 radius
* sin(M_PI
* theta
/ 180.0) * Transform
[1][1]);
183 Outputf("%.3f %.3f LI\n", x
, y
);
186 x
= (float)(PenPosition
[0] +
187 radius
* cos(M_PI
* end
/ 180.0) * Transform
[0][0] +
188 radius
* sin(M_PI
* end
/ 180.0) * Transform
[0][1]);
189 y
= (float)(PenPosition
[1] +
190 radius
* cos(M_PI
* end
/ 180.0) * Transform
[1][0] +
191 radius
* sin(M_PI
* end
/ 180.0) * Transform
[1][1]);
192 Outputf("%.3f %.3f LI\n", x
, y
);
201 * 'FP_fill_polygon()' - Fill a polygon.
205 FP_fill_polygon(int num_params
, /* I - Number of parameters */
206 param_t
*params
) /* I - Parameters */
216 * 'PM_polygon_mode()' - Set the polygon drawing mode.
220 PM_polygon_mode(int num_params
, /* I - Number of parameters */
221 param_t
*params
) /* I - Parameters */
223 if (num_params
== 0 ||
224 params
[0].value
.number
== 0)
230 else if (params
[0].value
.number
== 2)
236 * 'RA_fill_rect_absolute()' - Fill a rectangle.
240 RA_fill_rect_absolute(int num_params
, /* I - Number of parameters */
241 param_t
*params
) /* I - Parameters */
243 float x
, y
; /* Transformed coordinates */
249 x
= Transform
[0][0] * params
[0].value
.number
+
250 Transform
[0][1] * params
[1].value
.number
+
252 y
= Transform
[1][0] * params
[0].value
.number
+
253 Transform
[1][1] * params
[1].value
.number
+
261 Outputf("%.3f %.3f MO\n", PenPosition
[0], PenPosition
[1]);
262 Outputf("%.3f %.3f LI\n", PenPosition
[0], y
);
263 Outputf("%.3f %.3f LI\n", x
, y
);
264 Outputf("%.3f %.3f LI\n", x
, PenPosition
[1]);
273 * 'RR_fill_rect_relative()' - Fill a rectangle relative to the current
278 RR_fill_rect_relative(int num_params
, /* I - Number of parameters */
279 param_t
*params
) /* I - Parameters */
281 float x
, y
; /* Transformed coordinates */
287 x
= Transform
[0][0] * params
[0].value
.number
+
288 Transform
[0][1] * params
[1].value
.number
+
290 y
= Transform
[1][0] * params
[0].value
.number
+
291 Transform
[1][1] * params
[1].value
.number
+
299 Outputf("%.3f %.3f MO\n", PenPosition
[0], PenPosition
[1]);
300 Outputf("%.3f %.3f LI\n", PenPosition
[0], y
);
301 Outputf("%.3f %.3f LI\n", x
, y
);
302 Outputf("%.3f %.3f LI\n", x
, PenPosition
[1]);
311 * 'WG_fill_wedge()' - Fill a pie wedge.
315 WG_fill_wedge(int num_params
, /* I - Number of parameters */
316 param_t
*params
) /* I - Parameters */
318 float x
, y
; /* Transformed coordinates */
319 float start
, end
, /* Start and end angles */
320 theta
, /* Current angle */
321 dt
, /* Step between points */
322 radius
; /* Radius of arc */
328 radius
= params
[0].value
.number
;
329 start
= params
[1].value
.number
;
330 end
= start
+ params
[2].value
.number
;
333 dt
= (float)fabs(params
[3].value
.number
);
342 Outputf("%.3f %.3f MO\n", PenPosition
[0], PenPosition
[1]);
345 for (theta
= start
+ dt
; theta
< end
; theta
+= dt
)
347 x
= (float)(PenPosition
[0] +
348 radius
* cos(M_PI
* theta
/ 180.0) * Transform
[0][0] +
349 radius
* sin(M_PI
* theta
/ 180.0) * Transform
[0][1]);
350 y
= (float)(PenPosition
[1] +
351 radius
* cos(M_PI
* theta
/ 180.0) * Transform
[1][0] +
352 radius
* sin(M_PI
* theta
/ 180.0) * Transform
[1][1]);
354 Outputf("%.3f %.3f LI\n", x
, y
);
357 for (theta
= start
- dt
; theta
> end
; theta
-= dt
)
359 x
= (float)(PenPosition
[0] +
360 radius
* cos(M_PI
* theta
/ 180.0) * Transform
[0][0] +
361 radius
* sin(M_PI
* theta
/ 180.0) * Transform
[0][1]);
362 y
= (float)(PenPosition
[1] +
363 radius
* cos(M_PI
* theta
/ 180.0) * Transform
[1][0] +
364 radius
* sin(M_PI
* theta
/ 180.0) * Transform
[1][1]);
366 Outputf("%.3f %.3f LI\n", x
, y
);
369 x
= (float)(PenPosition
[0] +
370 radius
* cos(M_PI
* end
/ 180.0) * Transform
[0][0] +
371 radius
* sin(M_PI
* end
/ 180.0) * Transform
[0][1]);
372 y
= (float)(PenPosition
[1] +
373 radius
* cos(M_PI
* end
/ 180.0) * Transform
[1][0] +
374 radius
* sin(M_PI
* end
/ 180.0) * Transform
[1][1]);
375 Outputf("%.3f %.3f LI\n", x
, y
);
384 * End of "$Id: hpgl-polygon.c 6649 2007-07-11 21:46:42Z mike $".