]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - filter/texttops.c
Merge changes from CUPS 1.5svn-r9400
[thirdparty/cups.git] / filter / texttops.c
index 59460ce7a6618545253dcf258e7e4b6a0e5d4692..af549cefa92f9404d6d36c7298d8d0ca04836287 100644 (file)
@@ -1,9 +1,9 @@
 /*
  * "$Id: texttops.c 7720 2008-07-11 22:46:21Z mike $"
  *
- *   Text to PostScript filter for the Common UNIX Printing System (CUPS).
+ *   Text to PostScript filter for CUPS.
  *
- *   Copyright 2007-2008 by Apple Inc.
+ *   Copyright 2007-2010 by Apple Inc.
  *   Copyright 1993-2007 by Easy Software Products.
  *
  *   These coded instructions, statements, and computer programs are the
@@ -29,7 +29,7 @@
  */
 
 #include "textcommon.h"
-#include <cups/i18n.h>
+#include <cups/language-private.h>
 
 
 /*
@@ -173,8 +173,31 @@ WriteProlog(const char *title,             /* I - Title of job */
   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."),
+                         SizeColumns, SizeLines);
+    exit(1);
+  }
+
+  if ((Page = calloc(sizeof(lchar_t *), SizeLines)) == NULL)
+  {
+    _cupsLangPrintFilter(stderr, "ERROR",
+                         _("Unable to print %dx%d text page."),
+                         SizeColumns, SizeLines);
+    exit(1);
+  }
+
+  if ((Page[0] = calloc(sizeof(lchar_t), SizeColumns * SizeLines)) == NULL)
+  {
+    _cupsLangPrintFilter(stderr, "ERROR",
+                         _("Unable to print %dx%d text page."),
+                         SizeColumns, SizeLines);
+    exit(1);
+  }
+
   for (i = 1; i < SizeLines; i ++)
     Page[i] = Page[0] + i * SizeColumns;
 
@@ -187,6 +210,13 @@ WriteProlog(const char *title,             /* I - Title of job */
   else
     ColumnWidth = SizeColumns;
 
+  if (ColumnWidth <= 0)
+  {
+    _cupsLangPrintFilter(stderr, "ERROR",
+                         _("Unable to print %d text columns."), PageColumns);
+    exit(1);
+  }
+
  /*
   * Output the DSC header...
   */
@@ -230,8 +260,7 @@ WriteProlog(const char *title,              /* I - Title of job */
   }
   else
   {
-    fprintf(stderr, _("ERROR: Unable to open \"%s\" - %s\n"), filename,
-            strerror(errno));
+    _cupsLangPrintError("ERROR", _("Unable to open psglyphs"));
     exit(1);
   }
 
@@ -250,8 +279,7 @@ WriteProlog(const char *title,              /* I - Title of job */
       * Can't open charset file!
       */
 
-      fprintf(stderr, _("ERROR: Unable to open %s: %s\n"), filename,
-              strerror(errno));
+      _cupsLangPrintError("ERROR", _("Unable to open charset file"));
       exit(1);
     }
 
@@ -266,7 +294,8 @@ WriteProlog(const char *title,              /* I - Title of job */
       */
 
       fclose(fp);
-      fprintf(stderr, _("ERROR: Bad charset file %s\n"), filename);
+      _cupsLangPrintFilter(stderr, "ERROR", _("Bad charset file \"%s\"."),
+                           filename);
       exit(1);
     }
 
@@ -277,7 +306,8 @@ WriteProlog(const char *title,              /* I - Title of job */
       */
 
       fclose(fp);
-      fprintf(stderr, _("ERROR: Bad charset file %s\n"), filename);
+      _cupsLangPrintFilter(stderr, "ERROR", _("Bad charset file \"%s\"."),
+                           filename);
       exit(1);
     }
 
@@ -288,184 +318,12 @@ WriteProlog(const char *title,           /* I - Title of job */
     line[strlen(line) - 1] = '\0'; /* Drop \n */
     for (lineptr = line + 7; isspace(*lineptr & 255); 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 & 255))
-         lineptr ++;
-
-        if (!*lineptr)
-         break;        /* Must be a font mapping */
-
-       valptr = 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);
-         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 & 255))
-         lineptr ++;
-
-       valptr = 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);
-         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 & 255))
-           lineptr ++;
-
-         valptr = lineptr;
-
-         while (!isspace(*lineptr & 255) && *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...
-       */
-
-        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)
@@ -502,7 +360,8 @@ WriteProlog(const char *title,              /* I - Title of job */
          * Can't have a font without all required values...
          */
 
-         fprintf(stderr, _("ERROR: Bad font description line: %s\n"), valptr);
+         _cupsLangPrintFilter(stderr, "ERROR",
+                              _("Bad font description line: %s"), valptr);
          fclose(fp);
          exit(1);
        }
@@ -515,7 +374,8 @@ WriteProlog(const char *title,              /* I - Title of job */
          Directions[NumFonts] = -1;
        else
        {
-         fprintf(stderr, _("ERROR: Bad text direction %s\n"), valptr);
+         _cupsLangPrintFilter(stderr, "ERROR", _("Bad text direction: %s"),
+                              valptr);
          fclose(fp);
          exit(1);
        }
@@ -538,7 +398,8 @@ WriteProlog(const char *title,              /* I - Title of job */
          * Can't have a font without all required values...
          */
 
-         fprintf(stderr, _("ERROR: Bad font description line: %s\n"), valptr);
+         _cupsLangPrintFilter(stderr, "ERROR",
+                              _("Bad font description line: %s"), valptr);
          fclose(fp);
          exit(1);
        }
@@ -551,7 +412,8 @@ WriteProlog(const char *title,              /* I - Title of job */
           Widths[NumFonts] = 2;
        else 
        {
-         fprintf(stderr, _("ERROR: Bad text width %s\n"), valptr);
+         _cupsLangPrintFilter(stderr, "ERROR",
+                              _("Bad text width: %s"), valptr);
          fclose(fp);
          exit(1);
        }
@@ -607,7 +469,7 @@ WriteProlog(const char *title,              /* I - Title of job */
     }
     else
     {
-      fprintf(stderr, _("ERROR: Bad charset type %s\n"), lineptr);
+      _cupsLangPrintFilter(stderr, "ERROR", _("Bad charset type: %s"), lineptr);
       fclose(fp);
       exit(1);
     }
@@ -1243,7 +1105,7 @@ write_text(const char *s) /* I - String to write */
 
     while (*utf8)
     {
-      if (*utf8 < 0xc0 || !UTF8)
+      if (*utf8 < 0xc0)
         ch = *utf8 ++;
       else if ((*utf8 & 0xe0) == 0xc0)
       {