]> git.ipfire.org Git - thirdparty/cups.git/blame - filter/hpgl-polygon.c
Load cups into easysw/current.
[thirdparty/cups.git] / filter / hpgl-polygon.c
CommitLineData
ef416fc2 1/*
f7faf1f5 2 * "$Id: hpgl-polygon.c 4494 2005-02-18 02:18:11Z mike $"
ef416fc2 3 *
4 * HP-GL/2 polygon routines for the Common UNIX Printing System (CUPS).
5 *
6 * Copyright 1993-2005 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 USA
19 *
20 * Voice: (301) 373-9600
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
50void
51EA_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 PenValid = 1;
71
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]);
76
77 Outputf("CP\n");
78 if (!PolygonMode)
79 Outputf("ST\n");
80}
81
82
83/*
84 * 'EP_edge_polygon()' - Stroke the edges of a polygon.
85 */
86
87void
88EP_edge_polygon(int num_params, /* I - Number of parameters */
89 param_t *params) /* I - Parameters */
90{
91 (void)num_params;
92 (void)params;
93
94 Outputf("ST\n");
95}
96
97
98/*
99 * 'ER_edge_rect_relative()' - Draw a rectangle relative to the current
100 * pen position.
101 */
102
103void
104ER_edge_rect_relative(int num_params, /* I - Number of parameters */
105 param_t *params) /* I - Parameters */
106{
107 float x, y; /* Transformed coordinates */
108
109
110 if (num_params < 2)
111 return;
112
113 x = Transform[0][0] * params[0].value.number +
114 Transform[0][1] * params[1].value.number +
115 PenPosition[0];
116 y = Transform[1][0] * params[0].value.number +
117 Transform[1][1] * params[1].value.number +
118 PenPosition[1];
119
120 if (!PolygonMode)
121 Outputf("MP\n");
122
123 PenValid = 1;
124
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]);
129
130 Outputf("CP\n");
131 if (!PolygonMode)
132 Outputf("ST\n");
133}
134
135
136/*
137 * 'EW_edge_wedge()' - Draw a pie wedge.
138 */
139
140void
141EW_edge_wedge(int num_params, /* I - Number of parameters */
142 param_t *params) /* I - Parameters */
143{
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 */
149
150
151 if (num_params < 3)
152 return;
153
154 radius = params[0].value.number;
155 start = params[1].value.number;
156 end = start + params[2].value.number;
157
158 if (num_params > 3)
159 dt = (float)fabs(params[3].value.number);
160 else
161 dt = 5.0f;
162
163 if (!PolygonMode)
164 Outputf("MP\n");
165
166 PenValid = 1;
167
168 Outputf("%.3f %.3f MO\n", PenPosition[0], PenPosition[1]);
169
170 if (start < end)
171 for (theta = start + dt; theta < end; theta += dt)
172 {
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]);
179
180 Outputf("%.3f %.3f LI\n", x, y);
181 }
182 else
183 for (theta = start - dt; theta > end; theta -= dt)
184 {
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]);
191
192 Outputf("%.3f %.3f LI\n", x, y);
193 }
194
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);
202
203 Outputf("CP\n");
204 if (!PolygonMode)
205 Outputf("ST\n");
206}
207
208
209/*
210 * 'FP_fill_polygon()' - Fill a polygon.
211 */
212
213void
214FP_fill_polygon(int num_params, /* I - Number of parameters */
215 param_t *params) /* I - Parameters */
216{
217 (void)num_params;
218 (void)params;
219
220 Outputf("FI\n");
221}
222
223
224/*
225 * 'PM_polygon_mode()' - Set the polygon drawing mode.
226 */
227
228void
229PM_polygon_mode(int num_params, /* I - Number of parameters */
230 param_t *params) /* I - Parameters */
231{
232 if (num_params == 0 ||
233 params[0].value.number == 0)
234 {
235 Outputf("MP\n");
236 PenValid = 0;
237 PolygonMode = 1;
238 }
239 else if (params[0].value.number == 2)
240 PolygonMode = 0;
241}
242
243
244/*
245 * 'RA_fill_rect_absolute()' - Fill a rectangle.
246 */
247
248void
249RA_fill_rect_absolute(int num_params, /* I - Number of parameters */
250 param_t *params) /* I - Parameters */
251{
252 float x, y; /* Transformed coordinates */
253
254
255 if (num_params < 2)
256 return;
257
258 x = Transform[0][0] * params[0].value.number +
259 Transform[0][1] * params[1].value.number +
260 Transform[0][2];
261 y = Transform[1][0] * params[0].value.number +
262 Transform[1][1] * params[1].value.number +
263 Transform[1][2];
264
265 if (!PolygonMode)
266 Outputf("MP\n");
267
268 PenValid = 1;
269
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]);
274
275 Outputf("CP\n");
276 if (!PolygonMode)
277 Outputf("FI\n");
278}
279
280
281/*
282 * 'RR_fill_rect_relative()' - Fill a rectangle relative to the current
283 * pen position.
284 */
285
286void
287RR_fill_rect_relative(int num_params, /* I - Number of parameters */
288 param_t *params) /* I - Parameters */
289{
290 float x, y; /* Transformed coordinates */
291
292
293 if (num_params < 2)
294 return;
295
296 x = Transform[0][0] * params[0].value.number +
297 Transform[0][1] * params[1].value.number +
298 PenPosition[0];
299 y = Transform[1][0] * params[0].value.number +
300 Transform[1][1] * params[1].value.number +
301 PenPosition[1];
302
303 if (!PolygonMode)
304 Outputf("MP\n");
305
306 PenValid = 1;
307
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]);
312
313 Outputf("CP\n");
314 if (!PolygonMode)
315 Outputf("FI\n");
316}
317
318
319/*
320 * 'WG_fill_wedge()' - Fill a pie wedge.
321 */
322
323void
324WG_fill_wedge(int num_params, /* I - Number of parameters */
325 param_t *params) /* I - Parameters */
326{
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 */
332
333
334 if (num_params < 3)
335 return;
336
337 radius = params[0].value.number;
338 start = params[1].value.number;
339 end = start + params[2].value.number;
340
341 if (num_params > 3)
342 dt = (float)fabs(params[3].value.number);
343 else
344 dt = 5.0;
345
346 if (!PolygonMode)
347 Outputf("MP\n");
348
349 PenValid = 1;
350
351 Outputf("%.3f %.3f MO\n", PenPosition[0], PenPosition[1]);
352
353 if (start < end)
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 else
366 for (theta = start - dt; theta > end; theta -= dt)
367 {
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]);
374
375 Outputf("%.3f %.3f LI\n", x, y);
376 }
377
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);
385
386 Outputf("CP\n");
387 if (!PolygonMode)
388 Outputf("FI\n");
389}
390
391
392/*
f7faf1f5 393 * End of "$Id: hpgl-polygon.c 4494 2005-02-18 02:18:11Z mike $".
ef416fc2 394 */