2 * "$Id: rastertolabel.c 6649 2007-07-11 21:46:42Z mike $"
4 * Label printer filter for the Common UNIX Printing System (CUPS).
6 * Copyright 2007 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>
34 #include <cups/string.h>
35 #include <cups/i18n.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 on-line 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_header_t
*header
);
94 void EndPage(ppd_file_t
*ppd
, cups_page_header_t
*header
);
95 void CancelJob(int sig
);
96 void OutputLine(ppd_file_t
*ppd
, cups_page_header_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_header_t
*header
) /* I - Page header */
171 ppd_choice_t
*choice
; /* Marked choice */
172 int length
; /* Actual label length */
173 #if defined(HAVE_SIGACTION) && !defined(HAVE_SIGSET)
174 struct sigaction action
; /* Actions for POSIX signals */
175 #endif /* HAVE_SIGACTION && !HAVE_SIGSET */
179 * Show page device dictionary...
182 fprintf(stderr
, "DEBUG: StartPage...\n");
183 fprintf(stderr
, "DEBUG: MediaClass = \"%s\"\n", header
->MediaClass
);
184 fprintf(stderr
, "DEBUG: MediaColor = \"%s\"\n", header
->MediaColor
);
185 fprintf(stderr
, "DEBUG: MediaType = \"%s\"\n", header
->MediaType
);
186 fprintf(stderr
, "DEBUG: OutputType = \"%s\"\n", header
->OutputType
);
188 fprintf(stderr
, "DEBUG: AdvanceDistance = %d\n", header
->AdvanceDistance
);
189 fprintf(stderr
, "DEBUG: AdvanceMedia = %d\n", header
->AdvanceMedia
);
190 fprintf(stderr
, "DEBUG: Collate = %d\n", header
->Collate
);
191 fprintf(stderr
, "DEBUG: CutMedia = %d\n", header
->CutMedia
);
192 fprintf(stderr
, "DEBUG: Duplex = %d\n", header
->Duplex
);
193 fprintf(stderr
, "DEBUG: HWResolution = [ %d %d ]\n", header
->HWResolution
[0],
194 header
->HWResolution
[1]);
195 fprintf(stderr
, "DEBUG: ImagingBoundingBox = [ %d %d %d %d ]\n",
196 header
->ImagingBoundingBox
[0], header
->ImagingBoundingBox
[1],
197 header
->ImagingBoundingBox
[2], header
->ImagingBoundingBox
[3]);
198 fprintf(stderr
, "DEBUG: InsertSheet = %d\n", header
->InsertSheet
);
199 fprintf(stderr
, "DEBUG: Jog = %d\n", header
->Jog
);
200 fprintf(stderr
, "DEBUG: LeadingEdge = %d\n", header
->LeadingEdge
);
201 fprintf(stderr
, "DEBUG: Margins = [ %d %d ]\n", header
->Margins
[0],
203 fprintf(stderr
, "DEBUG: ManualFeed = %d\n", header
->ManualFeed
);
204 fprintf(stderr
, "DEBUG: MediaPosition = %d\n", header
->MediaPosition
);
205 fprintf(stderr
, "DEBUG: MediaWeight = %d\n", header
->MediaWeight
);
206 fprintf(stderr
, "DEBUG: MirrorPrint = %d\n", header
->MirrorPrint
);
207 fprintf(stderr
, "DEBUG: NegativePrint = %d\n", header
->NegativePrint
);
208 fprintf(stderr
, "DEBUG: NumCopies = %d\n", header
->NumCopies
);
209 fprintf(stderr
, "DEBUG: Orientation = %d\n", header
->Orientation
);
210 fprintf(stderr
, "DEBUG: OutputFaceUp = %d\n", header
->OutputFaceUp
);
211 fprintf(stderr
, "DEBUG: PageSize = [ %d %d ]\n", header
->PageSize
[0],
212 header
->PageSize
[1]);
213 fprintf(stderr
, "DEBUG: Separations = %d\n", header
->Separations
);
214 fprintf(stderr
, "DEBUG: TraySwitch = %d\n", header
->TraySwitch
);
215 fprintf(stderr
, "DEBUG: Tumble = %d\n", header
->Tumble
);
216 fprintf(stderr
, "DEBUG: cupsWidth = %d\n", header
->cupsWidth
);
217 fprintf(stderr
, "DEBUG: cupsHeight = %d\n", header
->cupsHeight
);
218 fprintf(stderr
, "DEBUG: cupsMediaType = %d\n", header
->cupsMediaType
);
219 fprintf(stderr
, "DEBUG: cupsBitsPerColor = %d\n", header
->cupsBitsPerColor
);
220 fprintf(stderr
, "DEBUG: cupsBitsPerPixel = %d\n", header
->cupsBitsPerPixel
);
221 fprintf(stderr
, "DEBUG: cupsBytesPerLine = %d\n", header
->cupsBytesPerLine
);
222 fprintf(stderr
, "DEBUG: cupsColorOrder = %d\n", header
->cupsColorOrder
);
223 fprintf(stderr
, "DEBUG: cupsColorSpace = %d\n", header
->cupsColorSpace
);
224 fprintf(stderr
, "DEBUG: cupsCompression = %d\n", header
->cupsCompression
);
225 fprintf(stderr
, "DEBUG: cupsRowCount = %d\n", header
->cupsRowCount
);
226 fprintf(stderr
, "DEBUG: cupsRowFeed = %d\n", header
->cupsRowFeed
);
227 fprintf(stderr
, "DEBUG: cupsRowStep = %d\n", header
->cupsRowStep
);
230 * Register a signal handler to eject the current page if the
234 #ifdef HAVE_SIGSET /* Use System V signals over POSIX to avoid bugs */
235 sigset(SIGTERM
, CancelJob
);
236 #elif defined(HAVE_SIGACTION)
237 memset(&action
, 0, sizeof(action
));
239 sigemptyset(&action
.sa_mask
);
240 action
.sa_handler
= CancelJob
;
241 sigaction(SIGTERM
, &action
, NULL
);
243 signal(SIGTERM
, CancelJob
);
244 #endif /* HAVE_SIGSET */
250 * Setup printer/job attributes...
253 length
= header
->PageSize
[1] * header
->HWResolution
[1] / 72;
255 printf("\033L%c%c", length
>> 8, length
);
256 printf("\033D%c", header
->cupsBytesPerLine
);
258 printf("\033%c", header
->cupsCompression
+ 'c'); /* Darkness */
261 case ZEBRA_EPL_LINE
:
266 if ((choice
= ppdFindMarkedChoice(ppd
, "zePrintRate")) != NULL
&&
267 strcmp(choice
->choice
, "Default"))
268 printf("\033S%.0f", atof(choice
->choice
) * 2.0 - 2.0);
274 if (header
->cupsCompression
> 0 && header
->cupsCompression
<= 100)
275 printf("\033D%d", 7 * header
->cupsCompression
/ 100);
278 * Set left margin to 0...
281 fputs("\033M01", stdout
);
284 * Start buffered output...
287 fputs("\033B", stdout
);
290 case ZEBRA_EPL_PAGE
:
292 * Start a new label...
299 * Set hardware options...
302 if (!strcmp(header
->MediaType
, "Direct"))
309 if ((choice
= ppdFindMarkedChoice(ppd
, "zePrintRate")) != NULL
&&
310 strcmp(choice
->choice
, "Default"))
312 float val
= atof(choice
->choice
);
315 printf("S%.0f\n", val
);
317 printf("S%.0f\n", val
* 2.0 - 2.0);
324 if (header
->cupsCompression
> 0 && header
->cupsCompression
<= 100)
325 printf("D%d\n", 15 * header
->cupsCompression
/ 100);
331 printf("q%d\n", (header
->cupsWidth
+ 7) & ~7);
339 if (header
->cupsCompression
> 0 && header
->cupsCompression
<= 100)
340 printf("~SD%02d\n", 30 * header
->cupsCompression
/ 100);
343 * Start bitmap graphics...
346 printf("~DGR:CUPS.GRF,%d,%d,\n",
347 header
->cupsHeight
* header
->cupsBytesPerLine
,
348 header
->cupsBytesPerLine
);
351 * Allocate compression buffers...
354 CompBuffer
= malloc(2 * header
->cupsBytesPerLine
+ 1);
355 LastBuffer
= malloc(header
->cupsBytesPerLine
);
364 printf("! 0 %u %u %u %u\r\n", header
->HWResolution
[0],
365 header
->HWResolution
[1], header
->cupsHeight
,
367 printf("PAGE-WIDTH %d\r\n", header
->cupsWidth
);
368 printf("PAGE-HEIGHT %d\r\n", header
->cupsWidth
);
371 case INTELLITECH_PCL
:
373 * Set the media size...
376 printf("\033&l6D\033&k12H"); /* Set 6 LPI, 10 CPI */
377 printf("\033&l0O"); /* Set portrait orientation */
379 switch (header
->PageSize
[1])
381 case 540 : /* Monarch Envelope */
382 printf("\033&l80A"); /* Set page size */
385 case 624 : /* DL Envelope */
386 printf("\033&l90A"); /* Set page size */
389 case 649 : /* C5 Envelope */
390 printf("\033&l91A"); /* Set page size */
393 case 684 : /* COM-10 Envelope */
394 printf("\033&l81A"); /* Set page size */
397 case 756 : /* Executive */
398 printf("\033&l1A"); /* Set page size */
401 case 792 : /* Letter */
402 printf("\033&l2A"); /* Set page size */
406 printf("\033&l26A"); /* Set page size */
409 case 1008 : /* Legal */
410 printf("\033&l3A"); /* Set page size */
413 default : /* Custom size */
414 printf("\033!f%dZ", header
->PageSize
[1] * 300 / 72);
418 printf("\033&l%dP", /* Set page length */
419 header
->PageSize
[1] / 12);
420 printf("\033&l0E"); /* Set top margin to 0 */
421 printf("\033&l%dX", header
->NumCopies
);
422 /* Set number copies */
423 printf("\033&l0L"); /* Turn off perforation skip */
431 if (header
->cupsRowFeed
) /* inPrintRate */
432 printf("\033!p%dS", header
->cupsRowFeed
);
434 if (header
->cupsCompression
!= ~0)
436 printf("\033&d%dA", 30 * header
->cupsCompression
/ 100 - 15);
438 if ((choice
= ppdFindMarkedChoice(ppd
, "inPrintMode")) != NULL
)
440 if (!strcmp(choice
->choice
, "Standard"))
441 fputs("\033!p0M", stdout
);
442 else if (!strcmp(choice
->choice
, "Tear"))
444 fputs("\033!p1M", stdout
);
446 if (header
->cupsRowCount
) /* inTearInterval */
447 printf("\033!n%dT", header
->cupsRowCount
);
451 fputs("\033!p2M", stdout
);
453 if (header
->cupsRowStep
) /* inCutInterval */
454 printf("\033!n%dC", header
->cupsRowStep
);
463 printf("\033*t%dR", header
->HWResolution
[0]);
466 printf("\033*r%dS", header
->cupsWidth
);
468 printf("\033*r%dT", header
->cupsHeight
);
471 printf("\033&a0H"); /* Set horizontal position */
472 printf("\033&a0V"); /* Set vertical position */
473 printf("\033*r1A"); /* Start graphics */
474 printf("\033*b3M"); /* Set compression */
477 * Allocate compression buffers...
480 CompBuffer
= malloc(2 * header
->cupsBytesPerLine
+ 1);
481 LastBuffer
= malloc(header
->cupsBytesPerLine
);
487 * Allocate memory for a line of graphics...
490 Buffer
= malloc(header
->cupsBytesPerLine
);
496 * 'EndPage()' - Finish a page of graphics.
500 EndPage(ppd_file_t
*ppd
, /* I - PPD file */
501 cups_page_header_t
*header
) /* I - Page header */
503 int val
; /* Option value */
504 ppd_choice_t
*choice
; /* Marked choice */
505 #if defined(HAVE_SIGACTION) && !defined(HAVE_SIGSET)
506 struct sigaction action
; /* Actions for POSIX signals */
507 #endif /* HAVE_SIGACTION && !HAVE_SIGSET */
514 * Eject the current page...
517 fputs("\033E", stdout
);
520 case ZEBRA_EPL_LINE
:
522 * End buffered output, eject the label...
525 fputs("\033E\014", stdout
);
528 case ZEBRA_EPL_PAGE
:
540 * Cancel bitmap download...
557 if ((choice
= ppdFindMarkedChoice(ppd
, "zePrintRate")) != NULL
&&
558 strcmp(choice
->choice
, "Default"))
560 val
= atoi(choice
->choice
);
561 printf("^PR%d,%d,%d\n", val
, val
, val
);
565 * Put label home in default position (0,0)...
571 * Set media tracking...
574 if (ppdIsMarked(ppd
, "zeMediaTracking", "Continuous"))
577 * Add label length command for continuous...
580 printf("^LL%d\n", header
->cupsHeight
);
583 else if (ppdIsMarked(ppd
, "zeMediaTracking", "Web"))
585 else if (ppdIsMarked(ppd
, "zeMediaTracking", "Mark"))
592 if (header
->cupsRowStep
!= 200)
593 printf("^LT%u\n", header
->cupsRowStep
);
599 if (!strcmp(header
->MediaType
, "Thermal"))
601 else if (!strcmp(header
->MediaType
, "Direct"))
608 if ((choice
= ppdFindMarkedChoice(ppd
, "zePrintMode")) != NULL
&&
609 strcmp(choice
->choice
, "Saved"))
613 if (!strcmp(choice
->choice
, "Tear"))
615 else if (!strcmp(choice
->choice
, "Peel"))
617 else if (!strcmp(choice
->choice
, "Rewind"))
619 else if (!strcmp(choice
->choice
, "Applicator"))
626 * Set tear-off adjust position...
629 if (header
->AdvanceDistance
!= 1000)
631 if ((int)header
->AdvanceDistance
< 0)
632 printf("~TA%04d\n", (int)header
->AdvanceDistance
);
634 printf("~TA%03d\n", (int)header
->AdvanceDistance
);
638 * Allow for reprinting after an error...
641 if (ppdIsMarked(ppd
, "zeErrorReprint", "Always"))
643 else if (ppdIsMarked(ppd
, "zeErrorReprint", "Never"))
647 * Print multiple copies
650 if (header
->NumCopies
> 1)
651 printf("^PQ%d, 0, 0, N\n", header
->NumCopies
);
654 * Display the label image...
657 puts("^FO0,0^XGR:CUPS.GRF,1,1^FS");
660 * End the label and eject...
666 * Free compression buffers...
675 * Set tear-off adjust position...
678 if (header
->AdvanceDistance
!= 1000)
679 printf("PRESENT-AT %d 1\r\n", (int)header
->AdvanceDistance
);
682 * Allow for reprinting after an error...
685 if (ppdIsMarked(ppd
, "zeErrorReprint", "Always"))
686 puts("ON-OUT-OF-PAPER WAIT\r");
687 else if (ppdIsMarked(ppd
, "zeErrorReprint", "Never"))
688 puts("ON-OUT-OF-PAPER PURGE\r");
694 if (header
->CutMedia
)
701 if (header
->cupsCompression
> 0)
702 printf("TONE %u\r\n", 2 * header
->cupsCompression
);
708 if ((choice
= ppdFindMarkedChoice(ppd
, "zePrintRate")) != NULL
&&
709 strcmp(choice
->choice
, "Default"))
711 val
= atoi(choice
->choice
);
712 printf("SPEED %d\r\n", val
);
719 if ((choice
= ppdFindMarkedChoice(ppd
, "zeMediaTracking")) == NULL
||
720 strcmp(choice
->choice
, "Continuous"))
726 case INTELLITECH_PCL
:
727 printf("\033*rB"); /* End GFX */
728 printf("\014"); /* Eject current page */
735 * Unregister the signal handler...
738 #ifdef HAVE_SIGSET /* Use System V signals over POSIX to avoid bugs */
739 sigset(SIGTERM
, SIG_IGN
);
740 #elif defined(HAVE_SIGACTION)
741 memset(&action
, 0, sizeof(action
));
743 sigemptyset(&action
.sa_mask
);
744 action
.sa_handler
= SIG_IGN
;
745 sigaction(SIGTERM
, &action
, NULL
);
747 signal(SIGTERM
, SIG_IGN
);
748 #endif /* HAVE_SIGSET */
759 * 'CancelJob()' - Cancel the current job...
763 CancelJob(int sig
) /* I - Signal */
766 * Tell the main loop to stop...
776 * 'OutputLine()' - Output a line of graphics...
780 OutputLine(ppd_file_t
*ppd
, /* I - PPD file */
781 cups_page_header_t
*header
, /* I - Page header */
782 int y
) /* I - Line number */
784 int i
; /* Looping var */
785 unsigned char *ptr
; /* Pointer into buffer */
786 unsigned char *compptr
; /* Pointer into compression buffer */
787 char repeat_char
; /* Repeated character */
788 int repeat_count
; /* Number of repeated characters */
789 static const char *hex
= "0123456789ABCDEF";
797 * See if the line is blank; if not, write it to the printer...
801 memcmp(Buffer
, Buffer
+ 1, header
->cupsBytesPerLine
- 1))
807 printf("\033f\001%c", 255);
811 printf("\033f\001%c", Feed
);
816 fwrite(Buffer
, header
->cupsBytesPerLine
, 1, stdout
);
821 * This hack works around a bug in the IRIX serial port driver when
822 * run at high baud rates (e.g. 115200 baud)... This results in
823 * slightly slower label printing, but at least the labels come
834 case ZEBRA_EPL_LINE
:
835 printf("\033g%03d", header
->cupsBytesPerLine
);
836 fwrite(Buffer
, 1, header
->cupsBytesPerLine
, stdout
);
840 case ZEBRA_EPL_PAGE
:
841 if (Buffer
[0] || memcmp(Buffer
, Buffer
+ 1, header
->cupsBytesPerLine
))
843 printf("GW0,%d,%d,1\n", y
, header
->cupsBytesPerLine
);
844 for (i
= header
->cupsBytesPerLine
, ptr
= Buffer
; i
> 0; i
--, ptr
++)
853 * Determine if this row is the same as the previous line.
854 * If so, output a ':' and return...
859 if (!memcmp(Buffer
, LastBuffer
, header
->cupsBytesPerLine
))
867 * Convert the line to hex digits...
870 for (ptr
= Buffer
, compptr
= CompBuffer
, i
= header
->cupsBytesPerLine
;
874 *compptr
++ = hex
[*ptr
>> 4];
875 *compptr
++ = hex
[*ptr
& 15];
881 * Run-length compress the graphics...
884 for (compptr
= CompBuffer
+ 1, repeat_char
= CompBuffer
[0], repeat_count
= 1;
887 if (*compptr
== repeat_char
)
891 ZPLCompress(repeat_char
, repeat_count
);
892 repeat_char
= *compptr
;
896 if (repeat_char
== '0')
899 * Handle 0's on the end of the line...
902 if (repeat_count
& 1)
908 if (repeat_count
> 0)
912 ZPLCompress(repeat_char
, repeat_count
);
917 * Save this line for the next round...
920 memcpy(LastBuffer
, Buffer
, header
->cupsBytesPerLine
);
925 if (Buffer
[0] || memcmp(Buffer
, Buffer
+ 1, header
->cupsBytesPerLine
))
927 printf("CG %u 1 0 %d ", header
->cupsBytesPerLine
, y
);
928 fwrite(Buffer
, 1, header
->cupsBytesPerLine
, stdout
);
934 case INTELLITECH_PCL
:
936 memcmp(Buffer
, Buffer
+ 1, header
->cupsBytesPerLine
- 1))
940 printf("\033*b%dY", Feed
);
945 PCLCompress(Buffer
, header
->cupsBytesPerLine
);
955 * 'PCLCompress()' - Output a PCL (mode 3) compressed line.
959 PCLCompress(unsigned char *line
, /* I - Line to compress */
960 int length
) /* I - Length of line */
962 unsigned char *line_ptr
, /* Current byte pointer */
963 *line_end
, /* End-of-line byte pointer */
964 *comp_ptr
, /* Pointer into compression buffer */
965 *start
, /* Start of compression sequence */
966 *seed
; /* Seed buffer pointer */
967 int count
, /* Count of bytes for output */
968 offset
; /* Offset of bytes for output */
972 * Do delta-row compression...
976 line_end
= line
+ length
;
978 comp_ptr
= CompBuffer
;
981 while (line_ptr
< line_end
)
984 * Find the next non-matching sequence...
992 * The seed buffer is invalid, so do the next 8 bytes, max...
997 if ((count
= line_end
- line_ptr
) > 8)
1005 * The seed buffer is valid, so compare against it...
1008 while (*line_ptr
== *seed
&&
1009 line_ptr
< line_end
)
1015 if (line_ptr
== line_end
)
1018 offset
= line_ptr
- start
;
1021 * Find up to 8 non-matching bytes...
1026 while (*line_ptr
!= *seed
&&
1027 line_ptr
< line_end
&&
1037 * Place mode 3 compression data in the buffer; see HP manuals
1044 * Output multi-byte offset...
1047 *comp_ptr
++ = ((count
- 1) << 5) | 31;
1050 while (offset
>= 255)
1056 *comp_ptr
++ = offset
;
1061 * Output single-byte offset...
1064 *comp_ptr
++ = ((count
- 1) << 5) | offset
;
1067 memcpy(comp_ptr
, start
, count
);
1071 line_ptr
= CompBuffer
;
1072 line_end
= comp_ptr
;
1075 * Set the length of the data and write it...
1078 printf("\033*b%dW", comp_ptr
- CompBuffer
);
1079 fwrite(CompBuffer
, comp_ptr
- CompBuffer
, 1, stdout
);
1082 * Save this line as a "seed" buffer for the next...
1085 memcpy(LastBuffer
, line
, length
);
1091 * 'ZPLCompress()' - Output a run-length compression sequence.
1095 ZPLCompress(char repeat_char
, /* I - Character to repeat */
1096 int repeat_count
) /* I - Number of repeated characters */
1098 if (repeat_count
> 1)
1101 * Print as many z's as possible - they are the largest denomination
1102 * representing 400 characters (zC stands for 400 adjacent C's)
1105 while (repeat_count
>= 400)
1108 repeat_count
-= 400;
1112 * Then print 'g' through 'y' as multiples of 20 characters...
1115 if (repeat_count
>= 20)
1117 putchar('f' + repeat_count
/ 20);
1122 * Finally, print 'G' through 'Y' as 1 through 19 characters...
1125 if (repeat_count
> 0)
1126 putchar('F' + repeat_count
);
1130 * Then the character to be repeated...
1133 putchar(repeat_char
);
1138 * 'main()' - Main entry and processing of driver.
1141 int /* O - Exit status */
1142 main(int argc
, /* I - Number of command-line arguments */
1143 char *argv
[]) /* I - Command-line arguments */
1145 int fd
; /* File descriptor */
1146 cups_raster_t
*ras
; /* Raster stream for printing */
1147 cups_page_header_t header
; /* Page header from file */
1148 int y
; /* Current line */
1149 ppd_file_t
*ppd
; /* PPD file */
1150 int num_options
; /* Number of options */
1151 cups_option_t
*options
; /* Options */
1155 * Make sure status messages are not buffered...
1158 setbuf(stderr
, NULL
);
1161 * Check command-line...
1164 if (argc
< 6 || argc
> 7)
1167 * We don't have the correct number of arguments; write an error message
1171 fprintf(stderr
, _("Usage: %s job-id user title copies options [file]\n"),
1177 * Open the page stream...
1182 if ((fd
= open(argv
[6], O_RDONLY
)) == -1)
1184 perror("ERROR: Unable to open raster file - ");
1192 ras
= cupsRasterOpen(fd
, CUPS_RASTER_READ
);
1195 * Open the PPD file and apply options...
1198 num_options
= cupsParseOptions(argv
[5], 0, &options
);
1200 if ((ppd
= ppdOpenFile(getenv("PPD"))) != NULL
)
1202 ppdMarkDefaults(ppd
);
1203 cupsMarkOptions(ppd
, num_options
, options
);
1207 * Initialize the print device...
1213 * Process pages as needed...
1219 while (cupsRasterReadHeader(ras
, &header
))
1222 * Write a status message with the page number and number of copies.
1227 fprintf(stderr
, "PAGE: %d 1\n", Page
);
1233 StartPage(ppd
, &header
);
1236 * Loop for each line on the page...
1239 for (y
= 0; y
< header
.cupsHeight
&& !Canceled
; y
++)
1242 * Let the user know how far we have progressed...
1246 fprintf(stderr
, _("INFO: Printing page %d, %d%% complete...\n"), Page
,
1247 100 * y
/ header
.cupsHeight
);
1250 * Read a line of graphics...
1253 if (cupsRasterReadPixels(ras
, Buffer
, header
.cupsBytesPerLine
) < 1)
1257 * Write it to the printer...
1260 OutputLine(ppd
, &header
, y
);
1267 EndPage(ppd
, &header
);
1274 * Close the raster stream...
1277 cupsRasterClose(ras
);
1282 * Close the PPD file and free the options...
1286 cupsFreeOptions(num_options
, options
);
1289 * If no pages were printed, send an error message...
1293 fputs(_("ERROR: No pages found!\n"), stderr
);
1295 fputs(_("INFO: Ready to print.\n"), stderr
);
1302 * End of "$Id: rastertolabel.c 6649 2007-07-11 21:46:42Z mike $".