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