]>
Commit | Line | Data |
---|---|---|
ef416fc2 | 1 | /* |
bc44d920 | 2 | * "$Id: hpgl-char.c 6649 2007-07-11 21:46:42Z mike $" |
ef416fc2 | 3 | * |
4 | * HP-GL/2 character processing 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 | * AD_define_alternate() - Define the alternate font. | |
20 | * CF_character_fill() - Set whether or not to fill or outline | |
21 | * characters. | |
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. | |
38 | * | |
39 | */ | |
40 | ||
41 | /* | |
42 | * Include necessary headers... | |
43 | */ | |
44 | ||
45 | #include "hpgltops.h" | |
46 | ||
47 | ||
48 | /* | |
49 | * 'define_font()' - Define the specified font... | |
50 | */ | |
51 | ||
52 | void | |
53 | define_font(int f) /* I - Font number */ | |
54 | { | |
55 | font_t *font; /* Font */ | |
56 | const char *fstring; /* Font string - SA or SS */ | |
57 | float xform[2][2]; /* Transform matrix */ | |
58 | ||
59 | ||
60 | /* | |
61 | * Get the correct font data... | |
62 | */ | |
63 | ||
64 | if (f) | |
65 | { | |
66 | font = &AlternateFont; | |
67 | fstring = "SA"; | |
68 | } | |
69 | else | |
70 | { | |
71 | font = &StandardFont; | |
72 | fstring = "SS"; | |
73 | } | |
74 | ||
75 | /* | |
76 | * Compute the font matrix, accounting for any rotation... | |
77 | */ | |
78 | ||
79 | switch (Rotation) | |
80 | { | |
81 | default : | |
82 | case 0 : | |
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; | |
87 | break; | |
88 | ||
89 | case 90 : | |
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; | |
94 | break; | |
95 | ||
96 | case 180 : | |
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; | |
101 | break; | |
102 | ||
103 | case 270 : | |
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; | |
108 | break; | |
109 | } | |
110 | ||
111 | /* | |
112 | * Send the font definition... | |
113 | */ | |
114 | ||
115 | printf("/%s {\n" | |
116 | " /%s%s%s%s findfont\n" | |
117 | " [ %f %f %f %f 0.0 0.0 ] makefont\n" | |
118 | " setfont\n" | |
119 | "} bind def\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]); | |
125 | ||
126 | if (f == CharFont) | |
127 | printf("%s\n", fstring); | |
128 | } | |
129 | ||
130 | ||
131 | /* | |
132 | * 'AD_define_alternate()' - Define the alternate font. | |
133 | */ | |
134 | ||
135 | void | |
136 | AD_define_alternate(int num_params, /* I - Number of parameters */ | |
137 | param_t *params) /* I - Parameters */ | |
138 | { | |
139 | int i; /* Looping var */ | |
140 | ||
141 | ||
142 | /* | |
143 | * Set default font attributes... | |
144 | */ | |
145 | ||
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; | |
155 | ||
156 | /* | |
157 | * Loop through parameter value pairs... | |
158 | */ | |
159 | ||
160 | for (i = 0; i < (num_params - 1); i += 2) | |
161 | switch ((int)params[i].value.number) | |
162 | { | |
163 | case 1 : /* Symbol Set */ | |
164 | AlternateFont.symbol_set = (int)params[i + 1].value.number; | |
165 | break; | |
166 | case 2 : /* Font Spacing */ | |
167 | AlternateFont.spacing = (int)params[i + 1].value.number; | |
168 | break; | |
169 | case 3 : /* Pitch */ | |
170 | AlternateFont.pitch = params[i + 1].value.number; | |
171 | break; | |
172 | case 4 : /* Height */ | |
173 | AlternateFont.height = params[i + 1].value.number; | |
174 | break; | |
175 | case 5 : /* Posture */ | |
176 | AlternateFont.posture = (int)params[i + 1].value.number; | |
177 | break; | |
178 | case 6 : /* Stroke Weight */ | |
179 | AlternateFont.weight = (int)params[i + 1].value.number; | |
180 | break; | |
181 | case 7 : /* Typeface */ | |
182 | AlternateFont.typeface = (int)params[i + 1].value.number; | |
183 | break; | |
184 | } | |
185 | ||
186 | if (AlternateFont.spacing) | |
187 | { | |
188 | /* | |
189 | * Set proportional spacing font... | |
190 | */ | |
191 | ||
192 | AlternateFont.xpitch = 1.0f; | |
193 | } | |
194 | else | |
195 | { | |
196 | /* | |
197 | * Set fixed-spaced font... | |
198 | */ | |
199 | ||
200 | AlternateFont.xpitch = 0.6f * AlternateFont.height / AlternateFont.pitch; | |
201 | } | |
202 | ||
203 | /* | |
204 | * Define the font... | |
205 | */ | |
206 | ||
207 | if (PageDirty) | |
208 | { | |
209 | printf("%% AD"); | |
210 | for (i = 0; i < num_params; i ++) | |
211 | if (i) | |
212 | printf(",%g", params[i].value.number); | |
213 | else | |
214 | printf("%g", params[i].value.number); | |
215 | puts(";"); | |
216 | ||
217 | define_font(1); | |
218 | } | |
219 | ||
220 | CharHeight[1] = AlternateFont.height; | |
221 | } | |
222 | ||
223 | ||
224 | /* | |
225 | * 'CF_character_fill()' - Set whether or not to fill or outline characters. | |
226 | */ | |
227 | ||
228 | void | |
229 | CF_character_fill(int num_params, /* I - Number of parameters */ | |
230 | param_t *params) /* I - Parameters */ | |
231 | { | |
232 | if (num_params == 0) | |
233 | CharFillMode = 0; | |
234 | else | |
235 | CharFillMode = (int)params[0].value.number; | |
236 | ||
237 | if (num_params == 2) | |
238 | CharPen = (int)params[1].value.number; | |
239 | } | |
240 | ||
241 | ||
242 | /* | |
243 | * 'CP_character_plot()' - Move the current pen position for the given number | |
244 | * of columns and rows. | |
245 | */ | |
246 | ||
247 | void | |
248 | CP_character_plot(int num_params, | |
249 | param_t *params) | |
250 | { | |
251 | if (num_params < 2) | |
252 | return; | |
253 | ||
254 | switch (Rotation) | |
255 | { | |
256 | case 0: | |
257 | PenPosition[0] += params[0].value.number * 1.2f / CharHeight[CharFont]; | |
258 | PenPosition[1] += params[1].value.number * CharHeight[CharFont]; | |
259 | break; | |
260 | case 90: | |
261 | PenPosition[0] -= params[1].value.number * 1.2f / CharHeight[CharFont]; | |
262 | PenPosition[1] += params[0].value.number * CharHeight[CharFont]; | |
263 | break; | |
264 | case 180: | |
265 | PenPosition[0] -= params[0].value.number * 1.2f / CharHeight[CharFont]; | |
266 | PenPosition[1] -= params[1].value.number * CharHeight[CharFont]; | |
267 | break; | |
268 | case 270: | |
269 | PenPosition[0] += params[1].value.number * 1.2f / CharHeight[CharFont]; | |
270 | PenPosition[1] -= params[0].value.number * CharHeight[CharFont]; | |
271 | break; | |
272 | } | |
273 | } | |
274 | ||
275 | ||
276 | /* | |
277 | * 'DI_absolute_direction()' - Set the direction vector for text. | |
278 | */ | |
279 | ||
280 | void | |
281 | DI_absolute_direction(int num_params, /* I - Number of parameters */ | |
282 | param_t *params) /* I - Parameters */ | |
283 | { | |
284 | if (num_params != 2) | |
285 | return; | |
286 | ||
287 | if (CharFont) | |
288 | { | |
289 | AlternateFont.x = params[0].value.number; | |
290 | AlternateFont.y = params[1].value.number; | |
291 | } | |
292 | else | |
293 | { | |
294 | StandardFont.x = params[0].value.number; | |
295 | StandardFont.y = params[1].value.number; | |
296 | } | |
297 | ||
298 | if (PageDirty) | |
299 | { | |
300 | printf("%% DI%g,%g\n", params[0].value.number, params[1].value.number); | |
301 | ||
302 | define_font(CharFont); | |
303 | } | |
304 | } | |
305 | ||
306 | ||
307 | /* | |
308 | * 'DR_relative_direction()' - Set the relative direction vector for text. | |
309 | */ | |
310 | ||
311 | void | |
312 | DR_relative_direction(int num_params, /* I - Number of parameters */ | |
313 | param_t *params) /* I - Parameters */ | |
314 | { | |
315 | (void)num_params; | |
316 | (void)params; | |
317 | } | |
318 | ||
319 | ||
320 | /* | |
321 | * 'DT_define_label_term()' - Set the label string terminator. | |
322 | */ | |
323 | ||
324 | void | |
325 | DT_define_label_term(int num_params, /* I - Number of parameters */ | |
326 | param_t *params) /* I - Parameters */ | |
327 | { | |
328 | if (num_params == 0) | |
329 | StringTerminator = '\003'; | |
330 | else | |
331 | StringTerminator = params[0].value.string[0]; | |
332 | } | |
333 | ||
334 | ||
335 | /* | |
336 | * 'DV_define_variable_path()' - Define a path for text. | |
337 | */ | |
338 | ||
339 | void | |
340 | DV_define_variable_path(int num_params, /* I - Number of parameters */ | |
341 | param_t *params) /* I - Parameters */ | |
342 | { | |
343 | (void)num_params; | |
344 | (void)params; | |
345 | } | |
346 | ||
347 | ||
348 | /* | |
349 | * 'ES_extra_space()' - Set extra spacing (kerning) between characters. | |
350 | */ | |
351 | ||
352 | void | |
353 | ES_extra_space(int num_params, /* I - Number of parameters */ | |
354 | param_t *params) /* I - Parameters */ | |
355 | { | |
356 | (void)num_params; | |
357 | (void)params; | |
358 | } | |
359 | ||
360 | ||
361 | /* | |
362 | * 'LB_label()' - Display a label string. | |
363 | */ | |
364 | ||
365 | void | |
366 | LB_label(int num_params, /* I - Number of parameters */ | |
367 | param_t *params) /* I - Parameters */ | |
368 | { | |
369 | char *s; /* Pointer into string */ | |
370 | ||
371 | ||
372 | if (num_params == 0) | |
373 | return; | |
374 | ||
375 | Outputf("gsave\n"); | |
376 | Outputf("currentmiterlimit 1.0 setmiterlimit\n"); | |
377 | Outputf("MP\n"); | |
378 | Outputf("%.3f %.3f MO\n", PenPosition[0], PenPosition[1]); | |
379 | PenValid = 1; | |
380 | ||
381 | Outputf("("); | |
382 | for (s = params[0].value.string; *s != '\0'; s ++) | |
383 | if (strchr("()\\", *s) != NULL) | |
384 | Outputf("\\%c", *s); | |
385 | else | |
386 | Outputf("%c", *s); | |
387 | Outputf(") true charpath\n"); | |
388 | ||
389 | if (CharFillMode != 1) | |
390 | Outputf("FI\n"); | |
391 | if (CharFillMode == 1 || CharFillMode == 3) | |
392 | { | |
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); | |
399 | } | |
400 | ||
401 | Outputf("setmiterlimit\n"); | |
402 | Outputf("grestore\n"); | |
403 | } | |
404 | ||
405 | ||
406 | /* | |
407 | * 'LO_label_origin()' - Set the label origin. | |
408 | */ | |
409 | ||
410 | void | |
411 | LO_label_origin(int num_params, /* I - Number of parameters */ | |
412 | param_t *params) /* I - Parameters */ | |
413 | { | |
414 | (void)num_params; | |
415 | (void)params; | |
416 | } | |
417 | ||
418 | ||
419 | /* | |
420 | * 'SA_select_alternate()' - Select the alternate font. | |
421 | */ | |
422 | ||
423 | void | |
424 | SA_select_alternate(int num_params, /* I - Number of parameters */ | |
425 | param_t *params) /* I - Parameters */ | |
426 | { | |
427 | (void)num_params; | |
428 | (void)params; | |
429 | ||
430 | if (PageDirty) | |
431 | puts("SA"); | |
432 | ||
433 | CharFont = 1; | |
434 | } | |
435 | ||
436 | ||
437 | /* | |
438 | * 'SD_define_standard()' - Define the standard font... | |
439 | */ | |
440 | ||
441 | void | |
442 | SD_define_standard(int num_params, /* I - Number of parameters */ | |
443 | param_t *params) /* I - Parameters */ | |
444 | { | |
445 | int i; /* Looping var */ | |
446 | ||
447 | ||
448 | /* | |
449 | * Set default font attributes... | |
450 | */ | |
451 | ||
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; | |
461 | ||
462 | /* | |
463 | * Loop through parameter value pairs... | |
464 | */ | |
465 | ||
466 | for (i = 0; i < (num_params - 1); i += 2) | |
467 | switch ((int)params[i].value.number) | |
468 | { | |
469 | case 1 : /* Symbol Set */ | |
470 | StandardFont.symbol_set = (int)params[i + 1].value.number; | |
471 | break; | |
472 | case 2 : /* Font Spacing */ | |
473 | StandardFont.spacing = (int)params[i + 1].value.number; | |
474 | break; | |
475 | case 3 : /* Pitch */ | |
476 | StandardFont.pitch = params[i + 1].value.number; | |
477 | break; | |
478 | case 4 : /* Height */ | |
479 | StandardFont.height = params[i + 1].value.number; | |
480 | break; | |
481 | case 5 : /* Posture */ | |
482 | StandardFont.posture = (int)params[i + 1].value.number; | |
483 | break; | |
484 | case 6 : /* Stroke Weight */ | |
485 | StandardFont.weight = (int)params[i + 1].value.number; | |
486 | break; | |
487 | case 7 : /* Typeface */ | |
488 | StandardFont.typeface = (int)params[i + 1].value.number; | |
489 | break; | |
490 | } | |
491 | ||
492 | if (StandardFont.spacing || StandardFont.pitch <= 0.0) | |
493 | { | |
494 | /* | |
495 | * Set proportional spacing font... | |
496 | */ | |
497 | ||
498 | StandardFont.xpitch = 1.0f; | |
499 | } | |
500 | else | |
501 | { | |
502 | /* | |
503 | * Set fixed-spaced font... | |
504 | */ | |
505 | ||
506 | StandardFont.xpitch = 0.6f * StandardFont.height / StandardFont.pitch; | |
507 | } | |
508 | ||
509 | /* | |
510 | * Define the font... | |
511 | */ | |
512 | ||
513 | if (PageDirty) | |
514 | { | |
515 | printf("%% SD"); | |
516 | for (i = 0; i < num_params; i ++) | |
517 | if (i) | |
518 | printf(",%g", params[i].value.number); | |
519 | else | |
520 | printf("%g", params[i].value.number); | |
521 | puts(";"); | |
522 | ||
523 | define_font(0); | |
524 | } | |
525 | ||
526 | CharHeight[0] = StandardFont.height; | |
527 | } | |
528 | ||
529 | ||
530 | /* | |
531 | * 'SI_absolute_size()' - Set the absolute size of text. | |
532 | */ | |
533 | ||
534 | void | |
535 | SI_absolute_size(int num_params, /* I - Number of parameters */ | |
536 | param_t *params) /* I - Parameters */ | |
537 | { | |
538 | float xsize, ysize; /* Font size... */ | |
539 | ||
540 | ||
541 | if (num_params != 2) | |
542 | return; | |
543 | ||
544 | /* | |
545 | * The "SI" values are supposed to be cm, but they appear to be inches | |
546 | * when tested on real HP devices... | |
547 | */ | |
548 | ||
549 | xsize = params[0].value.number * 72.0f; | |
550 | ysize = params[1].value.number * 72.0f * 0.6f; | |
551 | ||
552 | if (CharFont) | |
553 | { | |
554 | AlternateFont.xpitch = xsize / ysize; | |
555 | AlternateFont.height = ysize; | |
556 | } | |
557 | else | |
558 | { | |
559 | StandardFont.xpitch = xsize / ysize; | |
560 | StandardFont.height = ysize; | |
561 | } | |
562 | ||
563 | if (PageDirty) | |
564 | { | |
565 | printf("%% SI%g,%g\n", params[0].value.number, params[1].value.number); | |
566 | ||
567 | define_font(CharFont); | |
568 | } | |
569 | } | |
570 | ||
571 | ||
572 | /* | |
573 | * 'SL_character_slant()' - Set the slant of text. | |
574 | */ | |
575 | ||
576 | void | |
577 | SL_character_slant(int num_params, /* I - Number of parameters */ | |
578 | param_t *params) /* I - Parameters */ | |
579 | { | |
580 | (void)num_params; | |
581 | (void)params; | |
582 | } | |
583 | ||
584 | ||
585 | /* | |
586 | * 'SR_relative_size()' - Set the relative size of text. | |
587 | */ | |
588 | ||
589 | void | |
590 | SR_relative_size(int num_params, /* I - Number of parameters */ | |
591 | param_t *params) /* I - Parameters */ | |
592 | { | |
593 | (void)num_params; | |
594 | (void)params; | |
595 | } | |
596 | ||
597 | ||
598 | /* | |
599 | * 'SS_select_standard()' - Select the standard font for text. | |
600 | */ | |
601 | ||
602 | void | |
603 | SS_select_standard(int num_params, /* I - Number of parameters */ | |
604 | param_t *params) /* I - Parameters */ | |
605 | { | |
606 | (void)num_params; | |
607 | (void)params; | |
608 | ||
609 | if (PageDirty) | |
610 | puts("SS"); | |
611 | ||
612 | CharFont = 0; | |
613 | } | |
614 | ||
615 | ||
616 | /* | |
617 | * 'TD_transparent_data()' - Send transparent print data. | |
618 | */ | |
619 | ||
620 | void | |
621 | TD_transparent_data(int num_params, /* I - Number of parameters */ | |
622 | param_t *params) /* I - Parameters */ | |
623 | { | |
624 | (void)num_params; | |
625 | (void)params; | |
626 | } | |
627 | ||
628 | ||
629 | /* | |
bc44d920 | 630 | * End of "$Id: hpgl-char.c 6649 2007-07-11 21:46:42Z mike $". |
ef416fc2 | 631 | */ |