]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - filter/rastertoepson.c
Import CUPS v2.0b1
[thirdparty/cups.git] / filter / rastertoepson.c
index b528bc06ba9d4b947ec86a3b5a018509e6a573dd..908ec4852744e88f0860beba6f7dd17c85b0e2f3 100644 (file)
@@ -1,29 +1,18 @@
 /*
- * "$Id: rastertoepson.c 6649 2007-07-11 21:46:42Z mike $"
+ * "$Id: rastertoepson.c 11594 2014-02-14 20:09:01Z msweet $"
  *
- *   EPSON ESC/P and ESC/P2 filter for the Common UNIX Printing System
- *   (CUPS).
+ * EPSON ESC/P and ESC/P2 filter for CUPS.
  *
- *   Copyright 2007-2008 by Apple Inc.
- *   Copyright 1993-2007 by Easy Software Products.
+ * Copyright 2007-2014 by Apple Inc.
+ * Copyright 1993-2007 by Easy Software Products.
  *
- *   These coded instructions, statements, and computer programs are the
- *   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/".
+ * These coded instructions, statements, and computer programs are the
+ * 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.
- *
- * Contents:
- *
- *   Setup()        - Prepare the printer for printing.
- *   StartPage()    - Start a page of graphics.
- *   EndPage()      - Finish a page of graphics.
- *   Shutdown()     - Shutdown the printer.
- *   CompressData() - Compress a line of graphics.
- *   OutputLine()   - Output a line of graphics.
- *   main()         - Main entry and processing of driver.
+ * This file is subject to the Apple OS-Developed Software exception.
  */
 
 /*
 
 #include <cups/cups.h>
 #include <cups/ppd.h>
-#include <cups/string.h>
-#include <cups/i18n.h>
+#include <cups/string-private.h>
+#include <cups/language-private.h>
 #include <cups/raster.h>
-#include <stdlib.h>
 #include <unistd.h>
 #include <fcntl.h>
 #include <signal.h>
@@ -68,17 +56,17 @@ unsigned char       *Planes[6],             /* Output buffers */
                *CompBuffer,            /* Compression buffer */
                *LineBuffers[2];        /* Line bitmap buffers */
 int            Model,                  /* Model number */
-               NumPlanes,              /* Number of color planes */
+               EjectPage,              /* Eject the page when done? */
+               Shingling,              /* Shingle output? */
+               Canceled;               /* Has the current job been canceled? */
+unsigned       NumPlanes,              /* Number of color planes */
                Feed,                   /* Number of lines to skip */
-               EjectPage;              /* Eject the page when done? */
-int            DotBit,                 /* Bit in buffers */
+               DotBit,                 /* Bit in buffers */
                DotBytes,               /* # bytes in a dot column */
                DotColumns,             /* # columns in 1/60 inch */
                LineCount,              /* # of lines processed */
                EvenOffset,             /* Offset into 'even' buffers */
-               OddOffset,              /* Offset into 'odd' buffers */
-               Shingling,              /* Shingle output? */
-               Canceled;               /* Has the current job been canceled? */
+               OddOffset;              /* Offset into 'odd' buffers */
 
 
 /*
@@ -91,8 +79,8 @@ void  EndPage(const cups_page_header2_t *header);
 void   Shutdown(void);
 
 void   CancelJob(int sig);
-void   CompressData(const unsigned char *line, int length, int plane,
-                    int type, int xstep, int ystep);
+void   CompressData(const unsigned char *line, unsigned length, unsigned plane,
+                    unsigned type, unsigned xstep, unsigned ystep);
 void   OutputLine(const cups_page_header2_t *header);
 void   OutputRows(const cups_page_header2_t *header, int row);
 
@@ -104,7 +92,7 @@ void OutputRows(const cups_page_header2_t *header, int row);
 void
 Setup(void)
 {
-  const char   *device_uri;    /* The device for the printer... */
+  const char   *device_uri;            /* The device for the printer... */
 
 
  /*
@@ -123,11 +111,12 @@ Setup(void)
  */
 
 void
