]> git.ipfire.org Git - thirdparty/cups.git/blob - filter/hpgl-polygon.c
Copyright update.
[thirdparty/cups.git] / filter / hpgl-polygon.c
1 /*
2 * "$Id: hpgl-polygon.c,v 1.9.2.3 2003/01/07 18:26:52 mike Exp $"
3 *
4 * HP-GL/2 polygon routines for the Common UNIX Printing System (CUPS).
5 *
6 * Copyright 1993-2003 by Easy Software Products.
7 *
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
13 * at:
14 *
15 * Attn: CUPS Licensing Information
16 * Easy Software Products
17 * 44141 Airport View Drive, Suite 204
18 * Hollywood, Maryland 20636-3111 USA
19 *
20 * Voice: (301) 373-9603
21 * EMail: cups-info@cups.org
22 * WWW: http://www.cups.org
23 *
24 * This file is subject to the Apple OS-Developed Software exception.
25 *
26 * Contents:
27 *
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.
37 */
38
39 /*
40 * Include necessary headers...
41 */
42
43 #include "hpgltops.h"
44
45
46 /*
47 * 'EA_edge_rect_absolute()' - Draw a rectangle.
48 */
49
50 void
51 EA_edge_rect_absolute(int num_params, /* I - Number of parameters */
52 param_t *params) /* I - Parameters */
53 {
54 float x, y; /* Transformed coordinates */
55
56
57 if (num_params < 2)
58 return;
59
60 x = Transform[0][0] * params[0].value.number +
61 Transform[0][1] * params[1].value.number +
62 Transform[0][2];
63 y = Transform[1][0] * params[0].value.number +
64 Transform[1][1] * params[1].value.number +
65 Transform[1][2];
66
67 if (!PolygonMode)
68 Outputf("MP\n");
69
70 Outputf("%.3f %.3f MO\n", PenPosition[0], PenPosition[1]);
71 Outputf("%.3f %.3f LI\n", PenPosition[0], y);
72 Outputf("%.3f %.3f LI\n", x, y);
73 Outputf("%.3f %.3f LI\n", x, PenPosition[1]);
74
75 Outputf("CP\n");
76 if (!PolygonMode)
77 Outputf("ST\n");
78 }
79
80
81 /*
82 * 'EP_edge_polygon()' - Stroke the edges of a polygon.
83 */
84
85 void
86 EP_edge_polygon(int num_params, /* I - Number of parameters */
87 param_t *params) /* I - Parameters */
88 {
89 (void)num_params;
90 (void)params;
91
92 Outputf("ST\n");
93 }
94
95
96 /*
97 * 'ER_edge_rect_relative()' - Draw a rectangle relative to the current
98 * pen position.
99 */
100
101 void
102 ER_edge_rect_relative(int num_params, /* I - Number of parameters */
103 param_t *params) /* I - Parameters */
104 {
105 float x, y; /* Transformed coordinates */
106
107
108 if (num_params < 2)
109 return;
110
111 x = Transform[0][0] * params[0].value.number +
112 Transform[0][1] * params[1].value.number +
113 PenPosition[0];
114 y = Transform[1][0] * params[0].value.number +
115 Transform[1][1] * params[1].value.number +
116 PenPosition[1];
117
118 if (!PolygonMode)
119 Outputf("MP\n");
120
121 Outputf("%.3f %.3f MO\n", PenPosition[0], PenPosition[1]);
122 Outputf("%.3f %.3f LI\n", PenPosition[0], y);
123 Outputf("%.3f %.3f LI\n", x, y);
124 Outputf("%.3f %.3f LI\n", x, PenPosition[1]);
125
126 Outputf("CP\n");
127 if (!PolygonMode)
128 Outputf("ST\n");
129 }
130
131
132 /*
133 * 'EW_edge_wedge()' - Draw a pie wedge.
134 */
135
136 void
137 EW_edge_wedge(int num_params, /* I - Number of parameters */
138 param_t *params) /* I - Parameters */
139 {
140 float x, y; /* Transformed coordinates */
141 float start, end, /* Start and end of arc */
142 theta, /* Current angle */
143 dt, /* Step between points */
144 radius; /* Radius of arc */
145
146
147 if (num_params < 3)
148 return;
149
150 radius = params[0].value.number;
151 start = params[1].value.number;
152 end = start + params[2].value.number;
153
154 if (num_params > 3)
155 dt = (float)fabs(params[3].value.number);
156 else
157 dt = 5.0f;
158
159 if (!PolygonMode)
160 Outputf("MP\n");
161
162 Outputf("%.3f %.3f MO\n", PenPosition[0], PenPosition[1]);
163
164 if (start < end)
165 for (theta = start + dt; theta < end; theta += dt)
166 {
167 x = (float)(PenPosition[0] +
168 radius * cos(M_PI * theta / 180.0) * Transform[0][0] +
169 radius * sin(M_PI * theta / 180.0) * Transform[0][1]);
170 y = (float)(PenPosition[1] +
171 radius * cos(M_PI * theta / 180.0) * Transform[1][0] +
172 radius * sin(M_PI * theta / 180.0) * Transform[1][1]);
173
174 Outputf("%.3f %.3f LI\n", x, y);
175 }
176 else
177 for (theta = start - dt; theta > end; theta -= dt)
178 {
179 x = (float)(PenPosition[0] +
180 radius * cos(M_PI * theta / 180.0) * Transform[0][0] +
181 radius * sin(M_PI * theta / 180.0) * Transform[0][1]);
182 y = (float)(PenPosition[1] +
183 radius * cos(M_PI * theta / 180.0) * Transform[1][0] +
184 radius * sin(M_PI * theta / 180.0) * Transform[1][1]);
185
186 Outputf("%.3f %.3f LI\n", x, y);
187 }
188
189 x = (float)(PenPosition[0] +
190 radius * cos(M_PI * end / 180.0) * Transform[0][0] +
191 radius * sin(M_PI * end / 180.0) * Transform[0][1]);
192 y = (float)(PenPosition[1] +
193 radius * cos(M_PI * end / 180.0) * Transform[1][0] +
194 radius * sin(M_PI * end / 180.0) * Transform[1][1]);
195 Outputf("%.3f %.3f LI\n", x, y);
196
197 Outputf("CP\n");
198 if (!PolygonMode)
199 Outputf("ST\n");
200 }
201
202
203 /*
204 * 'FP_fill_polygon()' - Fill a polygon.
205 */
206
207 void
208 FP_fill_polygon(int num_params, /* I - Number of parameters */
209 param_t *params) /* I - Parameters */
210 {
211 (void)num_params;
212 (void)params;
213
214 Outputf("FI\n");
215 }
216
217
218 /*
219 * 'PM_polygon_mode()' - Set the polygon drawing mode.
220 */
221
222 void
223 PM_polygon_mode(int num_params, /* I - Number of parameters */
224 param_t *params) /* I - Parameters */
225 {
226 if (num_params == 0 ||
227 params[0].value.number == 0)
228 {
229 Outputf("MP\n");
230 Outputf("%.3f %.3f MO\n", PenPosition[0], PenPosition[1]);
231 PolygonMode = 1;
232 }
233 else if (params[0].value.number == 2)
234 PolygonMode = 0;
235 }
236
237
238 /*
239 * 'RA_fill_rect_absolute()' - Fill a rectangle.
240 */
241
242 void
243 RA_fill_rect_absolute(int num_params, /* I - Number of parameters */
244 param_t *params) /* I - Parameters */
245 {
246 float x, y; /* Transformed coordinates */
247
248
249 if (num_params < 2)
250 return;
251
252 x = Transform[0][0] * params[0].value.number +
253 Transform[0][1] * params[1].value.number +
254 Transform[0][2];
255 y = Transform[1][0] * params[0].value.number +
256 Transform[1][1] * params[1].value.number +
257 Transform[1][2];
258
259 if (!PolygonMode)
260 Outputf("MP\n");
261
262 Outputf("%.3f %.3f MO\n", PenPosition[0], PenPosition[1]);
263 Outputf("%.3f %.3f LI\n", PenPosition[0], y);
264 Outputf("%.3f %.3f LI\n", x, y);
265 Outputf("%.3f %.3f LI\n", x, PenPosition[1]);
266
267 Outputf("CP\n");
268 if (!PolygonMode)
269 Outputf("FI\n");
270 }
271
272
273 /*
274 * 'RR_fill_rect_relative()' - Fill a rectangle relative to the current
275 * pen position.
276 */
277
278 void
279 RR_fill_rect_relative(int num_params, /* I - Number of parameters */
280 param_t *params) /* I - Parameters */
281 {
282 float x, y; /* Transformed coordinates */
283
284
285 if (num_params < 2)
286 return;
287
288 x = Transform[0][0] * params[0].value.number +
289 Transform[0][1] * params[1].value.number +
290 PenPosition[0];
291 y = Transform[1][0] * params[0].value.number +
292 Transform[1][1] * params[1].value.number +
293 PenPosition[1];
294
295 if (!PolygonMode)
296 Outputf("MP\n");
297
298 Outputf("%.3f %.3f MO\n", PenPosition[0], PenPosition[1]);
299 Outputf("%.3f %.3f LI\n", PenPosition[0], y);
300 Outputf("%.3f %.3f LI\n", x, y);
301 Outputf("%.3f %.3f LI\n", x, PenPosition[1]);
302
303 Outputf("CP\n");
304 if (!PolygonMode)
305 Outputf("FI\n");
306 }
307
308
309 /*
310 * 'WG_fill_wedge()' - Fill a pie wedge.
311 */
312
313 void
314 WG_fill_wedge(int num_params, /* I - Number of parameters */
315 param_t *params) /* I - Parameters */
316 {
317 float x, y; /* Transformed coordinates */
318 float start, end, /* Start and end angles */
319 theta, /* Current angle */
320 dt, /* Step between points */
321 radius; /* Radius of arc */
322
323
324 if (num_params < 3)
325 return;
326
327 radius = params[0].value.number;
328 start = params[1].value.number;
329 end = start + params[2].value.number;
330
331 if (num_params > 3)
332 dt = (float)fabs(params[3].value.number);
333 else
334 dt = 5.0;
335
336 if (!PolygonMode)
337 Outputf("MP\n");
338
339 Outputf("%.3f %.3f MO\n", PenPosition[0], PenPosition[1]);
340
341 if (start < end)
342 for (theta = start + dt; theta < end; theta += dt)
343 {
344 x = (float)(PenPosition[0] +
345 radius * cos(M_PI * theta / 180.0) * Transform[0][0] +
346 radius * sin(M_PI * theta / 180.0) * Transform[0][1]);
347 y = (float)(PenPosition[1] +
348 radius * cos(M_PI * theta / 180.0) * Transform[1][0] +
349 radius * sin(M_PI * theta / 180.0) * Transform[1][1]);
350
351 Outputf("%.3f %.3f LI\n", x, y);
352 }
353 else
354 for (theta = start - dt; theta > end; theta -= dt)
355 {
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]);
362
363 Outputf("%.3f %.3f LI\n", x, y);
364 }
365
366 x = (float)(PenPosition[0] +
367 radius * cos(M_PI * end / 180.0) * Transform[0][0] +
368 radius * sin(M_PI * end / 180.0) * Transform[0][1]);
369 y = (float)(PenPosition[1] +
370 radius * cos(M_PI * end / 180.0) * Transform[1][0] +
371 radius * sin(M_PI * end / 180.0) * Transform[1][1]);
372 Outputf("%.3f %.3f LI\n", x, y);
373
374 Outputf("CP\n");
375 if (!PolygonMode)
376 Outputf("FI\n");
377 }
378
379
380 /*
381 * End of "$Id: hpgl-polygon.c,v 1.9.2.3 2003/01/07 18:26:52 mike Exp $".
382 */