4 * Label printer filter for CUPS.
6 * Copyright 2007-2010 by Apple Inc.
7 * Copyright 2001-2007 by Easy Software Products.
9 * These coded instructions, statements, and computer programs are the
10 * property of Apple Inc. and are protected by Federal copyright
11 * law. Distribution and use rights are outlined in the file "LICENSE.txt"
12 * which should have been included with this file. If this file is
13 * file is missing or damaged, see the license at "http://www.cups.org/".
15 * This file is subject to the Apple OS-Developed Software exception.
19 * Setup() - Prepare the printer for printing.
20 * StartPage() - Start a page of graphics.
21 * EndPage() - Finish a page of graphics.
22 * CancelJob() - Cancel the current job...
23 * OutputLine() - Output a line of graphics.
24 * PCLCompress() - Output a PCL (mode 3) compressed line.
25 * ZPLCompress() - Output a run-length compression sequence.
26 * main() - Main entry and processing of driver.
30 * Include necessary headers...
33 #include <cups/cups.h>
35 #include <cups/string-private.h>
36 #include <cups/language-private.h>
37 #include <cups/raster.h>
44 * This driver filter currently supports Dymo, Intellitech, and Zebra
47 * The Dymo portion of the driver has been tested with the 300, 330,
48 * and 330 Turbo label printers; it may also work with other models.
49 * The Dymo printers support printing at 136, 203, and 300 DPI.
51 * The Intellitech portion of the driver has been tested with the
52 * Intellibar 408, 412, and 808 and supports their PCL variant.
54 * The Zebra portion of the driver has been tested with the LP-2844,
55 * LP-2844Z, QL-320, and QL-420 label printers; it may also work with
56 * other models. The driver supports EPL line mode, EPL page mode,
57 * ZPL, and CPCL as defined in Zebra's online developer documentation.
61 * Model number constants...
64 #define DYMO_3x0 0 /* Dymo Labelwriter 300/330/330 Turbo */
66 #define ZEBRA_EPL_LINE 0x10 /* Zebra EPL line mode printers */
67 #define ZEBRA_EPL_PAGE 0x11 /* Zebra EPL page mode printers */
68 #define ZEBRA_ZPL 0x12 /* Zebra ZPL-based printers */
69 #define ZEBRA_CPCL 0x13 /* Zebra CPCL-based printers */
71 #define INTELLITECH_PCL 0x20 /* Intellitech PCL-based printers */
78 unsigned char *Buffer
; /* Output buffer */
79 unsigned char *CompBuffer
; /* Compression buffer */
80 unsigned char *LastBuffer
; /* Last buffer */
81 int LastSet
; /* Number of repeat characters */
82 int ModelNumber
, /* cupsModelNumber attribute */
83 Page
, /* Current page */
84 Feed
, /* Number of lines to skip */
85 Canceled
; /* Non-zero if job is canceled */
92 void Setup(ppd_file_t
*ppd
);
93 void StartPage(ppd_file_t
*ppd
, cups_page_header2_t
*header
);
94 void EndPage(ppd_file_t
*ppd
, cups_page_header2_t
*header
);
95 void CancelJob(int sig
);
96 void OutputLine(ppd_file_t
*ppd
, cups_page_header2_t
*header
, int y
);
97 void PCLCompress(unsigned char *line
, int length
);
98 void ZPLCompress(char repeat_char
, int repeat_count
);
102 * 'Setup()' - Prepare the printer for printing.
106 Setup(ppd_file_t
*ppd
) /* I - PPD file */
108 int i
; /* Looping var */
112 * Get the model number from the PPD file...
116 ModelNumber
= ppd
->model_number
;
119 * Initialize based on the model number...
126 * Clear any remaining data...
129 for (i
= 0; i
< 100; i
++)
133 * Reset the printer...
136 fputs("\033@", stdout
);
139 case ZEBRA_EPL_LINE
:
142 case ZEBRA_EPL_PAGE
:
151 case INTELLITECH_PCL
:
153 * Send a PCL reset sequence.
164 * 'StartPage()' - Start a page of graphics.
168 StartPage(ppd_file_t
*ppd
, /* I - PPD file */
169 cups_page_header2_t
*header
) /* I - Page header */
171 ppd_choice_t
*choice
; /* Marked choice */
172 int length
; /* Actual label length */
176 * Show page device dictionary...
179 fprintf(stderr
, "DEBUG: StartPage...\n");
180 fprintf(stderr
, "DEBUG: MediaClass = \"%s\"\n", header
->MediaClass
);
181 fprintf(stderr
, "DEBUG: MediaColor = \"%s\"\n", header
->MediaColor
);
182 fprintf(stderr
, "DEBUG: MediaType = \"%s\"\n", header
->MediaType
);
183 fprintf(stderr
, "DEBUG: OutputType = \"%s\"\n", header
->OutputType
);
185 fprintf(stderr
, "DEBUG: AdvanceDistance = %d\n", header
->AdvanceDistance
);
186 fprintf(stderr
, "DEBUG: AdvanceMedia = %d\n", header
->AdvanceMedia
);
187 fprintf(stderr
, "DEBUG: Collate = %d\n", header
->Collate
);
188 fprintf(stderr
, "DEBUG: CutMedia = %d\n", header
->CutMedia
);
189 fprintf(stderr
, "DEBUG: Duplex = %d\n", header
->Duplex
);
190 fprintf(stderr
, "DEBUG: HWResolution = [ %d %d ]\n", header
->HWResolution
[0],
191 header
->HWResolution
[1]);
192 fprintf(stderr
, "DEBUG: ImagingBoundingBox = [ %d %d %d %d ]\n",
193 header
->ImagingBoundingBox
[0], header
->ImagingBoundingBox
[1],
194 header
->ImagingBoundingBox
[2], header
->ImagingBoundingBox
[3]);
195 fprintf(stderr
, "DEBUG: InsertSheet = %d\n", header
->InsertSheet
);
196 fprintf(stderr
, "DEBUG: Jog = %d\n", header
->Jog
);
197 fprintf(stderr
, "DEBUG: LeadingEdge = %d\n", header
->LeadingEdge
);
198 fprintf(stderr
, "DEBUG: Margins = [ %d %d ]\n", header
->Margins
[0],
200 fprintf(stderr
, "DEBUG: ManualFeed = %d\n", header
->ManualFeed
);
201 fprintf(stderr
, "DEBUG: MediaPosition = %d\n", header
->MediaPosition
);
202 fprintf(stderr
, "DEBUG: MediaWeight = %d\n", header
->MediaWeight
);
203 fprintf(stderr
, "DEBUG: MirrorPrint = %d\n", header
->MirrorPrint
);
204 fprintf(stderr
, "DEBUG: NegativePrint = %d\n", header
->NegativePrint
);
205 fprintf(stderr
, "DEBUG: NumCopies = %d\n", header
->NumCopies
);
206 fprintf(stderr
, "DEBUG: Orientation = %d\n", header
->Orientation
);
207 fprintf(stderr
, "DEBUG: OutputFaceUp = %d\n", header
->OutputFaceUp
);
208 fprintf(stderr
, "DEBUG: PageSize = [ %d %d ]\n", header
->PageSize
[0],
209 header
->PageSize
[1]);
210 fprintf(stderr
, "DEBUG: Separations = %d\n", header
->Separations
);
211 fprintf(stderr
, "DEBUG: TraySwitch = %d\n", header
->TraySwitch
);
212 fprintf(stderr
, "DEBUG: Tumble = %d\n", header
->Tumble
);
213 fprintf(stderr
, "DEBUG: cupsWidth = %d\n", header
->cupsWidth
);
214 fprintf(stderr
, "DEBUG: cupsHeight = %d\n", header
->cupsHeight
);
215 fprintf(stderr
, "DEBUG: cupsMediaType = %d\n", header
->cupsMediaType
);
216 fprintf(stderr
, "DEBUG: cupsBitsPerColor = %d\n", header
->cupsBitsPerColor
);
217 fprintf(stderr
, "DEBUG: cupsBitsPerPixel = %d\n", header
->cupsBitsPerPixel
);
218 fprintf(stderr
, "DEBUG: cupsBytesPerLine = %d\n", header
->cupsBytesPerLine
);
219 fprintf(stderr
, "DEBUG: cupsColorOrder = %d\n", header
->cupsColorOrder
);
220 fprintf(stderr
, "DEBUG: cupsColorSpace = %d\n", header
->cupsColorSpace
);
221 fprintf(stderr
, "DEBUG: cupsCompression = %d\n", header
->cupsCompression
);
222 fprintf(stderr
, "DEBUG: cupsRowCount = %d\n", header
->cupsRowCount
);
223 fprintf(stderr
, "DEBUG: cupsRowFeed = %d\n", header
->cupsRowFeed
);
224 fprintf(stderr
, "DEBUG: cupsRowStep = %d\n", header
->cupsRowStep
);
230 * Setup printer/job attributes...
233 length
= header
->PageSize
[1] * header
->HWResolution
[1] / 72;
235 printf("\033L%c%c", length
>> 8, length
);
236 printf("\033D%c", header
->cupsBytesPerLine
);
238 printf("\033%c", header
->cupsCompression
+ 'c'); /* Darkness */
241 case ZEBRA_EPL_LINE
:
246 if ((choice
= ppdFindMarkedChoice(ppd
, "zePrintRate")) != NULL
&&
247 strcmp(choice
->choice
, "Default"))
248 printf("\033S%.0f", atof(choice
->choice
) * 2.0 - 2.0);
254 if (header
->cupsCompression
> 0 && header
->cupsCompression
<= 100)
255 printf("\033D%d", 7 * header
->cupsCompression
/ 100);
258 * Set left margin to 0...
261 fputs("\033M01", stdout
);
264 * Start buffered output...
267 fputs("\033B", stdout
);
270 case ZEBRA_EPL_PAGE
:
272 * Start a new label...
279 * Set hardware options...
282 if (!strcmp(header
->MediaType
, "Direct"))
289 if ((choice
= ppdFindMarkedChoice(ppd
, "zePrintRate")) != NULL
&&
290 strcmp(choice
->choice
, "Default"))
292 float val
= atof(choice
->choice
);
295 printf("S%.0f\n", val
);
297 printf("S%.0f\n", val
* 2.0 - 2.0);
304 if (header
->cupsCompression
> 0 && header
->cupsCompression
<= 100)
305 printf("D%d\n", 15 * header
->cupsCompression
/ 100);
311 printf("q%d\n", (header
->cupsWidth
+ 7) & ~7);
319 if (header
->cupsCompression
> 0 && header
->cupsCompression
<= 100)
320 printf("~SD%02d\n", 30 * header
->cupsCompression
/ 100);
323 * Start bitmap graphics...
326 printf("~DGR:CUPS.GRF,%d,%d,\n",
327 header
->cupsHeight
* header
->cupsBytesPerLine
,
328 header
->cupsBytesPerLine
);
331 * Allocate compression buffers...
334 CompBuffer
= malloc(2 * header
->cupsBytesPerLine
+ 1);
335 LastBuffer
= malloc(header
->cupsBytesPerLine
);
344 printf("! 0 %u %u %u %u\r\n", header
->HWResolution
[0],
345 header
->HWResolution
[1], header
->cupsHeight
,
347 printf("PAGE-WIDTH %d\r\n", header
->cupsWidth
);
348 printf("PAGE-HEIGHT %d\r\n", header
->cupsWidth
);
351 case INTELLITECH_PCL
:
353 * Set the media size...
356 printf("\033&l6D\033&k12H"); /* Set 6 LPI, 10 CPI */
357 printf("\033&l0O"); /* Set portrait orientation */
359 switch (header
->PageSize
[1])
361 case 540 : /* Monarch Envelope */
362 printf("\033&l80A"); /* Set page size */
365 case 624 : /* DL Envelope */
366 printf("\033&l90A"); /* Set page size */
369 case 649 : /* C5 Envelope */
370 printf("\033&l91A"); /* Set page size */
373 case 684 : /* COM-10 Envelope */
374 printf("\033&l81A"); /* Set page size */
377 case 756 : /* Executive */
378 printf("\033&l1A"); /* Set page size */
381 case 792 : /* Letter */
382 printf("\033&l2A"); /* Set page size */
386 printf("\033&l26A"); /* Set page size */
389 case 1008 : /* Legal */
390 printf("\033&l3A"); /* Set page size */
393 default : /* Custom size */
394 printf("\033!f%dZ", header
->PageSize
[1] * 300 / 72);
398 printf("\033&l%dP", /* Set page length */
399 header
->PageSize
[1] / 12);
400 printf("\033&l0E"); /* Set top margin to 0 */
401 printf("\033&l%dX", header
->NumCopies
);
402 /* Set number copies */
403 printf("\033&l0L"); /* Turn off perforation skip */
411 if (header
->cupsRowFeed
) /* inPrintRate */
412 printf("\033!p%dS", header
->cupsRowFeed
);
414 if (header
->cupsCompression
!= ~0)
416 printf("\033&d%dA", 30 * header
->cupsCompression
/ 100 - 15);
418 if ((choice
= ppdFindMarkedChoice(ppd
, "inPrintMode")) != NULL
)
420 if (!strcmp(choice
->choice
, "Standard"))
421 fputs("\033!p0M", stdout
);
422 else if (!strcmp(choice
->choice
, "Tear"))
424 fputs("\033!p1M", stdout
);
426 if (header
->cupsRowCount
) /* inTearInterval */
427 printf("\033!n%dT", header
->cupsRowCount
);
431 fputs("\033!p2M", stdout
);
433 if (header
->cupsRowStep
) /* inCutInterval */
434 printf("\033!n%dC", header
->cupsRowStep
);
443 printf("\033*t%dR", header
->HWResolution
[0]);
446 printf("\033*r%dS", header
->cupsWidth
);
448 printf("\033*r%dT", header
->cupsHeight
);
451 printf("\033&a0H"); /* Set horizontal position */
452 printf("\033&a0V"); /* Set vertical position */
453 printf("\033*r1A"); /* Start graphics */
454 printf("\033*b3M"); /* Set compression */
457 * Allocate compression buffers...
460 CompBuffer
= malloc(2 * header
->cupsBytesPerLine
+ 1);
461 LastBuffer
= malloc(header
->cupsBytesPerLine
);
467 * Allocate memory for a line of graphics...
470 Buffer
= malloc(header
->cupsBytesPerLine
);
476 * 'EndPage()' - Finish a page of graphics.
480 EndPage(ppd_file_t
*ppd
, /* I - PPD file */
481 cups_page_header2_t
*header
) /* I - Page header */
483 int val
; /* Option value */
484 ppd_choice_t
*choice
; /* Marked choice */
491 * Eject the current page...
494 fputs("\033E", stdout
);
497 case ZEBRA_EPL_LINE
:
499 * End buffered output, eject the label...
502 fputs("\033E\014", stdout
);
505 case ZEBRA_EPL_PAGE
:
517 * Cancel bitmap download...
534 if ((choice
= ppdFindMarkedChoice(ppd
, "zePrintRate")) != NULL
&&
535 strcmp(choice
->choice
, "Default"))
537 val
= atoi(choice
->choice
);
538 printf("^PR%d,%d,%d\n", val
, val
, val
);
542 * Put label home in default position (0,0)...
548 * Set media tracking...
551 if (ppdIsMarked(ppd
, "zeMediaTracking", "Continuous"))
554 * Add label length command for continuous...
557 printf("^LL%d\n", header
->cupsHeight
);
560 else if (ppdIsMarked(ppd
, "zeMediaTracking", "Web"))
562 else if (ppdIsMarked(ppd
, "zeMediaTracking", "Mark"))
569 if (header
->cupsRowStep
!= 200)
570 printf("^LT%u\n", header
->cupsRowStep
);
576 if (!strcmp(header
->MediaType
, "Thermal"))
578 else if (!strcmp(header
->MediaType
, "Direct"))
585 if ((choice
= ppdFindMarkedChoice(ppd
, "zePrintMode")) != NULL
&&
586 strcmp(choice
->choice
, "Saved"))
590 if (!strcmp(choice
->choice
, "Tear"))
592 else if (!strcmp(choice
->choice
, "Peel"))
594 else if (!strcmp(choice
->choice
, "Rewind"))
596 else if (!strcmp(choice
->choice
, "Applicator"))
603 * Set tear-off adjust position...
606 if (header
->AdvanceDistance
!= 1000)
608 if ((int)header
->AdvanceDistance
< 0)
609 printf("~TA%04d\n", (int)header
->AdvanceDistance
);
611 printf("~TA%03d\n", (int)header
->AdvanceDistance
);
615 * Allow for reprinting after an error...
618 if (ppdIsMarked(ppd
, "zeErrorReprint", "Always"))
620 else if (ppdIsMarked(ppd
, "zeErrorReprint", "Never"))
624 * Print multiple copies
627 if (header
->NumCopies
> 1)
628 printf("^PQ%d, 0, 0, N\n", header
->NumCopies
);
631 * Display the label image...
634 puts("^FO0,0^XGR:CUPS.GRF,1,1^FS");
637 * End the label and eject...
640 puts("^IDR:CUPS.GRF^FS");
644 * Free compression buffers...
653 * Set tear-off adjust position...
656 if (header
->AdvanceDistance
!= 1000)
657 printf("PRESENT-AT %d 1\r\n", (int)header
->AdvanceDistance
);
660 * Allow for reprinting after an error...
663 if (ppdIsMarked(ppd
, "zeErrorReprint", "Always"))
664 puts("ON-OUT-OF-PAPER WAIT\r");
665 else if (ppdIsMarked(ppd
, "zeErrorReprint", "Never"))
666 puts("ON-OUT-OF-PAPER PURGE\r");
672 if (header
->CutMedia
)
679 if (header
->cupsCompression
> 0)
680 printf("TONE %u\r\n", 2 * header
->cupsCompression
);
686 if ((choice
= ppdFindMarkedChoice(ppd
, "zePrintRate")) != NULL
&&
687 strcmp(choice
->choice
, "Default"))
689 val
= atoi(choice
->choice
);
690 printf("SPEED %d\r\n", val
);
697 if ((choice
= ppdFindMarkedChoice(ppd
, "zeMediaTracking")) == NULL
||
698 strcmp(choice
->choice
, "Continuous"))
704 case INTELLITECH_PCL
:
705 printf("\033*rB"); /* End GFX */
706 printf("\014"); /* Eject current page */
721 * 'CancelJob()' - Cancel the current job...
725 CancelJob(int sig
) /* I - Signal */
728 * Tell the main loop to stop...
738 * 'OutputLine()' - Output a line of graphics...
742 OutputLine(ppd_file_t
*ppd
, /* I - PPD file */
743 cups_page_header2_t
*header
, /* I - Page header */
744 int y
) /* I - Line number */
746 int i
; /* Looping var */
747 unsigned char *ptr
; /* Pointer into buffer */
748 unsigned char *compptr
; /* Pointer into compression buffer */
749 char repeat_char
; /* Repeated character */
750 int repeat_count
; /* Number of repeated characters */
751 static const char *hex
= "0123456789ABCDEF";
759 * See if the line is blank; if not, write it to the printer...
763 memcmp(Buffer
, Buffer
+ 1, header
->cupsBytesPerLine
- 1))
769 printf("\033f\001%c", 255);
773 printf("\033f\001%c", Feed
);
778 fwrite(Buffer
, header
->cupsBytesPerLine
, 1, stdout
);
783 * This hack works around a bug in the IRIX serial port driver when
784 * run at high baud rates (e.g. 115200 baud)... This results in
785 * slightly slower label printing, but at least the labels come
796 case ZEBRA_EPL_LINE
:
797 printf("\033g%03d", header
->cupsBytesPerLine
);
798 fwrite(Buffer
, 1, header
->cupsBytesPerLine
, stdout
);
802 case ZEBRA_EPL_PAGE
:
803 if (Buffer
[0] || memcmp(Buffer
, Buffer
+ 1, header
->cupsBytesPerLine
))
805 printf("GW0,%d,%d,1\n", y
, header
->cupsBytesPerLine
);
806 for (i
= header
->cupsBytesPerLine
, ptr
= Buffer
; i
> 0; i
--, ptr
++)
815 * Determine if this row is the same as the previous line.
816 * If so, output a ':' and return...
821 if (!memcmp(Buffer
, LastBuffer
, header
->cupsBytesPerLine
))
829 * Convert the line to hex digits...
832 for (ptr
= Buffer
, compptr
= CompBuffer
, i
= header
->cupsBytesPerLine
;
836 *compptr
++ = hex
[*ptr
>> 4];
837 *compptr
++ = hex
[*ptr
& 15];
843 * Run-length compress the graphics...
846 for (compptr
= CompBuffer
+ 1, repeat_char
= CompBuffer
[0], repeat_count
= 1;
849 if (*compptr
== repeat_char
)
853 ZPLCompress(repeat_char
, repeat_count
);
854 repeat_char
= *compptr
;
858 if (repeat_char
== '0')
861 * Handle 0's on the end of the line...
864 if (repeat_count
& 1)
870 if (repeat_count
> 0)
874 ZPLCompress(repeat_char
, repeat_count
);
879 * Save this line for the next round...
882 memcpy(LastBuffer
, Buffer
, header
->cupsBytesPerLine
);
887 if (Buffer
[0] || memcmp(Buffer
, Buffer
+ 1, header
->cupsBytesPerLine
))
889 printf("CG %u 1 0 %d ", header
->cupsBytesPerLine
, y
);
890 fwrite(Buffer
, 1, header
->cupsBytesPerLine
, stdout
);
896 case INTELLITECH_PCL
:
898 memcmp(Buffer
, Buffer
+ 1, header
->cupsBytesPerLine
- 1))
902 printf("\033*b%dY", Feed
);
907 PCLCompress(Buffer
, header
->cupsBytesPerLine
);
917 * 'PCLCompress()' - Output a PCL (mode 3) compressed line.
921 PCLCompress(unsigned char *line
, /* I - Line to compress */
922 int length
) /* I - Length of line */
924 unsigned char *line_ptr
, /* Current byte pointer */
925 *line_end
, /* End-of-line byte pointer */
926 *comp_ptr
, /* Pointer into compression buffer */
927 *start
, /* Start of compression sequence */
928 *seed
; /* Seed buffer pointer */
929 int count
, /* Count of bytes for output */
930 offset
; /* Offset of bytes for output */
934 * Do delta-row compression...
938 line_end
= line
+ length
;
940 comp_ptr
= CompBuffer
;
943 while (line_ptr
< line_end
)
946 * Find the next non-matching sequence...
954 * The seed buffer is invalid, so do the next 8 bytes, max...
959 if ((count
= line_end
- line_ptr
) > 8)
967 * The seed buffer is valid, so compare against it...
970 while (*line_ptr
== *seed
&&
977 if (line_ptr
== line_end
)
980 offset
= line_ptr
- start
;
983 * Find up to 8 non-matching bytes...
988 while (*line_ptr
!= *seed
&&
989 line_ptr
< line_end
&&
999 * Place mode 3 compression data in the buffer; see HP manuals
1006 * Output multi-byte offset...
1009 *comp_ptr
++ = ((count
- 1) << 5) | 31;
1012 while (offset
>= 255)
1018 *comp_ptr
++ = offset
;
1023 * Output single-byte offset...
1026 *comp_ptr
++ = ((count
- 1) << 5) | offset
;
1029 memcpy(comp_ptr
, start
, count
);
1034 * Set the length of the data and write it...
1037 printf("\033*b%dW", (int)(comp_ptr
- CompBuffer
));
1038 fwrite(CompBuffer
, comp_ptr
- CompBuffer
, 1, stdout
);
1041 * Save this line as a "seed" buffer for the next...
1044 memcpy(LastBuffer
, line
, length
);
1050 * 'ZPLCompress()' - Output a run-length compression sequence.
1054 ZPLCompress(char repeat_char
, /* I - Character to repeat */
1055 int repeat_count
) /* I - Number of repeated characters */
1057 if (repeat_count
> 1)
1060 * Print as many z's as possible - they are the largest denomination
1061 * representing 400 characters (zC stands for 400 adjacent C's)
1064 while (repeat_count
>= 400)
1067 repeat_count
-= 400;
1071 * Then print 'g' through 'y' as multiples of 20 characters...
1074 if (repeat_count
>= 20)
1076 putchar('f' + repeat_count
/ 20);
1081 * Finally, print 'G' through 'Y' as 1 through 19 characters...
1084 if (repeat_count
> 0)
1085 putchar('F' + repeat_count
);
1089 * Then the character to be repeated...
1092 putchar(repeat_char
);
1097 * 'main()' - Main entry and processing of driver.
1100 int /* O - Exit status */
1101 main(int argc
, /* I - Number of command-line arguments */
1102 char *argv
[]) /* I - Command-line arguments */
1104 int fd
; /* File descriptor */
1105 cups_raster_t
*ras
; /* Raster stream for printing */
1106 cups_page_header2_t header
; /* Page header from file */
1107 int y
; /* Current line */
1108 ppd_file_t
*ppd
; /* PPD file */
1109 int num_options
; /* Number of options */
1110 cups_option_t
*options
; /* Options */
1111 #if defined(HAVE_SIGACTION) && !defined(HAVE_SIGSET)
1112 struct sigaction action
; /* Actions for POSIX signals */
1113 #endif /* HAVE_SIGACTION && !HAVE_SIGSET */
1117 * Make sure status messages are not buffered...
1120 setbuf(stderr
, NULL
);
1123 * Check command-line...
1126 if (argc
< 6 || argc
> 7)
1129 * We don't have the correct number of arguments; write an error message
1133 _cupsLangPrintFilter(stderr
, "ERROR",
1134 _("%s job-id user title copies options [file]"),
1140 * Open the page stream...
1145 if ((fd
= open(argv
[6], O_RDONLY
)) == -1)
1147 _cupsLangPrintError("ERROR", _("Unable to open raster file"));
1155 ras
= cupsRasterOpen(fd
, CUPS_RASTER_READ
);
1158 * Register a signal handler to eject the current page if the
1164 #ifdef HAVE_SIGSET /* Use System V signals over POSIX to avoid bugs */
1165 sigset(SIGTERM
, CancelJob
);
1166 #elif defined(HAVE_SIGACTION)
1167 memset(&action
, 0, sizeof(action
));
1169 sigemptyset(&action
.sa_mask
);
1170 action
.sa_handler
= CancelJob
;
1171 sigaction(SIGTERM
, &action
, NULL
);
1173 signal(SIGTERM
, CancelJob
);
1174 #endif /* HAVE_SIGSET */
1177 * Open the PPD file and apply options...
1180 num_options
= cupsParseOptions(argv
[5], 0, &options
);
1182 ppd
= ppdOpenFile(getenv("PPD"));
1185 ppd_status_t status
; /* PPD error */
1186 int linenum
; /* Line number */
1188 _cupsLangPrintFilter(stderr
, "ERROR",
1189 _("The PPD file could not be opened."));
1191 status
= ppdLastError(&linenum
);
1193 fprintf(stderr
, "DEBUG: %s on line %d.\n", ppdErrorString(status
), linenum
);
1198 ppdMarkDefaults(ppd
);
1199 cupsMarkOptions(ppd
, num_options
, options
);
1202 * Initialize the print device...
1208 * Process pages as needed...
1213 while (cupsRasterReadHeader2(ras
, &header
))
1216 * Write a status message with the page number and number of copies.
1224 fprintf(stderr
, "PAGE: %d 1\n", Page
);
1225 _cupsLangPrintFilter(stderr
, "INFO", _("Starting page %d."), Page
);
1231 StartPage(ppd
, &header
);
1234 * Loop for each line on the page...
1237 for (y
= 0; y
< header
.cupsHeight
&& !Canceled
; y
++)
1240 * Let the user know how far we have progressed...
1248 _cupsLangPrintFilter(stderr
, "INFO",
1249 _("Printing page %d, %d%% complete."),
1250 Page
, 100 * y
/ header
.cupsHeight
);
1251 fprintf(stderr
, "ATTR: job-media-progress=%d\n",
1252 100 * y
/ header
.cupsHeight
);
1256 * Read a line of graphics...
1259 if (cupsRasterReadPixels(ras
, Buffer
, header
.cupsBytesPerLine
) < 1)
1263 * Write it to the printer...
1266 OutputLine(ppd
, &header
, y
);
1273 _cupsLangPrintFilter(stderr
, "INFO", _("Finished page %d."), Page
);
1275 EndPage(ppd
, &header
);
1282 * Close the raster stream...
1285 cupsRasterClose(ras
);
1290 * Close the PPD file and free the options...
1294 cupsFreeOptions(num_options
, options
);
1297 * If no pages were printed, send an error message...
1302 _cupsLangPrintFilter(stderr
, "ERROR", _("No pages were found."));
1307 _cupsLangPrintFilter(stderr
, "INFO", _("Ready to print."));