]>
Commit | Line | Data |
---|---|---|
898749d4 | 1 | /* |
58ec2a95 | 2 | * "$Id: hpgl-config.c,v 1.10 1999/03/21 02:10:11 mike Exp $" |
898749d4 | 3 | * |
58ec2a95 | 4 | * HP-GL/2 configuration routines for the Common UNIX Printing System (CUPS). |
898749d4 | 5 | * |
58ec2a95 | 6 | * Copyright 1993-1999 by Easy Software Products. |
898749d4 | 7 | * |
58ec2a95 | 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: | |
898749d4 | 14 | * |
58ec2a95 | 15 | * Attn: CUPS Licensing Information |
16 | * Easy Software Products | |
17 | * 44141 Airport View Drive, Suite 204 | |
18 | * Hollywood, Maryland 20636-3111 USA | |
80596f75 | 19 | * |
58ec2a95 | 20 | * Voice: (301) 373-9603 |
21 | * EMail: cups-info@cups.org | |
22 | * WWW: http://www.cups.org | |
11dc2cdf | 23 | * |
58ec2a95 | 24 | * Contents: |
898749d4 | 25 | * |
26 | */ | |
27 | ||
28 | /* | |
29 | * Include necessary headers... | |
30 | */ | |
31 | ||
58ec2a95 | 32 | #include "hpgltops.h" |
898749d4 | 33 | |
34 | ||
58ec2a95 | 35 | /* |
36 | * 'update_transform()' - Update the page transformation matrix as needed. | |
37 | */ | |
38 | ||
898749d4 | 39 | void |
40 | update_transform(void) | |
41 | { | |
42 | float p1[2], p2[2]; | |
11dc2cdf | 43 | float width, height; |
58ec2a95 | 44 | float page_width, page_length; |
297b9b4d | 45 | float xoff, yoff; |
11dc2cdf | 46 | float plotsize[2]; |
f42989ea | 47 | float scaling, |
48 | pen_scaling; | |
11dc2cdf | 49 | |
898749d4 | 50 | |
58ec2a95 | 51 | width = IW2[0] - IW1[0]; |
52 | height = IW2[1] - IW1[1]; | |
53 | page_width = PageRight - PageLeft; | |
54 | page_length = PageTop - PageBottom; | |
297b9b4d | 55 | |
56 | if (width == 0 || height == 0) | |
57 | return; | |
58 | ||
11dc2cdf | 59 | if (FitPlot) |
60 | { | |
11dc2cdf | 61 | if (Rotation == 0 || Rotation == 180) |
62 | { | |
58ec2a95 | 63 | scaling = page_width / width; |
64 | ||
65 | if (scaling > (page_length / height)) | |
66 | scaling = page_length / height; | |
67 | else if ((page_length / height * width) <= page_width) | |
68 | scaling = page_length / height; | |
11dc2cdf | 69 | } |
70 | else | |
71 | { | |
58ec2a95 | 72 | scaling = page_width / height; |
73 | ||
74 | if (scaling > (page_length / width)) | |
75 | scaling = page_length / width; | |
76 | else if ((page_length / width * height) <= page_width) | |
77 | scaling = page_length / width; | |
11dc2cdf | 78 | }; |
79 | ||
297b9b4d | 80 | plotsize[0] = width * scaling; |
81 | plotsize[1] = height * scaling; | |
11dc2cdf | 82 | } |
83 | else | |
84 | { | |
297b9b4d | 85 | plotsize[0] = width * 72.0 / 1016.0; |
86 | plotsize[1] = height * 72.0 / 1016.0; | |
87 | scaling = 72.0 / 1016.0; | |
11dc2cdf | 88 | }; |
898749d4 | 89 | |
90 | switch (ScalingType) | |
91 | { | |
c839cbc9 | 92 | case 2 : |
93 | if (Scaling2[0] != 0.0 && Scaling2[1] != 0.0) | |
94 | { | |
95 | p1[0] = P1[0] / fabs(Scaling2[0]); | |
96 | p1[1] = P1[1] / fabs(Scaling2[1]); | |
97 | p2[0] = P2[0] / fabs(Scaling2[0]); | |
98 | p2[1] = P2[1] / fabs(Scaling2[1]); | |
99 | break; | |
100 | }; | |
101 | ||
898749d4 | 102 | case -1 : |
103 | p1[0] = P1[0]; | |
104 | p1[1] = P1[1]; | |
105 | p2[0] = P2[0]; | |
106 | p2[1] = P2[1]; | |
107 | break; | |
108 | ||
109 | default : | |
110 | p1[0] = Scaling1[0]; | |
111 | p1[1] = Scaling1[1]; | |
112 | p2[0] = Scaling2[0]; | |
113 | p2[1] = Scaling2[1]; | |
114 | break; | |
115 | }; | |
116 | ||
f42989ea | 117 | if (p2[0] == p1[0]) |
118 | p2[0] ++; | |
119 | if (p2[1] == p1[1]) | |
120 | p2[1] ++; | |
121 | ||
898749d4 | 122 | switch (Rotation) |
123 | { | |
124 | case 0 : | |
297b9b4d | 125 | Transform[0][0] = scaling; |
898749d4 | 126 | Transform[0][1] = 0.0; |
297b9b4d | 127 | Transform[0][2] = -IW1[0] * scaling; |
11dc2cdf | 128 | Transform[1][0] = 0.0; |
297b9b4d | 129 | Transform[1][1] = scaling; |
130 | Transform[1][2] = -IW1[1] * scaling; | |
898749d4 | 131 | break; |
132 | ||
c839cbc9 | 133 | case 90 : |
11dc2cdf | 134 | Transform[0][0] = 0.0; |
297b9b4d | 135 | Transform[0][1] = -scaling; |
136 | Transform[0][2] = (height - IW1[0]) * scaling; | |
137 | Transform[1][0] = scaling; | |
11dc2cdf | 138 | Transform[1][1] = 0.0; |
297b9b4d | 139 | Transform[1][2] = -IW1[1] * scaling; |
11dc2cdf | 140 | break; |
141 | ||
142 | case 180 : | |
297b9b4d | 143 | Transform[0][0] = -scaling; |
11dc2cdf | 144 | Transform[0][1] = 0.0; |
297b9b4d | 145 | Transform[0][2] = (height - IW1[0]) * scaling; |
11dc2cdf | 146 | Transform[1][0] = 0.0; |
297b9b4d | 147 | Transform[1][1] = -scaling; |
148 | Transform[1][2] = (width - IW1[1]) * scaling; | |
11dc2cdf | 149 | break; |
150 | ||
898749d4 | 151 | case 270 : |
152 | Transform[0][0] = 0.0; | |
297b9b4d | 153 | Transform[0][1] = scaling; |
154 | Transform[0][2] = -IW1[0] * scaling; | |
155 | Transform[1][0] = -scaling; | |
898749d4 | 156 | Transform[1][1] = 0.0; |
297b9b4d | 157 | Transform[1][2] = (width - IW1[1]) * scaling; |
898749d4 | 158 | break; |
58ec2a95 | 159 | } |
f42989ea | 160 | |
161 | if (FitPlot) | |
162 | { | |
58ec2a95 | 163 | PenScaling = Transform[0][0] + Transform[0][1]; |
164 | ||
165 | if (PenScaling < 0.0) | |
166 | PenScaling = -pen_scaling; | |
f42989ea | 167 | } |
168 | else | |
58ec2a95 | 169 | PenScaling = 1.0; |
f42989ea | 170 | |
58ec2a95 | 171 | if (PageDirty) |
172 | printf("/PenScaling %.3f def W%d\n", PenScaling, PenNumber); | |
898749d4 | 173 | } |
174 | ||
175 | ||
176 | void | |
c839cbc9 | 177 | BP_begin_plot(int num_params, param_t *params) |
898749d4 | 178 | { |
898749d4 | 179 | } |
180 | ||
181 | ||
182 | void | |
183 | DF_default_values(int num_params, param_t *params) | |
184 | { | |
185 | AC_anchor_corner(0, NULL); | |
186 | AD_define_alternate(0, NULL); | |
187 | SD_define_standard(0, NULL); | |
188 | CF_character_fill(0, NULL); | |
189 | DI_absolute_direction(0, NULL); | |
190 | DT_define_label_term(0, NULL); | |
191 | DV_define_variable_path(0, NULL); | |
192 | ES_extra_space(0, NULL); | |
193 | FT_fill_type(0, NULL); | |
194 | IW_input_window(0, NULL); | |
195 | LA_line_attributes(0, NULL); | |
196 | LO_label_origin(0, NULL); | |
197 | LT_line_type(0, NULL); | |
198 | PA_plot_absolute(0, NULL); | |
199 | PolygonMode = 0; | |
200 | RF_raster_fill(0, NULL); | |
201 | SC_scale(0, NULL); | |
202 | SM_symbol_mode(0, NULL); | |
203 | SS_select_standard(0, NULL); | |
204 | TD_transparent_data(0, NULL); | |
205 | UL_user_line_type(0, NULL); | |
206 | } | |
207 | ||
208 | ||
c839cbc9 | 209 | void |
210 | IN_initialize(int num_params, param_t *params) | |
211 | { | |
212 | DF_default_values(0, NULL); | |
213 | PU_pen_up(0, NULL); | |
214 | RO_rotate(0, NULL); | |
215 | IP_input_absolute(0, NULL); | |
216 | WU_width_units(0, NULL); | |
217 | PW_pen_width(0, NULL); | |
218 | SP_select_pen(0, NULL); | |
219 | ||
220 | PenPosition[0] = PenPosition[1] = 0.0; | |
221 | } | |
222 | ||
223 | ||
898749d4 | 224 | void |
225 | IP_input_absolute(int num_params, param_t *params) | |
226 | { | |
227 | if (num_params == 0) | |
228 | { | |
11dc2cdf | 229 | P1[0] = 0.0; |
230 | P1[1] = 0.0; | |
231 | P2[0] = PlotSize[0] / 72.0 * 1016.0; | |
232 | P2[1] = PlotSize[1] / 72.0 * 1016.0; | |
898749d4 | 233 | } |
234 | else if (num_params == 2) | |
235 | { | |
236 | P2[0] -= P1[0]; | |
237 | P2[1] -= P1[1]; | |
238 | P1[0] = params[0].value.number; | |
239 | P1[1] = params[1].value.number; | |
240 | P2[0] += P1[0]; | |
241 | P2[1] += P1[1]; | |
242 | } | |
243 | else if (num_params == 4) | |
244 | { | |
245 | P1[0] = params[0].value.number; | |
246 | P1[1] = params[1].value.number; | |
247 | P2[0] = params[2].value.number; | |
248 | P2[1] = params[3].value.number; | |
249 | }; | |
250 | ||
297b9b4d | 251 | IW1[0] = P1[0]; |
252 | IW1[1] = P1[1]; | |
253 | IW2[0] = P2[0]; | |
254 | IW2[1] = P2[1]; | |
255 | ||
898749d4 | 256 | update_transform(); |
257 | } | |
258 | ||
259 | ||
260 | void | |
261 | IR_input_relative(int num_params, param_t *params) | |
262 | { | |
263 | if (num_params == 0) | |
264 | { | |
c839cbc9 | 265 | P1[0] = PageLeft / 72.0 * 1016.0; |
266 | P1[1] = PageBottom / 72.0 * 1016.0; | |
58ec2a95 | 267 | P2[0] = PageRight / 72.0 * 1016.0; |
268 | P2[1] = PageTop / 72.0 * 1016.0; | |
898749d4 | 269 | } |
270 | else if (num_params == 2) | |
271 | { | |
272 | P2[0] -= P1[0]; | |
273 | P2[1] -= P1[1]; | |
58ec2a95 | 274 | P1[0] = params[0].value.number * (PageRight - PageLeft) / 72.0 * 1016.0 / 100.0; |
275 | P1[1] = params[1].value.number * (PageTop - PageBottom) / 72.0 * 1016.0 / 100.0; | |
898749d4 | 276 | P2[0] += P1[0]; |
277 | P2[1] += P1[1]; | |
278 | } | |
279 | else if (num_params == 4) | |
280 | { | |
58ec2a95 | 281 | P1[0] = params[0].value.number * (PageRight - PageLeft) / 72.0 * 1016.0 / 100.0; |
282 | P1[1] = params[1].value.number * (PageTop - PageBottom) / 72.0 * 1016.0 / 100.0; | |
283 | P2[0] = params[2].value.number * (PageRight - PageLeft) / 72.0 * 1016.0 / 100.0; | |
284 | P2[1] = params[3].value.number * (PageTop - PageBottom) / 72.0 * 1016.0 / 100.0; | |
898749d4 | 285 | }; |
286 | ||
297b9b4d | 287 | IW1[0] = P1[0]; |
288 | IW1[1] = P1[1]; | |
289 | IW2[0] = P2[0]; | |
290 | IW2[1] = P2[1]; | |
291 | ||
898749d4 | 292 | update_transform(); |
293 | } | |
294 | ||
295 | ||
296 | void | |
297 | IW_input_window(int num_params, param_t *params) | |
298 | { | |
297b9b4d | 299 | if (num_params == 0) |
300 | { | |
301 | IW1[0] = P1[0]; | |
302 | IW1[1] = P1[1]; | |
303 | IW2[0] = P2[0]; | |
304 | IW2[1] = P2[1]; | |
305 | } | |
306 | else if (num_params == 4) | |
307 | { | |
308 | IW1[0] = params[0].value.number; | |
309 | IW1[1] = params[1].value.number; | |
310 | IW2[0] = params[2].value.number; | |
311 | IW2[1] = params[3].value.number; | |
312 | }; | |
313 | ||
314 | update_transform(); | |
898749d4 | 315 | } |
316 | ||
317 | ||
318 | void | |
319 | PG_advance_page(int num_params, param_t *params) | |
320 | { | |
58ec2a95 | 321 | if (PageDirty) |
e142a5d9 | 322 | { |
58ec2a95 | 323 | puts("grestore"); |
324 | puts("showpage"); | |
325 | puts("%%EndPage"); | |
e142a5d9 | 326 | |
58ec2a95 | 327 | PageDirty = 0; |
328 | } | |
898749d4 | 329 | } |
330 | ||
331 | ||
c839cbc9 | 332 | void |
333 | PS_plot_size(int num_params, param_t *params) | |
334 | { | |
335 | switch (num_params) | |
336 | { | |
337 | case 0 : | |
9078a167 | 338 | /* |
339 | * This is a hack for programs that assume a DesignJet's hard limits... | |
340 | */ | |
341 | ||
11dc2cdf | 342 | PlotSize[0] = 72.0 * 36.0; |
343 | PlotSize[1] = 72.0 * 48.0; | |
c839cbc9 | 344 | break; |
345 | case 1 : | |
f42989ea | 346 | if (Rotation == 0 || Rotation == 180) |
347 | { | |
348 | PlotSize[1] = 72.0 * params[0].value.number / 1016.0; | |
349 | PlotSize[0] = 0.75 * PlotSize[1]; | |
350 | } | |
351 | else | |
352 | { | |
353 | PlotSize[0] = 72.0 * params[0].value.number / 1016.0; | |
354 | PlotSize[1] = 0.75 * PlotSize[0]; | |
355 | }; | |
c839cbc9 | 356 | break; |
357 | case 2 : | |
358 | if (Rotation == 0 || Rotation == 180) | |
359 | { | |
11dc2cdf | 360 | PlotSize[0] = 72.0 * params[1].value.number / 1016.0; |
361 | PlotSize[1] = 72.0 * params[0].value.number / 1016.0; | |
c839cbc9 | 362 | } |
363 | else | |
364 | { | |
11dc2cdf | 365 | PlotSize[0] = 72.0 * params[0].value.number / 1016.0; |
366 | PlotSize[1] = 72.0 * params[1].value.number / 1016.0; | |
c839cbc9 | 367 | }; |
368 | break; | |
369 | }; | |
370 | ||
80596f75 | 371 | /* |
372 | * This is required for buggy files that don't set the input window. | |
373 | */ | |
374 | ||
11dc2cdf | 375 | IP_input_absolute(0, NULL); |
c839cbc9 | 376 | } |
377 | ||
378 | ||
898749d4 | 379 | void |
380 | RO_rotate(int num_params, param_t *params) | |
381 | { | |
382 | if (num_params == 0) | |
11dc2cdf | 383 | Rotation = 0; |
898749d4 | 384 | else |
385 | Rotation = params[0].value.number; | |
386 | ||
387 | update_transform(); | |
388 | } | |
389 | ||
390 | ||
391 | void | |
392 | RP_replot(int num_params, param_t *params) | |
393 | { | |
898749d4 | 394 | } |
395 | ||
396 | ||
397 | void | |
398 | SC_scale(int num_params, param_t *params) | |
399 | { | |
400 | if (num_params == 0) | |
401 | ScalingType = -1; | |
402 | else if (num_params > 3) | |
403 | { | |
404 | Scaling1[0] = params[0].value.number; | |
405 | Scaling2[0] = params[1].value.number; | |
406 | Scaling1[1] = params[2].value.number; | |
407 | Scaling2[1] = params[3].value.number; | |
408 | ||
409 | if (num_params > 4) | |
410 | ScalingType = params[4].value.number; | |
411 | else | |
412 | ScalingType = 0; | |
413 | }; | |
414 | ||
415 | update_transform(); | |
416 | } | |
417 | ||
418 | ||
419 | /* | |
58ec2a95 | 420 | * End of "$Id: hpgl-config.c,v 1.10 1999/03/21 02:10:11 mike Exp $". |
898749d4 | 421 | */ |