]>
Commit | Line | Data |
---|---|---|
070c29a1 | 1 | /* |
da275f55 | 2 | * "$Id: texttops.c,v 1.34.2.13 2004/02/25 20:01:37 mike Exp $" |
070c29a1 | 3 | * |
e2a47002 | 4 | * Text to PostScript filter for the Common UNIX Printing System (CUPS). |
070c29a1 | 5 | * |
1d9595ab | 6 | * Copyright 1993-2003 by Easy Software Products. |
070c29a1 | 7 | * |
e2a47002 | 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: | |
070c29a1 | 14 | * |
e2a47002 | 15 | * Attn: CUPS Licensing Information |
16 | * Easy Software Products | |
58ec2a95 | 17 | * 44141 Airport View Drive, Suite 204 |
e2a47002 | 18 | * Hollywood, Maryland 20636-3111 USA |
77bdfb41 | 19 | * |
e2a47002 | 20 | * Voice: (301) 373-9603 |
21 | * EMail: cups-info@cups.org | |
22 | * WWW: http://www.cups.org | |
57945030 | 23 | * |
dab1a4d8 | 24 | * This file is subject to the Apple OS-Developed Software exception. |
25 | * | |
e2a47002 | 26 | * Contents: |
070c29a1 | 27 | * |
2d35d8ee | 28 | * main() - Main entry for text to PostScript filter. |
29 | * WriteEpilogue() - Write the PostScript file epilogue. | |
30 | * WritePage() - Write a page of text. | |
31 | * WriteProlog() - Write the PostScript file prolog with options. | |
32 | * write_line() - Write a row of text. | |
33 | * write_string() - Write a string of text. | |
070c29a1 | 34 | */ |
35 | ||
36 | /* | |
37 | * Include necessary headers... | |
38 | */ | |
39 | ||
2d35d8ee | 40 | #include "textcommon.h" |
070c29a1 | 41 | |
42 | ||
43 | /* | |
44 | * Globals... | |
45 | */ | |
46 | ||
3b9a00b0 | 47 | char *Glyphs[65536]; /* PostScript glyphs for Unicode */ |
48 | int NumFonts; /* Number of fonts to use */ | |
49 | char *Fonts[256][4]; /* Fonts to use */ | |
50 | unsigned short Chars[65536]; /* 0xffcc (ff = font, cc = char) */ | |
51 | unsigned short Codes[65536]; /* Unicode glyph mapping to fonts */ | |
52 | int Widths[256]; /* Widths of each font */ | |
53 | int Directions[256];/* Text directions for each font */ | |
54 | ||
e2a47002 | 55 | |
56 | /* | |
57 | * Local functions... | |
58 | */ | |
59 | ||
58ec2a95 | 60 | static void write_line(int row, lchar_t *line); |
58ec2a95 | 61 | static void write_string(int col, int row, int len, lchar_t *s); |
b5cb0608 | 62 | static void write_text(const char *s); |
58ec2a95 | 63 | |
64 | ||
65 | /* | |
2d35d8ee | 66 | * 'main()' - Main entry for text to PostScript filter. |
77dbfbdc | 67 | */ |
68 | ||
2d35d8ee | 69 | int /* O - Exit status */ |
70 | main(int argc, /* I - Number of command-line arguments */ | |
71 | char *argv[]) /* I - Command-line arguments */ | |
77dbfbdc | 72 | { |
2d35d8ee | 73 | return (TextMain("texttops", argc, argv)); |
77dbfbdc | 74 | } |
e2a47002 | 75 | |
e2a47002 | 76 | |
77dbfbdc | 77 | /* |
2d35d8ee | 78 | * 'WriteEpilogue()' - Write the PostScript file epilogue. |
77dbfbdc | 79 | */ |
e2a47002 | 80 | |
2d35d8ee | 81 | void |
82 | WriteEpilogue(void) | |
77dbfbdc | 83 | { |
415199da | 84 | puts("%%Trailer"); |
77dbfbdc | 85 | printf("%%%%Pages: %d\n", NumPages); |
86 | puts("%%EOF"); | |
e2a47002 | 87 | |
77dbfbdc | 88 | free(Page[0]); |
89 | free(Page); | |
90 | } | |
91 | ||
92 | ||
93 | /* | |
2d35d8ee | 94 | * 'WritePage()' - Write a page of text. |
77dbfbdc | 95 | */ |
96 | ||
2d35d8ee | 97 | void |
98 | WritePage(void) | |
070c29a1 | 99 | { |
77dbfbdc | 100 | int line; /* Current line */ |
57945030 | 101 | |
070c29a1 | 102 | |
77dbfbdc | 103 | NumPages ++; |
104 | printf("%%%%Page: %d %d\n", NumPages, NumPages); | |
070c29a1 | 105 | |
77dbfbdc | 106 | puts("gsave"); |
070c29a1 | 107 | |
77dbfbdc | 108 | if (PrettyPrint) |
109 | printf("%d H\n", NumPages); | |
070c29a1 | 110 | |
77dbfbdc | 111 | for (line = 0; line < SizeLines; line ++) |
112 | write_line(line, Page[line]); | |
070c29a1 | 113 | |
77dbfbdc | 114 | puts("grestore"); |
115 | puts("showpage"); | |
070c29a1 | 116 | |
77dbfbdc | 117 | memset(Page[0], 0, sizeof(lchar_t) * SizeColumns * SizeLines); |
118 | } | |
070c29a1 | 119 | |
f6bdbd14 | 120 | |
77dbfbdc | 121 | /* |
2d35d8ee | 122 | * 'WriteProlog()' - Write the PostScript file prolog with options. |
77dbfbdc | 123 | */ |
f6bdbd14 | 124 | |
2d35d8ee | 125 | void |
b5cb0608 | 126 | WriteProlog(const char *title, /* I - Title of job */ |
127 | const char *user, /* I - Username */ | |
128 | const char *classification, /* I - Classification */ | |
129 | const char *label, /* I - Page label */ | |
130 | ppd_file_t *ppd) /* I - PPD file info */ | |
77dbfbdc | 131 | { |
3b9a00b0 | 132 | int i, j, k; /* Looping vars */ |
77dbfbdc | 133 | char *charset; /* Character set string */ |
77dbfbdc | 134 | char filename[1024]; /* Glyph filenames */ |
135 | FILE *fp; /* Glyph files */ | |
571292aa | 136 | const char *datadir; /* CUPS_DATADIR environment variable */ |
3b9a00b0 | 137 | char line[1024], /* Line from file */ |
138 | *lineptr, /* Pointer into line */ | |
139 | *valptr; /* Pointer to value in line */ | |
77dbfbdc | 140 | int ch, unicode; /* Character values */ |
3b9a00b0 | 141 | int start, end; /* Start and end values for range */ |
77dbfbdc | 142 | char glyph[64]; /* Glyph name */ |
77dbfbdc | 143 | time_t curtime; /* Current time */ |
144 | struct tm *curtm; /* Current date */ | |
145 | char curdate[255]; /* Current date (text format) */ | |
3b9a00b0 | 146 | int num_fonts; /* Number of unique fonts */ |
147 | char *fonts[1024]; /* Unique fonts */ | |
148 | static char *names[] = /* Font names */ | |
149 | { | |
150 | "cupsNormal", | |
151 | "cupsBold", | |
152 | "cupsItalic" | |
153 | }; | |
154 | ||
155 | ||
571292aa | 156 | /* |
157 | * Get the data directory... | |
158 | */ | |
159 | ||
160 | if ((datadir = getenv("CUPS_DATADIR")) == NULL) | |
161 | datadir = CUPS_DATADIR; | |
162 | ||
b5cb0608 | 163 | /* |
164 | * Adjust margins as necessary... | |
165 | */ | |
166 | ||
167 | if (classification || label) | |
168 | { | |
169 | /* | |
170 | * Leave room for labels... | |
171 | */ | |
172 | ||
173 | PageBottom += 36; | |
174 | PageTop -= 36; | |
175 | } | |
176 | ||
3b9a00b0 | 177 | /* |
178 | * Allocate memory for the page... | |
179 | */ | |
180 | ||
181 | SizeColumns = (PageRight - PageLeft) / 72.0 * CharsPerInch; | |
182 | SizeLines = (PageTop - PageBottom) / 72.0 * LinesPerInch; | |
183 | ||
184 | Page = calloc(sizeof(lchar_t *), SizeLines); | |
185 | Page[0] = calloc(sizeof(lchar_t), SizeColumns * SizeLines); | |
186 | for (i = 1; i < SizeLines; i ++) | |
187 | Page[i] = Page[0] + i * SizeColumns; | |
188 | ||
189 | if (PageColumns > 1) | |
190 | { | |
191 | ColumnGutter = CharsPerInch / 2; | |
192 | ColumnWidth = (SizeColumns - ColumnGutter * (PageColumns - 1)) / | |
193 | PageColumns; | |
194 | } | |
195 | else | |
196 | ColumnWidth = SizeColumns; | |
f6bdbd14 | 197 | |
3b9a00b0 | 198 | /* |
199 | * Output the DSC header... | |
200 | */ | |
f6bdbd14 | 201 | |
77dbfbdc | 202 | curtime = time(NULL); |
203 | curtm = localtime(&curtime); | |
8a32fc08 | 204 | strftime(curdate, sizeof(curdate), CUPS_STRFTIME_FORMAT, curtm); |
f6bdbd14 | 205 | |
77dbfbdc | 206 | puts("%!PS-Adobe-3.0"); |
da1bfd3d | 207 | printf("%%%%BoundingBox: 0 0 %.0f %.0f\n", PageWidth, PageLength); |
1f1822fd | 208 | printf("%%cupsRotation: %d\n", (Orientation & 3) * 90); |
13fd65af | 209 | puts("%%Creator: texttops/" CUPS_SVERSION); |
77dbfbdc | 210 | printf("%%%%CreationDate: %s\n", curdate); |
211 | printf("%%%%Title: %s\n", title); | |
212 | printf("%%%%For: %s\n", user); | |
77dbfbdc | 213 | puts("%%Pages: (atend)"); |
f6bdbd14 | 214 | |
3b9a00b0 | 215 | /* |
216 | * Initialize globals... | |
217 | */ | |
f6bdbd14 | 218 | |
3b9a00b0 | 219 | NumFonts = 0; |
220 | memset(Fonts, 0, sizeof(Fonts)); | |
221 | memset(Glyphs, 0, sizeof(Glyphs)); | |
222 | memset(Chars, 0, sizeof(Chars)); | |
223 | memset(Codes, 0, sizeof(Codes)); | |
f6bdbd14 | 224 | |
3b9a00b0 | 225 | /* |
226 | * Load the PostScript glyph names and the corresponding character | |
227 | * set definition... | |
228 | */ | |
58ec2a95 | 229 | |
571292aa | 230 | snprintf(filename, sizeof(filename), "%s/data/psglyphs", datadir); |
231 | ||
232 | if ((fp = fopen(filename, "r")) != NULL) | |
f6bdbd14 | 233 | { |
3b9a00b0 | 234 | while (fscanf(fp, "%x%63s", &unicode, glyph) == 2) |
235 | Glyphs[unicode] = strdup(glyph); | |
236 | ||
237 | fclose(fp); | |
f6bdbd14 | 238 | } |
77dbfbdc | 239 | else |
3b9a00b0 | 240 | { |
571292aa | 241 | fprintf(stderr, "ERROR: Unable to open \"%s\" - %s\n", filename, |
242 | strerror(errno)); | |
3b9a00b0 | 243 | exit(1); |
244 | } | |
070c29a1 | 245 | |
246 | /* | |
3b9a00b0 | 247 | * Get the output character set... |
070c29a1 | 248 | */ |
249 | ||
77dbfbdc | 250 | charset = getenv("CHARSET"); |
251 | if (charset != NULL && strcmp(charset, "us-ascii") != 0) | |
070c29a1 | 252 | { |
571292aa | 253 | snprintf(filename, sizeof(filename), "%s/charsets/%s", datadir, charset); |
3b9a00b0 | 254 | |
255 | if ((fp = fopen(filename, "r")) == NULL) | |
256 | { | |
257 | /* | |
258 | * Can't open charset file! | |
259 | */ | |
260 | ||
261 | fprintf(stderr, "ERROR: Unable to open %s: %s\n", filename, | |
262 | strerror(errno)); | |
263 | exit(1); | |
264 | } | |
265 | ||
58ec2a95 | 266 | /* |
3b9a00b0 | 267 | * Opened charset file; now see if this is really a charset file... |
58ec2a95 | 268 | */ |
070c29a1 | 269 | |
3b9a00b0 | 270 | if (fgets(line, sizeof(line), fp) == NULL) |
271 | { | |
272 | /* | |
273 | * Bad/empty charset file! | |
274 | */ | |
58ec2a95 | 275 | |
3b9a00b0 | 276 | fclose(fp); |
277 | fprintf(stderr, "ERROR: Bad/empty charset file %s\n", filename); | |
278 | exit(1); | |
279 | } | |
280 | ||
281 | if (strncmp(line, "charset", 7) != 0) | |
77dbfbdc | 282 | { |
3b9a00b0 | 283 | /* |
284 | * Bad format/not a charset file! | |
285 | */ | |
58ec2a95 | 286 | |
77dbfbdc | 287 | fclose(fp); |
3b9a00b0 | 288 | fprintf(stderr, "ERROR: Bad charset file %s\n", filename); |
289 | exit(1); | |
77dbfbdc | 290 | } |
f6bdbd14 | 291 | |
3b9a00b0 | 292 | /* |
293 | * See if this is an 8-bit or UTF-8 character set file... | |
294 | */ | |
295 | ||
296 | line[strlen(line) - 1] = '\0'; /* Drop \n */ | |
da275f55 | 297 | for (lineptr = line + 7; isspace(*lineptr & 255); lineptr ++); /* Skip whitespace */ |
3b9a00b0 | 298 | |
299 | if (strcmp(lineptr, "8bit") == 0) | |
77dbfbdc | 300 | { |
3b9a00b0 | 301 | /* |
302 | * 8-bit text... | |
303 | */ | |
304 | ||
305 | UTF8 = 0; | |
3d9e2586 | 306 | NumFonts = 0; |
3b9a00b0 | 307 | |
308 | /* | |
3d9e2586 | 309 | * Read the font description(s)... |
3b9a00b0 | 310 | */ |
311 | ||
312 | while (fgets(line, sizeof(line), fp) != NULL) | |
313 | { | |
314 | /* | |
315 | * Skip comment and blank lines... | |
316 | */ | |
317 | ||
3d9e2586 | 318 | if (line[0] == '#' || line[0] == '\n') |
319 | continue; | |
58ec2a95 | 320 | |
3d9e2586 | 321 | /* |
322 | * Read the font descriptions that should look like: | |
323 | * | |
324 | * first last direction width normal [bold italic bold-italic] | |
325 | */ | |
326 | ||
327 | lineptr = line; | |
328 | ||
329 | start = strtol(lineptr, &lineptr, 16); | |
330 | end = strtol(lineptr, &lineptr, 16); | |
f6bdbd14 | 331 | |
da275f55 | 332 | while (isspace(*lineptr & 255)) |
3d9e2586 | 333 | lineptr ++; |
3b9a00b0 | 334 | |
3d9e2586 | 335 | if (!*lineptr) |
972c5ace | 336 | break; /* Must be a font mapping */ |
3b9a00b0 | 337 | |
3d9e2586 | 338 | valptr = lineptr; |
339 | ||
da275f55 | 340 | while (!isspace(*lineptr & 255) && *lineptr) |
3d9e2586 | 341 | lineptr ++; |
342 | ||
343 | if (!*lineptr) | |
344 | { | |
345 | /* | |
346 | * Can't have a font without all required values... | |
347 | */ | |
348 | ||
349 | fprintf(stderr, "ERROR: bad font description line: %s\n", valptr); | |
350 | fclose(fp); | |
351 | exit(1); | |
352 | } | |
353 | ||
354 | *lineptr++ = '\0'; | |
355 | ||
356 | if (strcmp(valptr, "ltor") == 0) | |
357 | Directions[NumFonts] = 1; | |
358 | else if (strcmp(valptr, "rtol") == 0) | |
359 | Directions[NumFonts] = -1; | |
360 | else | |
361 | { | |
362 | fprintf(stderr, "ERROR: Bad text direction %s\n", valptr); | |
363 | fclose(fp); | |
364 | exit(1); | |
365 | } | |
3b9a00b0 | 366 | |
3b9a00b0 | 367 | /* |
3d9e2586 | 368 | * Got the direction, now get the width... |
3b9a00b0 | 369 | */ |
f6bdbd14 | 370 | |
da275f55 | 371 | while (isspace(*lineptr & 255)) |
3d9e2586 | 372 | lineptr ++; |
3b9a00b0 | 373 | |
3d9e2586 | 374 | valptr = lineptr; |
3b9a00b0 | 375 | |
da275f55 | 376 | while (!isspace(*lineptr & 255) && *lineptr) |
3d9e2586 | 377 | lineptr ++; |
3b9a00b0 | 378 | |
3d9e2586 | 379 | if (!*lineptr) |
380 | { | |
381 | /* | |
382 | * Can't have a font without all required values... | |
383 | */ | |
3b9a00b0 | 384 | |
3d9e2586 | 385 | fprintf(stderr, "ERROR: bad font description line: %s\n", valptr); |
386 | fclose(fp); | |
387 | exit(1); | |
388 | } | |
3b9a00b0 | 389 | |
3d9e2586 | 390 | *lineptr++ = '\0'; |
3b9a00b0 | 391 | |
3d9e2586 | 392 | if (strcmp(valptr, "single") == 0) |
393 | Widths[NumFonts] = 1; | |
394 | else if (strcmp(valptr, "double") == 0) | |
395 | Widths[NumFonts] = 2; | |
396 | else | |
397 | { | |
398 | fprintf(stderr, "ERROR: Bad text width %s\n", valptr); | |
399 | fclose(fp); | |
400 | exit(1); | |
401 | } | |
3b9a00b0 | 402 | |
3fb23871 | 403 | /* |
3d9e2586 | 404 | * Get the fonts... |
3fb23871 | 405 | */ |
406 | ||
3d9e2586 | 407 | for (i = 0; *lineptr && i < 4; i ++) |
408 | { | |
da275f55 | 409 | while (isspace(*lineptr & 255)) |
3d9e2586 | 410 | lineptr ++; |
3b9a00b0 | 411 | |
3d9e2586 | 412 | valptr = lineptr; |
3b9a00b0 | 413 | |
da275f55 | 414 | while (!isspace(*lineptr & 255) && *lineptr) |
3d9e2586 | 415 | lineptr ++; |
3b9a00b0 | 416 | |
3d9e2586 | 417 | if (*lineptr) |
418 | *lineptr++ = '\0'; | |
3b9a00b0 | 419 | |
3d9e2586 | 420 | if (lineptr > valptr) |
421 | Fonts[NumFonts][i] = strdup(valptr); | |
422 | } | |
3b9a00b0 | 423 | |
3d9e2586 | 424 | /* |
425 | * Fill in remaining fonts as needed... | |
426 | */ | |
3b9a00b0 | 427 | |
3d9e2586 | 428 | for (j = i; j < 4; j ++) |
429 | Fonts[NumFonts][j] = strdup(Fonts[NumFonts][0]); | |
3b9a00b0 | 430 | |
3d9e2586 | 431 | /* |
432 | * Define the character mappings... | |
433 | */ | |
3b9a00b0 | 434 | |
3d9e2586 | 435 | for (i = start, j = NumFonts * 256; i <= end; i ++, j ++) |
436 | Chars[i] = j; | |
3b9a00b0 | 437 | |
3d9e2586 | 438 | NumFonts ++; |
439 | } | |
3b9a00b0 | 440 | |
441 | /* | |
442 | * Read encoding lines... | |
443 | */ | |
444 | ||
3d9e2586 | 445 | do |
3b9a00b0 | 446 | { |
447 | /* | |
448 | * Skip comment and blank lines... | |
449 | */ | |
450 | ||
451 | if (line[0] == '#' || line[0] == '\n') | |
452 | continue; | |
453 | ||
454 | /* | |
455 | * Grab the character and unicode glyph number. | |
456 | */ | |
457 | ||
458 | if (sscanf(line, "%x%x", &ch, &unicode) == 2 && ch < 256) | |
3d9e2586 | 459 | Codes[Chars[ch]] = unicode; |
3b9a00b0 | 460 | } |
3d9e2586 | 461 | while (fgets(line, sizeof(line), fp) != NULL); |
3b9a00b0 | 462 | |
463 | fclose(fp); | |
77dbfbdc | 464 | } |
3b9a00b0 | 465 | else if (strcmp(lineptr, "utf8") == 0) |
77dbfbdc | 466 | { |
467 | /* | |
3b9a00b0 | 468 | * UTF-8 (Unicode) text... |
77dbfbdc | 469 | */ |
f6bdbd14 | 470 | |
77dbfbdc | 471 | UTF8 = 1; |
f6bdbd14 | 472 | |
3b9a00b0 | 473 | /* |
474 | * Read the font descriptions... | |
475 | */ | |
476 | ||
477 | NumFonts = 0; | |
478 | ||
479 | while (fgets(line, sizeof(line), fp) != NULL) | |
480 | { | |
481 | /* | |
482 | * Skip comment and blank lines... | |
483 | */ | |
484 | ||
485 | if (line[0] == '#' || line[0] == '\n') | |
486 | continue; | |
487 | ||
488 | /* | |
489 | * Read the font descriptions that should look like: | |
490 | * | |
491 | * start end direction width normal [bold italic bold-italic] | |
492 | */ | |
493 | ||
494 | lineptr = line; | |
495 | ||
496 | start = strtol(lineptr, &lineptr, 16); | |
497 | end = strtol(lineptr, &lineptr, 16); | |
498 | ||
da275f55 | 499 | while (isspace(*lineptr & 255)) |
3b9a00b0 | 500 | lineptr ++; |
501 | ||
502 | valptr = lineptr; | |
503 | ||
da275f55 | 504 | while (!isspace(*lineptr & 255) && *lineptr) |
3b9a00b0 | 505 | lineptr ++; |
506 | ||
507 | if (!*lineptr) | |
508 | { | |
509 | /* | |
510 | * Can't have a font without all required values... | |
511 | */ | |
512 | ||
513 | fprintf(stderr, "ERROR: bad font description line: %s\n", valptr); | |
514 | fclose(fp); | |
515 | exit(1); | |
516 | } | |
517 | ||
518 | *lineptr++ = '\0'; | |
519 | ||
520 | if (strcmp(valptr, "ltor") == 0) | |
521 | Directions[NumFonts] = 1; | |
522 | else if (strcmp(valptr, "rtol") == 0) | |
523 | Directions[NumFonts] = -1; | |
524 | else | |
525 | { | |
526 | fprintf(stderr, "ERROR: Bad text direction %s\n", valptr); | |
527 | fclose(fp); | |
528 | exit(1); | |
529 | } | |
530 | ||
531 | /* | |
532 | * Got the direction, now get the width... | |
533 | */ | |
534 | ||
da275f55 | 535 | while (isspace(*lineptr & 255)) |
3b9a00b0 | 536 | lineptr ++; |
537 | ||
538 | valptr = lineptr; | |
539 | ||
da275f55 | 540 | while (!isspace(*lineptr & 255) && *lineptr) |
3b9a00b0 | 541 | lineptr ++; |
542 | ||
543 | if (!*lineptr) | |
544 | { | |
545 | /* | |
546 | * Can't have a font without all required values... | |
547 | */ | |
548 | ||
549 | fprintf(stderr, "ERROR: bad font description line: %s\n", valptr); | |
550 | fclose(fp); | |
551 | exit(1); | |
552 | } | |
553 | ||
554 | *lineptr++ = '\0'; | |
555 | ||
556 | if (strcmp(valptr, "single") == 0) | |
557 | Widths[NumFonts] = 1; | |
558 | else if (strcmp(valptr, "double") == 0) | |
559 | Widths[NumFonts] = 2; | |
560 | else | |
561 | { | |
562 | fprintf(stderr, "ERROR: Bad text width %s\n", valptr); | |
563 | fclose(fp); | |
564 | exit(1); | |
565 | } | |
566 | ||
567 | /* | |
568 | * Get the fonts... | |
569 | */ | |
570 | ||
571 | for (i = 0; *lineptr && i < 4; i ++) | |
572 | { | |
da275f55 | 573 | while (isspace(*lineptr & 255)) |
3b9a00b0 | 574 | lineptr ++; |
575 | ||
576 | valptr = lineptr; | |
577 | ||
da275f55 | 578 | while (!isspace(*lineptr & 255) && *lineptr) |
3b9a00b0 | 579 | lineptr ++; |
580 | ||
581 | if (*lineptr) | |
582 | *lineptr++ = '\0'; | |
583 | ||
584 | if (lineptr > valptr) | |
585 | Fonts[NumFonts][i] = strdup(valptr); | |
586 | } | |
587 | ||
588 | /* | |
589 | * Fill in remaining fonts as needed... | |
590 | */ | |
591 | ||
592 | for (j = i; j < 4; j ++) | |
593 | Fonts[NumFonts][j] = strdup(Fonts[NumFonts][0]); | |
594 | ||
595 | /* | |
596 | * Define the character mappings... | |
597 | */ | |
598 | ||
599 | for (i = start, j = NumFonts * 256; i <= end; i ++, j ++) | |
600 | { | |
601 | Chars[i] = j; | |
602 | Codes[j] = i; | |
603 | } | |
604 | ||
605 | /* | |
606 | * Move to the next font, stopping if needed... | |
607 | */ | |
608 | ||
609 | NumFonts ++; | |
610 | if (NumFonts >= 256) | |
611 | break; | |
612 | } | |
613 | ||
614 | fclose(fp); | |
615 | } | |
616 | else | |
617 | { | |
618 | fprintf(stderr, "ERROR: Bad charset type %s\n", lineptr); | |
619 | fclose(fp); | |
620 | exit(1); | |
77dbfbdc | 621 | } |
3b9a00b0 | 622 | } |
623 | else | |
624 | { | |
625 | /* | |
626 | * Standard ASCII output just uses Courier, Courier-Bold, and | |
627 | * possibly Courier-Oblique. | |
628 | */ | |
629 | ||
630 | NumFonts = 1; | |
631 | ||
632 | Fonts[0][ATTR_NORMAL] = strdup("Courier"); | |
633 | Fonts[0][ATTR_BOLD] = strdup("Courier-Bold"); | |
634 | Fonts[0][ATTR_ITALIC] = strdup("Courier-Oblique"); | |
635 | Fonts[0][ATTR_BOLDITALIC] = strdup("Courier-BoldOblique"); | |
636 | ||
637 | Widths[0] = 1; | |
638 | Directions[0] = 1; | |
f6bdbd14 | 639 | |
77dbfbdc | 640 | /* |
3b9a00b0 | 641 | * Define US-ASCII characters... |
77dbfbdc | 642 | */ |
58ec2a95 | 643 | |
3b9a00b0 | 644 | for (i = 32; i < 127; i ++) |
645 | { | |
646 | Chars[i] = i; | |
647 | Codes[i] = i; | |
648 | } | |
649 | } | |
650 | ||
651 | /* | |
652 | * Generate a list of unique fonts to use... | |
653 | */ | |
654 | ||
655 | for (i = 0, num_fonts = 0; i < NumFonts; i ++) | |
e2a4ce3e | 656 | for (j = PrettyPrint ? 2 : 1; j >= 0; j --) |
3b9a00b0 | 657 | { |
658 | for (k = 0; k < num_fonts; k ++) | |
659 | if (strcmp(Fonts[i][j], fonts[k]) == 0) | |
660 | break; | |
661 | ||
662 | if (k >= num_fonts) | |
663 | { | |
664 | /* | |
665 | * Add new font... | |
666 | */ | |
667 | ||
668 | fonts[num_fonts] = Fonts[i][j]; | |
669 | num_fonts ++; | |
670 | } | |
671 | } | |
672 | ||
673 | /* | |
674 | * List the fonts that will be used... | |
675 | */ | |
676 | ||
677 | for (i = 0; i < num_fonts; i ++) | |
678 | if (i == 0) | |
85569ef7 | 679 | printf("%%%%DocumentNeededResources: font %s\n", fonts[i]); |
3b9a00b0 | 680 | else |
85569ef7 | 681 | printf("%%%%+ font %s\n", fonts[i]); |
682 | ||
683 | puts("%%DocumentSuppliedResources: procset texttops 1.1 0"); | |
684 | ||
685 | for (i = 0; i < num_fonts; i ++) | |
686 | { | |
687 | if (ppd != NULL) | |
688 | { | |
689 | fprintf(stderr, "DEBUG: ppd->num_fonts = %d\n", ppd->num_fonts); | |
690 | ||
691 | for (j = 0; j < ppd->num_fonts; j ++) | |
692 | { | |
693 | fprintf(stderr, "DEBUG: ppd->fonts[%d] = %s\n", j, ppd->fonts[j]); | |
694 | ||
695 | if (strcmp(fonts[i], ppd->fonts[j]) == 0) | |
696 | break; | |
697 | } | |
698 | } | |
9d13ae31 | 699 | else |
700 | j = 0; | |
85569ef7 | 701 | |
7aaf9b47 | 702 | if (ppd != NULL && j >= ppd->num_fonts) |
85569ef7 | 703 | { |
704 | /* | |
705 | * Need to embed this font... | |
706 | */ | |
707 | ||
708 | printf("%%%%+ font %s\n", fonts[i]); | |
709 | } | |
710 | } | |
3b9a00b0 | 711 | |
712 | puts("%%EndComments"); | |
713 | ||
714 | puts("%%BeginProlog"); | |
715 | ||
85569ef7 | 716 | /* |
717 | * Download any missing fonts... | |
718 | */ | |
719 | ||
720 | for (i = 0; i < num_fonts; i ++) | |
721 | { | |
722 | if (ppd != NULL) | |
9d13ae31 | 723 | { |
85569ef7 | 724 | for (j = 0; j < ppd->num_fonts; j ++) |
725 | if (strcmp(fonts[i], ppd->fonts[j]) == 0) | |
726 | break; | |
9d13ae31 | 727 | } |
728 | else | |
729 | j = 0; | |
85569ef7 | 730 | |
7aaf9b47 | 731 | if (ppd != NULL && j >= ppd->num_fonts) |
85569ef7 | 732 | { |
733 | /* | |
734 | * Need to embed this font... | |
735 | */ | |
736 | ||
737 | printf("%%%%BeginResource: font %s\n", fonts[i]); | |
738 | ||
571292aa | 739 | snprintf(filename, sizeof(filename), "%s/fonts/%s", datadir, fonts[i]); |
85569ef7 | 740 | if ((fp = fopen(filename, "rb")) != NULL) |
741 | { | |
e2a4ce3e | 742 | while ((j = fread(line, 1, sizeof(line), fp)) > 0) |
743 | fwrite(line, 1, j, stdout); | |
85569ef7 | 744 | |
745 | fclose(fp); | |
746 | } | |
747 | ||
e2a4ce3e | 748 | puts("\n%%EndResource"); |
85569ef7 | 749 | } |
750 | } | |
751 | ||
3b9a00b0 | 752 | /* |
753 | * Write the encoding array(s)... | |
754 | */ | |
755 | ||
756 | puts("% character encoding(s)"); | |
757 | ||
758 | for (i = 0; i < NumFonts; i ++) | |
759 | { | |
760 | printf("/cupsEncoding%02x [\n", i); | |
58ec2a95 | 761 | |
77dbfbdc | 762 | for (ch = 0; ch < 256; ch ++) |
763 | { | |
3b9a00b0 | 764 | if (Glyphs[Codes[i * 256 + ch]]) |
765 | printf("/%s", Glyphs[Codes[i * 256 + ch]]); | |
77dbfbdc | 766 | else |
767 | printf("/.notdef"); | |
58ec2a95 | 768 | |
77dbfbdc | 769 | if ((ch & 7) == 7) |
3b9a00b0 | 770 | putchar('\n'); |
77dbfbdc | 771 | } |
f6bdbd14 | 772 | |
77dbfbdc | 773 | puts("] def"); |
3b9a00b0 | 774 | } |
775 | ||
776 | /* | |
777 | * Create the fonts... | |
778 | */ | |
779 | ||
780 | if (NumFonts == 1) | |
781 | { | |
782 | /* | |
783 | * Just reencode the named fonts... | |
784 | */ | |
f6bdbd14 | 785 | |
77dbfbdc | 786 | puts("% Reencode fonts"); |
3b9a00b0 | 787 | |
e2a4ce3e | 788 | for (i = PrettyPrint ? 2 : 1; i >= 0; i --) |
2d35d8ee | 789 | { |
3b9a00b0 | 790 | printf("/%s findfont\n", Fonts[0][i]); |
c18f2cf9 | 791 | puts("dup length 1 add dict begin\n" |
3b9a00b0 | 792 | " { 1 index /FID ne { def } { pop pop } ifelse } forall\n" |
793 | " /Encoding cupsEncoding00 def\n" | |
794 | " currentdict\n" | |
795 | "end"); | |
796 | printf("/%s exch definefont pop\n", names[i]); | |
797 | } | |
798 | } | |
799 | else | |
800 | { | |
801 | /* | |
802 | * Construct composite fonts... Start by reencoding the base fonts... | |
803 | */ | |
804 | ||
805 | puts("% Reencode base fonts"); | |
806 | ||
807 | for (i = 1 + PrettyPrint; i >= 0; i --) | |
808 | for (j = 0; j < NumFonts; j ++) | |
809 | { | |
810 | printf("/%s findfont\n", Fonts[j][i]); | |
c18f2cf9 | 811 | printf("dup length 1 add dict begin\n" |
3b9a00b0 | 812 | " { 1 index /FID ne { def } { pop pop } ifelse } forall\n" |
813 | " /Encoding cupsEncoding%02x def\n" | |
814 | " currentdict\n" | |
815 | "end\n", j); | |
c18f2cf9 | 816 | printf("/%s%02x exch definefont /%s%02x exch def\n", names[i], j, |
817 | names[i], j); | |
3b9a00b0 | 818 | } |
819 | ||
820 | /* | |
821 | * Then merge them into composite fonts... | |
822 | */ | |
823 | ||
c18f2cf9 | 824 | puts("% Create composite fonts..."); |
825 | ||
3b9a00b0 | 826 | for (i = 1 + PrettyPrint; i >= 0; i --) |
827 | { | |
c18f2cf9 | 828 | puts("8 dict begin"); |
829 | puts("/FontType 0 def/FontMatrix[1.0 0 0 1.0 0 0]def/FMapType 2 def/Encoding["); | |
3b9a00b0 | 830 | for (j = 0; j < NumFonts; j ++) |
831 | if (j == (NumFonts - 1)) | |
832 | printf("%d", j); | |
833 | else if ((j & 15) == 15) | |
834 | printf("%d\n", j); | |
835 | else | |
836 | printf("%d ", j); | |
837 | puts("]def/FDepVector["); | |
838 | for (j = 0; j < NumFonts; j ++) | |
839 | if (j == (NumFonts - 1)) | |
c18f2cf9 | 840 | printf("%s%02x", names[i], j); |
3b9a00b0 | 841 | else if ((j & 3) == 3) |
c18f2cf9 | 842 | printf("%s%02x\n", names[i], j); |
3b9a00b0 | 843 | else |
c18f2cf9 | 844 | printf("%s%02x ", names[i], j); |
845 | puts("]def currentdict end"); | |
846 | printf("/%s exch definefont pop\n", names[i]); | |
2d35d8ee | 847 | } |
77dbfbdc | 848 | } |
f6bdbd14 | 849 | |
3b9a00b0 | 850 | /* |
851 | * Output the texttops procset... | |
852 | */ | |
853 | ||
854 | puts("%%BeginResource: procset texttops 1.1 0"); | |
855 | ||
77dbfbdc | 856 | puts("% Define fonts"); |
f6bdbd14 | 857 | |
0f74081c | 858 | printf("/FN /cupsNormal findfont [%.3f 0 0 %.3f 0 0] makefont def\n", |
77dbfbdc | 859 | 120.0 / CharsPerInch, 68.0 / LinesPerInch); |
0f74081c | 860 | printf("/FB /cupsBold findfont [%.3f 0 0 %.3f 0 0] makefont def\n", |
77dbfbdc | 861 | 120.0 / CharsPerInch, 68.0 / LinesPerInch); |
862 | if (PrettyPrint) | |
0f74081c | 863 | printf("/FI /cupsItalic findfont [%.3f 0 0 %.3f 0 0] makefont def\n", |
77dbfbdc | 864 | 120.0 / CharsPerInch, 68.0 / LinesPerInch); |
f6bdbd14 | 865 | |
77dbfbdc | 866 | puts("% Common procedures"); |
f6bdbd14 | 867 | |
77dbfbdc | 868 | puts("/N { FN setfont moveto } bind def"); |
869 | puts("/B { FB setfont moveto } bind def"); | |
0f74081c | 870 | printf("/U { gsave 0.5 setlinewidth 0 %.3f rmoveto " |
6f609fd7 | 871 | "0 rlineto stroke grestore } bind def\n", -6.8 / LinesPerInch); |
58ec2a95 | 872 | |
77dbfbdc | 873 | if (PrettyPrint) |
874 | { | |
875 | if (ColorDevice) | |
876 | { | |
877 | puts("/S { 0.0 setgray show } bind def"); | |
878 | puts("/r { 0.5 0.0 0.0 setrgbcolor show } bind def"); | |
879 | puts("/g { 0.0 0.5 0.0 setrgbcolor show } bind def"); | |
880 | puts("/b { 0.0 0.0 0.5 setrgbcolor show } bind def"); | |
881 | } | |
882 | else | |
883 | { | |
884 | puts("/S { 0.0 setgray show } bind def"); | |
885 | puts("/r { 0.2 setgray show } bind def"); | |
886 | puts("/g { 0.2 setgray show } bind def"); | |
887 | puts("/b { 0.2 setgray show } bind def"); | |
888 | } | |
58ec2a95 | 889 | |
77dbfbdc | 890 | puts("/I { FI setfont moveto } bind def"); |
58ec2a95 | 891 | |
c18f2cf9 | 892 | puts("/n {"); |
893 | puts("\t20 string cvs % convert page number to string"); | |
da1bfd3d | 894 | if (NumFonts > 1) |
895 | { | |
896 | /* | |
897 | * Convert a number to double-byte chars... | |
898 | */ | |
899 | ||
900 | puts("\tdup length % get length"); | |
901 | puts("\tdup 2 mul string /P exch def % P = string twice as long"); | |
902 | puts("\t0 1 2 index 1 sub { % loop through each character in the page number"); | |
903 | puts("\t\tdup 3 index exch get % get character N from the page number"); | |
904 | puts("\t\texch 2 mul dup % compute offset in P"); | |
905 | puts("\t\tP exch 0 put % font 0"); | |
906 | puts("\t\t1 add P exch 2 index put % character"); | |
907 | puts("\t\tpop % discard character"); | |
908 | puts("\t} for % do for loop"); | |
909 | puts("\tpop pop % discard string and length"); | |
910 | puts("\tP % put string on stack"); | |
911 | } | |
c18f2cf9 | 912 | puts("} bind def"); |
58ec2a95 | 913 | |
c18f2cf9 | 914 | printf("/T"); |
915 | write_text(title); | |
916 | puts("def"); | |
58ec2a95 | 917 | |
c18f2cf9 | 918 | printf("/D"); |
919 | write_text(curdate); | |
920 | puts("def"); | |
58ec2a95 | 921 | |
77dbfbdc | 922 | puts("/H {"); |
da1bfd3d | 923 | puts("\tgsave"); |
77dbfbdc | 924 | puts("\t0.9 setgray"); |
070c29a1 | 925 | |
77dbfbdc | 926 | if (Duplex) |
927 | { | |
928 | puts("\tdup 2 mod 0 eq {"); | |
0f74081c | 929 | printf("\t\t%.3f %.3f translate } {\n", |
77dbfbdc | 930 | PageWidth - PageRight, PageTop + 72.0f / LinesPerInch); |
0f74081c | 931 | printf("\t\t%.3f %.3f translate } ifelse\n", |
77dbfbdc | 932 | PageLeft, PageTop + 72.0f / LinesPerInch); |
933 | } | |
2d35d8ee | 934 | else |
0f74081c | 935 | printf("\t%.3f %.3f translate\n", |
2d35d8ee | 936 | PageLeft, PageTop + 72.0f / LinesPerInch); |
f6bdbd14 | 937 | |
0f74081c | 938 | printf("\t0 0 %.3f %.3f rectfill\n", PageRight - PageLeft, |
77dbfbdc | 939 | 144.0f / LinesPerInch); |
f6bdbd14 | 940 | |
b1ac64aa | 941 | puts("\tFB setfont"); |
77dbfbdc | 942 | puts("\t0 setgray"); |
f6bdbd14 | 943 | |
77dbfbdc | 944 | if (Duplex) |
945 | { | |
946 | puts("\tdup 2 mod 0 eq {"); | |
0f74081c | 947 | printf("\t\tT stringwidth pop neg %.3f add %.3f } {\n", |
5d4b6bc1 | 948 | PageRight - PageLeft - 36.0f / LinesPerInch, |
949 | (0.5f + 0.157f) * 72.0f / LinesPerInch); | |
0f74081c | 950 | printf("\t\t%.3f %.3f } ifelse\n", 36.0f / LinesPerInch, |
5d4b6bc1 | 951 | (0.5f + 0.157f) * 72.0f / LinesPerInch); |
77dbfbdc | 952 | } |
953 | else | |
0f74081c | 954 | printf("\t%.3f %.3f\n", 36.0f / LinesPerInch, |
5d4b6bc1 | 955 | (0.5f + 0.157f) * 72.0f / LinesPerInch); |
f6bdbd14 | 956 | |
77dbfbdc | 957 | puts("\tmoveto T show"); |
f6bdbd14 | 958 | |
0f74081c | 959 | printf("\tD dup stringwidth pop neg 2 div %.3f add %.3f\n", |
5d4b6bc1 | 960 | (PageRight - PageLeft) * 0.5, |
961 | (0.5f + 0.157f) * 72.0f / LinesPerInch); | |
77dbfbdc | 962 | puts("\tmoveto show"); |
963 | ||
964 | if (Duplex) | |
965 | { | |
c18f2cf9 | 966 | puts("\tdup n exch 2 mod 0 eq {"); |
0f74081c | 967 | printf("\t\t%.3f %.3f } {\n", 36.0f / LinesPerInch, |
5d4b6bc1 | 968 | (0.5f + 0.157f) * 72.0f / LinesPerInch); |
0f74081c | 969 | printf("\t\tdup stringwidth pop neg %.3f add %.3f } ifelse\n", |
77dbfbdc | 970 | PageRight - PageLeft - 36.0f / LinesPerInch, |
5d4b6bc1 | 971 | (0.5f + 0.157f) * 72.0f / LinesPerInch); |
77dbfbdc | 972 | } |
973 | else | |
0f74081c | 974 | printf("\tn dup stringwidth pop neg %.3f add %.3f\n", |
77dbfbdc | 975 | PageRight - PageLeft - 36.0f / LinesPerInch, |
5d4b6bc1 | 976 | (0.5f + 0.157f) * 72.0f / LinesPerInch); |
f6bdbd14 | 977 | |
77dbfbdc | 978 | puts("\tmoveto show"); |
979 | puts("\tgrestore"); | |
980 | puts("} bind def"); | |
981 | } | |
982 | else | |
983 | puts("/S { show } bind def"); | |
f6bdbd14 | 984 | |
77dbfbdc | 985 | puts("%%EndResource"); |
f6bdbd14 | 986 | |
77dbfbdc | 987 | puts("%%EndProlog"); |
988 | } | |
f6bdbd14 | 989 | |
f6bdbd14 | 990 | |
2d35d8ee | 991 | /* |
992 | * 'write_line()' - Write a row of text. | |
993 | */ | |
994 | ||
995 | static void | |
996 | write_line(int row, /* I - Row number (0 to N) */ | |
997 | lchar_t *line) /* I - Line to print */ | |
998 | { | |
3d9e2586 | 999 | int i; /* Looping var */ |
2d35d8ee | 1000 | int col; /* Current column */ |
1001 | int attr; /* Current attribute */ | |
3d9e2586 | 1002 | int font, /* Font to use */ |
2889d62d | 1003 | lastfont, /* Last font */ |
3d9e2586 | 1004 | mono; /* Monospaced? */ |
2d35d8ee | 1005 | lchar_t *start; /* First character in sequence */ |
1006 | ||
c18f2cf9 | 1007 | |
2d35d8ee | 1008 | for (col = 0, start = line; col < SizeColumns;) |
1009 | { | |
1010 | while (col < SizeColumns && (line->ch == ' ' || line->ch == 0)) | |
1011 | { | |
1012 | col ++; | |
1013 | line ++; | |
1014 | } | |
1015 | ||
1016 | if (col >= SizeColumns) | |
1017 | break; | |
1018 | ||
3d9e2586 | 1019 | if (NumFonts == 1) |
1020 | { | |
1021 | /* | |
1022 | * All characters in a single font - assume monospaced... | |
1023 | */ | |
1024 | ||
1025 | attr = line->attr; | |
1026 | start = line; | |
1027 | ||
1028 | while (col < SizeColumns && line->ch != 0 && attr == line->attr) | |
1029 | { | |
1030 | col ++; | |
1031 | line ++; | |
1032 | } | |
2d35d8ee | 1033 | |
3d9e2586 | 1034 | write_string(col - (line - start), row, line - start, start); |
1035 | } | |
1036 | else | |
2d35d8ee | 1037 | { |
3d9e2586 | 1038 | /* |
1039 | * Multiple fonts; break up based on the font... | |
1040 | */ | |
1041 | ||
2889d62d | 1042 | attr = line->attr; |
1043 | start = line; | |
1044 | lastfont = Chars[line->ch] / 256; | |
1045 | mono = strncmp(Fonts[lastfont][0], "Courier", 7) == 0; | |
2d35d8ee | 1046 | col ++; |
1047 | line ++; | |
2d35d8ee | 1048 | |
3d9e2586 | 1049 | if (mono) |
1050 | { | |
1051 | while (col < SizeColumns && line->ch != 0 && attr == line->attr) | |
1052 | { | |
1053 | font = Chars[line->ch] / 256; | |
2889d62d | 1054 | if (strncmp(Fonts[font][0], "Courier", 7) != 0 || |
1055 | font != lastfont) | |
3d9e2586 | 1056 | break; |
1057 | ||
1058 | col ++; | |
1059 | line ++; | |
1060 | } | |
1061 | } | |
1062 | ||
2889d62d | 1063 | if (Directions[lastfont] > 0) |
3d9e2586 | 1064 | write_string(col - (line - start), row, line - start, start); |
1065 | else | |
1066 | { | |
1067 | /* | |
1068 | * Do right-to-left text... | |
1069 | */ | |
1070 | ||
1071 | while (col < SizeColumns && line->ch != 0 && attr == line->attr) | |
1072 | { | |
1073 | if (Directions[Chars[line->ch] / 256] > 0 && | |
da275f55 | 1074 | !ispunct(line->ch & 255) && !isspace(line->ch & 255)) |
3d9e2586 | 1075 | break; |
1076 | ||
1077 | col ++; | |
1078 | line ++; | |
1079 | } | |
1080 | ||
2889d62d | 1081 | for (i = 1; start < line; i ++, start ++) |
da275f55 | 1082 | if (!isspace(start->ch & 255)) |
3d9e2586 | 1083 | write_string(col - i, row, 1, start); |
1084 | } | |
1085 | } | |
2d35d8ee | 1086 | } |
1087 | } | |
1088 | ||
1089 | ||
77dbfbdc | 1090 | /* |
1091 | * 'write_string()' - Write a string of text. | |
1092 | */ | |
f6bdbd14 | 1093 | |
77dbfbdc | 1094 | static void |
1095 | write_string(int col, /* I - Start column */ | |
1096 | int row, /* I - Row */ | |
1097 | int len, /* I - Number of characters */ | |
1098 | lchar_t *s) /* I - String to print */ | |
1099 | { | |
3b9a00b0 | 1100 | int ch; /* Current character */ |
77dbfbdc | 1101 | float x, y; /* Position of text */ |
1102 | unsigned attr; /* Character attributes */ | |
f6bdbd14 | 1103 | |
f6bdbd14 | 1104 | |
77dbfbdc | 1105 | /* |
1106 | * Position the text and set the font... | |
1107 | */ | |
58ec2a95 | 1108 | |
77dbfbdc | 1109 | if (Duplex && (NumPages & 1) == 0) |
1110 | { | |
1111 | x = PageWidth - PageRight; | |
1112 | y = PageTop; | |
1113 | } | |
1114 | else | |
1115 | { | |
1116 | x = PageLeft; | |
1117 | y = PageTop; | |
1118 | } | |
58ec2a95 | 1119 | |
b1ac64aa | 1120 | x += (float)col * 72.0f / (float)CharsPerInch; |
5d4b6bc1 | 1121 | y -= (float)(row + 0.843) * 72.0f / (float)LinesPerInch; |
070c29a1 | 1122 | |
77dbfbdc | 1123 | attr = s->attr; |
f6bdbd14 | 1124 | |
77dbfbdc | 1125 | if (attr & ATTR_RAISED) |
1126 | y += 36.0 / (float)LinesPerInch; | |
1127 | else if (attr & ATTR_LOWERED) | |
1128 | y -= 36.0 / (float)LinesPerInch; | |
58ec2a95 | 1129 | |
77dbfbdc | 1130 | if (x == (int)x) |
1131 | printf("%.0f ", x); | |
1132 | else | |
0f74081c | 1133 | printf("%.3f ", x); |
77bdfb41 | 1134 | |
77dbfbdc | 1135 | if (y == (int)y) |
1136 | printf("%.0f ", y); | |
1137 | else | |
0f74081c | 1138 | printf("%.3f ", y); |
070c29a1 | 1139 | |
77dbfbdc | 1140 | if (attr & ATTR_BOLD) |
1141 | putchar('B'); | |
1142 | else if (attr & ATTR_ITALIC) | |
1143 | putchar('I'); | |
1144 | else | |
1145 | putchar('N'); | |
f6bdbd14 | 1146 | |
77dbfbdc | 1147 | if (attr & ATTR_UNDERLINE) |
0f74081c | 1148 | printf(" %.3f U", (float)len * 72.0 / (float)CharsPerInch); |
f6bdbd14 | 1149 | |
3d9e2586 | 1150 | if (NumFonts > 1) |
c18f2cf9 | 1151 | { |
1152 | /* | |
1153 | * Write a hex string... | |
1154 | */ | |
f6bdbd14 | 1155 | |
c18f2cf9 | 1156 | putchar('<'); |
f6bdbd14 | 1157 | |
c18f2cf9 | 1158 | while (len > 0) |
1159 | { | |
1160 | printf("%04x", Chars[s->ch]); | |
1161 | ||
1162 | len --; | |
1163 | s ++; | |
1164 | } | |
f6bdbd14 | 1165 | |
c18f2cf9 | 1166 | putchar('>'); |
1167 | } | |
1168 | else | |
77dbfbdc | 1169 | { |
c18f2cf9 | 1170 | /* |
1171 | * Write a quoted string... | |
1172 | */ | |
1173 | ||
1174 | putchar('('); | |
f6bdbd14 | 1175 | |
c18f2cf9 | 1176 | while (len > 0) |
77dbfbdc | 1177 | { |
c18f2cf9 | 1178 | ch = Chars[s->ch]; |
1179 | ||
1180 | if (ch < 32 || ch > 126) | |
1181 | { | |
1182 | /* | |
1183 | * Quote 8-bit and control characters... | |
1184 | */ | |
1185 | ||
1186 | printf("\\%03o", ch); | |
1187 | } | |
77dbfbdc | 1188 | else |
1189 | { | |
c18f2cf9 | 1190 | /* |
1191 | * Quote the parenthesis and backslash as needed... | |
1192 | */ | |
1193 | ||
3b9a00b0 | 1194 | if (ch == '(' || ch == ')' || ch == '\\') |
77dbfbdc | 1195 | putchar('\\'); |
070c29a1 | 1196 | |
c18f2cf9 | 1197 | putchar(ch); |
77dbfbdc | 1198 | } |
3b9a00b0 | 1199 | |
c18f2cf9 | 1200 | len --; |
1201 | s ++; | |
3b9a00b0 | 1202 | } |
3b9a00b0 | 1203 | |
c18f2cf9 | 1204 | putchar(')'); |
b1ac64aa | 1205 | } |
77dbfbdc | 1206 | |
b1ac64aa | 1207 | if (PrettyPrint) |
1208 | { | |
77dbfbdc | 1209 | if (attr & ATTR_RED) |
1210 | puts("r"); | |
1211 | else if (attr & ATTR_GREEN) | |
1212 | puts("g"); | |
1213 | else if (attr & ATTR_BLUE) | |
1214 | puts("b"); | |
1215 | else | |
1216 | puts("S"); | |
1217 | } | |
b1ac64aa | 1218 | else |
1219 | puts("S"); | |
070c29a1 | 1220 | } |
1221 | ||
1222 | ||
1223 | /* | |
c18f2cf9 | 1224 | * 'write_text()' - Write a text string, quoting/encoding as needed. |
1225 | */ | |
1226 | ||
1227 | static void | |
b5cb0608 | 1228 | write_text(const char *s) /* I - String to write */ |
c18f2cf9 | 1229 | { |
b5cb0608 | 1230 | int ch; /* Actual character value (UTF8) */ |
1231 | const unsigned char *utf8; /* UTF8 text */ | |
c18f2cf9 | 1232 | |
1233 | ||
3d9e2586 | 1234 | if (NumFonts > 1) |
c18f2cf9 | 1235 | { |
1236 | /* | |
1237 | * 8/8 encoding... | |
1238 | */ | |
1239 | ||
1240 | putchar('<'); | |
1241 | ||
b5cb0608 | 1242 | utf8 = (const unsigned char *)s; |
c18f2cf9 | 1243 | |
1244 | while (*utf8) | |
1245 | { | |
3d9e2586 | 1246 | if (*utf8 < 0xc0 || !UTF8) |
c18f2cf9 | 1247 | ch = *utf8 ++; |
1248 | else if ((*utf8 & 0xe0) == 0xc0) | |
1249 | { | |
1250 | /* | |
1251 | * Two byte character... | |
1252 | */ | |
1253 | ||
1254 | ch = ((utf8[0] & 0x1f) << 6) | (utf8[1] & 0x3f); | |
1255 | utf8 += 2; | |
1256 | } | |
1257 | else | |
1258 | { | |
1259 | /* | |
1260 | * Three byte character... | |
1261 | */ | |
1262 | ||
1263 | ch = ((((utf8[0] & 0x1f) << 6) | (utf8[1] & 0x3f)) << 6) | | |
1264 | (utf8[2] & 0x3f); | |
1265 | utf8 += 3; | |
1266 | } | |
1267 | ||
1268 | printf("%04x", Chars[ch]); | |
1269 | } | |
1270 | ||
1271 | putchar('>'); | |
1272 | } | |
1273 | else | |
1274 | { | |
1275 | /* | |
1276 | * Standard 8-bit encoding... | |
1277 | */ | |
1278 | ||
1279 | putchar('('); | |
1280 | ||
1281 | while (*s) | |
1282 | { | |
1283 | if (*s < 32 || *s > 126) | |
1284 | printf("\\%03o", *s); | |
1285 | else | |
1286 | { | |
1287 | if (*s == '(' || *s == ')' || *s == '\\') | |
1288 | putchar('\\'); | |
1289 | ||
1290 | putchar(*s); | |
1291 | } | |
1292 | ||
1293 | s ++; | |
1294 | } | |
1295 | ||
1296 | putchar(')'); | |
1297 | } | |
1298 | } | |
1299 | ||
1300 | ||
1301 | /* | |
da275f55 | 1302 | * End of "$Id: texttops.c,v 1.34.2.13 2004/02/25 20:01:37 mike Exp $". |
070c29a1 | 1303 | */ |