4 * Label printer filter for CUPS.
6 * Copyright 2007-2014 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 * Include necessary headers...
22 #include <cups/cups.h>
24 #include <cups/string-private.h>
25 #include <cups/language-private.h>
26 #include <cups/raster.h>
33 * This driver filter currently supports Dymo, Intellitech, and Zebra
36 * The Dymo portion of the driver has been tested with the 300, 330,
37 * and 330 Turbo label printers; it may also work with other models.
38 * The Dymo printers support printing at 136, 203, and 300 DPI.
40 * The Intellitech portion of the driver has been tested with the
41 * Intellibar 408, 412, and 808 and supports their PCL variant.
43 * The Zebra portion of the driver has been tested with the LP-2844,
44 * LP-2844Z, QL-320, and QL-420 label printers; it may also work with
45 * other models. The driver supports EPL line mode, EPL page mode,
46 * ZPL, and CPCL as defined in Zebra's online developer documentation.
50 * Model number constants...
53 #define DYMO_3x0 0 /* Dymo Labelwriter 300/330/330 Turbo */
55 #define ZEBRA_EPL_LINE 0x10 /* Zebra EPL line mode printers */
56 #define ZEBRA_EPL_PAGE 0x11 /* Zebra EPL page mode printers */
57 #define ZEBRA_ZPL 0x12 /* Zebra ZPL-based printers */
58 #define ZEBRA_CPCL 0x13 /* Zebra CPCL-based printers */
60 #define INTELLITECH_PCL 0x20 /* Intellitech PCL-based printers */
67 unsigned char *Buffer
; /* Output buffer */
68 unsigned char *CompBuffer
; /* Compression buffer */
69 unsigned char *LastBuffer
; /* Last buffer */
70 unsigned Feed
; /* Number of lines to skip */
71 int LastSet
; /* Number of repeat characters */
72 int ModelNumber
, /* cupsModelNumber attribute */
73 Page
, /* Current page */
74 Canceled
; /* Non-zero if job is canceled */
81 void Setup(ppd_file_t
*ppd
);
82 void StartPage(ppd_file_t
*ppd
, cups_page_header2_t
*header
);
83 void EndPage(ppd_file_t
*ppd
, cups_page_header2_t
*header
);
84 void CancelJob(int sig
);
85 void OutputLine(ppd_file_t
*ppd
, cups_page_header2_t
*header
, unsigned y
);
86 void PCLCompress(unsigned char *line
, unsigned length
);
87 void ZPLCompress(unsigned char repeat_char
, unsigned repeat_count
);
91 * 'Setup()' - Prepare the printer for printing.
95 Setup(ppd_file_t
*ppd
) /* I - PPD file */
97 int i
; /* Looping var */
101 * Get the model number from the PPD file...
105 ModelNumber
= ppd
->model_number
;
108 * Initialize based on the model number...
115 * Clear any remaining data...
118 for (i
= 0; i
< 100; i
++)
122 * Reset the printer...
125 fputs("\033@", stdout
);
128 case ZEBRA_EPL_LINE
:
131 case ZEBRA_EPL_PAGE
:
140 case INTELLITECH_PCL
:
142 * Send a PCL reset sequence.
153 * 'StartPage()' - Start a page of graphics.
157 StartPage(ppd_file_t
*ppd
, /* I - PPD file */
158 cups_page_header2_t
*header
) /* I - Page header */
160 ppd_choice_t
*choice
; /* Marked choice */
161 unsigned length
; /* Actual label length */
165 * Show page device dictionary...
168 fprintf(stderr
, "DEBUG: StartPage...\n");
169 fprintf(stderr
, "DEBUG: MediaClass = \"%s\"\n", header
->MediaClass
);
170 fprintf(stderr
, "DEBUG: MediaColor = \"%s\"\n", header
->MediaColor
);
171 fprintf(stderr
, "DEBUG: MediaType = \"%s\"\n", header
->MediaType
);
172 fprintf(stderr
, "DEBUG: OutputType = \"%s\"\n", header
->OutputType
);
174 fprintf(stderr
, "DEBUG: AdvanceDistance = %d\n", header
->AdvanceDistance
);
175 fprintf(stderr
, "DEBUG: AdvanceMedia = %d\n", header
->AdvanceMedia
);
176 fprintf(stderr
, "DEBUG: Collate = %d\n", header
->Collate
);
177 fprintf(stderr
, "DEBUG: CutMedia = %d\n", header
->CutMedia
);
178 fprintf(stderr
, "DEBUG: Duplex = %d\n", header
->Duplex
);
179 fprintf(stderr
, "DEBUG: HWResolution = [ %d %d ]\n", header
->HWResolution
[0],
180 header
->HWResolution
[1]);
181 fprintf(stderr
, "DEBUG: ImagingBoundingBox = [ %d %d %d %d ]\n",
182 header
->ImagingBoundingBox
[0], header
->ImagingBoundingBox
[1],
183 header
->ImagingBoundingBox
[2], header
->ImagingBoundingBox
[3]);
184 fprintf(stderr
, "DEBUG: InsertSheet = %d\n", header
->InsertSheet
);
185 fprintf(stderr
, "DEBUG: Jog = %d\n", header
->Jog
);
186 fprintf(stderr
, "DEBUG: LeadingEdge = %d\n", header
->LeadingEdge
);
187 fprintf(stderr
, "DEBUG: Margins = [ %d %d ]\n", header
->Margins
[0],
189 fprintf(stderr
, "DEBUG: ManualFeed = %d\n", header
->ManualFeed
);
190 fprintf(stderr
, "DEBUG: MediaPosition = %d\n", header
->MediaPosition
);
191 fprintf(stderr
, "DEBUG: MediaWeight = %d\n", header
->MediaWeight
);
192 fprintf(stderr
, "DEBUG: MirrorPrint = %d\n", header
->MirrorPrint
);
193 fprintf(stderr
, "DEBUG: NegativePrint = %d\n", header
->NegativePrint
);
194 fprintf(stderr
, "DEBUG: NumCopies = %d\n", header
->NumCopies
);
195 fprintf(stderr
, "DEBUG: Orientation = %d\n", header
->Orientation
);
196 fprintf(stderr
, "DEBUG: OutputFaceUp = %d\n", header
->OutputFaceUp
);
197 fprintf(stderr
, "DEBUG: PageSize = [ %d %d ]\n", header
->PageSize
[0],
198 header
->PageSize
[1]);
199 fprintf(stderr
, "DEBUG: Separations = %d\n", header
->Separations
);
200 fprintf(stderr
, "DEBUG: TraySwitch = %d\n", header
->TraySwitch
);
201 fprintf(stderr
, "DEBUG: Tumble = %d\n", header
->Tumble
);
202 fprintf(stderr
, "DEBUG: cupsWidth = %d\n", header
->cupsWidth
);
203 fprintf(stderr
, "DEBUG: cupsHeight = %d\n", header
->cupsHeight
);
204 fprintf(stderr
, "DEBUG: cupsMediaType = %d\n", header
->cupsMediaType
);
205 fprintf(stderr
, "DEBUG: cupsBitsPerColor = %d\n", header
->cupsBitsPerColor
);
206 fprintf(stderr
, "DEBUG: cupsBitsPerPixel = %d\n", header
->cupsBitsPerPixel
);
207 fprintf(stderr
, "DEBUG: cupsBytesPerLine = %d\n", header
->cupsBytesPerLine
);
208 fprintf(stderr
, "DEBUG: cupsColorOrder = %d\n", header
->cupsColorOrder
);
209 fprintf(stderr
, "DEBUG: cupsColorSpace = %d\n", header
->cupsColorSpace
);
210 fprintf(stderr
, "DEBUG: cupsCompression = %d\n", header
->cupsCompression
);
211 fprintf(stderr
, "DEBUG: cupsRowCount = %d\n", header
->cupsRowCount
);
212 fprintf(stderr
, "DEBUG: cupsRowFeed = %d\n", header
->cupsRowFeed
);
213 fprintf(stderr
, "DEBUG: cupsRowStep = %d\n", header
->cupsRowStep
);
219 * Setup printer/job attributes...
222 length
= header
->PageSize
[1] * header
->HWResolution
[1] / 72;
224 printf("\033L%c%c", length
>> 8, length
);
225 printf("\033D%c", header
->cupsBytesPerLine
);
227 printf("\033%c", header
->cupsCompression
+ 'c'); /* Darkness */
230 case ZEBRA_EPL_LINE
:
235 if ((choice
= ppdFindMarkedChoice(ppd
, "zePrintRate")) != NULL
&&
236 strcmp(choice
->choice
, "Default"))
237 printf("\033S%.0f", atof(choice
->choice
) * 2.0 - 2.0);
243 if (header
->cupsCompression
> 0 && header
->cupsCompression
<= 100)
244 printf("\033D%d", 7 * header
->cupsCompression
/ 100);
247 * Set left margin to 0...
250 fputs("\033M01", stdout
);
253 * Start buffered output...
256 fputs("\033B", stdout
);
259 case ZEBRA_EPL_PAGE
:
261 * Start a new label...
268 * Set hardware options...
271 if (!strcmp(header
->MediaType
, "Direct"))
278 if ((choice
= ppdFindMarkedChoice(ppd
, "zePrintRate")) != NULL
&&
279 strcmp(choice
->choice
, "Default"))
281 double val
= atof(choice
->choice
);
284 printf("S%.0f\n", val
);
286 printf("S%.0f\n", val
* 2.0 - 2.0);
293 if (header
->cupsCompression
> 0 && header
->cupsCompression
<= 100)
294 printf("D%u\n", 15 * header
->cupsCompression
/ 100);
300 printf("q%u\n", (header
->cupsWidth
+ 7) & ~7U);
308 if (header
->cupsCompression
> 0 && header
->cupsCompression
<= 100)
309 printf("~SD%02u\n", 30 * header
->cupsCompression
/ 100);
312 * Start bitmap graphics...
315 printf("~DGR:CUPS.GRF,%u,%u,\n",
316 header
->cupsHeight
* header
->cupsBytesPerLine
,
317 header
->cupsBytesPerLine
);
320 * Allocate compression buffers...
323 CompBuffer
= malloc(2 * header
->cupsBytesPerLine
+ 1);
324 LastBuffer
= malloc(header
->cupsBytesPerLine
);
333 printf("! 0 %u %u %u %u\r\n", header
->HWResolution
[0],
334 header
->HWResolution
[1], header
->cupsHeight
,
336 printf("PAGE-WIDTH %u\r\n", header
->cupsWidth
);
337 printf("PAGE-HEIGHT %u\r\n", header
->cupsWidth
);
340 case INTELLITECH_PCL
:
342 * Set the media size...
345 printf("\033&l6D\033&k12H"); /* Set 6 LPI, 10 CPI */
346 printf("\033&l0O"); /* Set portrait orientation */
348 switch (header
->PageSize
[1])
350 case 540 : /* Monarch Envelope */
351 printf("\033&l80A"); /* Set page size */
354 case 624 : /* DL Envelope */
355 printf("\033&l90A"); /* Set page size */
358 case 649 : /* C5 Envelope */
359 printf("\033&l91A"); /* Set page size */
362 case 684 : /* COM-10 Envelope */
363 printf("\033&l81A"); /* Set page size */
366 case 756 : /* Executive */
367 printf("\033&l1A"); /* Set page size */
370 case 792 : /* Letter */
371 printf("\033&l2A"); /* Set page size */
375 printf("\033&l26A"); /* Set page size */
378 case 1008 : /* Legal */
379 printf("\033&l3A"); /* Set page size */
382 default : /* Custom size */
383 printf("\033!f%uZ", header
->PageSize
[1] * 300 / 72);
387 printf("\033&l%uP", /* Set page length */
388 header
->PageSize
[1] / 12);
389 printf("\033&l0E"); /* Set top margin to 0 */
390 if (header
->NumCopies
)
391 printf("\033&l%uX", header
->NumCopies
);
392 /* Set number copies */
393 printf("\033&l0L"); /* Turn off perforation skip */
401 if (header
->cupsRowFeed
) /* inPrintRate */
402 printf("\033!p%uS", header
->cupsRowFeed
);
404 if (header
->cupsCompression
!= ~0U)
406 printf("\033&d%uA", 30 * header
->cupsCompression
/ 100 - 15);
408 if ((choice
= ppdFindMarkedChoice(ppd
, "inPrintMode")) != NULL
)
410 if (!strcmp(choice
->choice
, "Standard"))
411 fputs("\033!p0M", stdout
);
412 else if (!strcmp(choice
->choice
, "Tear"))
414 fputs("\033!p1M", stdout
);
416 if (header
->cupsRowCount
) /* inTearInterval */
417 printf("\033!n%uT", header
->cupsRowCount
);
421 fputs("\033!p2M", stdout
);
423 if (header
->cupsRowStep
) /* inCutInterval */
424 printf("\033!n%uC", header
->cupsRowStep
);
433 printf("\033*t%uR", header
->HWResolution
[0]);
436 printf("\033*r%uS", header
->cupsWidth
);
438 printf("\033*r%uT", header
->cupsHeight
);
441 printf("\033&a0H"); /* Set horizontal position */
442 printf("\033&a0V"); /* Set vertical position */
443 printf("\033*r1A"); /* Start graphics */
444 printf("\033*b3M"); /* Set compression */
447 * Allocate compression buffers...
450 CompBuffer
= malloc(2 * header
->cupsBytesPerLine
+ 1);
451 LastBuffer
= malloc(header
->cupsBytesPerLine
);
457 * Allocate memory for a line of graphics...
460 Buffer
= malloc(header
->cupsBytesPerLine
);
466 * 'EndPage()' - Finish a page of graphics.
470 EndPage(ppd_file_t
*ppd
, /* I - PPD file */
471 cups_page_header2_t
*header
) /* I - Page header */
473 int val
; /* Option value */
474 ppd_choice_t
*choice
; /* Marked choice */
481 * Eject the current page...
484 fputs("\033E", stdout
);
487 case ZEBRA_EPL_LINE
:
489 * End buffered output, eject the label...
492 fputs("\033E\014", stdout
);
495 case ZEBRA_EPL_PAGE
:
507 * Cancel bitmap download...
524 if ((choice
= ppdFindMarkedChoice(ppd
, "zePrintRate")) != NULL
&&
525 strcmp(choice
->choice
, "Default"))
527 val
= atoi(choice
->choice
);
528 printf("^PR%d,%d,%d\n", val
, val
, val
);
532 * Put label home in default position (0,0)...
538 * Set media tracking...
541 if (ppdIsMarked(ppd
, "zeMediaTracking", "Continuous"))
544 * Add label length command for continuous...
547 printf("^LL%d\n", header
->cupsHeight
);
550 else if (ppdIsMarked(ppd
, "zeMediaTracking", "Web"))
552 else if (ppdIsMarked(ppd
, "zeMediaTracking", "Mark"))
559 if (header
->cupsRowStep
!= 200)
560 printf("^LT%u\n", header
->cupsRowStep
);
566 if (!strcmp(header
->MediaType
, "Thermal"))
568 else if (!strcmp(header
->MediaType
, "Direct"))
575 if ((choice
= ppdFindMarkedChoice(ppd
, "zePrintMode")) != NULL
&&
576 strcmp(choice
->choice
, "Saved"))
580 if (!strcmp(choice
->choice
, "Tear"))
582 else if (!strcmp(choice
->choice
, "Peel"))
584 else if (!strcmp(choice
->choice
, "Rewind"))
586 else if (!strcmp(choice
->choice
, "Applicator"))
593 * Set tear-off adjust position...
596 if (header
->AdvanceDistance
!= 1000)
598 if ((int)header
->AdvanceDistance
< 0)
599 printf("~TA%04d\n", (int)header
->AdvanceDistance
);
601 printf("~TA%03d\n", (int)header
->AdvanceDistance
);
605 * Allow for reprinting after an error...
608 if (ppdIsMarked(ppd
, "zeErrorReprint", "Always"))
610 else if (ppdIsMarked(ppd
, "zeErrorReprint", "Never"))
614 * Print multiple copies
617 if (header
->NumCopies
> 1)
618 printf("^PQ%d, 0, 0, N\n", header
->NumCopies
);
621 * Display the label image...
624 puts("^FO0,0^XGR:CUPS.GRF,1,1^FS");
627 * End the label and eject...
630 puts("^IDR:CUPS.GRF^FS");
634 * Free compression buffers...
643 * Set tear-off adjust position...
646 if (header
->AdvanceDistance
!= 1000)
647 printf("PRESENT-AT %d 1\r\n", (int)header
->AdvanceDistance
);
650 * Allow for reprinting after an error...
653 if (ppdIsMarked(ppd
, "zeErrorReprint", "Always"))
654 puts("ON-OUT-OF-PAPER WAIT\r");
655 else if (ppdIsMarked(ppd
, "zeErrorReprint", "Never"))
656 puts("ON-OUT-OF-PAPER PURGE\r");
662 if (header
->CutMedia
)
669 if (header
->cupsCompression
> 0)
670 printf("TONE %u\r\n", 2 * header
->cupsCompression
);
676 if ((choice
= ppdFindMarkedChoice(ppd
, "zePrintRate")) != NULL
&&
677 strcmp(choice
->choice
, "Default"))
679 val
= atoi(choice
->choice
);
680 printf("SPEED %d\r\n", val
);
687 if ((choice
= ppdFindMarkedChoice(ppd
, "zeMediaTracking")) == NULL
||
688 strcmp(choice
->choice
, "Continuous"))
694 case INTELLITECH_PCL
:
695 printf("\033*rB"); /* End GFX */
696 printf("\014"); /* Eject current page */
711 * 'CancelJob()' - Cancel the current job...
715 CancelJob(int sig
) /* I - Signal */
718 * Tell the main loop to stop...
728 * 'OutputLine()' - Output a line of graphics...
732 OutputLine(ppd_file_t
*ppd
, /* I - PPD file */
733 cups_page_header2_t
*header
, /* I - Page header */
734 unsigned y
) /* I - Line number */
736 unsigned i
; /* Looping var */
737 unsigned char *ptr
; /* Pointer into buffer */
738 unsigned char *compptr
; /* Pointer into compression buffer */
739 unsigned char repeat_char
; /* Repeated character */
740 unsigned repeat_count
; /* Number of repeated characters */
741 static const unsigned char *hex
= (const unsigned char *)"0123456789ABCDEF";
751 * See if the line is blank; if not, write it to the printer...
755 memcmp(Buffer
, Buffer
+ 1, header
->cupsBytesPerLine
- 1))
761 printf("\033f\001%c", 255);
765 printf("\033f\001%c", Feed
);
770 fwrite(Buffer
, header
->cupsBytesPerLine
, 1, stdout
);
777 case ZEBRA_EPL_LINE
:
778 printf("\033g%03d", header
->cupsBytesPerLine
);
779 fwrite(Buffer
, 1, header
->cupsBytesPerLine
, stdout
);
783 case ZEBRA_EPL_PAGE
:
784 if (Buffer
[0] || memcmp(Buffer
, Buffer
+ 1, header
->cupsBytesPerLine
))
786 printf("GW0,%d,%d,1\n", y
, header
->cupsBytesPerLine
);
787 for (i
= header
->cupsBytesPerLine
, ptr
= Buffer
; i
> 0; i
--, ptr
++)
796 * Determine if this row is the same as the previous line.
797 * If so, output a ':' and return...
802 if (!memcmp(Buffer
, LastBuffer
, header
->cupsBytesPerLine
))
810 * Convert the line to hex digits...
813 for (ptr
= Buffer
, compptr
= CompBuffer
, i
= header
->cupsBytesPerLine
;
817 *compptr
++ = hex
[*ptr
>> 4];
818 *compptr
++ = hex
[*ptr
& 15];
824 * Run-length compress the graphics...
827 for (compptr
= CompBuffer
+ 1, repeat_char
= CompBuffer
[0], repeat_count
= 1;
830 if (*compptr
== repeat_char
)
834 ZPLCompress(repeat_char
, repeat_count
);
835 repeat_char
= *compptr
;
839 if (repeat_char
== '0')
842 * Handle 0's on the end of the line...
845 if (repeat_count
& 1)
851 if (repeat_count
> 0)
855 ZPLCompress(repeat_char
, repeat_count
);
860 * Save this line for the next round...
863 memcpy(LastBuffer
, Buffer
, header
->cupsBytesPerLine
);
868 if (Buffer
[0] || memcmp(Buffer
, Buffer
+ 1, header
->cupsBytesPerLine
))
870 printf("CG %u 1 0 %d ", header
->cupsBytesPerLine
, y
);
871 fwrite(Buffer
, 1, header
->cupsBytesPerLine
, stdout
);
877 case INTELLITECH_PCL
:
879 memcmp(Buffer
, Buffer
+ 1, header
->cupsBytesPerLine
- 1))
883 printf("\033*b%dY", Feed
);
888 PCLCompress(Buffer
, header
->cupsBytesPerLine
);
898 * 'PCLCompress()' - Output a PCL (mode 3) compressed line.
902 PCLCompress(unsigned char *line
, /* I - Line to compress */
903 unsigned length
) /* I - Length of line */
905 unsigned char *line_ptr
, /* Current byte pointer */
906 *line_end
, /* End-of-line byte pointer */
907 *comp_ptr
, /* Pointer into compression buffer */
908 *start
, /* Start of compression sequence */
909 *seed
; /* Seed buffer pointer */
910 unsigned count
, /* Count of bytes for output */
911 offset
; /* Offset of bytes for output */
915 * Do delta-row compression...
919 line_end
= line
+ length
;
921 comp_ptr
= CompBuffer
;
924 while (line_ptr
< line_end
)
927 * Find the next non-matching sequence...
935 * The seed buffer is invalid, so do the next 8 bytes, max...
940 if ((count
= (unsigned)(line_end
- line_ptr
)) > 8)
948 * The seed buffer is valid, so compare against it...
951 while (*line_ptr
== *seed
&&
958 if (line_ptr
== line_end
)
961 offset
= (unsigned)(line_ptr
- start
);
964 * Find up to 8 non-matching bytes...
969 while (*line_ptr
!= *seed
&&
970 line_ptr
< line_end
&&
980 * Place mode 3 compression data in the buffer; see HP manuals
987 * Output multi-byte offset...
990 *comp_ptr
++ = (unsigned char)(((count
- 1) << 5) | 31);
993 while (offset
>= 255)
999 *comp_ptr
++ = (unsigned char)offset
;
1004 * Output single-byte offset...
1007 *comp_ptr
++ = (unsigned char)(((count
- 1) << 5) | offset
);
1010 memcpy(comp_ptr
, start
, count
);
1015 * Set the length of the data and write it...
1018 printf("\033*b%dW", (int)(comp_ptr
- CompBuffer
));
1019 fwrite(CompBuffer
, (size_t)(comp_ptr
- CompBuffer
), 1, stdout
);
1022 * Save this line as a "seed" buffer for the next...
1025 memcpy(LastBuffer
, line
, length
);
1031 * 'ZPLCompress()' - Output a run-length compression sequence.
1035 ZPLCompress(unsigned char repeat_char
, /* I - Character to repeat */
1036 unsigned repeat_count
) /* I - Number of repeated characters */
1038 if (repeat_count
> 1)
1041 * Print as many z's as possible - they are the largest denomination
1042 * representing 400 characters (zC stands for 400 adjacent C's)
1045 while (repeat_count
>= 400)
1048 repeat_count
-= 400;
1052 * Then print 'g' through 'y' as multiples of 20 characters...
1055 if (repeat_count
>= 20)
1057 putchar((int)('f' + repeat_count
/ 20));
1062 * Finally, print 'G' through 'Y' as 1 through 19 characters...
1065 if (repeat_count
> 0)
1066 putchar((int)('F' + repeat_count
));
1070 * Then the character to be repeated...
1073 putchar((int)repeat_char
);
1078 * 'main()' - Main entry and processing of driver.
1081 int /* O - Exit status */
1082 main(int argc
, /* I - Number of command-line arguments */
1083 char *argv
[]) /* I - Command-line arguments */
1085 int fd
; /* File descriptor */
1086 cups_raster_t
*ras
; /* Raster stream for printing */
1087 cups_page_header2_t header
; /* Page header from file */
1088 unsigned y
; /* Current line */
1089 ppd_file_t
*ppd
; /* PPD file */
1090 int num_options
; /* Number of options */
1091 cups_option_t
*options
; /* Options */
1092 #if defined(HAVE_SIGACTION) && !defined(HAVE_SIGSET)
1093 struct sigaction action
; /* Actions for POSIX signals */
1094 #endif /* HAVE_SIGACTION && !HAVE_SIGSET */
1098 * Make sure status messages are not buffered...
1101 setbuf(stderr
, NULL
);
1104 * Check command-line...
1107 if (argc
< 6 || argc
> 7)
1110 * We don't have the correct number of arguments; write an error message
1114 _cupsLangPrintFilter(stderr
, "ERROR",
1115 _("%s job-id user title copies options [file]"),
1121 * Open the page stream...
1126 if ((fd
= open(argv
[6], O_RDONLY
)) == -1)
1128 _cupsLangPrintError("ERROR", _("Unable to open raster file"));
1136 ras
= cupsRasterOpen(fd
, CUPS_RASTER_READ
);
1139 * Register a signal handler to eject the current page if the
1145 #ifdef HAVE_SIGSET /* Use System V signals over POSIX to avoid bugs */
1146 sigset(SIGTERM
, CancelJob
);
1147 #elif defined(HAVE_SIGACTION)
1148 memset(&action
, 0, sizeof(action
));
1150 sigemptyset(&action
.sa_mask
);
1151 action
.sa_handler
= CancelJob
;
1152 sigaction(SIGTERM
, &action
, NULL
);
1154 signal(SIGTERM
, CancelJob
);
1155 #endif /* HAVE_SIGSET */
1158 * Open the PPD file and apply options...
1161 num_options
= cupsParseOptions(argv
[5], 0, &options
);
1163 ppd
= ppdOpenFile(getenv("PPD"));
1166 ppd_status_t status
; /* PPD error */
1167 int linenum
; /* Line number */
1169 _cupsLangPrintFilter(stderr
, "ERROR",
1170 _("The PPD file could not be opened."));
1172 status
= ppdLastError(&linenum
);
1174 fprintf(stderr
, "DEBUG: %s on line %d.\n", ppdErrorString(status
), linenum
);
1179 ppdMarkDefaults(ppd
);
1180 cupsMarkOptions(ppd
, num_options
, options
);
1183 * Initialize the print device...
1189 * Process pages as needed...
1194 while (cupsRasterReadHeader2(ras
, &header
))
1197 * Write a status message with the page number and number of copies.
1205 fprintf(stderr
, "PAGE: %d 1\n", Page
);
1206 _cupsLangPrintFilter(stderr
, "INFO", _("Starting page %d."), Page
);
1212 StartPage(ppd
, &header
);
1215 * Loop for each line on the page...
1218 for (y
= 0; y
< header
.cupsHeight
&& !Canceled
; y
++)
1221 * Let the user know how far we have progressed...
1229 _cupsLangPrintFilter(stderr
, "INFO",
1230 _("Printing page %d, %u%% complete."),
1231 Page
, 100 * y
/ header
.cupsHeight
);
1232 fprintf(stderr
, "ATTR: job-media-progress=%u\n",
1233 100 * y
/ header
.cupsHeight
);
1237 * Read a line of graphics...
1240 if (cupsRasterReadPixels(ras
, Buffer
, header
.cupsBytesPerLine
) < 1)
1244 * Write it to the printer...
1247 OutputLine(ppd
, &header
, y
);
1254 _cupsLangPrintFilter(stderr
, "INFO", _("Finished page %d."), Page
);
1256 EndPage(ppd
, &header
);
1263 * Close the raster stream...
1266 cupsRasterClose(ras
);
1271 * Close the PPD file and free the options...
1275 cupsFreeOptions(num_options
, options
);
1278 * If no pages were printed, send an error message...
1283 _cupsLangPrintFilter(stderr
, "ERROR", _("No pages were found."));