]> git.ipfire.org Git - thirdparty/cups.git/blame - filter/hpgl-char.c
Copyright updates...
[thirdparty/cups.git] / filter / hpgl-char.c
CommitLineData
898749d4 1/*
71649dc9 2 * "$Id: hpgl-char.c,v 1.19 2004/02/25 20:14:51 mike Exp $"
898749d4 3 *
58ec2a95 4 * HP-GL/2 character processing for the Common UNIX Printing System (CUPS).
898749d4 5 *
71649dc9 6 * Copyright 1993-2004 by Easy Software Products.
898749d4 7 *
58ec2a95 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:
898749d4 14 *
58ec2a95 15 * Attn: CUPS Licensing Information
16 * Easy Software Products
17 * 44141 Airport View Drive, Suite 204
18 * Hollywood, Maryland 20636-3111 USA
297b9b4d 19 *
58ec2a95 20 * Voice: (301) 373-9603
21 * EMail: cups-info@cups.org
22 * WWW: http://www.cups.org
297b9b4d 23 *
34410ef2 24 * This file is subject to the Apple OS-Developed Software exception.
25 *
58ec2a95 26 * Contents:
898749d4 27 *
f6bdbd14 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.
e63a3a10 47 *
898749d4 48 */
49
50/*
51 * Include necessary headers...
52 */
53
58ec2a95 54#include "hpgltops.h"
898749d4 55
56
e63a3a10 57/*
58 * 'define_font()' - Define the specified font...
59 */
60
61void
62define_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
0bc94e3a 140/*
141 * 'AD_define_alternate()' - Define the alternate font.
142 */
143
898749d4 144void
0bc94e3a 145AD_define_alternate(int num_params, /* I - Number of parameters */
146 param_t *params) /* I - Parameters */
898749d4 147{
0bc94e3a 148 int i; /* Looping var */
0bc94e3a 149
898749d4 150
0bc94e3a 151 /*
152 * Set default font attributes...
153 */
898749d4 154
e63a3a10 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;
898749d4 164
0bc94e3a 165 /*
166 * Loop through parameter value pairs...
167 */
168
898749d4 169 for (i = 0; i < (num_params - 1); i += 2)
170 switch ((int)params[i].value.number)
171 {
e63a3a10 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 */
37cb600a 182 AlternateFont.height = params[i + 1].value.number;
898749d4 183 break;
e63a3a10 184 case 5 : /* Posture */
37cb600a 185 AlternateFont.posture = (int)params[i + 1].value.number;
898749d4 186 break;
e63a3a10 187 case 6 : /* Stroke Weight */
37cb600a 188 AlternateFont.weight = (int)params[i + 1].value.number;
898749d4 189 break;
e63a3a10 190 case 7 : /* Typeface */
37cb600a 191 AlternateFont.typeface = (int)params[i + 1].value.number;
898749d4 192 break;
0bc94e3a 193 }
194
e63a3a10 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
0bc94e3a 212 /*
213 * Define the font...
214 */
898749d4 215
37cb600a 216 if (PageDirty)
e63a3a10 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 }
37cb600a 228
229 CharHeight[1] = AlternateFont.height;
898749d4 230}
231
232
0bc94e3a 233/*
234 * 'CF_character_fill()' - Set whether or not to fill or outline characters.
235 */
236
898749d4 237void
0bc94e3a 238CF_character_fill(int num_params, /* I - Number of parameters */
239 param_t *params) /* I - Parameters */
898749d4 240{
241 if (num_params == 0)
242 CharFillMode = 0;
243 else
98dd54b9 244 CharFillMode = (int)params[0].value.number;
898749d4 245
246 if (num_params == 2)
98dd54b9 247 CharPen = (int)params[1].value.number;
898749d4 248}
249
250
0bc94e3a 251/*
252 * 'CP_character_plot()' - Move the current pen position for the given number
253 * of columns and rows.
254 */
255
898749d4 256void
0bc94e3a 257CP_character_plot(int num_params,
258 param_t *params)
898749d4 259{
260 if (num_params < 2)
261 return;
262
263 switch (Rotation)
264 {
265 case 0:
98dd54b9 266 PenPosition[0] += params[0].value.number * 1.2f / CharHeight[CharFont];
898749d4 267 PenPosition[1] += params[1].value.number * CharHeight[CharFont];
268 break;
269 case 90:
98dd54b9 270 PenPosition[0] -= params[1].value.number * 1.2f / CharHeight[CharFont];
898749d4 271 PenPosition[1] += params[0].value.number * CharHeight[CharFont];
272 break;
273 case 180:
98dd54b9 274 PenPosition[0] -= params[0].value.number * 1.2f / CharHeight[CharFont];
898749d4 275 PenPosition[1] -= params[1].value.number * CharHeight[CharFont];
276 break;
277 case 270:
98dd54b9 278 PenPosition[0] += params[1].value.number * 1.2f / CharHeight[CharFont];
898749d4 279 PenPosition[1] -= params[0].value.number * CharHeight[CharFont];
280 break;
0bc94e3a 281 }
898749d4 282}
283
284
0bc94e3a 285/*
286 * 'DI_absolute_direction()' - Set the direction vector for text.
287 */
288
898749d4 289void
0bc94e3a 290DI_absolute_direction(int num_params, /* I - Number of parameters */
291 param_t *params) /* I - Parameters */
898749d4 292{
e63a3a10 293 if (num_params != 2)
294 return;
295
37cb600a 296 if (CharFont)
297 {
e63a3a10 298 AlternateFont.x = params[0].value.number;
299 AlternateFont.y = params[1].value.number;
37cb600a 300 }
301 else
302 {
e63a3a10 303 StandardFont.x = params[0].value.number;
304 StandardFont.y = params[1].value.number;
305 }
37cb600a 306
e63a3a10 307 if (PageDirty)
308 {
309 printf("%% DI%g,%g\n", params[0].value.number, params[1].value.number);
310
311 define_font(CharFont);
37cb600a 312 }
898749d4 313}
314
315
0bc94e3a 316/*
317 * 'DR_relative_direction()' - Set the relative direction vector for text.
318 */
319
898749d4 320void
0bc94e3a 321DR_relative_direction(int num_params, /* I - Number of parameters */
322 param_t *params) /* I - Parameters */
898749d4 323{
0bc94e3a 324 (void)num_params;
325 (void)params;
898749d4 326}
327
328
0bc94e3a 329/*
330 * 'DT_define_label_term()' - Set the label string terminator.
331 */
332
898749d4 333void
0bc94e3a 334DT_define_label_term(int num_params, /* I - Number of parameters */
335 param_t *params) /* I - Parameters */
898749d4 336{
337 if (num_params == 0)
338 StringTerminator = '\003';
339 else
340 StringTerminator = params[0].value.string[0];
341}
342
343
0bc94e3a 344/*
345 * 'DV_define_variable_path()' - Define a path for text.
346 */
347
898749d4 348void
0bc94e3a 349DV_define_variable_path(int num_params, /* I - Number of parameters */
350 param_t *params) /* I - Parameters */
898749d4 351{
0bc94e3a 352 (void)num_params;
353 (void)params;
898749d4 354}
355
356
0bc94e3a 357/*
358 * 'ES_extra_space()' - Set extra spacing (kerning) between characters.
359 */
360
898749d4 361void
0bc94e3a 362ES_extra_space(int num_params, /* I - Number of parameters */
363 param_t *params) /* I - Parameters */
898749d4 364{
0bc94e3a 365 (void)num_params;
366 (void)params;
898749d4 367}
368
369
0bc94e3a 370/*
371 * 'LB_label()' - Display a label string.
372 */
373
898749d4 374void
0bc94e3a 375LB_label(int num_params, /* I - Number of parameters */
376 param_t *params) /* I - Parameters */
898749d4 377{
0bc94e3a 378 char *s; /* Pointer into string */
898749d4 379
380
381 if (num_params == 0)
382 return;
383
0bc94e3a 384 Outputf("gsave\n");
e63a3a10 385 Outputf("currentmiterlimit 1.0 setmiterlimit\n");
0bc94e3a 386 Outputf("MP\n");
387 Outputf("%.3f %.3f MO\n", PenPosition[0], PenPosition[1]);
03782c87 388 PenValid = 1;
898749d4 389
0bc94e3a 390 Outputf("(");
898749d4 391 for (s = params[0].value.string; *s != '\0'; s ++)
392 if (strchr("()\\", *s) != NULL)
0bc94e3a 393 Outputf("\\%c", *s);
898749d4 394 else
98dd54b9 395 Outputf("%c", *s);
0bc94e3a 396 Outputf(") true charpath\n");
898749d4 397
398 if (CharFillMode != 1)
0bc94e3a 399 Outputf("FI\n");
898749d4 400 if (CharFillMode == 1 || CharFillMode == 3)
48b5444b 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],
440be1ae 406 Pens[PenNumber].rgb[1], Pens[PenNumber].rgb[2],
48b5444b 407 Pens[PenNumber].width * PenScaling);
408 }
c839cbc9 409
0bc94e3a 410 Outputf("setmiterlimit\n");
411 Outputf("grestore\n");
898749d4 412}
413
414
0bc94e3a 415/*
416 * 'LO_label_origin()' - Set the label origin.
417 */
418
898749d4 419void
0bc94e3a 420LO_label_origin(int num_params, /* I - Number of parameters */
421 param_t *params) /* I - Parameters */
898749d4 422{
0bc94e3a 423 (void)num_params;
424 (void)params;
898749d4 425}
426
427
0bc94e3a 428/*
429 * 'SA_select_alternate()' - Select the alternate font.
430 */
431
898749d4 432void
0bc94e3a 433SA_select_alternate(int num_params, /* I - Number of parameters */
434 param_t *params) /* I - Parameters */
898749d4 435{
f6bdbd14 436 (void)num_params;
437 (void)params;
438
37cb600a 439 if (PageDirty)
440 puts("SA");
441
898749d4 442 CharFont = 1;
443}
444
445
0bc94e3a 446/*
447 * 'SD_define_standard()' - Define the standard font...
448 */
449
898749d4 450void
0bc94e3a 451SD_define_standard(int num_params, /* I - Number of parameters */
452 param_t *params) /* I - Parameters */
898749d4 453{
0bc94e3a 454 int i; /* Looping var */
898749d4 455
456
0bc94e3a 457 /*
458 * Set default font attributes...
459 */
460
e63a3a10 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;
898749d4 470
0bc94e3a 471 /*
472 * Loop through parameter value pairs...
473 */
474
898749d4 475 for (i = 0; i < (num_params - 1); i += 2)
476 switch ((int)params[i].value.number)
477 {
e63a3a10 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 */
37cb600a 488 StandardFont.height = params[i + 1].value.number;
898749d4 489 break;
e63a3a10 490 case 5 : /* Posture */
37cb600a 491 StandardFont.posture = (int)params[i + 1].value.number;
898749d4 492 break;
e63a3a10 493 case 6 : /* Stroke Weight */
37cb600a 494 StandardFont.weight = (int)params[i + 1].value.number;
898749d4 495 break;
e63a3a10 496 case 7 : /* Typeface */
37cb600a 497 StandardFont.typeface = (int)params[i + 1].value.number;
898749d4 498 break;
0bc94e3a 499 }
898749d4 500
e63a3a10 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
0bc94e3a 518 /*
519 * Define the font...
520 */
521
37cb600a 522 if (PageDirty)
e63a3a10 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 }
37cb600a 534
535 CharHeight[0] = StandardFont.height;
898749d4 536}
537
538
0bc94e3a 539/*
540 * 'SI_absolute_size()' - Set the absolute size of text.
541 */
542
898749d4 543void
0bc94e3a 544SI_absolute_size(int num_params, /* I - Number of parameters */
545 param_t *params) /* I - Parameters */
898749d4 546{
e63a3a10 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 }
898749d4 578}
579
580
0bc94e3a 581/*
582 * 'SL_character_slant()' - Set the slant of text.
583 */
584
898749d4 585void
0bc94e3a 586SL_character_slant(int num_params, /* I - Number of parameters */
587 param_t *params) /* I - Parameters */
898749d4 588{
0bc94e3a 589 (void)num_params;
590 (void)params;
898749d4 591}
592
593
0bc94e3a 594/*
595 * 'SR_relative_size()' - Set the relative size of text.
596 */
597
898749d4 598void
0bc94e3a 599SR_relative_size(int num_params, /* I - Number of parameters */
600 param_t *params) /* I - Parameters */
898749d4 601{
0bc94e3a 602 (void)num_params;
603 (void)params;
898749d4 604}
605
606
0bc94e3a 607/*
608 * 'SS_select_standard()' - Select the standard font for text.
609 */
610
898749d4 611void
0bc94e3a 612SS_select_standard(int num_params, /* I - Number of parameters */
613 param_t *params) /* I - Parameters */
898749d4 614{
f6bdbd14 615 (void)num_params;
616 (void)params;
617
37cb600a 618 if (PageDirty)
619 puts("SS");
620
898749d4 621 CharFont = 0;
622}
623
624
0bc94e3a 625/*
626 * 'TD_transparent_data()' - Send transparent print data.
627 */
628
898749d4 629void
0bc94e3a 630TD_transparent_data(int num_params, /* I - Number of parameters */
631 param_t *params) /* I - Parameters */
898749d4 632{
0bc94e3a 633 (void)num_params;
634 (void)params;
898749d4 635}
636
637
638/*
71649dc9 639 * End of "$Id: hpgl-char.c,v 1.19 2004/02/25 20:14:51 mike Exp $".
898749d4 640 */