/*
- * "$Id: texttops.c,v 1.47 2002/08/14 04:09:30 mike Exp $"
+ * "$Id$"
*
- * Text to PostScript filter for the Common UNIX Printing System (CUPS).
+ * Text to PostScript filter for CUPS.
*
- * Copyright 1993-2002 by Easy Software Products.
+ * Copyright 2007-2010 by Apple Inc.
+ * Copyright 1993-2007 by Easy Software Products.
*
* These coded instructions, statements, and computer programs are the
- * property of Easy Software Products and are protected by Federal
- * copyright law. Distribution and use rights are outlined in the file
- * "LICENSE.txt" which should have been included with this file. If this
- * file is missing or damaged please contact Easy Software Products
- * at:
- *
- * Attn: CUPS Licensing Information
- * Easy Software Products
- * 44141 Airport View Drive, Suite 204
- * Hollywood, Maryland 20636-3111 USA
- *
- * Voice: (301) 373-9603
- * EMail: cups-info@cups.org
- * WWW: http://www.cups.org
+ * property of Apple Inc. and are protected by Federal copyright
+ * law. Distribution and use rights are outlined in the file "LICENSE.txt"
+ * which should have been included with this file. If this file is
+ * file is missing or damaged, see the license at "http://www.cups.org/".
*
* This file is subject to the Apple OS-Developed Software exception.
*
*/
#include "textcommon.h"
+#include <cups/language-private.h>
/*
SizeColumns = (PageRight - PageLeft) / 72.0 * CharsPerInch;
SizeLines = (PageTop - PageBottom) / 72.0 * LinesPerInch;
- Page = calloc(sizeof(lchar_t *), SizeLines);
- Page[0] = calloc(sizeof(lchar_t), SizeColumns * SizeLines);
+ if (SizeColumns <= 0 || SizeColumns > 32767 ||
+ SizeLines <= 0 || SizeLines > 32767)
+ {
+ _cupsLangPrintFilter(stderr, "ERROR",
+ _("Unable to print %dx%d text page.\n"),
+ SizeColumns, SizeLines);
+ exit(1);
+ }
+
+ if ((Page = calloc(sizeof(lchar_t *), SizeLines)) == NULL)
+ {
+ _cupsLangPrintFilter(stderr, "ERROR",
+ _("Unable to print %dx%d text page.\n"),
+ SizeColumns, SizeLines);
+ exit(1);
+ }
+
+ if ((Page[0] = calloc(sizeof(lchar_t), SizeColumns * SizeLines)) == NULL)
+ {
+ _cupsLangPrintFilter(stderr, "ERROR",
+ _("Unable to print %dx%d text page.\n"),
+ SizeColumns, SizeLines);
+ exit(1);
+ }
+
for (i = 1; i < SizeLines; i ++)
Page[i] = Page[0] + i * SizeColumns;
else
ColumnWidth = SizeColumns;
+ if (ColumnWidth <= 0)
+ {
+ _cupsLangPrintFilter(stderr, "ERROR",
+ _("Unable to print %d text columns.\n"), PageColumns);
+ exit(1);
+ }
+
/*
* Output the DSC header...
*/
curtime = time(NULL);
curtm = localtime(&curtime);
- strftime(curdate, sizeof(curdate), CUPS_STRFTIME_FORMAT, curtm);
+ strftime(curdate, sizeof(curdate), "%c", curtm);
puts("%!PS-Adobe-3.0");
- printf("%%%%BoundingBox: %.0f %.0f %.0f %.0f\n", PageLeft, PageBottom,
- PageRight, PageTop);
+ printf("%%%%BoundingBox: 0 0 %.0f %.0f\n", PageWidth, PageLength);
printf("%%cupsRotation: %d\n", (Orientation & 3) * 90);
puts("%%Creator: texttops/" CUPS_SVERSION);
printf("%%%%CreationDate: %s\n", curdate);
- printf("%%%%Title: %s\n", title);
- printf("%%%%For: %s\n", user);
+ WriteTextComment("Title", title);
+ WriteTextComment("For", user);
puts("%%Pages: (atend)");
/*
}
else
{
- fprintf(stderr, "ERROR: Unable to open \"%s\" - %s\n", filename,
+ fprintf(stderr, _("ERROR: Unable to open \"%s\" - %s\n"), filename,
strerror(errno));
exit(1);
}
* Can't open charset file!
*/
- fprintf(stderr, "ERROR: Unable to open %s: %s\n", filename,
+ fprintf(stderr, _("ERROR: Unable to open %s: %s\n"), filename,
strerror(errno));
exit(1);
}
*/
fclose(fp);
- fprintf(stderr, "ERROR: Bad/empty charset file %s\n", filename);
+ fprintf(stderr, _("ERROR: Bad charset file %s\n"), filename);
exit(1);
}
*/
fclose(fp);
- fprintf(stderr, "ERROR: Bad charset file %s\n", filename);
+ fprintf(stderr, _("ERROR: Bad charset file %s\n"), filename);
exit(1);
}
*/
line[strlen(line) - 1] = '\0'; /* Drop \n */
- for (lineptr = line + 7; isspace(*lineptr); lineptr ++); /* Skip whitespace */
-
- if (strcmp(lineptr, "8bit") == 0)
- {
- /*
- * 8-bit text...
- */
-
- UTF8 = 0;
- NumFonts = 0;
-
- /*
- * Read the font description(s)...
- */
-
- while (fgets(line, sizeof(line), fp) != NULL)
- {
- /*
- * Skip comment and blank lines...
- */
-
- if (line[0] == '#' || line[0] == '\n')
- continue;
-
- /*
- * Read the font descriptions that should look like:
- *
- * first last direction width normal [bold italic bold-italic]
- */
-
- lineptr = line;
-
- start = strtol(lineptr, &lineptr, 16);
- end = strtol(lineptr, &lineptr, 16);
-
- while (isspace(*lineptr))
- lineptr ++;
-
- if (!*lineptr)
- break; /* Must be a font mapping */
-
- valptr = lineptr;
-
- while (!isspace(*lineptr) && *lineptr)
- lineptr ++;
-
- if (!*lineptr)
- {
- /*
- * Can't have a font without all required values...
- */
-
- fprintf(stderr, "ERROR: bad font description line: %s\n", valptr);
- fclose(fp);
- exit(1);
- }
-
- *lineptr++ = '\0';
-
- if (strcmp(valptr, "ltor") == 0)
- Directions[NumFonts] = 1;
- else if (strcmp(valptr, "rtol") == 0)
- Directions[NumFonts] = -1;
- else
- {
- fprintf(stderr, "ERROR: Bad text direction %s\n", valptr);
- fclose(fp);
- exit(1);
- }
-
- /*
- * Got the direction, now get the width...
- */
-
- while (isspace(*lineptr))
- lineptr ++;
-
- valptr = lineptr;
-
- while (!isspace(*lineptr) && *lineptr)
- lineptr ++;
-
- if (!*lineptr)
- {
- /*
- * Can't have a font without all required values...
- */
-
- fprintf(stderr, "ERROR: bad font description line: %s\n", valptr);
- fclose(fp);
- exit(1);
- }
-
- *lineptr++ = '\0';
-
- if (strcmp(valptr, "single") == 0)
- Widths[NumFonts] = 1;
- else if (strcmp(valptr, "double") == 0)
- Widths[NumFonts] = 2;
- else
- {
- fprintf(stderr, "ERROR: Bad text width %s\n", valptr);
- fclose(fp);
- exit(1);
- }
-
- /*
- * Get the fonts...
- */
-
- for (i = 0; *lineptr && i < 4; i ++)
- {
- while (isspace(*lineptr))
- lineptr ++;
-
- valptr = lineptr;
-
- while (!isspace(*lineptr) && *lineptr)
- lineptr ++;
-
- if (*lineptr)
- *lineptr++ = '\0';
-
- if (lineptr > valptr)
- Fonts[NumFonts][i] = strdup(valptr);
- }
-
- /*
- * Fill in remaining fonts as needed...
- */
-
- for (j = i; j < 4; j ++)
- Fonts[NumFonts][j] = strdup(Fonts[NumFonts][0]);
-
- /*
- * Define the character mappings...
- */
-
- for (i = start, j = NumFonts * 256; i <= end; i ++, j ++)
- Chars[i] = j;
-
- NumFonts ++;
- }
-
- /*
- * Read encoding lines...
- */
-
- do
- {
- /*
- * Skip comment and blank lines...
- */
+ for (lineptr = line + 7; isspace(*lineptr & 255); lineptr ++); /* Skip whitespace */
- if (line[0] == '#' || line[0] == '\n')
- continue;
-
- /*
- * Grab the character and unicode glyph number.
- */
-
- if (sscanf(line, "%x%x", &ch, &unicode) == 2 && ch < 256)
- Codes[Chars[ch]] = unicode;
- }
- while (fgets(line, sizeof(line), fp) != NULL);
-
- fclose(fp);
- }
- else if (strcmp(lineptr, "utf8") == 0)
+ if (strcmp(lineptr, "utf8") == 0)
{
/*
* UTF-8 (Unicode) text...
*/
- UTF8 = 1;
-
- /*
- * Read the font descriptions...
- */
-
NumFonts = 0;
while (fgets(line, sizeof(line), fp) != NULL)
start = strtol(lineptr, &lineptr, 16);
end = strtol(lineptr, &lineptr, 16);
- while (isspace(*lineptr))
+ while (isspace(*lineptr & 255))
lineptr ++;
valptr = lineptr;
- while (!isspace(*lineptr) && *lineptr)
+ while (!isspace(*lineptr & 255) && *lineptr)
lineptr ++;
if (!*lineptr)
* Can't have a font without all required values...
*/
- fprintf(stderr, "ERROR: bad font description line: %s\n", valptr);
+ fprintf(stderr, _("ERROR: Bad font description line: %s\n"), valptr);
fclose(fp);
exit(1);
}
Directions[NumFonts] = -1;
else
{
- fprintf(stderr, "ERROR: Bad text direction %s\n", valptr);
+ fprintf(stderr, _("ERROR: Bad text direction %s\n"), valptr);
fclose(fp);
exit(1);
}
* Got the direction, now get the width...
*/
- while (isspace(*lineptr))
+ while (isspace(*lineptr & 255))
lineptr ++;
valptr = lineptr;
- while (!isspace(*lineptr) && *lineptr)
+ while (!isspace(*lineptr & 255) && *lineptr)
lineptr ++;
if (!*lineptr)
* Can't have a font without all required values...
*/
- fprintf(stderr, "ERROR: bad font description line: %s\n", valptr);
+ fprintf(stderr, _("ERROR: Bad font description line: %s\n"), valptr);
fclose(fp);
exit(1);
}
Widths[NumFonts] = 2;
else
{
- fprintf(stderr, "ERROR: Bad text width %s\n", valptr);
+ fprintf(stderr, _("ERROR: Bad text width %s\n"), valptr);
fclose(fp);
exit(1);
}
for (i = 0; *lineptr && i < 4; i ++)
{
- while (isspace(*lineptr))
+ while (isspace(*lineptr & 255))
lineptr ++;
valptr = lineptr;
- while (!isspace(*lineptr) && *lineptr)
+ while (!isspace(*lineptr & 255) && *lineptr)
lineptr ++;
if (*lineptr)
}
else
{
- fprintf(stderr, "ERROR: Bad charset type %s\n", lineptr);
+ fprintf(stderr, _("ERROR: Bad charset type %s\n"), lineptr);
fclose(fp);
exit(1);
}
puts("% Reencode base fonts");
- for (i = 1 + PrettyPrint; i >= 0; i --)
+ for (i = PrettyPrint ? 2 : 1; i >= 0; i --)
for (j = 0; j < NumFonts; j ++)
{
printf("/%s findfont\n", Fonts[j][i]);
puts("% Create composite fonts...");
- for (i = 1 + PrettyPrint; i >= 0; i --)
+ for (i = PrettyPrint ? 2 : 1; i >= 0; i --)
{
puts("8 dict begin");
puts("/FontType 0 def/FontMatrix[1.0 0 0 1.0 0 0]def/FMapType 2 def/Encoding[");
puts("/n {");
puts("\t20 string cvs % convert page number to string");
- puts("\tdup length % get length");
- puts("\tdup 2 mul string /P exch def % P = string twice as long");
- puts("\t0 1 2 index 1 sub { % loop through each character in the page number");
- puts("\t\tdup 3 index exch get % get character N from the page number");
- puts("\t\texch 2 mul dup % compute offset in P");
- puts("\t\tP exch 0 put % font 0");
- puts("\t\t1 add P exch 2 index put % character");
- puts("\t\tpop % discard character");
- puts("\t} for % do for loop");
- puts("\tpop pop % discard string and length");
- puts("\tP % put string on stack");
+ if (NumFonts > 1)
+ {
+ /*
+ * Convert a number to double-byte chars...
+ */
+
+ puts("\tdup length % get length");
+ puts("\tdup 2 mul string /P exch def % P = string twice as long");
+ puts("\t0 1 2 index 1 sub { % loop through each character in the page number");
+ puts("\t\tdup 3 index exch get % get character N from the page number");
+ puts("\t\texch 2 mul dup % compute offset in P");
+ puts("\t\tP exch 0 put % font 0");
+ puts("\t\t1 add P exch 2 index put % character");
+ puts("\t\tpop % discard character");
+ puts("\t} for % do for loop");
+ puts("\tpop pop % discard string and length");
+ puts("\tP % put string on stack");
+ }
puts("} bind def");
printf("/T");
puts("def");
puts("/H {");
- puts("gsave");
+ puts("\tgsave");
puts("\t0.9 setgray");
if (Duplex)
lchar_t *start; /* First character in sequence */
- for (col = 0, start = line; col < SizeColumns;)
+ for (col = 0; col < SizeColumns;)
{
while (col < SizeColumns && (line->ch == ' ' || line->ch == 0))
{
while (col < SizeColumns && line->ch != 0 && attr == line->attr)
{
if (Directions[Chars[line->ch] / 256] > 0 &&
- !ispunct(line->ch) && !isspace(line->ch))
+ !ispunct(line->ch & 255) && !isspace(line->ch & 255))
break;
col ++;
}
for (i = 1; start < line; i ++, start ++)
- if (!isspace(start->ch))
+ if (!isspace(start->ch & 255))
write_string(col - i, row, 1, start);
}
}
while (*utf8)
{
- if (*utf8 < 0xc0 || !UTF8)
+ if (*utf8 < 0xc0)
ch = *utf8 ++;
else if ((*utf8 & 0xe0) == 0xc0)
{
/*
- * End of "$Id: texttops.c,v 1.47 2002/08/14 04:09:30 mike Exp $".
+ * End of "$Id$".
*/