4 * Label printer filter for the Common UNIX Printing System (CUPS).
6 * Copyright 2001-2006 by Easy Software Products.
8 * These coded instructions, statements, and computer programs are the
9 * property of Easy Software Products and are protected by Federal
10 * copyright law. Distribution and use rights are outlined in the file
11 * "LICENSE.txt" which should have been included with this file. If this
12 * file is missing or damaged please contact Easy Software Products
15 * Attn: CUPS Licensing Information
16 * Easy Software Products
17 * 44141 Airport View Drive, Suite 204
18 * Hollywood, Maryland 20636 USA
20 * Voice: (301) 373-9600
21 * EMail: cups-info@cups.org
22 * WWW: http://www.cups.org
24 * This file is subject to the Apple OS-Developed Software exception.
28 * Setup() - Prepare the printer for printing.
29 * StartPage() - Start a page of graphics.
30 * EndPage() - Finish a page of graphics.
31 * CancelJob() - Cancel the current job...
32 * OutputLine() - Output a line of graphics.
33 * PCLCompress() - Output a PCL (mode 3) compressed line.
34 * ZPLCompress() - Output a run-length compression sequence.
35 * main() - Main entry and processing of driver.
39 * Include necessary headers...
42 #include <cups/cups.h>
43 #include <cups/string.h>
52 * This driver filter currently supports Dymo, Intellitech, and Zebra
55 * The Dymo portion of the driver has been tested with the 300, 330,
56 * and 330 Turbo label printers; it may also work with other models.
57 * The Dymo printers support printing at 136, 203, and 300 DPI.
59 * The Intellitech portion of the driver has been tested with the
60 * Intellibar 408, 412, and 808 and supports their PCL variant.
62 * The Zebra portion of the driver has been tested with the LP-2844,
63 * LP-2844Z, QL-320, and QL-420 label printers; it may also work with
64 * other models. The driver supports EPL line mode, EPL page mode,
65 * ZPL, and CPCL as defined in Zebra's on-line developer documentation.
69 * Model number constants...
72 #define DYMO_3x0 0 /* Dymo Labelwriter 300/330/330 Turbo */
74 #define ZEBRA_EPL_LINE 0x10 /* Zebra EPL line mode printers */
75 #define ZEBRA_EPL_PAGE 0x11 /* Zebra EPL page mode printers */
76 #define ZEBRA_ZPL 0x12 /* Zebra ZPL-based printers */
77 #define ZEBRA_CPCL 0x13 /* Zebra CPCL-based printers */
79 #define INTELLITECH_PCL 0x20 /* Intellitech PCL-based printers */
86 unsigned char *Buffer
; /* Output buffer */
87 unsigned char *CompBuffer
; /* Compression buffer */
88 unsigned char *LastBuffer
; /* Last buffer */
89 int LastSet
; /* Number of repeat characters */
90 int ModelNumber
, /* cupsModelNumber attribute */
91 Page
, /* Current page */
92 Feed
, /* Number of lines to skip */
93 Canceled
; /* Non-zero if job is canceled */
100 void Setup(ppd_file_t
*ppd
);
101 void StartPage(ppd_file_t
*ppd
, cups_page_header_t
*header
);
102 void EndPage(ppd_file_t
*ppd
, cups_page_header_t
*header
);
103 void CancelJob(int sig
);
104 void OutputLine(ppd_file_t
*ppd
, cups_page_header_t
*header
, int y
);
105 void PCLCompress(unsigned char *line
, int length
);
106 void ZPLCompress(char repeat_char
, int repeat_count
);
110 * 'Setup()' - Prepare the printer for printing.
114 Setup(ppd_file_t
*ppd
) /* I - PPD file */
116 int i
; /* Looping var */
120 * Get the model number from the PPD file...
124 ModelNumber
= ppd
->model_number
;
127 * Initialize based on the model number...
134 * Clear any remaining data...
137 for (i
= 0; i
< 100; i
++)
141 * Reset the printer...
144 fputs("\033@", stdout
);
147 case ZEBRA_EPL_LINE
:
150 case ZEBRA_EPL_PAGE
:
159 case INTELLITECH_PCL
:
161 * Send a PCL reset sequence.
172 * 'StartPage()' - Start a page of graphics.
176 StartPage(ppd_file_t
*ppd
, /* I - PPD file */
177 cups_page_header_t
*header
) /* I - Page header */
179 ppd_choice_t
*choice
; /* Marked choice */
180 int length
; /* Actual label length */
181 #if defined(HAVE_SIGACTION) && !defined(HAVE_SIGSET)
182 struct sigaction action
; /* Actions for POSIX signals */
183 #endif /* HAVE_SIGACTION && !HAVE_SIGSET */
187 * Show page device dictionary...
190 fprintf(stderr
, "DEBUG: StartPage...\n");
191 fprintf(stderr
, "DEBUG: MediaClass = \"%s\"\n", header
->MediaClass
);
192 fprintf(stderr
, "DEBUG: MediaColor = \"%s\"\n", header
->MediaColor
);
193 fprintf(stderr
, "DEBUG: MediaType = \"%s\"\n", header
->MediaType
);
194 fprintf(stderr
, "DEBUG: OutputType = \"%s\"\n", header
->OutputType
);
196 fprintf(stderr
, "DEBUG: AdvanceDistance = %d\n", header
->AdvanceDistance
);
197 fprintf(stderr
, "DEBUG: AdvanceMedia = %d\n", header
->AdvanceMedia
);
198 fprintf(stderr
, "DEBUG: Collate = %d\n", header
->Collate
);
199 fprintf(stderr
, "DEBUG: CutMedia = %d\n", header
->CutMedia
);
200 fprintf(stderr
, "DEBUG: Duplex = %d\n", header
->Duplex
);
201 fprintf(stderr
, "DEBUG: HWResolution = [ %d %d ]\n", header
->HWResolution
[0],
202 header
->HWResolution
[1]);
203 fprintf(stderr
, "DEBUG: ImagingBoundingBox = [ %d %d %d %d ]\n",
204 header
->ImagingBoundingBox
[0], header
->ImagingBoundingBox
[1],
205 header
->ImagingBoundingBox
[2], header
->ImagingBoundingBox
[3]);
206 fprintf(stderr
, "DEBUG: InsertSheet = %d\n", header
->InsertSheet
);
207 fprintf(stderr
, "DEBUG: Jog = %d\n", header
->Jog
);
208 fprintf(stderr
, "DEBUG: LeadingEdge = %d\n", header
->LeadingEdge
);
209 fprintf(stderr
, "DEBUG: Margins = [ %d %d ]\n", header
->Margins
[0],
211 fprintf(stderr
, "DEBUG: ManualFeed = %d\n", header
->ManualFeed
);
212 fprintf(stderr
, "DEBUG: MediaPosition = %d\n", header
->MediaPosition
);
213 fprintf(stderr
, "DEBUG: MediaWeight = %d\n", header
->MediaWeight
);
214 fprintf(stderr
, "DEBUG: MirrorPrint = %d\n", header
->MirrorPrint
);
215 fprintf(stderr
, "DEBUG: NegativePrint = %d\n", header
->NegativePrint
);
216 fprintf(stderr
, "DEBUG: NumCopies = %d\n", header
->NumCopies
);
217 fprintf(stderr
, "DEBUG: Orientation = %d\n", header
->Orientation
);
218 fprintf(stderr
, "DEBUG: OutputFaceUp = %d\n", header
->OutputFaceUp
);
219 fprintf(stderr
, "DEBUG: PageSize = [ %d %d ]\n", header
->PageSize
[0],
220 header
->PageSize
[1]);
221 fprintf(stderr
, "DEBUG: Separations = %d\n", header
->Separations
);
222 fprintf(stderr
, "DEBUG: TraySwitch = %d\n", header
->TraySwitch
);
223 fprintf(stderr
, "DEBUG: Tumble = %d\n", header
->Tumble
);
224 fprintf(stderr
, "DEBUG: cupsWidth = %d\n", header
->cupsWidth
);
225 fprintf(stderr
, "DEBUG: cupsHeight = %d\n", header
->cupsHeight
);
226 fprintf(stderr
, "DEBUG: cupsMediaType = %d\n", header
->cupsMediaType
);
227 fprintf(stderr
, "DEBUG: cupsBitsPerColor = %d\n", header
->cupsBitsPerColor
);
228 fprintf(stderr
, "DEBUG: cupsBitsPerPixel = %d\n", header
->cupsBitsPerPixel
);
229 fprintf(stderr
, "DEBUG: cupsBytesPerLine = %d\n", header
->cupsBytesPerLine
);
230 fprintf(stderr
, "DEBUG: cupsColorOrder = %d\n", header
->cupsColorOrder
);
231 fprintf(stderr
, "DEBUG: cupsColorSpace = %d\n", header
->cupsColorSpace
);
232 fprintf(stderr
, "DEBUG: cupsCompression = %d\n", header
->cupsCompression
);
233 fprintf(stderr
, "DEBUG: cupsRowCount = %d\n", header
->cupsRowCount
);
234 fprintf(stderr
, "DEBUG: cupsRowFeed = %d\n", header
->cupsRowFeed
);
235 fprintf(stderr
, "DEBUG: cupsRowStep = %d\n", header
->cupsRowStep
);
238 * Register a signal handler to eject the current page if the
242 #ifdef HAVE_SIGSET /* Use System V signals over POSIX to avoid bugs */
243 sigset(SIGTERM
, CancelJob
);
244 #elif defined(HAVE_SIGACTION)
245 memset(&action
, 0, sizeof(action
));
247 sigemptyset(&action
.sa_mask
);
248 action
.sa_handler
= CancelJob
;
249 sigaction(SIGTERM
, &action
, NULL
);
251 signal(SIGTERM
, CancelJob
);
252 #endif /* HAVE_SIGSET */
258 * Setup printer/job attributes...
261 length
= header
->PageSize
[1] * header
->HWResolution
[1] / 72;
263 printf("\033L%c%c", length
>> 8, length
);
264 printf("\033D%c", header
->cupsBytesPerLine
);
266 printf("\033%c", header
->cupsCompression
+ 'c'); /* Darkness */
269 case ZEBRA_EPL_LINE
:
274 if ((choice
= ppdFindMarkedChoice(ppd
, "zePrintRate")) != NULL
&&
275 strcmp(choice
->choice
, "Default"))
276 printf("\033S%.0f", atof(choice
->choice
) * 2.0 - 2.0);
282 if (header
->cupsCompression
> 0 && header
->cupsCompression
<= 100)
283 printf("\033D%d", 7 * header
->cupsCompression
/ 100);
286 * Set left margin to 0...
289 fputs("\033M01", stdout
);
292 * Start buffered output...
295 fputs("\033B", stdout
);
298 case ZEBRA_EPL_PAGE
:
300 * Start a new label...
307 * Set hardware options...
310 if (!strcmp(header
->MediaType
, "Direct"))
317 if ((choice
= ppdFindMarkedChoice(ppd
, "zePrintRate")) != NULL
&&
318 strcmp(choice
->choice
, "Default"))
320 float val
= atof(choice
->choice
);
323 printf("S%.0f\n", val
);
325 printf("S%.0f\n", val
* 2.0 - 2.0);
332 if (header
->cupsCompression
> 0 && header
->cupsCompression
<= 100)
333 printf("D%d\n", 15 * header
->cupsCompression
/ 100);
339 printf("q%d\n", header
->cupsWidth
);
347 if (header
->cupsCompression
> 0 && header
->cupsCompression
<= 100)
348 printf("~SD%02d\n", 30 * header
->cupsCompression
/ 100);
351 * Start bitmap graphics...
354 printf("~DGR:CUPS.GRF,%d,%d,\n",
355 header
->cupsHeight
* header
->cupsBytesPerLine
,
356 header
->cupsBytesPerLine
);
359 * Allocate compression buffers...
362 CompBuffer
= malloc(2 * header
->cupsBytesPerLine
+ 1);
363 LastBuffer
= malloc(header
->cupsBytesPerLine
);
372 printf("! 0 %u %u %u %u\r\n", header
->HWResolution
[0],
373 header
->HWResolution
[1], header
->cupsHeight
,
377 case INTELLITECH_PCL
:
379 * Set the media size...
382 printf("\033&l6D\033&k12H"); /* Set 6 LPI, 10 CPI */
383 printf("\033&l0O"); /* Set portrait orientation */
385 switch (header
->PageSize
[1])
387 case 540 : /* Monarch Envelope */
388 printf("\033&l80A"); /* Set page size */
391 case 624 : /* DL Envelope */
392 printf("\033&l90A"); /* Set page size */
395 case 649 : /* C5 Envelope */
396 printf("\033&l91A"); /* Set page size */
399 case 684 : /* COM-10 Envelope */
400 printf("\033&l81A"); /* Set page size */
403 case 756 : /* Executive */
404 printf("\033&l1A"); /* Set page size */
407 case 792 : /* Letter */
408 printf("\033&l2A"); /* Set page size */
412 printf("\033&l26A"); /* Set page size */
415 case 1008 : /* Legal */
416 printf("\033&l3A"); /* Set page size */
419 default : /* Custom size */
420 printf("\033!f%dZ", header
->PageSize
[1] * 300 / 72);
424 printf("\033&l%dP", /* Set page length */
425 header
->PageSize
[1] / 12);
426 printf("\033&l0E"); /* Set top margin to 0 */
427 printf("\033&l%dX", header
->NumCopies
);
428 /* Set number copies */
429 printf("\033&l0L"); /* Turn off perforation skip */
437 if (header
->cupsRowFeed
) /* inPrintRate */
438 printf("\033!p%dS", header
->cupsRowFeed
);
440 if (header
->cupsCompression
!= ~0)
442 printf("\033&d%dA", 30 * header
->cupsCompression
/ 100 - 15);
444 if (header
->cupsRowCount
!= ~0)
446 printf("\033!n%dT", header
->cupsRowCount
);
448 if (header
->cupsRowStep
!= ~0)
450 printf("\033!n%dC", header
->cupsRowStep
);
457 printf("\033*t%dR", header
->HWResolution
[0]);
460 printf("\033*r%dS", header
->cupsWidth
);
462 printf("\033*r%dT", header
->cupsHeight
);
465 printf("\033&a0H"); /* Set horizontal position */
466 printf("\033&a0V"); /* Set vertical position */
467 printf("\033*r1A"); /* Start graphics */
468 printf("\033*b3M"); /* Set compression */
471 * Allocate compression buffers...
474 CompBuffer
= malloc(2 * header
->cupsBytesPerLine
+ 1);
475 LastBuffer
= malloc(header
->cupsBytesPerLine
);
481 * Allocate memory for a line of graphics...
484 Buffer
= malloc(header
->cupsBytesPerLine
);
490 * 'EndPage()' - Finish a page of graphics.
494 EndPage(ppd_file_t
*ppd
, /* I - PPD file */
495 cups_page_header_t
*header
) /* I - Page header */
497 int val
; /* Option value */
498 ppd_choice_t
*choice
; /* Marked choice */
499 #if defined(HAVE_SIGACTION) && !defined(HAVE_SIGSET)
500 struct sigaction action
; /* Actions for POSIX signals */
501 #endif /* HAVE_SIGACTION && !HAVE_SIGSET */
508 * Eject the current page...
511 fputs("\033E", stdout
);
514 case ZEBRA_EPL_LINE
:
516 * End buffered output, eject the label...
519 fputs("\033E\014", stdout
);
522 case ZEBRA_EPL_PAGE
:
534 * Cancel bitmap download...
551 if ((choice
= ppdFindMarkedChoice(ppd
, "zePrintRate")) != NULL
&&
552 strcmp(choice
->choice
, "Default"))
554 val
= atoi(choice
->choice
);
555 printf("^PR%d,%d,%d\n", val
, val
, val
);
559 * Put label home in default position (0,0)...
565 * Set media tracking...
568 if (ppdIsMarked(ppd
, "zeMediaTracking", "Continuous"))
571 * Add label length command for continuous...
574 printf("^LL%d\n", header
->cupsHeight
);
577 else if (ppdIsMarked(ppd
, "zeMediaTracking", "Web"))
579 else if (ppdIsMarked(ppd
, "zeMediaTracking", "Mark"))
586 if (header
->cupsRowStep
!= 200)
587 printf("^LT%u\n", header
->cupsRowStep
);
593 if (!strcmp(header
->MediaType
, "Thermal"))
595 else if (!strcmp(header
->MediaType
, "Direct"))
602 if ((choice
= ppdFindMarkedChoice(ppd
, "zePrintMode")) != NULL
&&
603 strcmp(choice
->choice
, "Saved"))
607 if (!strcmp(choice
->choice
, "Tear"))
609 else if (!strcmp(choice
->choice
, "Peel"))
611 else if (!strcmp(choice
->choice
, "Rewind"))
613 else if (!strcmp(choice
->choice
, "Applicator"))
620 * Set tear-off adjust position...
623 if (header
->AdvanceDistance
!= 1000)
625 if ((int)header
->AdvanceDistance
< 0)
626 printf("~TA%04d\n", (int)header
->AdvanceDistance
);
628 printf("~TA%03d\n", (int)header
->AdvanceDistance
);
632 * Allow for reprinting after an error...
635 if (ppdIsMarked(ppd
, "zeErrorReprint", "Always"))
637 else if (ppdIsMarked(ppd
, "zeErrorReprint", "Never"))
641 * Print multiple copies
644 if (header
->NumCopies
> 1)
645 printf("^PQ%d, 0, 0, N\n", header
->NumCopies
);
648 * Display the label image...
651 puts("^FO0,0^XGR:CUPS.GRF,1,1^FS");
654 * End the label and eject...
660 * Free compression buffers...
669 * Set tear-off adjust position...
672 if (header
->AdvanceDistance
!= 1000)
673 printf("PRESENT-AT %d 1\r\n", (int)header
->AdvanceDistance
);
676 * Allow for reprinting after an error...
679 if (ppdIsMarked(ppd
, "zeErrorReprint", "Always"))
680 puts("ON-OUT-OF-PAPER WAIT\r");
681 else if (ppdIsMarked(ppd
, "zeErrorReprint", "Never"))
682 puts("ON-OUT-OF-PAPER PURGE\r");
688 if (header
->CutMedia
)
695 if (header
->cupsCompression
> 0)
696 printf("TONE %u\r\n", 2 * header
->cupsCompression
);
702 if ((choice
= ppdFindMarkedChoice(ppd
, "zePrintRate")) != NULL
&&
703 strcmp(choice
->choice
, "Default"))
705 val
= atoi(choice
->choice
);
706 printf("SPEED %d\r\n", val
);
717 case INTELLITECH_PCL
:
718 printf("\033*rB"); /* End GFX */
719 printf("\014"); /* Eject current page */
726 * Unregister the signal handler...
729 #ifdef HAVE_SIGSET /* Use System V signals over POSIX to avoid bugs */
730 sigset(SIGTERM
, SIG_IGN
);
731 #elif defined(HAVE_SIGACTION)
732 memset(&action
, 0, sizeof(action
));
734 sigemptyset(&action
.sa_mask
);
735 action
.sa_handler
= SIG_IGN
;
736 sigaction(SIGTERM
, &action
, NULL
);
738 signal(SIGTERM
, SIG_IGN
);
739 #endif /* HAVE_SIGSET */
750 * 'CancelJob()' - Cancel the current job...
754 CancelJob(int sig
) /* I - Signal */
757 * Tell the main loop to stop...
767 * 'OutputLine()' - Output a line of graphics...
771 OutputLine(ppd_file_t
*ppd
, /* I - PPD file */
772 cups_page_header_t
*header
, /* I - Page header */
773 int y
) /* I - Line number */
775 int i
; /* Looping var */
776 unsigned char *ptr
; /* Pointer into buffer */
777 unsigned char *compptr
; /* Pointer into compression buffer */
778 char repeat_char
; /* Repeated character */
779 int repeat_count
; /* Number of repeated characters */
780 static const char *hex
= "0123456789ABCDEF";
788 * See if the line is blank; if not, write it to the printer...
792 memcmp(Buffer
, Buffer
+ 1, header
->cupsBytesPerLine
- 1))
798 printf("\033f\001%c", 255);
802 printf("\033f\001%c", Feed
);
807 fwrite(Buffer
, header
->cupsBytesPerLine
, 1, stdout
);
812 * This hack works around a bug in the IRIX serial port driver when
813 * run at high baud rates (e.g. 115200 baud)... This results in
814 * slightly slower label printing, but at least the labels come
825 case ZEBRA_EPL_LINE
:
826 printf("\033g%03d", header
->cupsBytesPerLine
);
827 fwrite(Buffer
, 1, header
->cupsBytesPerLine
, stdout
);
831 case ZEBRA_EPL_PAGE
:
832 if (Buffer
[0] || memcmp(Buffer
, Buffer
+ 1, header
->cupsBytesPerLine
))
834 printf("GW0,%d,%d,1\n", y
, header
->cupsBytesPerLine
);
835 for (i
= header
->cupsBytesPerLine
, ptr
= Buffer
; i
> 0; i
--, ptr
++)
844 * Determine if this row is the same as the previous line.
845 * If so, output a ':' and return...
850 if (!memcmp(Buffer
, LastBuffer
, header
->cupsBytesPerLine
))
858 * Convert the line to hex digits...
861 for (ptr
= Buffer
, compptr
= CompBuffer
, i
= header
->cupsBytesPerLine
;
865 *compptr
++ = hex
[*ptr
>> 4];
866 *compptr
++ = hex
[*ptr
& 15];
872 * Run-length compress the graphics...
875 for (compptr
= CompBuffer
, repeat_char
= CompBuffer
[0], repeat_count
= 1;
878 if (*compptr
== repeat_char
)
882 ZPLCompress(repeat_char
, repeat_count
);
883 repeat_char
= *compptr
;
887 if (repeat_char
== '0')
890 * Handle 0's on the end of the line...
893 if (repeat_count
& 1)
899 ZPLCompress(repeat_char
, repeat_count
);
902 * Save this line for the next round...
905 memcpy(LastBuffer
, Buffer
, header
->cupsBytesPerLine
);
910 if (Buffer
[0] || memcmp(Buffer
, Buffer
+ 1, header
->cupsBytesPerLine
))
912 printf("CG %u 1 0 %d ", header
->cupsBytesPerLine
, y
);
913 fwrite(Buffer
, 1, header
->cupsBytesPerLine
, stdout
);
919 case INTELLITECH_PCL
:
921 memcmp(Buffer
, Buffer
+ 1, header
->cupsBytesPerLine
- 1))
925 printf("\033*b%dY", Feed
);
930 PCLCompress(Buffer
, header
->cupsBytesPerLine
);
940 * 'PCLCompress()' - Output a PCL (mode 3) compressed line.
944 PCLCompress(unsigned char *line
, /* I - Line to compress */
945 int length
) /* I - Length of line */
947 unsigned char *line_ptr
, /* Current byte pointer */
948 *line_end
, /* End-of-line byte pointer */
949 *comp_ptr
, /* Pointer into compression buffer */
950 *start
, /* Start of compression sequence */
951 *seed
; /* Seed buffer pointer */
952 int count
, /* Count of bytes for output */
953 offset
; /* Offset of bytes for output */
957 * Do delta-row compression...
961 line_end
= line
+ length
;
963 comp_ptr
= CompBuffer
;
966 while (line_ptr
< line_end
)
969 * Find the next non-matching sequence...
977 * The seed buffer is invalid, so do the next 8 bytes, max...
982 if ((count
= line_end
- line_ptr
) > 8)
990 * The seed buffer is valid, so compare against it...
993 while (*line_ptr
== *seed
&&
1000 if (line_ptr
== line_end
)
1003 offset
= line_ptr
- start
;
1006 * Find up to 8 non-matching bytes...
1011 while (*line_ptr
!= *seed
&&
1012 line_ptr
< line_end
&&
1022 * Place mode 3 compression data in the buffer; see HP manuals
1029 * Output multi-byte offset...
1032 *comp_ptr
++ = ((count
- 1) << 5) | 31;
1035 while (offset
>= 255)
1041 *comp_ptr
++ = offset
;
1046 * Output single-byte offset...
1049 *comp_ptr
++ = ((count
- 1) << 5) | offset
;
1052 memcpy(comp_ptr
, start
, count
);
1056 line_ptr
= CompBuffer
;
1057 line_end
= comp_ptr
;
1060 * Set the length of the data and write it...
1063 printf("\033*b%dW", comp_ptr
- CompBuffer
);
1064 fwrite(CompBuffer
, comp_ptr
- CompBuffer
, 1, stdout
);
1067 * Save this line as a "seed" buffer for the next...
1070 memcpy(LastBuffer
, line
, length
);
1076 * 'ZPLCompress()' - Output a run-length compression sequence.
1080 ZPLCompress(char repeat_char
, /* I - Character to repeat */
1081 int repeat_count
) /* I - Number of repeated characters */
1083 if (repeat_count
> 1)
1086 * Print as many z's as possible - they are the largest denomination
1087 * representing 400 characters (zC stands for 400 adjacent C's)
1090 while (repeat_count
>= 400)
1093 repeat_count
-= 400;
1097 * Then print 'g' through 'y' as multiples of 20 characters...
1100 if (repeat_count
>= 20)
1102 putchar('f' + repeat_count
/ 20);
1107 * Finally, print 'G' through 'Y' as 1 through 19 characters...
1110 if (repeat_count
> 0)
1111 putchar('F' + repeat_count
);
1115 * Then the character to be repeated...
1118 putchar(repeat_char
);
1123 * 'main()' - Main entry and processing of driver.
1126 int /* O - Exit status */
1127 main(int argc
, /* I - Number of command-line arguments */
1128 char *argv
[]) /* I - Command-line arguments */
1130 int fd
; /* File descriptor */
1131 cups_raster_t
*ras
; /* Raster stream for printing */
1132 cups_page_header_t header
; /* Page header from file */
1133 int y
; /* Current line */
1134 ppd_file_t
*ppd
; /* PPD file */
1135 int num_options
; /* Number of options */
1136 cups_option_t
*options
; /* Options */
1140 * Make sure status messages are not buffered...
1143 setbuf(stderr
, NULL
);
1146 * Check command-line...
1149 if (argc
< 6 || argc
> 7)
1152 * We don't have the correct number of arguments; write an error message
1156 fputs("ERROR: rastertolabel job-id user title copies options [file]\n", stderr
);
1161 * Open the page stream...
1166 if ((fd
= open(argv
[6], O_RDONLY
)) == -1)
1168 perror("ERROR: Unable to open raster file - ");
1176 ras
= cupsRasterOpen(fd
, CUPS_RASTER_READ
);
1179 * Open the PPD file and apply options...
1182 num_options
= cupsParseOptions(argv
[5], 0, &options
);
1184 if ((ppd
= ppdOpenFile(getenv("PPD"))) != NULL
)
1186 ppdMarkDefaults(ppd
);
1187 cupsMarkOptions(ppd
, num_options
, options
);
1191 * Initialize the print device...
1197 * Process pages as needed...
1203 while (cupsRasterReadHeader(ras
, &header
))
1206 * Write a status message with the page number and number of copies.
1211 fprintf(stderr
, "PAGE: %d 1\n", Page
);
1217 StartPage(ppd
, &header
);
1220 * Loop for each line on the page...
1223 for (y
= 0; y
< header
.cupsHeight
&& !Canceled
; y
++)
1226 * Let the user know how far we have progressed...
1230 fprintf(stderr
, "INFO: Printing page %d, %d%% complete...\n", Page
,
1231 100 * y
/ header
.cupsHeight
);
1234 * Read a line of graphics...
1237 if (cupsRasterReadPixels(ras
, Buffer
, header
.cupsBytesPerLine
) < 1)
1241 * Write it to the printer...
1244 OutputLine(ppd
, &header
, y
);
1251 EndPage(ppd
, &header
);
1258 * Close the raster stream...
1261 cupsRasterClose(ras
);
1266 * Close the PPD file and free the options...
1270 cupsFreeOptions(num_options
, options
);
1273 * If no pages were printed, send an error message...
1277 fputs("ERROR: No pages found!\n", stderr
);
1279 fputs("INFO: Ready to print.\n", stderr
);