]>
git.ipfire.org Git - thirdparty/cups.git/blob - filter/hpgl-polygon.c
2 * "$Id: hpgl-polygon.c 4494 2005-02-18 02:18:11Z mike $"
4 * HP-GL/2 polygon routines for the Common UNIX Printing System (CUPS).
6 * Copyright 1993-2005 by Easy Software Products.
8 * These coded instructions, statements, and computer programs are the
9 * property of Easy Software Products and are protected by Federal
10 * copyright law. Distribution and use rights are outlined in the file
11 * "LICENSE.txt" which should have been included with this file. If this
12 * file is missing or damaged please contact Easy Software Products
15 * Attn: CUPS Licensing Information
16 * Easy Software Products
17 * 44141 Airport View Drive, Suite 204
18 * Hollywood, Maryland 20636 USA
20 * Voice: (301) 373-9600
21 * EMail: cups-info@cups.org
22 * WWW: http://www.cups.org
24 * This file is subject to the Apple OS-Developed Software exception.
28 * EA_edge_rect_absolute() - Draw a rectangle.
29 * EP_edge_polygon() - Stroke the edges of a polygon.
30 * ER_edge_rect_relative() - Draw a rectangle relative to the current
31 * EW_edge_wedge() - Draw a pie wedge.
32 * FP_fill_polygon() - Fill a polygon.
33 * PM_polygon_mode() - Set the polygon drawing mode.
34 * RA_fill_rect_absolute() - Fill a rectangle.
35 * RR_fill_rect_relative() - Fill a rectangle relative to the current
36 * WG_fill_wedge() - Fill a pie wedge.
40 * Include necessary headers...
47 * 'EA_edge_rect_absolute()' - Draw a rectangle.
51 EA_edge_rect_absolute(int num_params
, /* I - Number of parameters */
52 param_t
*params
) /* I - Parameters */
54 float x
, y
; /* Transformed coordinates */
60 x
= Transform
[0][0] * params
[0].value
.number
+
61 Transform
[0][1] * params
[1].value
.number
+
63 y
= Transform
[1][0] * params
[0].value
.number
+
64 Transform
[1][1] * params
[1].value
.number
+
72 Outputf("%.3f %.3f MO\n", PenPosition
[0], PenPosition
[1]);
73 Outputf("%.3f %.3f LI\n", PenPosition
[0], y
);
74 Outputf("%.3f %.3f LI\n", x
, y
);
75 Outputf("%.3f %.3f LI\n", x
, PenPosition
[1]);
84 * 'EP_edge_polygon()' - Stroke the edges of a polygon.
88 EP_edge_polygon(int num_params
, /* I - Number of parameters */
89 param_t
*params
) /* I - Parameters */
99 * 'ER_edge_rect_relative()' - Draw a rectangle relative to the current
104 ER_edge_rect_relative(int num_params
, /* I - Number of parameters */
105 param_t
*params
) /* I - Parameters */
107 float x
, y
; /* Transformed coordinates */
113 x
= Transform
[0][0] * params
[0].value
.number
+
114 Transform
[0][1] * params
[1].value
.number
+
116 y
= Transform
[1][0] * params
[0].value
.number
+
117 Transform
[1][1] * params
[1].value
.number
+
125 Outputf("%.3f %.3f MO\n", PenPosition
[0], PenPosition
[1]);
126 Outputf("%.3f %.3f LI\n", PenPosition
[0], y
);
127 Outputf("%.3f %.3f LI\n", x
, y
);
128 Outputf("%.3f %.3f LI\n", x
, PenPosition
[1]);
137 * 'EW_edge_wedge()' - Draw a pie wedge.
141 EW_edge_wedge(int num_params
, /* I - Number of parameters */
142 param_t
*params
) /* I - Parameters */
144 float x
, y
; /* Transformed coordinates */
145 float start
, end
, /* Start and end of arc */
146 theta
, /* Current angle */
147 dt
, /* Step between points */
148 radius
; /* Radius of arc */
154 radius
= params
[0].value
.number
;
155 start
= params
[1].value
.number
;
156 end
= start
+ params
[2].value
.number
;
159 dt
= (float)fabs(params
[3].value
.number
);
168 Outputf("%.3f %.3f MO\n", PenPosition
[0], PenPosition
[1]);
171 for (theta
= start
+ dt
; theta
< end
; theta
+= dt
)
173 x
= (float)(PenPosition
[0] +
174 radius
* cos(M_PI
* theta
/ 180.0) * Transform
[0][0] +
175 radius
* sin(M_PI
* theta
/ 180.0) * Transform
[0][1]);
176 y
= (float)(PenPosition
[1] +
177 radius
* cos(M_PI
* theta
/ 180.0) * Transform
[1][0] +
178 radius
* sin(M_PI
* theta
/ 180.0) * Transform
[1][1]);
180 Outputf("%.3f %.3f LI\n", x
, y
);
183 for (theta
= start
- dt
; theta
> end
; theta
-= dt
)
185 x
= (float)(PenPosition
[0] +
186 radius
* cos(M_PI
* theta
/ 180.0) * Transform
[0][0] +
187 radius
* sin(M_PI
* theta
/ 180.0) * Transform
[0][1]);
188 y
= (float)(PenPosition
[1] +
189 radius
* cos(M_PI
* theta
/ 180.0) * Transform
[1][0] +
190 radius
* sin(M_PI
* theta
/ 180.0) * Transform
[1][1]);
192 Outputf("%.3f %.3f LI\n", x
, y
);
195 x
= (float)(PenPosition
[0] +
196 radius
* cos(M_PI
* end
/ 180.0) * Transform
[0][0] +
197 radius
* sin(M_PI
* end
/ 180.0) * Transform
[0][1]);
198 y
= (float)(PenPosition
[1] +
199 radius
* cos(M_PI
* end
/ 180.0) * Transform
[1][0] +
200 radius
* sin(M_PI
* end
/ 180.0) * Transform
[1][1]);
201 Outputf("%.3f %.3f LI\n", x
, y
);
210 * 'FP_fill_polygon()' - Fill a polygon.
214 FP_fill_polygon(int num_params
, /* I - Number of parameters */
215 param_t
*params
) /* I - Parameters */
225 * 'PM_polygon_mode()' - Set the polygon drawing mode.
229 PM_polygon_mode(int num_params
, /* I - Number of parameters */
230 param_t
*params
) /* I - Parameters */
232 if (num_params
== 0 ||
233 params
[0].value
.number
== 0)
239 else if (params
[0].value
.number
== 2)
245 * 'RA_fill_rect_absolute()' - Fill a rectangle.
249 RA_fill_rect_absolute(int num_params
, /* I - Number of parameters */
250 param_t
*params
) /* I - Parameters */
252 float x
, y
; /* Transformed coordinates */
258 x
= Transform
[0][0] * params
[0].value
.number
+
259 Transform
[0][1] * params
[1].value
.number
+
261 y
= Transform
[1][0] * params
[0].value
.number
+
262 Transform
[1][1] * params
[1].value
.number
+
270 Outputf("%.3f %.3f MO\n", PenPosition
[0], PenPosition
[1]);
271 Outputf("%.3f %.3f LI\n", PenPosition
[0], y
);
272 Outputf("%.3f %.3f LI\n", x
, y
);
273 Outputf("%.3f %.3f LI\n", x
, PenPosition
[1]);
282 * 'RR_fill_rect_relative()' - Fill a rectangle relative to the current
287 RR_fill_rect_relative(int num_params
, /* I - Number of parameters */
288 param_t
*params
) /* I - Parameters */
290 float x
, y
; /* Transformed coordinates */
296 x
= Transform
[0][0] * params
[0].value
.number
+
297 Transform
[0][1] * params
[1].value
.number
+
299 y
= Transform
[1][0] * params
[0].value
.number
+
300 Transform
[1][1] * params
[1].value
.number
+
308 Outputf("%.3f %.3f MO\n", PenPosition
[0], PenPosition
[1]);
309 Outputf("%.3f %.3f LI\n", PenPosition
[0], y
);
310 Outputf("%.3f %.3f LI\n", x
, y
);
311 Outputf("%.3f %.3f LI\n", x
, PenPosition
[1]);
320 * 'WG_fill_wedge()' - Fill a pie wedge.
324 WG_fill_wedge(int num_params
, /* I - Number of parameters */
325 param_t
*params
) /* I - Parameters */
327 float x
, y
; /* Transformed coordinates */
328 float start
, end
, /* Start and end angles */
329 theta
, /* Current angle */
330 dt
, /* Step between points */
331 radius
; /* Radius of arc */
337 radius
= params
[0].value
.number
;
338 start
= params
[1].value
.number
;
339 end
= start
+ params
[2].value
.number
;
342 dt
= (float)fabs(params
[3].value
.number
);
351 Outputf("%.3f %.3f MO\n", PenPosition
[0], PenPosition
[1]);
354 for (theta
= start
+ dt
; theta
< end
; theta
+= dt
)
356 x
= (float)(PenPosition
[0] +
357 radius
* cos(M_PI
* theta
/ 180.0) * Transform
[0][0] +
358 radius
* sin(M_PI
* theta
/ 180.0) * Transform
[0][1]);
359 y
= (float)(PenPosition
[1] +
360 radius
* cos(M_PI
* theta
/ 180.0) * Transform
[1][0] +
361 radius
* sin(M_PI
* theta
/ 180.0) * Transform
[1][1]);
363 Outputf("%.3f %.3f LI\n", x
, y
);
366 for (theta
= start
- dt
; theta
> end
; theta
-= dt
)
368 x
= (float)(PenPosition
[0] +
369 radius
* cos(M_PI
* theta
/ 180.0) * Transform
[0][0] +
370 radius
* sin(M_PI
* theta
/ 180.0) * Transform
[0][1]);
371 y
= (float)(PenPosition
[1] +
372 radius
* cos(M_PI
* theta
/ 180.0) * Transform
[1][0] +
373 radius
* sin(M_PI
* theta
/ 180.0) * Transform
[1][1]);
375 Outputf("%.3f %.3f LI\n", x
, y
);
378 x
= (float)(PenPosition
[0] +
379 radius
* cos(M_PI
* end
/ 180.0) * Transform
[0][0] +
380 radius
* sin(M_PI
* end
/ 180.0) * Transform
[0][1]);
381 y
= (float)(PenPosition
[1] +
382 radius
* cos(M_PI
* end
/ 180.0) * Transform
[1][0] +
383 radius
* sin(M_PI
* end
/ 180.0) * Transform
[1][1]);
384 Outputf("%.3f %.3f LI\n", x
, y
);
393 * End of "$Id: hpgl-polygon.c 4494 2005-02-18 02:18:11Z mike $".