]>
git.ipfire.org Git - thirdparty/cups.git/blob - filter/bannertops.c
4 * Banner to PostScript filter for the Common UNIX Printing System (CUPS).
6 * Copyright 2008 by Apple Inc.
8 * These coded instructions, statements, and computer programs are the
9 * property of Apple Inc. and are protected by Federal copyright
10 * law. Distribution and use rights are outlined in the file "LICENSE.txt"
11 * which should have been included with this file. If this file is
12 * file is missing or damaged, see the license at "http://www.cups.org/".
14 * This file is subject to the Apple OS-Developed Software exception.
21 * Include necessary headers...
26 #include <cups/i18n.h>
33 char *Glyphs
[65536]; /* PostScript glyphs for Unicode */
34 int NumFonts
; /* Number of fonts to use */
35 char *Fonts
[256][4]; /* Fonts to use */
36 unsigned short Chars
[65536]; /* 0xffcc (ff = font, cc = char) */
37 unsigned short Codes
[65536]; /* Unicode glyph mapping to fonts */
38 int Widths
[256]; /* Widths of each font */
39 int Directions
[256];/* Text directions for each font */
46 static void write_line(int row
, lchar_t
*line
);
47 static void write_string(int col
, int row
, int len
, lchar_t
*s
);
48 static void write_text(const char *s
);
52 * 'main()' - Generate PostScript cover pages.
55 int /* O - Exit status */
56 main(int argc
, /* I - Number of command-line arguments */
57 char *argv
[]) /* I - Command-line arguments */
63 * 'WriteEpilogue()' - Write the PostScript file epilogue.
70 printf("%%%%Pages: %d\n", NumPages
);
79 * 'WritePage()' - Write a page of text.
85 int line
; /* Current line */
89 printf("%%%%Page: %d %d\n", NumPages
, NumPages
);
94 printf("%d H\n", NumPages
);
96 for (line
= 0; line
< SizeLines
; line
++)
97 write_line(line
, Page
[line
]);
102 memset(Page
[0], 0, sizeof(lchar_t
) * SizeColumns
* SizeLines
);
107 * 'WriteProlog()' - Write the PostScript file prolog with options.
111 WriteProlog(const char *title
, /* I - Title of job */
112 const char *user
, /* I - Username */
113 const char *classification
, /* I - Classification */
114 const char *label
, /* I - Page label */
115 ppd_file_t
*ppd
) /* I - PPD file info */
117 int i
, j
, k
; /* Looping vars */
118 char *charset
; /* Character set string */
119 char filename
[1024]; /* Glyph filenames */
120 FILE *fp
; /* Glyph files */
121 const char *datadir
; /* CUPS_DATADIR environment variable */
122 char line
[1024], /* Line from file */
123 *lineptr
, /* Pointer into line */
124 *valptr
; /* Pointer to value in line */
125 int ch
, unicode
; /* Character values */
126 int start
, end
; /* Start and end values for range */
127 char glyph
[64]; /* Glyph name */
128 time_t curtime
; /* Current time */
129 struct tm
*curtm
; /* Current date */
130 char curdate
[255]; /* Current date (text format) */
131 int num_fonts
; /* Number of unique fonts */
132 char *fonts
[1024]; /* Unique fonts */
133 static char *names
[] = /* Font names */
142 * Get the data directory...
145 if ((datadir
= getenv("CUPS_DATADIR")) == NULL
)
146 datadir
= CUPS_DATADIR
;
149 * Adjust margins as necessary...
152 if (classification
|| label
)
155 * Leave room for labels...
163 * Allocate memory for the page...
166 SizeColumns
= (PageRight
- PageLeft
) / 72.0 * CharsPerInch
;
167 SizeLines
= (PageTop
- PageBottom
) / 72.0 * LinesPerInch
;
169 Page
= calloc(sizeof(lchar_t
*), SizeLines
);
170 Page
[0] = calloc(sizeof(lchar_t
), SizeColumns
* SizeLines
);
171 for (i
= 1; i
< SizeLines
; i
++)
172 Page
[i
] = Page
[0] + i
* SizeColumns
;
176 ColumnGutter
= CharsPerInch
/ 2;
177 ColumnWidth
= (SizeColumns
- ColumnGutter
* (PageColumns
- 1)) /
181 ColumnWidth
= SizeColumns
;
184 * Output the DSC header...
187 curtime
= time(NULL
);
188 curtm
= localtime(&curtime
);
189 strftime(curdate
, sizeof(curdate
), "%c", curtm
);
191 puts("%!PS-Adobe-3.0");
192 printf("%%%%BoundingBox: 0 0 %.0f %.0f\n", PageWidth
, PageLength
);
193 printf("%%cupsRotation: %d\n", (Orientation
& 3) * 90);
194 puts("%%Creator: texttops/" CUPS_SVERSION
);
195 printf("%%%%CreationDate: %s\n", curdate
);
196 WriteTextComment("Title", title
);
197 WriteTextComment("For", user
);
198 puts("%%Pages: (atend)");
201 * Initialize globals...
205 memset(Fonts
, 0, sizeof(Fonts
));
206 memset(Glyphs
, 0, sizeof(Glyphs
));
207 memset(Chars
, 0, sizeof(Chars
));
208 memset(Codes
, 0, sizeof(Codes
));
211 * Load the PostScript glyph names and the corresponding character
215 snprintf(filename
, sizeof(filename
), "%s/data/psglyphs", datadir
);
217 if ((fp
= fopen(filename
, "r")) != NULL
)
219 while (fscanf(fp
, "%x%63s", &unicode
, glyph
) == 2)
220 Glyphs
[unicode
] = strdup(glyph
);
226 fprintf(stderr
, _("ERROR: Unable to open \"%s\" - %s\n"), filename
,
232 * Get the output character set...
235 charset
= getenv("CHARSET");
236 if (charset
!= NULL
&& strcmp(charset
, "us-ascii") != 0)
238 snprintf(filename
, sizeof(filename
), "%s/charsets/%s", datadir
, charset
);
240 if ((fp
= fopen(filename
, "r")) == NULL
)
243 * Can't open charset file!
246 fprintf(stderr
, _("ERROR: Unable to open %s: %s\n"), filename
,
252 * Opened charset file; now see if this is really a charset file...
255 if (fgets(line
, sizeof(line
), fp
) == NULL
)
258 * Bad/empty charset file!
262 fprintf(stderr
, _("ERROR: Bad charset file %s\n"), filename
);
266 if (strncmp(line
, "charset", 7) != 0)
269 * Bad format/not a charset file!
273 fprintf(stderr
, _("ERROR: Bad charset file %s\n"), filename
);
278 * See if this is an 8-bit or UTF-8 character set file...
281 line
[strlen(line
) - 1] = '\0'; /* Drop \n */
282 for (lineptr
= line
+ 7; isspace(*lineptr
& 255); lineptr
++); /* Skip whitespace */
284 if (strcmp(lineptr
, "8bit") == 0)
294 * Read the font description(s)...
297 while (fgets(line
, sizeof(line
), fp
) != NULL
)
300 * Skip comment and blank lines...
303 if (line
[0] == '#' || line
[0] == '\n')
307 * Read the font descriptions that should look like:
309 * first last direction width normal [bold italic bold-italic]
314 start
= strtol(lineptr
, &lineptr
, 16);
315 end
= strtol(lineptr
, &lineptr
, 16);
317 while (isspace(*lineptr
& 255))
321 break; /* Must be a font mapping */
325 while (!isspace(*lineptr
& 255) && *lineptr
)
331 * Can't have a font without all required values...
334 fprintf(stderr
, _("ERROR: Bad font description line: %s\n"), valptr
);
341 if (strcmp(valptr
, "ltor") == 0)
342 Directions
[NumFonts
] = 1;
343 else if (strcmp(valptr
, "rtol") == 0)
344 Directions
[NumFonts
] = -1;
347 fprintf(stderr
, _("ERROR: Bad text direction %s\n"), valptr
);
353 * Got the direction, now get the width...
356 while (isspace(*lineptr
& 255))
361 while (!isspace(*lineptr
& 255) && *lineptr
)
367 * Can't have a font without all required values...
370 fprintf(stderr
, _("ERROR: Bad font description line: %s\n"), valptr
);
377 if (strcmp(valptr
, "single") == 0)
378 Widths
[NumFonts
] = 1;
379 else if (strcmp(valptr
, "double") == 0)
380 Widths
[NumFonts
] = 2;
383 fprintf(stderr
, _("ERROR: Bad text width %s\n"), valptr
);
392 for (i
= 0; *lineptr
&& i
< 4; i
++)
394 while (isspace(*lineptr
& 255))
399 while (!isspace(*lineptr
& 255) && *lineptr
)
405 if (lineptr
> valptr
)
406 Fonts
[NumFonts
][i
] = strdup(valptr
);
410 * Fill in remaining fonts as needed...
413 for (j
= i
; j
< 4; j
++)
414 Fonts
[NumFonts
][j
] = strdup(Fonts
[NumFonts
][0]);
417 * Define the character mappings...
420 for (i
= start
, j
= NumFonts
* 256; i
<= end
; i
++, j
++)
427 * Read encoding lines...
433 * Skip comment and blank lines...
436 if (line
[0] == '#' || line
[0] == '\n')
440 * Grab the character and unicode glyph number.
443 if (sscanf(line
, "%x%x", &ch
, &unicode
) == 2 && ch
< 256)
444 Codes
[Chars
[ch
]] = unicode
;
446 while (fgets(line
, sizeof(line
), fp
) != NULL
);
450 else if (strcmp(lineptr
, "utf8") == 0)
453 * UTF-8 (Unicode) text...
459 * Read the font descriptions...
464 while (fgets(line
, sizeof(line
), fp
) != NULL
)
467 * Skip comment and blank lines...
470 if (line
[0] == '#' || line
[0] == '\n')
474 * Read the font descriptions that should look like:
476 * start end direction width normal [bold italic bold-italic]
481 start
= strtol(lineptr
, &lineptr
, 16);
482 end
= strtol(lineptr
, &lineptr
, 16);
484 while (isspace(*lineptr
& 255))
489 while (!isspace(*lineptr
& 255) && *lineptr
)
495 * Can't have a font without all required values...
498 fprintf(stderr
, _("ERROR: Bad font description line: %s\n"), valptr
);
505 if (strcmp(valptr
, "ltor") == 0)
506 Directions
[NumFonts
] = 1;
507 else if (strcmp(valptr
, "rtol") == 0)
508 Directions
[NumFonts
] = -1;
511 fprintf(stderr
, _("ERROR: Bad text direction %s\n"), valptr
);
517 * Got the direction, now get the width...
520 while (isspace(*lineptr
& 255))
525 while (!isspace(*lineptr
& 255) && *lineptr
)
531 * Can't have a font without all required values...
534 fprintf(stderr
, _("ERROR: Bad font description line: %s\n"), valptr
);
541 if (strcmp(valptr
, "single") == 0)
542 Widths
[NumFonts
] = 1;
543 else if (strcmp(valptr
, "double") == 0)
544 Widths
[NumFonts
] = 2;
547 fprintf(stderr
, _("ERROR: Bad text width %s\n"), valptr
);
556 for (i
= 0; *lineptr
&& i
< 4; i
++)
558 while (isspace(*lineptr
& 255))
563 while (!isspace(*lineptr
& 255) && *lineptr
)
569 if (lineptr
> valptr
)
570 Fonts
[NumFonts
][i
] = strdup(valptr
);
574 * Fill in remaining fonts as needed...
577 for (j
= i
; j
< 4; j
++)
578 Fonts
[NumFonts
][j
] = strdup(Fonts
[NumFonts
][0]);
581 * Define the character mappings...
584 for (i
= start
, j
= NumFonts
* 256; i
<= end
; i
++, j
++)
591 * Move to the next font, stopping if needed...
603 fprintf(stderr
, _("ERROR: Bad charset type %s\n"), lineptr
);
611 * Standard ASCII output just uses Courier, Courier-Bold, and
612 * possibly Courier-Oblique.
617 Fonts
[0][ATTR_NORMAL
] = strdup("Courier");
618 Fonts
[0][ATTR_BOLD
] = strdup("Courier-Bold");
619 Fonts
[0][ATTR_ITALIC
] = strdup("Courier-Oblique");
620 Fonts
[0][ATTR_BOLDITALIC
] = strdup("Courier-BoldOblique");
626 * Define US-ASCII characters...
629 for (i
= 32; i
< 127; i
++)
637 * Generate a list of unique fonts to use...
640 for (i
= 0, num_fonts
= 0; i
< NumFonts
; i
++)
641 for (j
= PrettyPrint
? 2 : 1; j
>= 0; j
--)
643 for (k
= 0; k
< num_fonts
; k
++)
644 if (strcmp(Fonts
[i
][j
], fonts
[k
]) == 0)
653 fonts
[num_fonts
] = Fonts
[i
][j
];
659 * List the fonts that will be used...
662 for (i
= 0; i
< num_fonts
; i
++)
664 printf("%%%%DocumentNeededResources: font %s\n", fonts
[i
]);
666 printf("%%%%+ font %s\n", fonts
[i
]);
668 puts("%%DocumentSuppliedResources: procset texttops 1.1 0");
670 for (i
= 0; i
< num_fonts
; i
++)
674 fprintf(stderr
, "DEBUG: ppd->num_fonts = %d\n", ppd
->num_fonts
);
676 for (j
= 0; j
< ppd
->num_fonts
; j
++)
678 fprintf(stderr
, "DEBUG: ppd->fonts[%d] = %s\n", j
, ppd
->fonts
[j
]);
680 if (strcmp(fonts
[i
], ppd
->fonts
[j
]) == 0)
687 if ((ppd
!= NULL
&& j
>= ppd
->num_fonts
) ||
688 strncmp(fonts
[i
], "Courier", 7) == 0 ||
689 strcmp(fonts
[i
], "Symbol") == 0)
692 * Need to embed this font...
695 printf("%%%%+ font %s\n", fonts
[i
]);
699 puts("%%EndComments");
701 puts("%%BeginProlog");
704 * Download any missing fonts...
707 for (i
= 0; i
< num_fonts
; i
++)
711 for (j
= 0; j
< ppd
->num_fonts
; j
++)
712 if (strcmp(fonts
[i
], ppd
->fonts
[j
]) == 0)
718 if ((ppd
!= NULL
&& j
>= ppd
->num_fonts
) ||
719 strncmp(fonts
[i
], "Courier", 7) == 0 ||
720 strcmp(fonts
[i
], "Symbol") == 0)
723 * Need to embed this font...
726 printf("%%%%BeginResource: font %s\n", fonts
[i
]);
728 /**** MRS: Need to use CUPS_FONTPATH env var! ****/
729 /**** Also look for Fontmap file or name.pfa, name.pfb... ****/
730 snprintf(filename
, sizeof(filename
), "%s/fonts/%s", datadir
, fonts
[i
]);
731 if ((fp
= fopen(filename
, "rb")) != NULL
)
733 while ((j
= fread(line
, 1, sizeof(line
), fp
)) > 0)
734 fwrite(line
, 1, j
, stdout
);
739 puts("\n%%EndResource");
744 * Write the encoding array(s)...
747 puts("% character encoding(s)");
749 for (i
= 0; i
< NumFonts
; i
++)
751 printf("/cupsEncoding%02x [\n", i
);
753 for (ch
= 0; ch
< 256; ch
++)
755 if (Glyphs
[Codes
[i
* 256 + ch
]])
756 printf("/%s", Glyphs
[Codes
[i
* 256 + ch
]]);
757 else if (Codes
[i
* 256 + ch
] > 255)
758 printf("/uni%04X", Codes
[i
* 256 + ch
]);
770 * Create the fonts...
776 * Just reencode the named fonts...
779 puts("% Reencode fonts");
781 for (i
= PrettyPrint
? 2 : 1; i
>= 0; i
--)
783 printf("/%s findfont\n", Fonts
[0][i
]);
784 puts("dup length 1 add dict begin\n"
785 " { 1 index /FID ne { def } { pop pop } ifelse } forall\n"
786 " /Encoding cupsEncoding00 def\n"
789 printf("/%s exch definefont pop\n", names
[i
]);
795 * Construct composite fonts... Start by reencoding the base fonts...
798 puts("% Reencode base fonts");
800 for (i
= PrettyPrint
? 2 : 1; i
>= 0; i
--)
801 for (j
= 0; j
< NumFonts
; j
++)
803 printf("/%s findfont\n", Fonts
[j
][i
]);
804 printf("dup length 1 add dict begin\n"
805 " { 1 index /FID ne { def } { pop pop } ifelse } forall\n"
806 " /Encoding cupsEncoding%02x def\n"
809 printf("/%s%02x exch definefont /%s%02x exch def\n", names
[i
], j
,
814 * Then merge them into composite fonts...
817 puts("% Create composite fonts...");
819 for (i
= PrettyPrint
? 2 : 1; i
>= 0; i
--)
821 puts("8 dict begin");
822 puts("/FontType 0 def/FontMatrix[1.0 0 0 1.0 0 0]def/FMapType 2 def/Encoding[");
823 for (j
= 0; j
< NumFonts
; j
++)
824 if (j
== (NumFonts
- 1))
826 else if ((j
& 15) == 15)
830 puts("]def/FDepVector[");
831 for (j
= 0; j
< NumFonts
; j
++)
832 if (j
== (NumFonts
- 1))
833 printf("%s%02x", names
[i
], j
);
834 else if ((j
& 3) == 3)
835 printf("%s%02x\n", names
[i
], j
);
837 printf("%s%02x ", names
[i
], j
);
838 puts("]def currentdict end");
839 printf("/%s exch definefont pop\n", names
[i
]);
844 * Output the texttops procset...
847 puts("%%BeginResource: procset texttops 1.1 0");
849 puts("% Define fonts");
851 printf("/FN /cupsNormal findfont [%.3f 0 0 %.3f 0 0] makefont def\n",
852 120.0 / CharsPerInch
, 68.0 / LinesPerInch
);
853 printf("/FB /cupsBold findfont [%.3f 0 0 %.3f 0 0] makefont def\n",
854 120.0 / CharsPerInch
, 68.0 / LinesPerInch
);
856 printf("/FI /cupsItalic findfont [%.3f 0 0 %.3f 0 0] makefont def\n",
857 120.0 / CharsPerInch
, 68.0 / LinesPerInch
);
859 puts("% Common procedures");
861 puts("/N { FN setfont moveto } bind def");
862 puts("/B { FB setfont moveto } bind def");
863 printf("/U { gsave 0.5 setlinewidth 0 %.3f rmoveto "
864 "0 rlineto stroke grestore } bind def\n", -6.8 / LinesPerInch
);
870 puts("/S { 0.0 setgray show } bind def");
871 puts("/r { 0.5 0.0 0.0 setrgbcolor show } bind def");
872 puts("/g { 0.0 0.5 0.0 setrgbcolor show } bind def");
873 puts("/b { 0.0 0.0 0.5 setrgbcolor show } bind def");
877 puts("/S { 0.0 setgray show } bind def");
878 puts("/r { 0.2 setgray show } bind def");
879 puts("/g { 0.2 setgray show } bind def");
880 puts("/b { 0.2 setgray show } bind def");
883 puts("/I { FI setfont moveto } bind def");
886 puts("\t20 string cvs % convert page number to string");
890 * Convert a number to double-byte chars...
893 puts("\tdup length % get length");
894 puts("\tdup 2 mul string /P exch def % P = string twice as long");
895 puts("\t0 1 2 index 1 sub { % loop through each character in the page number");
896 puts("\t\tdup 3 index exch get % get character N from the page number");
897 puts("\t\texch 2 mul dup % compute offset in P");
898 puts("\t\tP exch 0 put % font 0");
899 puts("\t\t1 add P exch 2 index put % character");
900 puts("\t\tpop % discard character");
901 puts("\t} for % do for loop");
902 puts("\tpop pop % discard string and length");
903 puts("\tP % put string on stack");
917 puts("\t0.9 setgray");
921 puts("\tdup 2 mod 0 eq {");
922 printf("\t\t%.3f %.3f translate } {\n",
923 PageWidth
- PageRight
, PageTop
+ 72.0f
/ LinesPerInch
);
924 printf("\t\t%.3f %.3f translate } ifelse\n",
925 PageLeft
, PageTop
+ 72.0f
/ LinesPerInch
);
928 printf("\t%.3f %.3f translate\n",
929 PageLeft
, PageTop
+ 72.0f
/ LinesPerInch
);
931 printf("\t0 0 %.3f %.3f rectfill\n", PageRight
- PageLeft
,
932 144.0f
/ LinesPerInch
);
934 puts("\tFB setfont");
939 puts("\tdup 2 mod 0 eq {");
940 printf("\t\tT stringwidth pop neg %.3f add %.3f } {\n",
941 PageRight
- PageLeft
- 36.0f
/ LinesPerInch
,
942 (0.5f
+ 0.157f
) * 72.0f
/ LinesPerInch
);
943 printf("\t\t%.3f %.3f } ifelse\n", 36.0f
/ LinesPerInch
,
944 (0.5f
+ 0.157f
) * 72.0f
/ LinesPerInch
);
947 printf("\t%.3f %.3f\n", 36.0f
/ LinesPerInch
,
948 (0.5f
+ 0.157f
) * 72.0f
/ LinesPerInch
);
950 puts("\tmoveto T show");
952 printf("\tD dup stringwidth pop neg 2 div %.3f add %.3f\n",
953 (PageRight
- PageLeft
) * 0.5,
954 (0.5f
+ 0.157f
) * 72.0f
/ LinesPerInch
);
955 puts("\tmoveto show");
959 puts("\tdup n exch 2 mod 0 eq {");
960 printf("\t\t%.3f %.3f } {\n", 36.0f
/ LinesPerInch
,
961 (0.5f
+ 0.157f
) * 72.0f
/ LinesPerInch
);
962 printf("\t\tdup stringwidth pop neg %.3f add %.3f } ifelse\n",
963 PageRight
- PageLeft
- 36.0f
/ LinesPerInch
,
964 (0.5f
+ 0.157f
) * 72.0f
/ LinesPerInch
);
967 printf("\tn dup stringwidth pop neg %.3f add %.3f\n",
968 PageRight
- PageLeft
- 36.0f
/ LinesPerInch
,
969 (0.5f
+ 0.157f
) * 72.0f
/ LinesPerInch
);
971 puts("\tmoveto show");
976 puts("/S { show } bind def");
978 puts("%%EndResource");
985 * 'write_line()' - Write a row of text.
989 write_line(int row
, /* I - Row number (0 to N) */
990 lchar_t
*line
) /* I - Line to print */
992 int i
; /* Looping var */
993 int col
; /* Current column */
994 int attr
; /* Current attribute */
995 int font
, /* Font to use */
996 lastfont
, /* Last font */
997 mono
; /* Monospaced? */
998 lchar_t
*start
; /* First character in sequence */
1001 for (col
= 0; col
< SizeColumns
;)
1003 while (col
< SizeColumns
&& (line
->ch
== ' ' || line
->ch
== 0))
1009 if (col
>= SizeColumns
)
1015 * All characters in a single font - assume monospaced...
1021 while (col
< SizeColumns
&& line
->ch
!= 0 && attr
== line
->attr
)
1027 write_string(col
- (line
- start
), row
, line
- start
, start
);
1032 * Multiple fonts; break up based on the font...
1037 lastfont
= Chars
[line
->ch
] / 256;
1038 mono
= strncmp(Fonts
[lastfont
][0], "Courier", 7) == 0;
1044 while (col
< SizeColumns
&& line
->ch
!= 0 && attr
== line
->attr
)
1046 font
= Chars
[line
->ch
] / 256;
1047 if (strncmp(Fonts
[font
][0], "Courier", 7) != 0 ||
1056 if (Directions
[lastfont
] > 0)
1057 write_string(col
- (line
- start
), row
, line
- start
, start
);
1061 * Do right-to-left text...
1064 while (col
< SizeColumns
&& line
->ch
!= 0 && attr
== line
->attr
)
1066 if (Directions
[Chars
[line
->ch
] / 256] > 0 &&
1067 !ispunct(line
->ch
& 255) && !isspace(line
->ch
& 255))
1074 for (i
= 1; start
< line
; i
++, start
++)
1075 if (!isspace(start
->ch
& 255))
1076 write_string(col
- i
, row
, 1, start
);
1084 * 'write_string()' - Write a string of text.
1088 write_string(int col
, /* I - Start column */
1089 int row
, /* I - Row */
1090 int len
, /* I - Number of characters */
1091 lchar_t
*s
) /* I - String to print */
1093 int ch
; /* Current character */
1094 float x
, y
; /* Position of text */
1095 unsigned attr
; /* Character attributes */
1099 * Position the text and set the font...
1102 if (Duplex
&& (NumPages
& 1) == 0)
1104 x
= PageWidth
- PageRight
;
1113 x
+= (float)col
* 72.0f
/ (float)CharsPerInch
;
1114 y
-= (float)(row
+ 0.843) * 72.0f
/ (float)LinesPerInch
;
1118 if (attr
& ATTR_RAISED
)
1119 y
+= 36.0 / (float)LinesPerInch
;
1120 else if (attr
& ATTR_LOWERED
)
1121 y
-= 36.0 / (float)LinesPerInch
;
1133 if (attr
& ATTR_BOLD
)
1135 else if (attr
& ATTR_ITALIC
)
1140 if (attr
& ATTR_UNDERLINE
)
1141 printf(" %.3f U", (float)len
* 72.0 / (float)CharsPerInch
);
1146 * Write a hex string...
1153 printf("%04x", Chars
[s
->ch
]);
1164 * Write a quoted string...
1173 if (ch
< 32 || ch
> 126)
1176 * Quote 8-bit and control characters...
1179 printf("\\%03o", ch
);
1184 * Quote the parenthesis and backslash as needed...
1187 if (ch
== '(' || ch
== ')' || ch
== '\\')
1202 if (attr
& ATTR_RED
)
1204 else if (attr
& ATTR_GREEN
)
1206 else if (attr
& ATTR_BLUE
)
1217 * 'write_text()' - Write a text string, quoting/encoding as needed.
1221 write_text(const char *s
) /* I - String to write */
1223 int ch
; /* Actual character value (UTF8) */
1224 const unsigned char *utf8
; /* UTF8 text */
1235 utf8
= (const unsigned char *)s
;
1239 if (*utf8
< 0xc0 || !UTF8
)
1241 else if ((*utf8
& 0xe0) == 0xc0)
1244 * Two byte character...
1247 ch
= ((utf8
[0] & 0x1f) << 6) | (utf8
[1] & 0x3f);
1253 * Three byte character...
1256 ch
= ((((utf8
[0] & 0x1f) << 6) | (utf8
[1] & 0x3f)) << 6) |
1261 printf("%04x", Chars
[ch
]);
1269 * Standard 8-bit encoding...
1276 if (*s
< 32 || *s
> 126)
1277 printf("\\%03o", *s
);
1280 if (*s
== '(' || *s
== ')' || *s
== '\\')