/*
- * "$Id: rastertolabel.c 181 2006-06-22 20:01:18Z jlovell $"
+ * "$Id: rastertolabel.c 7615 2008-05-25 07:17:07Z mike $"
*
* Label printer filter for the Common UNIX Printing System (CUPS).
*
- * Copyright 2001-2006 by Easy Software Products.
+ * Copyright 2007-2008 by Apple Inc.
+ * Copyright 2001-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 USA
- *
- * Voice: (301) 373-9600
- * 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 <cups/cups.h>
#include <cups/string.h>
-#include "raster.h"
+#include <cups/i18n.h>
+#include <cups/raster.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
* The Zebra portion of the driver has been tested with the LP-2844,
* LP-2844Z, QL-320, and QL-420 label printers; it may also work with
* other models. The driver supports EPL line mode, EPL page mode,
- * ZPL, and CPCL as defined in Zebra's on-line developer documentation.
+ * ZPL, and CPCL as defined in Zebra's online developer documentation.
*/
/*
*/
void Setup(ppd_file_t *ppd);
-void StartPage(ppd_file_t *ppd, cups_page_header_t *header);
-void EndPage(ppd_file_t *ppd, cups_page_header_t *header);
+void StartPage(ppd_file_t *ppd, cups_page_header2_t *header);
+void EndPage(ppd_file_t *ppd, cups_page_header2_t *header);
void CancelJob(int sig);
-void OutputLine(ppd_file_t *ppd, cups_page_header_t *header, int y);
+void OutputLine(ppd_file_t *ppd, cups_page_header2_t *header, int y);
void PCLCompress(unsigned char *line, int length);
void ZPLCompress(char repeat_char, int repeat_count);
void
StartPage(ppd_file_t *ppd, /* I - PPD file */
- cups_page_header_t *header) /* I - Page header */
+ cups_page_header2_t *header) /* I - Page header */
{
ppd_choice_t *choice; /* Marked choice */
int length; /* Actual label length */
-#if defined(HAVE_SIGACTION) && !defined(HAVE_SIGSET)
- struct sigaction action; /* Actions for POSIX signals */
-#endif /* HAVE_SIGACTION && !HAVE_SIGSET */
/*
fprintf(stderr, "DEBUG: cupsRowFeed = %d\n", header->cupsRowFeed);
fprintf(stderr, "DEBUG: cupsRowStep = %d\n", header->cupsRowStep);
- /*
- * Register a signal handler to eject the current page if the
- * job is canceled.
- */
-
-#ifdef HAVE_SIGSET /* Use System V signals over POSIX to avoid bugs */
- sigset(SIGTERM, CancelJob);
-#elif defined(HAVE_SIGACTION)
- memset(&action, 0, sizeof(action));
-
- sigemptyset(&action.sa_mask);
- action.sa_handler = CancelJob;
- sigaction(SIGTERM, &action, NULL);
-#else
- signal(SIGTERM, CancelJob);
-#endif /* HAVE_SIGSET */
-
switch (ModelNumber)
{
case DYMO_3x0 :
* Set label size...
*/
- printf("q%d\n", header->cupsWidth);
+ printf("q%d\n", (header->cupsWidth + 7) & ~7);
break;
case ZEBRA_ZPL :
printf("! 0 %u %u %u %u\r\n", header->HWResolution[0],
header->HWResolution[1], header->cupsHeight,
header->NumCopies);
+ printf("PAGE-WIDTH %d\r\n", header->cupsWidth);
+ printf("PAGE-HEIGHT %d\r\n", header->cupsWidth);
break;
case INTELLITECH_PCL :
/* inPrintDensity */
printf("\033&d%dA", 30 * header->cupsCompression / 100 - 15);
- if (header->cupsRowCount != ~0)
- /* inTearInterval */
- printf("\033!n%dT", header->cupsRowCount);
+ if ((choice = ppdFindMarkedChoice(ppd, "inPrintMode")) != NULL)
+ {
+ if (!strcmp(choice->choice, "Standard"))
+ fputs("\033!p0M", stdout);
+ else if (!strcmp(choice->choice, "Tear"))
+ {
+ fputs("\033!p1M", stdout);
- if (header->cupsRowStep != ~0)
- /* inCutInterval */
- printf("\033!n%dC", header->cupsRowStep);
+ if (header->cupsRowCount) /* inTearInterval */
+ printf("\033!n%dT", header->cupsRowCount);
+ }
+ else
+ {
+ fputs("\033!p2M", stdout);
+
+ if (header->cupsRowStep) /* inCutInterval */
+ printf("\033!n%dC", header->cupsRowStep);
+ }
+ }
}
/*
void
EndPage(ppd_file_t *ppd, /* I - PPD file */
- cups_page_header_t *header) /* I - Page header */
+ cups_page_header2_t *header) /* I - Page header */
{
int val; /* Option value */
ppd_choice_t *choice; /* Marked choice */
-#if defined(HAVE_SIGACTION) && !defined(HAVE_SIGSET)
- struct sigaction action; /* Actions for POSIX signals */
-#endif /* HAVE_SIGACTION && !HAVE_SIGSET */
switch (ModelNumber)
* End the label and eject...
*/
- puts("^XZ");
+ puts("^IDR:CUPS.GRF^FS");
+ puts("^XZ");
/*
* Free compression buffers...
* Print the label...
*/
- puts("FORM\r");
+ if ((choice = ppdFindMarkedChoice(ppd, "zeMediaTracking")) == NULL ||
+ strcmp(choice->choice, "Continuous"))
+ puts("FORM\r");
+
puts("PRINT\r");
break;
fflush(stdout);
- /*
- * Unregister the signal handler...
- */
-
-#ifdef HAVE_SIGSET /* Use System V signals over POSIX to avoid bugs */
- sigset(SIGTERM, SIG_IGN);
-#elif defined(HAVE_SIGACTION)
- memset(&action, 0, sizeof(action));
-
- sigemptyset(&action.sa_mask);
- action.sa_handler = SIG_IGN;
- sigaction(SIGTERM, &action, NULL);
-#else
- signal(SIGTERM, SIG_IGN);
-#endif /* HAVE_SIGSET */
-
/*
* Free memory...
*/
void
OutputLine(ppd_file_t *ppd, /* I - PPD file */
- cups_page_header_t *header, /* I - Page header */
+ cups_page_header2_t *header, /* I - Page header */
int y) /* I - Line number */
{
int i; /* Looping var */
* Run-length compress the graphics...
*/
- for (compptr = CompBuffer, repeat_char = CompBuffer[0], repeat_count = 1;
+ for (compptr = CompBuffer + 1, repeat_char = CompBuffer[0], repeat_count = 1;
*compptr;
compptr ++)
if (*compptr == repeat_char)
*/
if (repeat_count & 1)
+ {
+ repeat_count --;
putchar('0');
+ }
- putchar(',');
+ if (repeat_count > 0)
+ putchar(',');
}
else
ZPLCompress(repeat_char, repeat_count);
+ fflush(stdout);
+
/*
* Save this line for the next round...
*/
* Set the length of the data and write it...
*/
- printf("\033*b%dW", comp_ptr - CompBuffer);
+ printf("\033*b%dW", (int)(comp_ptr - CompBuffer));
fwrite(CompBuffer, comp_ptr - CompBuffer, 1, stdout);
/*
{
int fd; /* File descriptor */
cups_raster_t *ras; /* Raster stream for printing */
- cups_page_header_t header; /* Page header from file */
+ cups_page_header2_t header; /* Page header from file */
int y; /* Current line */
ppd_file_t *ppd; /* PPD file */
int num_options; /* Number of options */
cups_option_t *options; /* Options */
+#if defined(HAVE_SIGACTION) && !defined(HAVE_SIGSET)
+ struct sigaction action; /* Actions for POSIX signals */
+#endif /* HAVE_SIGACTION && !HAVE_SIGSET */
/*
* and return.
*/
- fputs("ERROR: rastertolabel job-id user title copies options [file]\n", stderr);
+ fprintf(stderr, _("Usage: %s job-id user title copies options [file]\n"),
+ argv[0]);
return (1);
}
ras = cupsRasterOpen(fd, CUPS_RASTER_READ);
+ /*
+ * Register a signal handler to eject the current page if the
+ * job is cancelled.
+ */
+
+ Canceled = 0;
+
+#ifdef HAVE_SIGSET /* Use System V signals over POSIX to avoid bugs */
+ sigset(SIGTERM, CancelJob);
+#elif defined(HAVE_SIGACTION)
+ memset(&action, 0, sizeof(action));
+
+ sigemptyset(&action.sa_mask);
+ action.sa_handler = CancelJob;
+ sigaction(SIGTERM, &action, NULL);
+#else
+ signal(SIGTERM, CancelJob);
+#endif /* HAVE_SIGSET */
+
/*
* Open the PPD file and apply options...
*/
* Process pages as needed...
*/
- Page = 0;
- Canceled = 0;
+ Page = 0;
- while (cupsRasterReadHeader(ras, &header))
+ while (cupsRasterReadHeader2(ras, &header))
{
/*
* Write a status message with the page number and number of copies.
*/
+ if (Canceled)
+ break;
+
Page ++;
fprintf(stderr, "PAGE: %d 1\n", Page);
* Let the user know how far we have progressed...
*/
+ if (Canceled)
+ break;
+
if ((y & 15) == 0)
- fprintf(stderr, "INFO: Printing page %d, %d%% complete...\n", Page,
+ fprintf(stderr, _("INFO: Printing page %d, %d%% complete...\n"), Page,
100 * y / header.cupsHeight);
/*
*/
if (Page == 0)
- fputs("ERROR: No pages found!\n", stderr);
+ fputs(_("ERROR: No pages found!\n"), stderr);
else
- fputs("INFO: Ready to print.\n", stderr);
+ fputs(_("INFO: Ready to print.\n"), stderr);
return (Page == 0);
}
/*
- * End of "$Id: rastertolabel.c 181 2006-06-22 20:01:18Z jlovell $".
+ * End of "$Id: rastertolabel.c 7615 2008-05-25 07:17:07Z mike $".
*/