]>
Commit | Line | Data |
---|---|---|
ef416fc2 | 1 | /* |
bc44d920 | 2 | * "$Id: hpgl-polygon.c 6649 2007-07-11 21:46:42Z mike $" |
ef416fc2 | 3 | * |
4 | * HP-GL/2 polygon routines for the Common UNIX Printing System (CUPS). | |
5 | * | |
bc44d920 | 6 | * Copyright 2007 by Apple Inc. |
ef416fc2 | 7 | * Copyright 1993-2005 by Easy Software Products. |
8 | * | |
9 | * These coded instructions, statements, and computer programs are the | |
bc44d920 | 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/". | |
ef416fc2 | 14 | * |
15 | * This file is subject to the Apple OS-Developed Software exception. | |
16 | * | |
17 | * Contents: | |
18 | * | |
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. | |
28 | */ | |
29 | ||
30 | /* | |
31 | * Include necessary headers... | |
32 | */ | |
33 | ||
34 | #include "hpgltops.h" | |
35 | ||
36 | ||
37 | /* | |
38 | * 'EA_edge_rect_absolute()' - Draw a rectangle. | |
39 | */ | |
40 | ||
41 | void | |
42 | EA_edge_rect_absolute(int num_params, /* I - Number of parameters */ | |
43 | param_t *params) /* I - Parameters */ | |
44 | { | |
45 | float x, y; /* Transformed coordinates */ | |
46 | ||
47 | ||
48 | if (num_params < 2) | |
49 | return; | |
50 | ||
51 | x = Transform[0][0] * params[0].value.number + | |
52 | Transform[0][1] * params[1].value.number + | |
53 | Transform[0][2]; | |
54 | y = Transform[1][0] * params[0].value.number + | |
55 | Transform[1][1] * params[1].value.number + | |
56 | Transform[1][2]; | |
57 | ||
58 | if (!PolygonMode) | |
59 | Outputf("MP\n"); | |
60 | ||
61 | PenValid = 1; | |
62 | ||
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]); | |
67 | ||
68 | Outputf("CP\n"); | |
69 | if (!PolygonMode) | |
70 | Outputf("ST\n"); | |
71 | } | |
72 | ||
73 | ||
74 | /* | |
75 | * 'EP_edge_polygon()' - Stroke the edges of a polygon. | |
76 | */ | |
77 | ||
78 | void | |
79 | EP_edge_polygon(int num_params, /* I - Number of parameters */ | |
80 | param_t *params) /* I - Parameters */ | |
81 | { | |
82 | (void)num_params; | |
83 | (void)params; | |
84 | ||
85 | Outputf("ST\n"); | |
86 | } | |
87 | ||
88 | ||
89 | /* | |
90 | * 'ER_edge_rect_relative()' - Draw a rectangle relative to the current | |
91 | * pen position. | |
92 | */ | |
93 | ||
94 | void | |
95 | ER_edge_rect_relative(int num_params, /* I - Number of parameters */ | |
96 | param_t *params) /* I - Parameters */ | |
97 | { | |
98 | float x, y; /* Transformed coordinates */ | |
99 | ||
100 | ||
101 | if (num_params < 2) | |
102 | return; | |
103 | ||
104 | x = Transform[0][0] * params[0].value.number + | |
105 | Transform[0][1] * params[1].value.number + | |
106 | PenPosition[0]; | |
107 | y = Transform[1][0] * params[0].value.number + | |
108 | Transform[1][1] * params[1].value.number + | |
109 | PenPosition[1]; | |
110 | ||
111 | if (!PolygonMode) | |
112 | Outputf("MP\n"); | |
113 | ||
114 | PenValid = 1; | |
115 | ||
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]); | |
120 | ||
121 | Outputf("CP\n"); | |
122 | if (!PolygonMode) | |
123 | Outputf("ST\n"); | |
124 | } | |
125 | ||
126 | ||
127 | /* | |
128 | * 'EW_edge_wedge()' - Draw a pie wedge. | |
129 | */ | |
130 | ||
131 | void | |
132 | EW_edge_wedge(int num_params, /* I - Number of parameters */ | |
133 | param_t *params) /* I - Parameters */ | |
134 | { | |
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 */ | |
140 | ||
141 | ||
142 | if (num_params < 3) | |
143 | return; | |
144 | ||
145 | radius = params[0].value.number; | |
146 | start = params[1].value.number; | |
147 | end = start + params[2].value.number; | |
148 | ||
149 | if (num_params > 3) | |
150 | dt = (float)fabs(params[3].value.number); | |
151 | else | |
152 | dt = 5.0f; | |
153 | ||
154 | if (!PolygonMode) | |
155 | Outputf("MP\n"); | |
156 | ||
157 | PenValid = 1; | |
158 | ||
159 | Outputf("%.3f %.3f MO\n", PenPosition[0], PenPosition[1]); | |
160 | ||
161 | if (start < end) | |
162 | for (theta = start + dt; theta < end; theta += dt) | |
163 | { | |
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]); | |
170 | ||
171 | Outputf("%.3f %.3f LI\n", x, y); | |
172 | } | |
173 | else | |
174 | for (theta = start - dt; theta > end; theta -= dt) | |
175 | { | |
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]); | |
182 | ||
183 | Outputf("%.3f %.3f LI\n", x, y); | |
184 | } | |
185 | ||
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); | |
193 | ||
194 | Outputf("CP\n"); | |
195 | if (!PolygonMode) | |
196 | Outputf("ST\n"); | |
197 | } | |
198 | ||
199 | ||
200 | /* | |
201 | * 'FP_fill_polygon()' - Fill a polygon. | |
202 | */ | |
203 | ||
204 | void | |
205 | FP_fill_polygon(int num_params, /* I - Number of parameters */ | |
206 | param_t *params) /* I - Parameters */ | |
207 | { | |
208 | (void)num_params; | |
209 | (void)params; | |
210 | ||
211 | Outputf("FI\n"); | |
212 | } | |
213 | ||
214 | ||
215 | /* | |
216 | * 'PM_polygon_mode()' - Set the polygon drawing mode. | |
217 | */ | |
218 | ||
219 | void | |
220 | PM_polygon_mode(int num_params, /* I - Number of parameters */ | |
221 | param_t *params) /* I - Parameters */ | |
222 | { | |
223 | if (num_params == 0 || | |
224 | params[0].value.number == 0) | |
225 | { | |
226 | Outputf("MP\n"); | |
227 | PenValid = 0; | |
228 | PolygonMode = 1; | |
229 | } | |
230 | else if (params[0].value.number == 2) | |
231 | PolygonMode = 0; | |
232 | } | |
233 | ||
234 | ||
235 | /* | |
236 | * 'RA_fill_rect_absolute()' - Fill a rectangle. | |
237 | */ | |
238 | ||
239 | void | |
240 | RA_fill_rect_absolute(int num_params, /* I - Number of parameters */ | |
241 | param_t *params) /* I - Parameters */ | |
242 | { | |
243 | float x, y; /* Transformed coordinates */ | |
244 | ||
245 | ||
246 | if (num_params < 2) | |
247 | return; | |
248 | ||
249 | x = Transform[0][0] * params[0].value.number + | |
250 | Transform[0][1] * params[1].value.number + | |
251 | Transform[0][2]; | |
252 | y = Transform[1][0] * params[0].value.number + | |
253 | Transform[1][1] * params[1].value.number + | |
254 | Transform[1][2]; | |
255 | ||
256 | if (!PolygonMode) | |
257 | Outputf("MP\n"); | |
258 | ||
259 | PenValid = 1; | |
260 | ||
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]); | |
265 | ||
266 | Outputf("CP\n"); | |
267 | if (!PolygonMode) | |
268 | Outputf("FI\n"); | |
269 | } | |
270 | ||
271 | ||
272 | /* | |
273 | * 'RR_fill_rect_relative()' - Fill a rectangle relative to the current | |
274 | * pen position. | |
275 | */ | |
276 | ||
277 | void | |
278 | RR_fill_rect_relative(int num_params, /* I - Number of parameters */ | |
279 | param_t *params) /* I - Parameters */ | |
280 | { | |
281 | float x, y; /* Transformed coordinates */ | |
282 | ||
283 | ||
284 | if (num_params < 2) | |
285 | return; | |
286 | ||
287 | x = Transform[0][0] * params[0].value.number + | |
288 | Transform[0][1] * params[1].value.number + | |
289 | PenPosition[0]; | |
290 | y = Transform[1][0] * params[0].value.number + | |
291 | Transform[1][1] * params[1].value.number + | |
292 | PenPosition[1]; | |
293 | ||
294 | if (!PolygonMode) | |
295 | Outputf("MP\n"); | |
296 | ||
297 | PenValid = 1; | |
298 | ||
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]); | |
303 | ||
304 | Outputf("CP\n"); | |
305 | if (!PolygonMode) | |
306 | Outputf("FI\n"); | |
307 | } | |
308 | ||
309 | ||
310 | /* | |
311 | * 'WG_fill_wedge()' - Fill a pie wedge. | |
312 | */ | |
313 | ||
314 | void | |
315 | WG_fill_wedge(int num_params, /* I - Number of parameters */ | |
316 | param_t *params) /* I - Parameters */ | |
317 | { | |
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 */ | |
323 | ||
324 | ||
325 | if (num_params < 3) | |
326 | return; | |
327 | ||
328 | radius = params[0].value.number; | |
329 | start = params[1].value.number; | |
330 | end = start + params[2].value.number; | |
331 | ||
332 | if (num_params > 3) | |
333 | dt = (float)fabs(params[3].value.number); | |
334 | else | |
335 | dt = 5.0; | |
336 | ||
337 | if (!PolygonMode) | |
338 | Outputf("MP\n"); | |
339 | ||
340 | PenValid = 1; | |
341 | ||
342 | Outputf("%.3f %.3f MO\n", PenPosition[0], PenPosition[1]); | |
343 | ||
344 | if (start < end) | |
345 | for (theta = start + dt; theta < end; theta += dt) | |
346 | { | |
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]); | |
353 | ||
354 | Outputf("%.3f %.3f LI\n", x, y); | |
355 | } | |
356 | else | |
357 | for (theta = start - dt; theta > end; theta -= dt) | |
358 | { | |
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]); | |
365 | ||
366 | Outputf("%.3f %.3f LI\n", x, y); | |
367 | } | |
368 | ||
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); | |
376 | ||
377 | Outputf("CP\n"); | |
378 | if (!PolygonMode) | |
379 | Outputf("FI\n"); | |
380 | } | |
381 | ||
382 | ||
383 | /* | |
bc44d920 | 384 | * End of "$Id: hpgl-polygon.c 6649 2007-07-11 21:46:42Z mike $". |
ef416fc2 | 385 | */ |