]>
git.ipfire.org Git - thirdparty/cups.git/blob - filter/hpgl-char.c
2 * "$Id: hpgl-char.c 4494 2005-02-18 02:18:11Z mike $"
4 * HP-GL/2 character processing for the Common UNIX Printing System (CUPS).
6 * Copyright 1993-2005 by Easy Software Products.
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
15 * Attn: CUPS Licensing Information
16 * Easy Software Products
17 * 44141 Airport View Drive, Suite 204
18 * Hollywood, Maryland 20636 USA
20 * Voice: (301) 373-9600
21 * EMail: cups-info@cups.org
22 * WWW: http://www.cups.org
24 * This file is subject to the Apple OS-Developed Software exception.
28 * AD_define_alternate() - Define the alternate font.
29 * CF_character_fill() - Set whether or not to fill or outline
31 * CP_character_plot() - Move the current pen position for the given
32 * number of columns and rows.
33 * DI_absolute_direction() - Set the direction vector for text.
34 * DR_relative_direction() - Set the relative direction vector for text.
35 * DT_define_label_term() - Set the label string terminator.
36 * DV_define_variable_path() - Define a path for text.
37 * ES_extra_space() - Set extra spacing (kerning) between characters.
38 * LB_label() - Display a label string.
39 * LO_label_origin() - Set the label origin.
40 * SA_select_alternate() - Select the alternate font.
41 * SD_define_standard() - Define the standard font...
42 * SI_absolute_size() - Set the absolute size of text.
43 * SL_character_slant() - Set the slant of text.
44 * SR_relative_size() - Set the relative size of text.
45 * SS_select_standard() - Select the standard font for text.
46 * TD_transparent_data() - Send transparent print data.
51 * Include necessary headers...
58 * 'define_font()' - Define the specified font...
62 define_font(int f
) /* I - Font number */
64 font_t
*font
; /* Font */
65 const char *fstring
; /* Font string - SA or SS */
66 float xform
[2][2]; /* Transform matrix */
70 * Get the correct font data...
75 font
= &AlternateFont
;
85 * Compute the font matrix, accounting for any rotation...
92 xform
[0][0] = font
->xpitch
* font
->x
* font
->height
;
93 xform
[0][1] = font
->xpitch
* font
->y
* font
->height
;
94 xform
[1][0] = -font
->y
* font
->height
;
95 xform
[1][1] = font
->x
* font
->height
;
99 xform
[0][0] = -font
->xpitch
* font
->y
* font
->height
;
100 xform
[0][1] = font
->xpitch
* font
->x
* font
->height
;
101 xform
[1][0] = -font
->x
* font
->height
;
102 xform
[1][1] = -font
->y
* font
->height
;
106 xform
[0][0] = -font
->xpitch
* font
->x
* font
->height
;
107 xform
[0][1] = -font
->xpitch
* font
->y
* font
->height
;
108 xform
[1][0] = font
->y
* font
->height
;
109 xform
[1][1] = -font
->x
* font
->height
;
113 xform
[0][0] = font
->xpitch
* font
->y
* font
->height
;
114 xform
[0][1] = -font
->xpitch
* font
->x
* font
->height
;
115 xform
[1][0] = font
->x
* font
->height
;
116 xform
[1][1] = font
->y
* font
->height
;
121 * Send the font definition...
125 " /%s%s%s%s findfont\n"
126 " [ %f %f %f %f 0.0 0.0 ] makefont\n"
129 fstring
, font
->spacing
? "Helvetica" : "Courier",
130 (font
->weight
> 0 || font
->posture
) ? "-" : "",
131 font
->weight
> 0 ? "Bold" : "",
132 font
->posture
? "Oblique" : "",
133 xform
[0][0], xform
[0][1], xform
[1][0], xform
[1][1]);
136 printf("%s\n", fstring
);
141 * 'AD_define_alternate()' - Define the alternate font.
145 AD_define_alternate(int num_params
, /* I - Number of parameters */
146 param_t
*params
) /* I - Parameters */
148 int i
; /* Looping var */
152 * Set default font attributes...
155 AlternateFont
.symbol_set
= 277;
156 AlternateFont
.spacing
= 0;
157 AlternateFont
.pitch
= 9;
158 AlternateFont
.height
= 11.5;
159 AlternateFont
.posture
= 0;
160 AlternateFont
.weight
= 0;
161 AlternateFont
.typeface
= 48;
162 AlternateFont
.x
= 1.0;
163 AlternateFont
.y
= 0.0;
166 * Loop through parameter value pairs...
169 for (i
= 0; i
< (num_params
- 1); i
+= 2)
170 switch ((int)params
[i
].value
.number
)
172 case 1 : /* Symbol Set */
173 AlternateFont
.symbol_set
= (int)params
[i
+ 1].value
.number
;
175 case 2 : /* Font Spacing */
176 AlternateFont
.spacing
= (int)params
[i
+ 1].value
.number
;
179 AlternateFont
.pitch
= params
[i
+ 1].value
.number
;
181 case 4 : /* Height */
182 AlternateFont
.height
= params
[i
+ 1].value
.number
;
184 case 5 : /* Posture */
185 AlternateFont
.posture
= (int)params
[i
+ 1].value
.number
;
187 case 6 : /* Stroke Weight */
188 AlternateFont
.weight
= (int)params
[i
+ 1].value
.number
;
190 case 7 : /* Typeface */
191 AlternateFont
.typeface
= (int)params
[i
+ 1].value
.number
;
195 if (AlternateFont
.spacing
)
198 * Set proportional spacing font...
201 AlternateFont
.xpitch
= 1.0f
;
206 * Set fixed-spaced font...
209 AlternateFont
.xpitch
= 0.6f
* AlternateFont
.height
/ AlternateFont
.pitch
;
219 for (i
= 0; i
< num_params
; i
++)
221 printf(",%g", params
[i
].value
.number
);
223 printf("%g", params
[i
].value
.number
);
229 CharHeight
[1] = AlternateFont
.height
;
234 * 'CF_character_fill()' - Set whether or not to fill or outline characters.
238 CF_character_fill(int num_params
, /* I - Number of parameters */
239 param_t
*params
) /* I - Parameters */
244 CharFillMode
= (int)params
[0].value
.number
;
247 CharPen
= (int)params
[1].value
.number
;
252 * 'CP_character_plot()' - Move the current pen position for the given number
253 * of columns and rows.
257 CP_character_plot(int num_params
,
266 PenPosition
[0] += params
[0].value
.number
* 1.2f
/ CharHeight
[CharFont
];
267 PenPosition
[1] += params
[1].value
.number
* CharHeight
[CharFont
];
270 PenPosition
[0] -= params
[1].value
.number
* 1.2f
/ CharHeight
[CharFont
];
271 PenPosition
[1] += params
[0].value
.number
* CharHeight
[CharFont
];
274 PenPosition
[0] -= params
[0].value
.number
* 1.2f
/ CharHeight
[CharFont
];
275 PenPosition
[1] -= params
[1].value
.number
* CharHeight
[CharFont
];
278 PenPosition
[0] += params
[1].value
.number
* 1.2f
/ CharHeight
[CharFont
];
279 PenPosition
[1] -= params
[0].value
.number
* CharHeight
[CharFont
];
286 * 'DI_absolute_direction()' - Set the direction vector for text.
290 DI_absolute_direction(int num_params
, /* I - Number of parameters */
291 param_t
*params
) /* I - Parameters */
298 AlternateFont
.x
= params
[0].value
.number
;
299 AlternateFont
.y
= params
[1].value
.number
;
303 StandardFont
.x
= params
[0].value
.number
;
304 StandardFont
.y
= params
[1].value
.number
;
309 printf("%% DI%g,%g\n", params
[0].value
.number
, params
[1].value
.number
);
311 define_font(CharFont
);
317 * 'DR_relative_direction()' - Set the relative direction vector for text.
321 DR_relative_direction(int num_params
, /* I - Number of parameters */
322 param_t
*params
) /* I - Parameters */
330 * 'DT_define_label_term()' - Set the label string terminator.
334 DT_define_label_term(int num_params
, /* I - Number of parameters */
335 param_t
*params
) /* I - Parameters */
338 StringTerminator
= '\003';
340 StringTerminator
= params
[0].value
.string
[0];
345 * 'DV_define_variable_path()' - Define a path for text.
349 DV_define_variable_path(int num_params
, /* I - Number of parameters */
350 param_t
*params
) /* I - Parameters */
358 * 'ES_extra_space()' - Set extra spacing (kerning) between characters.
362 ES_extra_space(int num_params
, /* I - Number of parameters */
363 param_t
*params
) /* I - Parameters */
371 * 'LB_label()' - Display a label string.
375 LB_label(int num_params
, /* I - Number of parameters */
376 param_t
*params
) /* I - Parameters */
378 char *s
; /* Pointer into string */
385 Outputf("currentmiterlimit 1.0 setmiterlimit\n");
387 Outputf("%.3f %.3f MO\n", PenPosition
[0], PenPosition
[1]);
391 for (s
= params
[0].value
.string
; *s
!= '\0'; s
++)
392 if (strchr("()\\", *s
) != NULL
)
396 Outputf(") true charpath\n");
398 if (CharFillMode
!= 1)
400 if (CharFillMode
== 1 || CharFillMode
== 3)
402 Outputf("%.3f %.3f %.3f %.2f SP ST\n", Pens
[CharPen
].rgb
[0],
403 Pens
[CharPen
].rgb
[CharPen
], Pens
[CharPen
].rgb
[2],
404 Pens
[CharPen
].width
* PenScaling
);
405 Outputf("%.3f %.3f %.3f %.2f SP\n", Pens
[PenNumber
].rgb
[0],
406 Pens
[PenNumber
].rgb
[1], Pens
[PenNumber
].rgb
[2],
407 Pens
[PenNumber
].width
* PenScaling
);
410 Outputf("setmiterlimit\n");
411 Outputf("grestore\n");
416 * 'LO_label_origin()' - Set the label origin.
420 LO_label_origin(int num_params
, /* I - Number of parameters */
421 param_t
*params
) /* I - Parameters */
429 * 'SA_select_alternate()' - Select the alternate font.
433 SA_select_alternate(int num_params
, /* I - Number of parameters */
434 param_t
*params
) /* I - Parameters */
447 * 'SD_define_standard()' - Define the standard font...
451 SD_define_standard(int num_params
, /* I - Number of parameters */
452 param_t
*params
) /* I - Parameters */
454 int i
; /* Looping var */
458 * Set default font attributes...
461 StandardFont
.symbol_set
= 277;
462 StandardFont
.spacing
= 0;
463 StandardFont
.pitch
= 9;
464 StandardFont
.height
= 11.5;
465 StandardFont
.posture
= 0;
466 StandardFont
.weight
= 0;
467 StandardFont
.typeface
= 48;
468 StandardFont
.x
= 1.0;
469 StandardFont
.y
= 0.0;
472 * Loop through parameter value pairs...
475 for (i
= 0; i
< (num_params
- 1); i
+= 2)
476 switch ((int)params
[i
].value
.number
)
478 case 1 : /* Symbol Set */
479 StandardFont
.symbol_set
= (int)params
[i
+ 1].value
.number
;
481 case 2 : /* Font Spacing */
482 StandardFont
.spacing
= (int)params
[i
+ 1].value
.number
;
485 StandardFont
.pitch
= params
[i
+ 1].value
.number
;
487 case 4 : /* Height */
488 StandardFont
.height
= params
[i
+ 1].value
.number
;
490 case 5 : /* Posture */
491 StandardFont
.posture
= (int)params
[i
+ 1].value
.number
;
493 case 6 : /* Stroke Weight */
494 StandardFont
.weight
= (int)params
[i
+ 1].value
.number
;
496 case 7 : /* Typeface */
497 StandardFont
.typeface
= (int)params
[i
+ 1].value
.number
;
501 if (StandardFont
.spacing
|| StandardFont
.pitch
<= 0.0)
504 * Set proportional spacing font...
507 StandardFont
.xpitch
= 1.0f
;
512 * Set fixed-spaced font...
515 StandardFont
.xpitch
= 0.6f
* StandardFont
.height
/ StandardFont
.pitch
;
525 for (i
= 0; i
< num_params
; i
++)
527 printf(",%g", params
[i
].value
.number
);
529 printf("%g", params
[i
].value
.number
);
535 CharHeight
[0] = StandardFont
.height
;
540 * 'SI_absolute_size()' - Set the absolute size of text.
544 SI_absolute_size(int num_params
, /* I - Number of parameters */
545 param_t
*params
) /* I - Parameters */
547 float xsize
, ysize
; /* Font size... */
554 * The "SI" values are supposed to be cm, but they appear to be inches
555 * when tested on real HP devices...
558 xsize
= params
[0].value
.number
* 72.0f
;
559 ysize
= params
[1].value
.number
* 72.0f
* 0.6f
;
563 AlternateFont
.xpitch
= xsize
/ ysize
;
564 AlternateFont
.height
= ysize
;
568 StandardFont
.xpitch
= xsize
/ ysize
;
569 StandardFont
.height
= ysize
;
574 printf("%% SI%g,%g\n", params
[0].value
.number
, params
[1].value
.number
);
576 define_font(CharFont
);
582 * 'SL_character_slant()' - Set the slant of text.
586 SL_character_slant(int num_params
, /* I - Number of parameters */
587 param_t
*params
) /* I - Parameters */
595 * 'SR_relative_size()' - Set the relative size of text.
599 SR_relative_size(int num_params
, /* I - Number of parameters */
600 param_t
*params
) /* I - Parameters */
608 * 'SS_select_standard()' - Select the standard font for text.
612 SS_select_standard(int num_params
, /* I - Number of parameters */
613 param_t
*params
) /* I - Parameters */
626 * 'TD_transparent_data()' - Send transparent print data.
630 TD_transparent_data(int num_params
, /* I - Number of parameters */
631 param_t
*params
) /* I - Parameters */
639 * End of "$Id: hpgl-char.c 4494 2005-02-18 02:18:11Z mike $".