]>
git.ipfire.org Git - thirdparty/cups.git/blob - filter/texttops.c
4 * Text to PostScript filter for the Common UNIX Printing System (CUPS).
6 * Copyright 1993-2005 by Easy Software Products.
8 * These coded instructions, statements, and computer programs are the
9 * property of Easy Software Products and are protected by Federal
10 * copyright law. Distribution and use rights are outlined in the file
11 * "LICENSE.txt" which should have been included with this file. If this
12 * file is missing or damaged please contact Easy Software Products
15 * Attn: CUPS Licensing Information
16 * Easy Software Products
17 * 44141 Airport View Drive, Suite 204
18 * Hollywood, Maryland 20636 USA
20 * Voice: (301) 373-9600
21 * EMail: cups-info@cups.org
22 * WWW: http://www.cups.org
24 * This file is subject to the Apple OS-Developed Software exception.
28 * 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.
37 * Include necessary headers...
40 #include "textcommon.h"
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 */
60 static void write_line(int row
, lchar_t
*line
);
61 static void write_string(int col
, int row
, int len
, lchar_t
*s
);
62 static void write_text(const char *s
);
66 * 'main()' - Main entry for text to PostScript filter.
69 int /* O - Exit status */
70 main(int argc
, /* I - Number of command-line arguments */
71 char *argv
[]) /* I - Command-line arguments */
73 return (TextMain("texttops", argc
, argv
));
78 * 'WriteEpilogue()' - Write the PostScript file epilogue.
85 printf("%%%%Pages: %d\n", NumPages
);
94 * 'WritePage()' - Write a page of text.
100 int line
; /* Current line */
104 printf("%%%%Page: %d %d\n", NumPages
, NumPages
);
109 printf("%d H\n", NumPages
);
111 for (line
= 0; line
< SizeLines
; line
++)
112 write_line(line
, Page
[line
]);
117 memset(Page
[0], 0, sizeof(lchar_t
) * SizeColumns
* SizeLines
);
122 * 'WriteProlog()' - Write the PostScript file prolog with options.
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 */
132 int i
, j
, k
; /* Looping vars */
133 char *charset
; /* Character set string */
134 char filename
[1024]; /* Glyph filenames */
135 FILE *fp
; /* Glyph files */
136 const char *datadir
; /* CUPS_DATADIR environment variable */
137 char line
[1024], /* Line from file */
138 *lineptr
, /* Pointer into line */
139 *valptr
; /* Pointer to value in line */
140 int ch
, unicode
; /* Character values */
141 int start
, end
; /* Start and end values for range */
142 char glyph
[64]; /* Glyph name */
143 time_t curtime
; /* Current time */
144 struct tm
*curtm
; /* Current date */
145 char curdate
[255]; /* Current date (text format) */
146 int num_fonts
; /* Number of unique fonts */
147 char *fonts
[1024]; /* Unique fonts */
148 static char *names
[] = /* Font names */
157 * Get the data directory...
160 if ((datadir
= getenv("CUPS_DATADIR")) == NULL
)
161 datadir
= CUPS_DATADIR
;
164 * Adjust margins as necessary...
167 if (classification
|| label
)
170 * Leave room for labels...
178 * Allocate memory for the page...
181 SizeColumns
= (PageRight
- PageLeft
) / 72.0 * CharsPerInch
;
182 SizeLines
= (PageTop
- PageBottom
) / 72.0 * LinesPerInch
;
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
;
191 ColumnGutter
= CharsPerInch
/ 2;
192 ColumnWidth
= (SizeColumns
- ColumnGutter
* (PageColumns
- 1)) /
196 ColumnWidth
= SizeColumns
;
199 * Output the DSC header...
202 curtime
= time(NULL
);
203 curtm
= localtime(&curtime
);
204 strftime(curdate
, sizeof(curdate
), "%c", curtm
);
206 puts("%!PS-Adobe-3.0");
207 printf("%%%%BoundingBox: 0 0 %.0f %.0f\n", PageWidth
, PageLength
);
208 printf("%%cupsRotation: %d\n", (Orientation
& 3) * 90);
209 puts("%%Creator: texttops/" CUPS_SVERSION
);
210 printf("%%%%CreationDate: %s\n", curdate
);
211 printf("%%%%Title: %s\n", title
);
212 printf("%%%%For: %s\n", user
);
213 puts("%%Pages: (atend)");
216 * Initialize globals...
220 memset(Fonts
, 0, sizeof(Fonts
));
221 memset(Glyphs
, 0, sizeof(Glyphs
));
222 memset(Chars
, 0, sizeof(Chars
));
223 memset(Codes
, 0, sizeof(Codes
));
226 * Load the PostScript glyph names and the corresponding character
230 snprintf(filename
, sizeof(filename
), "%s/data/psglyphs", datadir
);
232 if ((fp
= fopen(filename
, "r")) != NULL
)
234 while (fscanf(fp
, "%x%63s", &unicode
, glyph
) == 2)
235 Glyphs
[unicode
] = strdup(glyph
);
241 fprintf(stderr
, "ERROR: Unable to open \"%s\" - %s\n", filename
,
247 * Get the output character set...
250 charset
= getenv("CHARSET");
251 if (charset
!= NULL
&& strcmp(charset
, "us-ascii") != 0)
253 snprintf(filename
, sizeof(filename
), "%s/charsets/%s", datadir
, charset
);
255 if ((fp
= fopen(filename
, "r")) == NULL
)
258 * Can't open charset file!
261 fprintf(stderr
, "ERROR: Unable to open %s: %s\n", filename
,
267 * Opened charset file; now see if this is really a charset file...
270 if (fgets(line
, sizeof(line
), fp
) == NULL
)
273 * Bad/empty charset file!
277 fprintf(stderr
, "ERROR: Bad/empty charset file %s\n", filename
);
281 if (strncmp(line
, "charset", 7) != 0)
284 * Bad format/not a charset file!
288 fprintf(stderr
, "ERROR: Bad charset file %s\n", filename
);
293 * See if this is an 8-bit or UTF-8 character set file...
296 line
[strlen(line
) - 1] = '\0'; /* Drop \n */
297 for (lineptr
= line
+ 7; isspace(*lineptr
& 255); lineptr
++); /* Skip whitespace */
299 if (strcmp(lineptr
, "8bit") == 0)
309 * Read the font description(s)...
312 while (fgets(line
, sizeof(line
), fp
) != NULL
)
315 * Skip comment and blank lines...
318 if (line
[0] == '#' || line
[0] == '\n')
322 * Read the font descriptions that should look like:
324 * first last direction width normal [bold italic bold-italic]
329 start
= strtol(lineptr
, &lineptr
, 16);
330 end
= strtol(lineptr
, &lineptr
, 16);
332 while (isspace(*lineptr
& 255))
336 break; /* Must be a font mapping */
340 while (!isspace(*lineptr
& 255) && *lineptr
)
346 * Can't have a font without all required values...
349 fprintf(stderr
, "ERROR: bad font description line: %s\n", valptr
);
356 if (strcmp(valptr
, "ltor") == 0)
357 Directions
[NumFonts
] = 1;
358 else if (strcmp(valptr
, "rtol") == 0)
359 Directions
[NumFonts
] = -1;
362 fprintf(stderr
, "ERROR: Bad text direction %s\n", valptr
);
368 * Got the direction, now get the width...
371 while (isspace(*lineptr
& 255))
376 while (!isspace(*lineptr
& 255) && *lineptr
)
382 * Can't have a font without all required values...
385 fprintf(stderr
, "ERROR: bad font description line: %s\n", valptr
);
392 if (strcmp(valptr
, "single") == 0)
393 Widths
[NumFonts
] = 1;
394 else if (strcmp(valptr
, "double") == 0)
395 Widths
[NumFonts
] = 2;
398 fprintf(stderr
, "ERROR: Bad text width %s\n", valptr
);
407 for (i
= 0; *lineptr
&& i
< 4; i
++)
409 while (isspace(*lineptr
& 255))
414 while (!isspace(*lineptr
& 255) && *lineptr
)
420 if (lineptr
> valptr
)
421 Fonts
[NumFonts
][i
] = strdup(valptr
);
425 * Fill in remaining fonts as needed...
428 for (j
= i
; j
< 4; j
++)
429 Fonts
[NumFonts
][j
] = strdup(Fonts
[NumFonts
][0]);
432 * Define the character mappings...
435 for (i
= start
, j
= NumFonts
* 256; i
<= end
; i
++, j
++)
442 * Read encoding lines...
448 * Skip comment and blank lines...
451 if (line
[0] == '#' || line
[0] == '\n')
455 * Grab the character and unicode glyph number.
458 if (sscanf(line
, "%x%x", &ch
, &unicode
) == 2 && ch
< 256)
459 Codes
[Chars
[ch
]] = unicode
;
461 while (fgets(line
, sizeof(line
), fp
) != NULL
);
465 else if (strcmp(lineptr
, "utf8") == 0)
468 * UTF-8 (Unicode) text...
474 * Read the font descriptions...
479 while (fgets(line
, sizeof(line
), fp
) != NULL
)
482 * Skip comment and blank lines...
485 if (line
[0] == '#' || line
[0] == '\n')
489 * Read the font descriptions that should look like:
491 * start end direction width normal [bold italic bold-italic]
496 start
= strtol(lineptr
, &lineptr
, 16);
497 end
= strtol(lineptr
, &lineptr
, 16);
499 while (isspace(*lineptr
& 255))
504 while (!isspace(*lineptr
& 255) && *lineptr
)
510 * Can't have a font without all required values...
513 fprintf(stderr
, "ERROR: bad font description line: %s\n", valptr
);
520 if (strcmp(valptr
, "ltor") == 0)
521 Directions
[NumFonts
] = 1;
522 else if (strcmp(valptr
, "rtol") == 0)
523 Directions
[NumFonts
] = -1;
526 fprintf(stderr
, "ERROR: Bad text direction %s\n", valptr
);
532 * Got the direction, now get the width...
535 while (isspace(*lineptr
& 255))
540 while (!isspace(*lineptr
& 255) && *lineptr
)
546 * Can't have a font without all required values...
549 fprintf(stderr
, "ERROR: bad font description line: %s\n", valptr
);
556 if (strcmp(valptr
, "single") == 0)
557 Widths
[NumFonts
] = 1;
558 else if (strcmp(valptr
, "double") == 0)
559 Widths
[NumFonts
] = 2;
562 fprintf(stderr
, "ERROR: Bad text width %s\n", valptr
);
571 for (i
= 0; *lineptr
&& i
< 4; i
++)
573 while (isspace(*lineptr
& 255))
578 while (!isspace(*lineptr
& 255) && *lineptr
)
584 if (lineptr
> valptr
)
585 Fonts
[NumFonts
][i
] = strdup(valptr
);
589 * Fill in remaining fonts as needed...
592 for (j
= i
; j
< 4; j
++)
593 Fonts
[NumFonts
][j
] = strdup(Fonts
[NumFonts
][0]);
596 * Define the character mappings...
599 for (i
= start
, j
= NumFonts
* 256; i
<= end
; i
++, j
++)
606 * Move to the next font, stopping if needed...
618 fprintf(stderr
, "ERROR: Bad charset type %s\n", lineptr
);
626 * Standard ASCII output just uses Courier, Courier-Bold, and
627 * possibly Courier-Oblique.
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");
641 * Define US-ASCII characters...
644 for (i
= 32; i
< 127; i
++)
652 * Generate a list of unique fonts to use...
655 for (i
= 0, num_fonts
= 0; i
< NumFonts
; i
++)
656 for (j
= PrettyPrint
? 2 : 1; j
>= 0; j
--)
658 for (k
= 0; k
< num_fonts
; k
++)
659 if (strcmp(Fonts
[i
][j
], fonts
[k
]) == 0)
668 fonts
[num_fonts
] = Fonts
[i
][j
];
674 * List the fonts that will be used...
677 for (i
= 0; i
< num_fonts
; i
++)
679 printf("%%%%DocumentNeededResources: font %s\n", fonts
[i
]);
681 printf("%%%%+ font %s\n", fonts
[i
]);
683 puts("%%DocumentSuppliedResources: procset texttops 1.1 0");
685 for (i
= 0; i
< num_fonts
; i
++)
689 fprintf(stderr
, "DEBUG: ppd->num_fonts = %d\n", ppd
->num_fonts
);
691 for (j
= 0; j
< ppd
->num_fonts
; j
++)
693 fprintf(stderr
, "DEBUG: ppd->fonts[%d] = %s\n", j
, ppd
->fonts
[j
]);
695 if (strcmp(fonts
[i
], ppd
->fonts
[j
]) == 0)
702 if ((ppd
!= NULL
&& j
>= ppd
->num_fonts
) ||
703 strncmp(fonts
[i
], "Courier", 7) == 0 ||
704 strcmp(fonts
[i
], "Symbol") == 0)
707 * Need to embed this font...
710 printf("%%%%+ font %s\n", fonts
[i
]);
714 puts("%%EndComments");
716 puts("%%BeginProlog");
719 * Download any missing fonts...
722 for (i
= 0; i
< num_fonts
; i
++)
726 for (j
= 0; j
< ppd
->num_fonts
; j
++)
727 if (strcmp(fonts
[i
], ppd
->fonts
[j
]) == 0)
733 if ((ppd
!= NULL
&& j
>= ppd
->num_fonts
) ||
734 strncmp(fonts
[i
], "Courier", 7) == 0 ||
735 strcmp(fonts
[i
], "Symbol") == 0)
738 * Need to embed this font...
741 printf("%%%%BeginResource: font %s\n", fonts
[i
]);
743 /**** MRS: Need to use CUPS_FONTPATH env var! ****/
744 /**** Also look for Fontmap file or name.pfa, name.pfb... ****/
745 snprintf(filename
, sizeof(filename
), "%s/fonts/%s", datadir
, fonts
[i
]);
746 if ((fp
= fopen(filename
, "rb")) != NULL
)
748 while ((j
= fread(line
, 1, sizeof(line
), fp
)) > 0)
749 fwrite(line
, 1, j
, stdout
);
754 puts("\n%%EndResource");
759 * Write the encoding array(s)...
762 puts("% character encoding(s)");
764 for (i
= 0; i
< NumFonts
; i
++)
766 printf("/cupsEncoding%02x [\n", i
);
768 for (ch
= 0; ch
< 256; ch
++)
770 if (Glyphs
[Codes
[i
* 256 + ch
]])
771 printf("/%s", Glyphs
[Codes
[i
* 256 + ch
]]);
772 else if (Codes
[i
* 256 + ch
] > 255)
773 printf("/uni%04X", Codes
[i
* 256 + ch
]);
785 * Create the fonts...
791 * Just reencode the named fonts...
794 puts("% Reencode fonts");
796 for (i
= PrettyPrint
? 2 : 1; i
>= 0; i
--)
798 printf("/%s findfont\n", Fonts
[0][i
]);
799 puts("dup length 1 add dict begin\n"
800 " { 1 index /FID ne { def } { pop pop } ifelse } forall\n"
801 " /Encoding cupsEncoding00 def\n"
804 printf("/%s exch definefont pop\n", names
[i
]);
810 * Construct composite fonts... Start by reencoding the base fonts...
813 puts("% Reencode base fonts");
815 for (i
= 1 + PrettyPrint
; i
>= 0; i
--)
816 for (j
= 0; j
< NumFonts
; j
++)
818 printf("/%s findfont\n", Fonts
[j
][i
]);
819 printf("dup length 1 add dict begin\n"
820 " { 1 index /FID ne { def } { pop pop } ifelse } forall\n"
821 " /Encoding cupsEncoding%02x def\n"
824 printf("/%s%02x exch definefont /%s%02x exch def\n", names
[i
], j
,
829 * Then merge them into composite fonts...
832 puts("% Create composite fonts...");
834 for (i
= 1 + PrettyPrint
; i
>= 0; i
--)
836 puts("8 dict begin");
837 puts("/FontType 0 def/FontMatrix[1.0 0 0 1.0 0 0]def/FMapType 2 def/Encoding[");
838 for (j
= 0; j
< NumFonts
; j
++)
839 if (j
== (NumFonts
- 1))
841 else if ((j
& 15) == 15)
845 puts("]def/FDepVector[");
846 for (j
= 0; j
< NumFonts
; j
++)
847 if (j
== (NumFonts
- 1))
848 printf("%s%02x", names
[i
], j
);
849 else if ((j
& 3) == 3)
850 printf("%s%02x\n", names
[i
], j
);
852 printf("%s%02x ", names
[i
], j
);
853 puts("]def currentdict end");
854 printf("/%s exch definefont pop\n", names
[i
]);
859 * Output the texttops procset...
862 puts("%%BeginResource: procset texttops 1.1 0");
864 puts("% Define fonts");
866 printf("/FN /cupsNormal findfont [%.3f 0 0 %.3f 0 0] makefont def\n",
867 120.0 / CharsPerInch
, 68.0 / LinesPerInch
);
868 printf("/FB /cupsBold findfont [%.3f 0 0 %.3f 0 0] makefont def\n",
869 120.0 / CharsPerInch
, 68.0 / LinesPerInch
);
871 printf("/FI /cupsItalic findfont [%.3f 0 0 %.3f 0 0] makefont def\n",
872 120.0 / CharsPerInch
, 68.0 / LinesPerInch
);
874 puts("% Common procedures");
876 puts("/N { FN setfont moveto } bind def");
877 puts("/B { FB setfont moveto } bind def");
878 printf("/U { gsave 0.5 setlinewidth 0 %.3f rmoveto "
879 "0 rlineto stroke grestore } bind def\n", -6.8 / LinesPerInch
);
885 puts("/S { 0.0 setgray show } bind def");
886 puts("/r { 0.5 0.0 0.0 setrgbcolor show } bind def");
887 puts("/g { 0.0 0.5 0.0 setrgbcolor show } bind def");
888 puts("/b { 0.0 0.0 0.5 setrgbcolor show } bind def");
892 puts("/S { 0.0 setgray show } bind def");
893 puts("/r { 0.2 setgray show } bind def");
894 puts("/g { 0.2 setgray show } bind def");
895 puts("/b { 0.2 setgray show } bind def");
898 puts("/I { FI setfont moveto } bind def");
901 puts("\t20 string cvs % convert page number to string");
905 * Convert a number to double-byte chars...
908 puts("\tdup length % get length");
909 puts("\tdup 2 mul string /P exch def % P = string twice as long");
910 puts("\t0 1 2 index 1 sub { % loop through each character in the page number");
911 puts("\t\tdup 3 index exch get % get character N from the page number");
912 puts("\t\texch 2 mul dup % compute offset in P");
913 puts("\t\tP exch 0 put % font 0");
914 puts("\t\t1 add P exch 2 index put % character");
915 puts("\t\tpop % discard character");
916 puts("\t} for % do for loop");
917 puts("\tpop pop % discard string and length");
918 puts("\tP % put string on stack");
932 puts("\t0.9 setgray");
936 puts("\tdup 2 mod 0 eq {");
937 printf("\t\t%.3f %.3f translate } {\n",
938 PageWidth
- PageRight
, PageTop
+ 72.0f
/ LinesPerInch
);
939 printf("\t\t%.3f %.3f translate } ifelse\n",
940 PageLeft
, PageTop
+ 72.0f
/ LinesPerInch
);
943 printf("\t%.3f %.3f translate\n",
944 PageLeft
, PageTop
+ 72.0f
/ LinesPerInch
);
946 printf("\t0 0 %.3f %.3f rectfill\n", PageRight
- PageLeft
,
947 144.0f
/ LinesPerInch
);
949 puts("\tFB setfont");
954 puts("\tdup 2 mod 0 eq {");
955 printf("\t\tT stringwidth pop neg %.3f add %.3f } {\n",
956 PageRight
- PageLeft
- 36.0f
/ LinesPerInch
,
957 (0.5f
+ 0.157f
) * 72.0f
/ LinesPerInch
);
958 printf("\t\t%.3f %.3f } ifelse\n", 36.0f
/ LinesPerInch
,
959 (0.5f
+ 0.157f
) * 72.0f
/ LinesPerInch
);
962 printf("\t%.3f %.3f\n", 36.0f
/ LinesPerInch
,
963 (0.5f
+ 0.157f
) * 72.0f
/ LinesPerInch
);
965 puts("\tmoveto T show");
967 printf("\tD dup stringwidth pop neg 2 div %.3f add %.3f\n",
968 (PageRight
- PageLeft
) * 0.5,
969 (0.5f
+ 0.157f
) * 72.0f
/ LinesPerInch
);
970 puts("\tmoveto show");
974 puts("\tdup n exch 2 mod 0 eq {");
975 printf("\t\t%.3f %.3f } {\n", 36.0f
/ LinesPerInch
,
976 (0.5f
+ 0.157f
) * 72.0f
/ LinesPerInch
);
977 printf("\t\tdup stringwidth pop neg %.3f add %.3f } ifelse\n",
978 PageRight
- PageLeft
- 36.0f
/ LinesPerInch
,
979 (0.5f
+ 0.157f
) * 72.0f
/ LinesPerInch
);
982 printf("\tn dup stringwidth pop neg %.3f add %.3f\n",
983 PageRight
- PageLeft
- 36.0f
/ LinesPerInch
,
984 (0.5f
+ 0.157f
) * 72.0f
/ LinesPerInch
);
986 puts("\tmoveto show");
991 puts("/S { show } bind def");
993 puts("%%EndResource");
1000 * 'write_line()' - Write a row of text.
1004 write_line(int row
, /* I - Row number (0 to N) */
1005 lchar_t
*line
) /* I - Line to print */
1007 int i
; /* Looping var */
1008 int col
; /* Current column */
1009 int attr
; /* Current attribute */
1010 int font
, /* Font to use */
1011 lastfont
, /* Last font */
1012 mono
; /* Monospaced? */
1013 lchar_t
*start
; /* First character in sequence */
1016 for (col
= 0, start
= line
; col
< SizeColumns
;)
1018 while (col
< SizeColumns
&& (line
->ch
== ' ' || line
->ch
== 0))
1024 if (col
>= SizeColumns
)
1030 * All characters in a single font - assume monospaced...
1036 while (col
< SizeColumns
&& line
->ch
!= 0 && attr
== line
->attr
)
1042 write_string(col
- (line
- start
), row
, line
- start
, start
);
1047 * Multiple fonts; break up based on the font...
1052 lastfont
= Chars
[line
->ch
] / 256;
1053 mono
= strncmp(Fonts
[lastfont
][0], "Courier", 7) == 0;
1059 while (col
< SizeColumns
&& line
->ch
!= 0 && attr
== line
->attr
)
1061 font
= Chars
[line
->ch
] / 256;
1062 if (strncmp(Fonts
[font
][0], "Courier", 7) != 0 ||
1071 if (Directions
[lastfont
] > 0)
1072 write_string(col
- (line
- start
), row
, line
- start
, start
);
1076 * Do right-to-left text...
1079 while (col
< SizeColumns
&& line
->ch
!= 0 && attr
== line
->attr
)
1081 if (Directions
[Chars
[line
->ch
] / 256] > 0 &&
1082 !ispunct(line
->ch
& 255) && !isspace(line
->ch
& 255))
1089 for (i
= 1; start
< line
; i
++, start
++)
1090 if (!isspace(start
->ch
& 255))
1091 write_string(col
- i
, row
, 1, start
);
1099 * 'write_string()' - Write a string of text.
1103 write_string(int col
, /* I - Start column */
1104 int row
, /* I - Row */
1105 int len
, /* I - Number of characters */
1106 lchar_t
*s
) /* I - String to print */
1108 int ch
; /* Current character */
1109 float x
, y
; /* Position of text */
1110 unsigned attr
; /* Character attributes */
1114 * Position the text and set the font...
1117 if (Duplex
&& (NumPages
& 1) == 0)
1119 x
= PageWidth
- PageRight
;
1128 x
+= (float)col
* 72.0f
/ (float)CharsPerInch
;
1129 y
-= (float)(row
+ 0.843) * 72.0f
/ (float)LinesPerInch
;
1133 if (attr
& ATTR_RAISED
)
1134 y
+= 36.0 / (float)LinesPerInch
;
1135 else if (attr
& ATTR_LOWERED
)
1136 y
-= 36.0 / (float)LinesPerInch
;
1148 if (attr
& ATTR_BOLD
)
1150 else if (attr
& ATTR_ITALIC
)
1155 if (attr
& ATTR_UNDERLINE
)
1156 printf(" %.3f U", (float)len
* 72.0 / (float)CharsPerInch
);
1161 * Write a hex string...
1168 printf("%04x", Chars
[s
->ch
]);
1179 * Write a quoted string...
1188 if (ch
< 32 || ch
> 126)
1191 * Quote 8-bit and control characters...
1194 printf("\\%03o", ch
);
1199 * Quote the parenthesis and backslash as needed...
1202 if (ch
== '(' || ch
== ')' || ch
== '\\')
1217 if (attr
& ATTR_RED
)
1219 else if (attr
& ATTR_GREEN
)
1221 else if (attr
& ATTR_BLUE
)
1232 * 'write_text()' - Write a text string, quoting/encoding as needed.
1236 write_text(const char *s
) /* I - String to write */
1238 int ch
; /* Actual character value (UTF8) */
1239 const unsigned char *utf8
; /* UTF8 text */
1250 utf8
= (const unsigned char *)s
;
1254 if (*utf8
< 0xc0 || !UTF8
)
1256 else if ((*utf8
& 0xe0) == 0xc0)
1259 * Two byte character...
1262 ch
= ((utf8
[0] & 0x1f) << 6) | (utf8
[1] & 0x3f);
1268 * Three byte character...
1271 ch
= ((((utf8
[0] & 0x1f) << 6) | (utf8
[1] & 0x3f)) << 6) |
1276 printf("%04x", Chars
[ch
]);
1284 * Standard 8-bit encoding...
1291 if (*s
< 32 || *s
> 126)
1292 printf("\\%03o", *s
);
1295 if (*s
== '(' || *s
== ')' || *s
== '\\')