]>
git.ipfire.org Git - thirdparty/cups.git/blob - filter/hpgl-char.c
2 * "$Id: hpgl-char.c 6649 2007-07-11 21:46:42Z mike $"
4 * HP-GL/2 character processing 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 * AD_define_alternate() - Define the alternate font.
20 * CF_character_fill() - Set whether or not to fill or outline
22 * CP_character_plot() - Move the current pen position for the given
23 * number of columns and rows.
24 * DI_absolute_direction() - Set the direction vector for text.
25 * DR_relative_direction() - Set the relative direction vector for text.
26 * DT_define_label_term() - Set the label string terminator.
27 * DV_define_variable_path() - Define a path for text.
28 * ES_extra_space() - Set extra spacing (kerning) between characters.
29 * LB_label() - Display a label string.
30 * LO_label_origin() - Set the label origin.
31 * SA_select_alternate() - Select the alternate font.
32 * SD_define_standard() - Define the standard font...
33 * SI_absolute_size() - Set the absolute size of text.
34 * SL_character_slant() - Set the slant of text.
35 * SR_relative_size() - Set the relative size of text.
36 * SS_select_standard() - Select the standard font for text.
37 * TD_transparent_data() - Send transparent print data.
42 * Include necessary headers...
49 * 'define_font()' - Define the specified font...
53 define_font(int f
) /* I - Font number */
55 font_t
*font
; /* Font */
56 const char *fstring
; /* Font string - SA or SS */
57 float xform
[2][2]; /* Transform matrix */
61 * Get the correct font data...
66 font
= &AlternateFont
;
76 * Compute the font matrix, accounting for any rotation...
83 xform
[0][0] = font
->xpitch
* font
->x
* font
->height
;
84 xform
[0][1] = font
->xpitch
* font
->y
* font
->height
;
85 xform
[1][0] = -font
->y
* font
->height
;
86 xform
[1][1] = font
->x
* font
->height
;
90 xform
[0][0] = -font
->xpitch
* font
->y
* font
->height
;
91 xform
[0][1] = font
->xpitch
* font
->x
* font
->height
;
92 xform
[1][0] = -font
->x
* font
->height
;
93 xform
[1][1] = -font
->y
* font
->height
;
97 xform
[0][0] = -font
->xpitch
* font
->x
* font
->height
;
98 xform
[0][1] = -font
->xpitch
* font
->y
* font
->height
;
99 xform
[1][0] = font
->y
* font
->height
;
100 xform
[1][1] = -font
->x
* font
->height
;
104 xform
[0][0] = font
->xpitch
* font
->y
* font
->height
;
105 xform
[0][1] = -font
->xpitch
* font
->x
* font
->height
;
106 xform
[1][0] = font
->x
* font
->height
;
107 xform
[1][1] = font
->y
* font
->height
;
112 * Send the font definition...
116 " /%s%s%s%s findfont\n"
117 " [ %f %f %f %f 0.0 0.0 ] makefont\n"
120 fstring
, font
->spacing
? "Helvetica" : "Courier",
121 (font
->weight
> 0 || font
->posture
) ? "-" : "",
122 font
->weight
> 0 ? "Bold" : "",
123 font
->posture
? "Oblique" : "",
124 xform
[0][0], xform
[0][1], xform
[1][0], xform
[1][1]);
127 printf("%s\n", fstring
);
132 * 'AD_define_alternate()' - Define the alternate font.
136 AD_define_alternate(int num_params
, /* I - Number of parameters */
137 param_t
*params
) /* I - Parameters */
139 int i
; /* Looping var */
143 * Set default font attributes...
146 AlternateFont
.symbol_set
= 277;
147 AlternateFont
.spacing
= 0;
148 AlternateFont
.pitch
= 9;
149 AlternateFont
.height
= 11.5;
150 AlternateFont
.posture
= 0;
151 AlternateFont
.weight
= 0;
152 AlternateFont
.typeface
= 48;
153 AlternateFont
.x
= 1.0;
154 AlternateFont
.y
= 0.0;
157 * Loop through parameter value pairs...
160 for (i
= 0; i
< (num_params
- 1); i
+= 2)
161 switch ((int)params
[i
].value
.number
)
163 case 1 : /* Symbol Set */
164 AlternateFont
.symbol_set
= (int)params
[i
+ 1].value
.number
;
166 case 2 : /* Font Spacing */
167 AlternateFont
.spacing
= (int)params
[i
+ 1].value
.number
;
170 AlternateFont
.pitch
= params
[i
+ 1].value
.number
;
172 case 4 : /* Height */
173 AlternateFont
.height
= params
[i
+ 1].value
.number
;
175 case 5 : /* Posture */
176 AlternateFont
.posture
= (int)params
[i
+ 1].value
.number
;
178 case 6 : /* Stroke Weight */
179 AlternateFont
.weight
= (int)params
[i
+ 1].value
.number
;
181 case 7 : /* Typeface */
182 AlternateFont
.typeface
= (int)params
[i
+ 1].value
.number
;
186 if (AlternateFont
.spacing
)
189 * Set proportional spacing font...
192 AlternateFont
.xpitch
= 1.0f
;
197 * Set fixed-spaced font...
200 AlternateFont
.xpitch
= 0.6f
* AlternateFont
.height
/ AlternateFont
.pitch
;
210 for (i
= 0; i
< num_params
; i
++)
212 printf(",%g", params
[i
].value
.number
);
214 printf("%g", params
[i
].value
.number
);
220 CharHeight
[1] = AlternateFont
.height
;
225 * 'CF_character_fill()' - Set whether or not to fill or outline characters.
229 CF_character_fill(int num_params
, /* I - Number of parameters */
230 param_t
*params
) /* I - Parameters */
235 CharFillMode
= (int)params
[0].value
.number
;
238 CharPen
= (int)params
[1].value
.number
;
243 * 'CP_character_plot()' - Move the current pen position for the given number
244 * of columns and rows.
248 CP_character_plot(int num_params
,
257 PenPosition
[0] += params
[0].value
.number
* 1.2f
/ CharHeight
[CharFont
];
258 PenPosition
[1] += params
[1].value
.number
* CharHeight
[CharFont
];
261 PenPosition
[0] -= params
[1].value
.number
* 1.2f
/ CharHeight
[CharFont
];
262 PenPosition
[1] += params
[0].value
.number
* CharHeight
[CharFont
];
265 PenPosition
[0] -= params
[0].value
.number
* 1.2f
/ CharHeight
[CharFont
];
266 PenPosition
[1] -= params
[1].value
.number
* CharHeight
[CharFont
];
269 PenPosition
[0] += params
[1].value
.number
* 1.2f
/ CharHeight
[CharFont
];
270 PenPosition
[1] -= params
[0].value
.number
* CharHeight
[CharFont
];
277 * 'DI_absolute_direction()' - Set the direction vector for text.
281 DI_absolute_direction(int num_params
, /* I - Number of parameters */
282 param_t
*params
) /* I - Parameters */
289 AlternateFont
.x
= params
[0].value
.number
;
290 AlternateFont
.y
= params
[1].value
.number
;
294 StandardFont
.x
= params
[0].value
.number
;
295 StandardFont
.y
= params
[1].value
.number
;
300 printf("%% DI%g,%g\n", params
[0].value
.number
, params
[1].value
.number
);
302 define_font(CharFont
);
308 * 'DR_relative_direction()' - Set the relative direction vector for text.
312 DR_relative_direction(int num_params
, /* I - Number of parameters */
313 param_t
*params
) /* I - Parameters */
321 * 'DT_define_label_term()' - Set the label string terminator.
325 DT_define_label_term(int num_params
, /* I - Number of parameters */
326 param_t
*params
) /* I - Parameters */
329 StringTerminator
= '\003';
331 StringTerminator
= params
[0].value
.string
[0];
336 * 'DV_define_variable_path()' - Define a path for text.
340 DV_define_variable_path(int num_params
, /* I - Number of parameters */
341 param_t
*params
) /* I - Parameters */
349 * 'ES_extra_space()' - Set extra spacing (kerning) between characters.
353 ES_extra_space(int num_params
, /* I - Number of parameters */
354 param_t
*params
) /* I - Parameters */
362 * 'LB_label()' - Display a label string.
366 LB_label(int num_params
, /* I - Number of parameters */
367 param_t
*params
) /* I - Parameters */
369 char *s
; /* Pointer into string */
376 Outputf("currentmiterlimit 1.0 setmiterlimit\n");
378 Outputf("%.3f %.3f MO\n", PenPosition
[0], PenPosition
[1]);
382 for (s
= params
[0].value
.string
; *s
!= '\0'; s
++)
383 if (strchr("()\\", *s
) != NULL
)
387 Outputf(") true charpath\n");
389 if (CharFillMode
!= 1)
391 if (CharFillMode
== 1 || CharFillMode
== 3)
393 Outputf("%.3f %.3f %.3f %.2f SP ST\n", Pens
[CharPen
].rgb
[0],
394 Pens
[CharPen
].rgb
[CharPen
], Pens
[CharPen
].rgb
[2],
395 Pens
[CharPen
].width
* PenScaling
);
396 Outputf("%.3f %.3f %.3f %.2f SP\n", Pens
[PenNumber
].rgb
[0],
397 Pens
[PenNumber
].rgb
[1], Pens
[PenNumber
].rgb
[2],
398 Pens
[PenNumber
].width
* PenScaling
);
401 Outputf("setmiterlimit\n");
402 Outputf("grestore\n");
407 * 'LO_label_origin()' - Set the label origin.
411 LO_label_origin(int num_params
, /* I - Number of parameters */
412 param_t
*params
) /* I - Parameters */
420 * 'SA_select_alternate()' - Select the alternate font.
424 SA_select_alternate(int num_params
, /* I - Number of parameters */
425 param_t
*params
) /* I - Parameters */
438 * 'SD_define_standard()' - Define the standard font...
442 SD_define_standard(int num_params
, /* I - Number of parameters */
443 param_t
*params
) /* I - Parameters */
445 int i
; /* Looping var */
449 * Set default font attributes...
452 StandardFont
.symbol_set
= 277;
453 StandardFont
.spacing
= 0;
454 StandardFont
.pitch
= 9;
455 StandardFont
.height
= 11.5;
456 StandardFont
.posture
= 0;
457 StandardFont
.weight
= 0;
458 StandardFont
.typeface
= 48;
459 StandardFont
.x
= 1.0;
460 StandardFont
.y
= 0.0;
463 * Loop through parameter value pairs...
466 for (i
= 0; i
< (num_params
- 1); i
+= 2)
467 switch ((int)params
[i
].value
.number
)
469 case 1 : /* Symbol Set */
470 StandardFont
.symbol_set
= (int)params
[i
+ 1].value
.number
;
472 case 2 : /* Font Spacing */
473 StandardFont
.spacing
= (int)params
[i
+ 1].value
.number
;
476 StandardFont
.pitch
= params
[i
+ 1].value
.number
;
478 case 4 : /* Height */
479 StandardFont
.height
= params
[i
+ 1].value
.number
;
481 case 5 : /* Posture */
482 StandardFont
.posture
= (int)params
[i
+ 1].value
.number
;
484 case 6 : /* Stroke Weight */
485 StandardFont
.weight
= (int)params
[i
+ 1].value
.number
;
487 case 7 : /* Typeface */
488 StandardFont
.typeface
= (int)params
[i
+ 1].value
.number
;
492 if (StandardFont
.spacing
|| StandardFont
.pitch
<= 0.0)
495 * Set proportional spacing font...
498 StandardFont
.xpitch
= 1.0f
;
503 * Set fixed-spaced font...
506 StandardFont
.xpitch
= 0.6f
* StandardFont
.height
/ StandardFont
.pitch
;
516 for (i
= 0; i
< num_params
; i
++)
518 printf(",%g", params
[i
].value
.number
);
520 printf("%g", params
[i
].value
.number
);
526 CharHeight
[0] = StandardFont
.height
;
531 * 'SI_absolute_size()' - Set the absolute size of text.
535 SI_absolute_size(int num_params
, /* I - Number of parameters */
536 param_t
*params
) /* I - Parameters */
538 float xsize
, ysize
; /* Font size... */
545 * The "SI" values are supposed to be cm, but they appear to be inches
546 * when tested on real HP devices...
549 xsize
= params
[0].value
.number
* 72.0f
;
550 ysize
= params
[1].value
.number
* 72.0f
* 0.6f
;
554 AlternateFont
.xpitch
= xsize
/ ysize
;
555 AlternateFont
.height
= ysize
;
559 StandardFont
.xpitch
= xsize
/ ysize
;
560 StandardFont
.height
= ysize
;
565 printf("%% SI%g,%g\n", params
[0].value
.number
, params
[1].value
.number
);
567 define_font(CharFont
);
573 * 'SL_character_slant()' - Set the slant of text.
577 SL_character_slant(int num_params
, /* I - Number of parameters */
578 param_t
*params
) /* I - Parameters */
586 * 'SR_relative_size()' - Set the relative size of text.
590 SR_relative_size(int num_params
, /* I - Number of parameters */
591 param_t
*params
) /* I - Parameters */
599 * 'SS_select_standard()' - Select the standard font for text.
603 SS_select_standard(int num_params
, /* I - Number of parameters */
604 param_t
*params
) /* I - Parameters */
617 * 'TD_transparent_data()' - Send transparent print data.
621 TD_transparent_data(int num_params
, /* I - Number of parameters */
622 param_t
*params
) /* I - Parameters */
630 * End of "$Id: hpgl-char.c 6649 2007-07-11 21:46:42Z mike $".