]>
git.ipfire.org Git - thirdparty/cups.git/blob - filter/hpgl-config.c
180674d79fb16db89526c4d050bf5b367b25dbb7
2 * "$Id: hpgl-config.c 6649 2007-07-11 21:46:42Z mike $"
4 * HP-GL/2 configuration routines for the Common UNIX Printing System (CUPS).
6 * Copyright 2007 by Apple Inc.
7 * Copyright 1993-2005 by Easy Software Products.
9 * These coded instructions, statements, and computer programs are the
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/".
15 * This file is subject to the Apple OS-Developed Software exception.
19 * update_transform() - Update the page transformation matrix as needed.
20 * BP_begin_plot() - Start a plot...
21 * DF_default_values() - Set all state info to the default values.
22 * IN_initialize() - Initialize the plotter.
23 * IP_input_absolute() - Set P1 and P2 values for the plot.
24 * IR_input_relative() - Update P1 and P2.
25 * IW_input_window() - Setup an input window.
26 * PG_advance_page() - Eject the current page.
27 * PS_plot_size() - Set the plot size.
28 * RO_rotate() - Rotate the plot.
29 * RP_replot() - Replot the current page.
30 * SC_scale() - Set user-defined scaling.
34 * Include necessary headers...
39 #define max(a,b) ((a) < (b) ? (b) : (a))
43 * 'update_transform()' - Update the page transformation matrix as needed.
47 update_transform(void)
49 float page_width
, /* Actual page width */
50 page_height
; /* Actual page height */
51 float scaling
; /* Scaling factor */
52 float left
, right
, /* Scaling window */
54 float width
, height
; /* Scaling width and height */
55 float iw1
[2], iw2
[2]; /* Clipping window */
59 * Get the page and input window sizes...
64 page_width
= PageRight
- PageLeft
;
65 page_height
= PageTop
- PageBottom
;
69 page_width
= (P2
[0] - P1
[0]) * 72.0f
/ 1016.0f
;
70 page_height
= (P2
[1] - P1
[1]) * 72.0f
/ 1016.0f
;
73 fprintf(stderr
, "DEBUG: page_width = %.0f, page_height = %.0f\n",
74 page_width
, page_height
);
76 if (page_width
== 0 || page_height
== 0)
80 * Set the scaling window...
85 default : /* No user scaling */
92 case 0 : /* Anisotropic (non-uniform) scaling */
99 case 1 : /* Isotropic (uniform) scaling */
101 bottom
= Scaling1
[1];
105 width
= right
- left
;
106 height
= top
- bottom
;
108 if (width
== 0 || height
== 0)
111 if ((width
* page_height
) != (height
* page_width
))
113 scaling
= height
* page_width
/ page_height
;
117 left
= 0.5f
* (left
+ right
- width
);
118 right
= left
+ width
;
122 height
= width
* page_height
/ page_width
;
123 bottom
= 0.5f
* (bottom
+ top
- height
);
124 top
= bottom
+ height
;
131 bottom
= Scaling1
[1];
132 right
= left
+ page_width
* Scaling2
[0] * 1016.0f
/ 72.0f
;
133 top
= bottom
+ page_height
* Scaling2
[1] * 1016.0f
/ 72.0f
;
137 width
= right
- left
;
138 height
= top
- bottom
;
140 if (width
== 0 || height
== 0)
144 * Scale the plot as needed...
147 if (Rotation
== 0 || Rotation
== 180)
148 scaling
= page_width
/ width
;
150 scaling
= page_width
/ height
;
153 scaling
*= max(page_width
, page_height
) / max(PlotSize
[1], PlotSize
[0]);
156 * Offset for the current P1 location...
166 left
= P1
[0] * 72.0f
/ 1016.0f
;
167 bottom
= P1
[1] * 72.0f
/ 1016.0f
;
171 * Generate a new transformation matrix...
178 Transform
[0][0] = scaling
;
179 Transform
[0][1] = 0.0;
180 Transform
[0][2] = -left
;
181 Transform
[1][0] = 0.0;
182 Transform
[1][1] = scaling
;
183 Transform
[1][2] = -bottom
;
187 Transform
[0][0] = 0.0;
188 Transform
[0][1] = -scaling
;
189 Transform
[0][2] = PageLength
- left
;
190 Transform
[1][0] = scaling
;
191 Transform
[1][1] = 0.0;
192 Transform
[1][2] = -bottom
;
196 Transform
[0][0] = -scaling
;
197 Transform
[0][1] = 0.0;
198 Transform
[0][2] = PageLength
- left
;
199 Transform
[1][0] = 0.0;
200 Transform
[1][1] = -scaling
;
201 Transform
[1][2] = PageWidth
- bottom
;
205 Transform
[0][0] = 0.0;
206 Transform
[0][1] = scaling
;
207 Transform
[0][2] = -left
;
208 Transform
[1][0] = -scaling
;
209 Transform
[1][1] = 0.0;
210 Transform
[1][2] = PageWidth
- bottom
;
214 fprintf(stderr
, "DEBUG: Transform = [ %.3f %.3f\n"
216 "DEBUG: %.3f %.3f ]\n",
217 Transform
[0][0], Transform
[1][0], Transform
[0][1],
218 Transform
[1][1], Transform
[0][2], Transform
[1][2]);
222 if (Rotation
== 0 || Rotation
== 180)
223 PenScaling
= page_width
/ PlotSize
[1];
225 PenScaling
= page_width
/ PlotSize
[0];
230 if (PenScaling
< 0.0)
231 PenScaling
= -PenScaling
;
235 printf("%.2f setlinewidth\n", Pens
[PenNumber
].width
* PenScaling
);
237 if (IW1
[0] != IW2
[0] && IW1
[1] != IW2
[1])
239 iw1
[0] = IW1
[0] * 72.0f
/ 1016.0f
;
240 iw1
[1] = IW1
[1] * 72.0f
/ 1016.0f
;
241 iw2
[0] = IW2
[0] * 72.0f
/ 1016.0f
;
242 iw2
[1] = IW2
[1] * 72.0f
/ 1016.0f
;
244 printf("initclip MP %.3f %.3f MO %.3f %.3f LI %.3f %.3f LI %.3f %.3f LI CP clip\n",
245 iw1
[0], iw1
[1], iw1
[0], iw2
[1], iw2
[0], iw2
[1], iw2
[0], iw1
[1]);
252 * 'BP_begin_plot()' - Start a plot...
256 BP_begin_plot(int num_params
, /* I - Number of parameters */
257 param_t
*params
) /* I - Parameters */
265 * 'DF_default_values()' - Set all state info to the default values.
269 DF_default_values(int num_params
, /* I - Number of parameters */
270 param_t
*params
) /* I - Parameters */
275 NP_number_pens(0, NULL
);
276 AC_anchor_corner(0, NULL
);
277 AD_define_alternate(0, NULL
);
278 SD_define_standard(0, NULL
);
279 CF_character_fill(0, NULL
);
280 DI_absolute_direction(0, NULL
);
281 DT_define_label_term(0, NULL
);
282 DV_define_variable_path(0, NULL
);
283 ES_extra_space(0, NULL
);
284 FT_fill_type(0, NULL
);
285 IW_input_window(0, NULL
);
286 LA_line_attributes(0, NULL
);
287 LO_label_origin(0, NULL
);
288 LT_line_type(0, NULL
);
289 PA_plot_absolute(0, NULL
);
291 RF_raster_fill(0, NULL
);
293 SM_symbol_mode(0, NULL
);
294 SS_select_standard(0, NULL
);
295 TD_transparent_data(0, NULL
);
296 UL_user_line_type(0, NULL
);
301 * 'IN_initialize()' - Initialize the plotter.
305 IN_initialize(int num_params
, /* I - Number of parameters */
306 param_t
*params
) /* I - Parameters */
311 DF_default_values(0, NULL
);
314 PS_plot_size(0, NULL
);
315 WU_width_units(0, NULL
);
316 PW_pen_width(0, NULL
);
320 PenPosition
[0] = PenPosition
[1] = 0.0;
325 * 'IP_input_absolute()' - Set P1 and P2 values for the plot.
329 IP_input_absolute(int num_params
, /* I - Number of parameters */
330 param_t
*params
) /* I - Parameters */
334 P1
[0] = PageLeft
/ 72.0f
* 1016.0f
;
335 P1
[1] = PageBottom
/ 72.0f
* 1016.0f
;
336 P2
[0] = PageRight
/ 72.0f
* 1016.0f
;
337 P2
[1] = PageTop
/ 72.0f
* 1016.0f
;
339 else if (num_params
== 2)
343 P1
[0] = params
[0].value
.number
;
344 P1
[1] = params
[1].value
.number
;
348 else if (num_params
== 4)
350 P1
[0] = params
[0].value
.number
;
351 P1
[1] = params
[1].value
.number
;
352 P2
[0] = params
[2].value
.number
;
353 P2
[1] = params
[3].value
.number
;
374 * 'IR_input_relative()' - Update P1 and P2.
378 IR_input_relative(int num_params
, /* I - Number of parameters */
379 param_t
*params
) /* I - Parameters */
383 P1
[0] = PageLeft
/ 72.0f
* 1016.0f
;
384 P1
[1] = PageBottom
/ 72.0f
* 1016.0f
;
385 P2
[0] = PageRight
/ 72.0f
* 1016.0f
;
386 P2
[1] = PageTop
/ 72.0f
* 1016.0f
;
388 else if (num_params
== 2)
392 P1
[0] = params
[0].value
.number
* PlotSize
[0] / 72.0f
* 1016.0f
/ 100.0f
;
393 P1
[1] = params
[1].value
.number
* PlotSize
[1] / 72.0f
* 1016.0f
/ 100.0f
;
397 else if (num_params
== 4)
399 P1
[0] = params
[0].value
.number
* PlotSize
[0] / 72.0f
* 1016.0f
/ 100.0f
;
400 P1
[1] = params
[1].value
.number
* PlotSize
[1] / 72.0f
* 1016.0f
/ 100.0f
;
401 P2
[0] = params
[2].value
.number
* PlotSize
[0] / 72.0f
* 1016.0f
/ 100.0f
;
402 P2
[1] = params
[3].value
.number
* PlotSize
[1] / 72.0f
* 1016.0f
/ 100.0f
;
423 * 'IW_input_window()' - Setup an input window.
427 IW_input_window(int num_params
, /* I - Number of parameters */
428 param_t
*params
) /* I - Parameters */
432 IW1
[0] = PageLeft
/ 72.0f
* 1016.0f
;
433 IW1
[1] = PageBottom
/ 72.0f
* 1016.0f
;
434 IW2
[0] = PageRight
/ 72.0f
* 1016.0f
;
435 IW2
[1] = PageTop
/ 72.0f
* 1016.0f
;
437 else if (num_params
== 4)
442 IW1
[0] = params
[0].value
.number
;
443 IW1
[1] = params
[1].value
.number
;
444 IW2
[0] = params
[2].value
.number
;
445 IW2
[1] = params
[3].value
.number
;
449 IW1
[0] = (Transform
[0][0] * params
[0].value
.number
+
450 Transform
[0][1] * params
[1].value
.number
+
451 Transform
[0][2]) / 72.0f
* 1016.0f
;
452 IW1
[1] = (Transform
[1][0] * params
[0].value
.number
+
453 Transform
[1][1] * params
[1].value
.number
+
454 Transform
[1][2]) / 72.0f
* 1016.0f
;
455 IW2
[0] = (Transform
[0][0] * params
[2].value
.number
+
456 Transform
[0][1] * params
[3].value
.number
+
457 Transform
[0][2]) / 72.0f
* 1016.0f
;
458 IW2
[1] = (Transform
[1][0] * params
[2].value
.number
+
459 Transform
[1][1] * params
[3].value
.number
+
460 Transform
[1][2]) / 72.0f
* 1016.0f
;
463 fprintf(stderr
, "DEBUG: IW%.0f,%.0f,%.0f,%.0f = [ %.0f %.0f %.0f %.0f ]\n",
464 params
[0].value
.number
, params
[1].value
.number
,
465 params
[2].value
.number
, params
[3].value
.number
,
466 IW1
[0], IW1
[1], IW2
[0], IW2
[1]);
475 * 'PG_advance_page()' - Eject the current page.
479 PG_advance_page(int num_params
, /* I - Number of parameters */
480 param_t
*params
) /* I - Parameters */
496 * 'PS_plot_size()' - Set the plot size.
500 PS_plot_size(int num_params
, /* I - Number of parameters */
501 param_t
*params
) /* I - Parameters */
506 if (Rotation
== 0 || Rotation
== 180)
508 PlotSize
[0] = PageWidth
;
509 PlotSize
[1] = PageLength
;
513 PlotSize
[0] = PageLength
;
514 PlotSize
[1] = PageWidth
;
519 case 1 : /* PS length ; */
520 if (Rotation
== 0 || Rotation
== 180)
522 PlotSize
[1] = 72.0f
* params
[0].value
.number
/ 1016.0f
;
523 PlotSize
[0] = 0.75f
* PlotSize
[1];
527 PlotSize
[0] = 72.0f
* params
[0].value
.number
/ 1016.0f
;
528 PlotSize
[1] = 0.75f
* PlotSize
[0];
533 case 2 : /* PS length, width ; */
535 * Unfortunately, it appears that NO application correctly
536 * sends a two-argument PS command as documented in the
537 * HP-GL/2 Reference Manual from HP. Instead, applications
538 * send the width before the length, which causes all sorts
539 * of problems when scaling.
541 * Rather than fight it, we now look for them as width,length
542 * instead of length,width.
544 * Don't like it? Send mail to the folks that make Ideas, Pro/E,
548 if (Rotation
== 0 || Rotation
== 180)
550 PlotSize
[0] = 72.0f
* params
[0].value
.number
/ 1016.0f
;
551 PlotSize
[1] = 72.0f
* params
[1].value
.number
/ 1016.0f
;
555 PlotSize
[0] = 72.0f
* params
[1].value
.number
/ 1016.0f
;
556 PlotSize
[1] = 72.0f
* params
[0].value
.number
/ 1016.0f
;
564 * This is required for buggy files that don't set the input window.
567 IP_input_absolute(0, NULL
);
572 * 'RO_rotate()' - Rotate the plot.
576 RO_rotate(int num_params
, /* I - Number of parameters */
577 param_t
*params
) /* I - Parameters */
582 Rotation
= (int)params
[0].value
.number
;
589 * 'RP_replot()' - Replot the current page.
593 RP_replot(int num_params
, /* I - Number of parameters */
594 param_t
*params
) /* I - Parameters */
602 * 'SC_scale()' - Set user-defined scaling.
606 SC_scale(int num_params
, /* I - Number of parameters */
607 param_t
*params
) /* I - Parameters */
617 else if (num_params
> 3)
619 Scaling1
[0] = params
[0].value
.number
;
620 Scaling2
[0] = params
[1].value
.number
;
621 Scaling1
[1] = params
[2].value
.number
;
622 Scaling2
[1] = params
[3].value
.number
;
625 ScalingType
= (int)params
[4].value
.number
;
635 * End of "$Id: hpgl-config.c 6649 2007-07-11 21:46:42Z mike $".