-StartPage(const ppd_file_t         *ppd,       /* I - PPD file */
-          const cups_page_header2_t *header)   /* I - Page header */
+StartPage(
+    const ppd_file_t         *ppd,     /* I - PPD file */
+    const cups_page_header2_t *header) /* I - Page header */
 {
-  int  n, t;                                   /* Numbers */
-  int  plane;                                  /* Looping var */
+  int          n, t;                   /* Numbers */
+  unsigned     plane;                  /* Looping var */
 
 
  /*
@@ -143,8 +132,6 @@ StartPage(const ppd_file_t         *ppd,    /* I - PPD file */
   * See which type of printer we are using...
   */
 
-  EjectPage = header->Margins[0] || header->Margins[1];
-    
   switch (Model)
   {
     case EPSON_9PIN :
@@ -164,8 +151,8 @@ StartPage(const ppd_file_t         *ppd,    /* I - PPD file */
 
        printf("\033l%c\033Q%c", 0,     /* Side margins */
                       (int)(10.0 * header->PageSize[0] / 72.0 + 0.5));
-       printf("\033C%c%c", 0,          /* Page length */
-                      (int)(header->PageSize[1] / 72.0 + 0.5));
+       printf("\033\062\033C%c",       /* Page length in 1/6th inches */
+                     (int)(header->PageSize[1] / 12.0 + 0.5));
        printf("\033N%c", 0);           /* Bottom margin */
         printf("\033O");               /* No perforation skip */
 
@@ -226,15 +213,14 @@ StartPage(const ppd_file_t         *ppd,  /* I - PPD file */
          putchar(0x05);
        }
 
-       n = header->PageSize[1] * header->HWResolution[1] / 72.0;
+       n = (int)(header->PageSize[1] * header->HWResolution[1] / 72.0);
 
        pwrite("\033(C\002\000", 5);            /* Page length */
        putchar(n);
        putchar(n >> 8);
 
         if (ppd)
-         t = (ppd->sizes[1].length - ppd->sizes[1].top) *
-             header->HWResolution[1] / 72.0;
+         t = (int)((ppd->sizes[1].length - ppd->sizes[1].top) * header->HWResolution[1] / 72.0);
         else
          t = 0;
 
@@ -279,7 +265,7 @@ StartPage(const ppd_file_t         *ppd,    /* I - PPD file */
 
   if ((Planes[0] = malloc(header->cupsBytesPerLine)) == NULL)
   {
-    fputs("ERROR: Unable to allocate memory!\n", stderr);
+    fputs("ERROR: Unable to allocate memory\n", stderr);
     exit(1);
   }
 
@@ -290,7 +276,7 @@ StartPage(const ppd_file_t         *ppd,    /* I - PPD file */
   {
     if ((CompBuffer = calloc(2, header->cupsWidth)) == NULL)
     {
-      fputs("ERROR: Unable to allocate memory!\n", stderr);
+      fputs("ERROR: Unable to allocate memory\n", stderr);
       exit(1);
     }
   }
@@ -299,10 +285,9 @@ StartPage(const ppd_file_t         *ppd,   /* I - PPD file */
 
   if (DotBytes)
   {
-    if ((LineBuffers[0] = calloc(DotBytes,
-                                 header->cupsWidth * (Shingling + 1))) == NULL)
+    if ((LineBuffers[0] = calloc((size_t)DotBytes, header->cupsWidth * (size_t)(Shingling + 1))) == NULL)
     {
-      fputs("ERROR: Unable to allocate memory!\n", stderr);
+      fputs("ERROR: Unable to allocate memory\n", stderr);
       exit(1);
     }
 
@@ -320,7 +305,8 @@ StartPage(const ppd_file_t         *ppd,    /* I - PPD file */
  */
 
 void
-EndPage(const cups_page_header2_t *header)     /* I - Page header */
+EndPage(
+    const cups_page_header2_t *header) /* I - Page header */
 {
   if (DotBytes && header)
   {
@@ -349,8 +335,7 @@ EndPage(const cups_page_header2_t *header)  /* I - Page header */
   * Eject the current page...
   */
 
-  if (EjectPage)
-    putchar(12);               /* Form feed */
+  putchar(12);                         /* Form feed */
   fflush(stdout);
 
  /*
@@ -401,11 +386,11 @@ CancelJob(int sig)                        /* I - Signal */
 
 void
 CompressData(const unsigned char *line,        /* I - Data to compress */
-             int                 length,/* I - Number of bytes */
-            int                 plane, /* I - Color plane */
-            int                 type,  /* I - Type of compression */
-            int                 xstep, /* I - X resolution */
-            int                 ystep) /* I - Y resolution */
+             unsigned            length,/* I - Number of bytes */
+            unsigned            plane, /* I - Color plane */
+            unsigned            type,  /* I - Type of compression */
+            unsigned            xstep, /* I - X resolution */
+            unsigned            ystep) /* I - Y resolution */
 {
   const unsigned char  *line_ptr,      /* Current byte pointer */
                        *line_end,      /* End-of-line byte pointer */
@@ -512,7 +497,7 @@ CompressData(const unsigned char *line,     /* I - Data to compress */
               count ++;
            }
 
-           *comp_ptr++ = 257 - count;
+           *comp_ptr++ = (unsigned char)(257 - count);
            *comp_ptr++ = *line_ptr++;
          }
          else
@@ -533,9 +518,9 @@ CompressData(const unsigned char *line,     /* I - Data to compress */
               count ++;
            }
 
-           *comp_ptr++ = count - 1;
+           *comp_ptr++ = (unsigned char)(count - 1);
 
-           memcpy(comp_ptr, start, count);
+           memcpy(comp_ptr, start, (size_t)count);
            comp_ptr += count;
          }
        }
@@ -575,12 +560,12 @@ CompressData(const unsigned char *line,   /* I - Data to compress */
 
     length *= 8;
     printf("\033.");                   /* Raster graphics */
-    putchar(type);
-    putchar(ystep);
-    putchar(xstep);
+    putchar((int)type);
+    putchar((int)ystep);
+    putchar((int)xstep);
     putchar(1);
-    putchar(length);
-    putchar(length >> 8);
+    putchar((int)length);
+    putchar((int)(length >> 8));
   }
   else
   {
@@ -590,15 +575,15 @@ CompressData(const unsigned char *line,   /* I - Data to compress */
 
     printf("\033i");
     putchar(ctable[plane]);
-    putchar(type);
+    putchar((int)type);
     putchar(1);
-    putchar(length & 255);
-    putchar(length >> 8);
+    putchar((int)length);
+    putchar((int)(length >> 8));
     putchar(1);
     putchar(0);
   }
 
-  pwrite(line_ptr, line_end - line_ptr);
+  pwrite(line_ptr, (size_t)(line_end - line_ptr));
   fflush(stdout);
 }
 
@@ -608,15 +593,16 @@ CompressData(const unsigned char *line,   /* I - Data to compress */
  */
 
 void
-OutputLine(const cups_page_header2_t *header)  /* I - Page header */
+OutputLine(
+    const cups_page_header2_t *header) /* I - Page header */
 {
   if (header->cupsRowCount)
   {
-    int                        width;
+    unsigned           width;
     unsigned char      *tempptr,
                        *evenptr,
                        *oddptr;
-    register int       x;
+    unsigned int       x;
     unsigned char      bit;
     const unsigned char        *pixel;
     unsigned char      *temp;
@@ -726,10 +712,9 @@ OutputLine(const cups_page_header2_t *header)      /* I - Page header */
   }
   else
   {
-    int        plane;          /* Current plane */
-    int        bytes;          /* Bytes per plane */
-    int        xstep, ystep;   /* X & Y resolutions */
-
+    unsigned   plane;          /* Current plane */
+    unsigned   bytes;          /* Bytes per plane */
+    unsigned   xstep, ystep;   /* X & Y resolutions */
 
    /*
     * Write a single line of bitmap data as needed...
@@ -746,7 +731,7 @@ OutputLine(const cups_page_header2_t *header)       /* I - Page header */
       */
 
       if (!Planes[plane][0] &&
-          memcmp(Planes[plane], Planes[plane] + 1, bytes - 1) == 0)
+          memcmp(Planes[plane], Planes[plane] + 1, (size_t)bytes - 1) == 0)
        continue;
 
      /*
@@ -756,14 +741,13 @@ OutputLine(const cups_page_header2_t *header)     /* I - Page header */
       if (Feed > 0)
       {
        pwrite("\033(v\002\000", 5);    /* Relative vertical position */
-       putchar(Feed);
-       putchar(Feed >> 8);
+       putchar((int)Feed);
+       putchar((int)(Feed >> 8));
 
        Feed = 0;
       }
 
-      CompressData(Planes[plane], bytes, plane, header->cupsCompression, xstep,
-                   ystep);
+      CompressData(Planes[plane], bytes, plane, header->cupsCompression, xstep, ystep);
     }
 
     Feed ++;
@@ -776,21 +760,21 @@ OutputLine(const cups_page_header2_t *header)     /* I - Page header */
  */
 
 void
-OutputRows(const cups_page_header2_t *header,  /* I - Page image header */
-           int                      row)       /* I - Row number (0 or 1) */
+OutputRows(
+    const cups_page_header2_t *header, /* I - Page image header */
+    int                      row)      /* I - Row number (0 or 1) */
 {
-  unsigned     i, n;                           /* Looping vars */
-  int          dot_count,                      /* Number of bytes to print */
-                dot_min;                       /* Minimum number of bytes */
-  unsigned char *dot_ptr,                      /* Pointer to print data */
-               *ptr;                           /* Current data */
+  unsigned     i, n,                   /* Looping vars */
+               dot_count,              /* Number of bytes to print */
+                dot_min;               /* Minimum number of bytes */
+  unsigned char *dot_ptr,              /* Pointer to print data */
+               *ptr;                   /* Current data */
 
 
   dot_min = DotBytes * DotColumns;
 
   if (LineBuffers[row][0] != 0 ||
-      memcmp(LineBuffers[row], LineBuffers[row] + 1,
-             header->cupsWidth * DotBytes - 1))
+      memcmp(LineBuffers[row], LineBuffers[row] + 1, header->cupsWidth * DotBytes - 1))
   {
    /*
     * Skip leading space...
@@ -868,7 +852,7 @@ OutputRows(const cups_page_header2_t *header,       /* I - Page image header */
           break;
     }
 
-    n = (unsigned)dot_count / DotBytes;
+    n = dot_count / DotBytes;
     putchar(n & 255);
     putchar(n / 256);
 
@@ -959,7 +943,7 @@ main(int  argc,                             /* I - Number of command-line arguments */
   cups_page_header2_t  header;         /* Page header from file */
   ppd_file_t           *ppd;           /* PPD file */
   int                  page;           /* Current page */
-  int                  y;              /* Current line */
+  unsigned             y;              /* Current line */
 #if defined(HAVE_SIGACTION) && !defined(HAVE_SIGSET)
   struct sigaction action;             /* Actions for POSIX signals */
 #endif /* HAVE_SIGACTION && !HAVE_SIGSET */
@@ -982,8 +966,9 @@ main(int  argc,                             /* I - Number of command-line arguments */
     * and return.
     */
 
-    fprintf(stderr, _("Usage: %s job-id user title copies options [file]\n"),
-            argv[0]);
+    _cupsLangPrintFilter(stderr, "ERROR",
+                         _("%s job-id user title copies options [file]"),
+                         "rastertoepson");
     return (1);
   }
 
@@ -995,7 +980,7 @@ main(int  argc,                             /* I - Number of command-line arguments */
   {
     if ((fd = open(argv[6], O_RDONLY)) == -1)
     {
-      perror("ERROR: Unable to open raster file - ");
+      _cupsLangPrintError("ERROR", _("Unable to open raster file"));
       sleep(1);
       return (1);
     }
@@ -1029,8 +1014,22 @@ main(int  argc,                          /* I - Number of command-line arguments */
   */
 
   ppd = ppdOpenFile(getenv("PPD"));
-  if (ppd)
-    Model = ppd->model_number;
+  if (!ppd)
+  {
+    ppd_status_t       status;         /* PPD error */
+    int                        linenum;        /* Line number */
+
+    _cupsLangPrintFilter(stderr, "ERROR",
+                         _("The PPD file could not be opened."));
+
+    status = ppdLastError(&linenum);
+
+    fprintf(stderr, "DEBUG: %s on line %d.\n", ppdErrorString(status), linenum);
+
+    return (1);
+  }
+
+  Model = ppd->model_number;
 
   Setup();
 
@@ -1052,6 +1051,7 @@ main(int  argc,                           /* I - Number of command-line arguments */
     page ++;
 
     fprintf(stderr, "PAGE: %d %d\n", page, header.NumCopies);
+    _cupsLangPrintFilter(stderr, "INFO", _("Starting page %d."), page);
 
    /*
     * Start the page...
@@ -1073,8 +1073,13 @@ main(int  argc,                          /* I - Number of command-line arguments */
        break;
 
       if ((y & 127) == 0)
-        fprintf(stderr, _("INFO: Printing page %d, %d%% complete...\n"), page,
-               100 * y / header.cupsHeight);
+      {
+        _cupsLangPrintFilter(stderr, "INFO",
+                            _("Printing page %d, %u%% complete."),
+                            page, 100 * y / header.cupsHeight);
+        fprintf(stderr, "ATTR: job-media-progress=%u\n",
+               100 * y / header.cupsHeight);
+      }
 
      /*
       * Read a line of graphics...
@@ -1094,6 +1099,8 @@ main(int  argc,                           /* I - Number of command-line arguments */
     * Eject the page...
     */
 
+    _cupsLangPrintFilter(stderr, "INFO", _("Finished page %d."), page);
+
     EndPage(&header);
 
     if (Canceled)
@@ -1121,14 +1128,15 @@ main(int  argc,                         /* I - Number of command-line arguments */
   */
 
   if (page == 0)
-    fputs(_("ERROR: No pages found!\n"), stderr);
+  {
+    _cupsLangPrintFilter(stderr, "ERROR", _("No pages were found."));
+    return (1);
+  }
   else
-    fputs(_("INFO: Ready to print.\n"), stderr);
-
-  return (page == 0);
+    return (0);
 }
 
 
 /*
- * End of "$Id: rastertoepson.c 6649 2007-07-11 21:46:42Z mike $".
+ * End of "$Id: rastertoepson.c 11594 2014-02-14 20:09:01Z msweet $".
  */