]> git.ipfire.org Git - thirdparty/cups.git/blame - filter/rastertolabel.c
Load cups into easysw/current.
[thirdparty/cups.git] / filter / rastertolabel.c
CommitLineData
ef416fc2 1/*
f7faf1f5 2 * "$Id: rastertolabel.c 5665 2006-06-16 00:59:10Z mike $"
ef416fc2 3 *
4 * Label printer filter for the Common UNIX Printing System (CUPS).
5 *
6 * Copyright 2001-2006 by Easy Software Products.
7 *
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
13 * at:
14 *
15 * Attn: CUPS Licensing Information
16 * Easy Software Products
17 * 44141 Airport View Drive, Suite 204
18 * Hollywood, Maryland 20636 USA
19 *
20 * Voice: (301) 373-9600
21 * EMail: cups-info@cups.org
22 * WWW: http://www.cups.org
23 *
24 * This file is subject to the Apple OS-Developed Software exception.
25 *
26 * Contents:
27 *
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 * ZPLCompress() - Output a run-length compression sequence.
34 * main() - Main entry and processing of driver.
35 */
36
37/*
38 * Include necessary headers...
39 */
40
41#include <cups/cups.h>
42#include <cups/string.h>
43#include "raster.h"
44#include <stdlib.h>
45#include <unistd.h>
46#include <fcntl.h>
47#include <signal.h>
48
49
50/*
f7faf1f5 51 * This driver filter currently supports Dymo and Zebra label printers.
ef416fc2 52 *
53 * The Dymo portion of the driver has been tested with the 300, 330,
f7faf1f5 54 * and 330 Turbo label printers; it may also work with older models.
ef416fc2 55 * The Dymo printers support printing at 136, 203, and 300 DPI.
56 *
f7faf1f5 57 * The Zebra portion of the driver has been tested with the LP-2844Z label
58 * printer; it may also work with other models. The driver supports EPL
59 * line mode, EPL page mode, ZPL, and CPCL as defined in Zebra's on-line
60 * developer documentation.
ef416fc2 61 */
62
63/*
64 * Model number constants...
65 */
66
67#define DYMO_3x0 0 /* Dymo Labelwriter 300/330/330 Turbo */
68
69#define ZEBRA_EPL_LINE 0x10 /* Zebra EPL line mode printers */
70#define ZEBRA_EPL_PAGE 0x11 /* Zebra EPL page mode printers */
71#define ZEBRA_ZPL 0x12 /* Zebra ZPL-based printers */
72#define ZEBRA_CPCL 0x13 /* Zebra CPCL-based printers */
73
74
75/*
76 * Globals...
77 */
78
79unsigned char *Buffer; /* Output buffer */
f7faf1f5 80char *CompBuffer; /* Compression buffer */
ef416fc2 81unsigned char *LastBuffer; /* Last buffer */
82int LastSet; /* Number of repeat characters */
83int ModelNumber, /* cupsModelNumber attribute */
84 Page, /* Current page */
85 Feed, /* Number of lines to skip */
86 Canceled; /* Non-zero if job is canceled */
87
88
89/*
90 * Prototypes...
91 */
92
93void Setup(ppd_file_t *ppd);
94void StartPage(ppd_file_t *ppd, cups_page_header_t *header);
95void EndPage(ppd_file_t *ppd, cups_page_header_t *header);
96void CancelJob(int sig);
97void OutputLine(ppd_file_t *ppd, cups_page_header_t *header, int y);
98void ZPLCompress(char repeat_char, int repeat_count);
99
100
101/*
102 * 'Setup()' - Prepare the printer for printing.
103 */
104
105void
106Setup(ppd_file_t *ppd) /* I - PPD file */
107{
108 int i; /* Looping var */
109
110
111 /*
112 * Get the model number from the PPD file...
113 */
114
115 if (ppd)
116 ModelNumber = ppd->model_number;
117
118 /*
119 * Initialize based on the model number...
120 */
121
122 switch (ModelNumber)
123 {
124 case DYMO_3x0 :
125 /*
126 * Clear any remaining data...
127 */
128
129 for (i = 0; i < 100; i ++)
130 putchar(0x1b);
131
132 /*
133 * Reset the printer...
134 */
135
136 fputs("\033@", stdout);
137 break;
138
139 case ZEBRA_EPL_LINE :
140 break;
141
142 case ZEBRA_EPL_PAGE :
143 break;
144
145 case ZEBRA_ZPL :
146 break;
147
148 case ZEBRA_CPCL :
149 break;
150 }
151}
152
153
154/*
155 * 'StartPage()' - Start a page of graphics.
156 */
157
158void
e1d6a774 159StartPage(ppd_file_t *ppd, /* I - PPD file */
ef416fc2 160 cups_page_header_t *header) /* I - Page header */
161{
162 ppd_choice_t *choice; /* Marked choice */
163 int length; /* Actual label length */
164#if defined(HAVE_SIGACTION) && !defined(HAVE_SIGSET)
165 struct sigaction action; /* Actions for POSIX signals */
166#endif /* HAVE_SIGACTION && !HAVE_SIGSET */
167
168
e1d6a774 169 /*
170 * Show page device dictionary...
171 */
172
173 fprintf(stderr, "DEBUG: StartPage...\n");
174 fprintf(stderr, "DEBUG: MediaClass = \"%s\"\n", header->MediaClass);
175 fprintf(stderr, "DEBUG: MediaColor = \"%s\"\n", header->MediaColor);
176 fprintf(stderr, "DEBUG: MediaType = \"%s\"\n", header->MediaType);
177 fprintf(stderr, "DEBUG: OutputType = \"%s\"\n", header->OutputType);
178
179 fprintf(stderr, "DEBUG: AdvanceDistance = %d\n", header->AdvanceDistance);
180 fprintf(stderr, "DEBUG: AdvanceMedia = %d\n", header->AdvanceMedia);
181 fprintf(stderr, "DEBUG: Collate = %d\n", header->Collate);
182 fprintf(stderr, "DEBUG: CutMedia = %d\n", header->CutMedia);
183 fprintf(stderr, "DEBUG: Duplex = %d\n", header->Duplex);
184 fprintf(stderr, "DEBUG: HWResolution = [ %d %d ]\n", header->HWResolution[0],
185 header->HWResolution[1]);
186 fprintf(stderr, "DEBUG: ImagingBoundingBox = [ %d %d %d %d ]\n",
187 header->ImagingBoundingBox[0], header->ImagingBoundingBox[1],
188 header->ImagingBoundingBox[2], header->ImagingBoundingBox[3]);
189 fprintf(stderr, "DEBUG: InsertSheet = %d\n", header->InsertSheet);
190 fprintf(stderr, "DEBUG: Jog = %d\n", header->Jog);
191 fprintf(stderr, "DEBUG: LeadingEdge = %d\n", header->LeadingEdge);
192 fprintf(stderr, "DEBUG: Margins = [ %d %d ]\n", header->Margins[0],
193 header->Margins[1]);
194 fprintf(stderr, "DEBUG: ManualFeed = %d\n", header->ManualFeed);
195 fprintf(stderr, "DEBUG: MediaPosition = %d\n", header->MediaPosition);
196 fprintf(stderr, "DEBUG: MediaWeight = %d\n", header->MediaWeight);
197 fprintf(stderr, "DEBUG: MirrorPrint = %d\n", header->MirrorPrint);
198 fprintf(stderr, "DEBUG: NegativePrint = %d\n", header->NegativePrint);
199 fprintf(stderr, "DEBUG: NumCopies = %d\n", header->NumCopies);
200 fprintf(stderr, "DEBUG: Orientation = %d\n", header->Orientation);
201 fprintf(stderr, "DEBUG: OutputFaceUp = %d\n", header->OutputFaceUp);
202 fprintf(stderr, "DEBUG: PageSize = [ %d %d ]\n", header->PageSize[0],
203 header->PageSize[1]);
204 fprintf(stderr, "DEBUG: Separations = %d\n", header->Separations);
205 fprintf(stderr, "DEBUG: TraySwitch = %d\n", header->TraySwitch);
206 fprintf(stderr, "DEBUG: Tumble = %d\n", header->Tumble);
207 fprintf(stderr, "DEBUG: cupsWidth = %d\n", header->cupsWidth);
208 fprintf(stderr, "DEBUG: cupsHeight = %d\n", header->cupsHeight);
209 fprintf(stderr, "DEBUG: cupsMediaType = %d\n", header->cupsMediaType);
210 fprintf(stderr, "DEBUG: cupsBitsPerColor = %d\n", header->cupsBitsPerColor);
211 fprintf(stderr, "DEBUG: cupsBitsPerPixel = %d\n", header->cupsBitsPerPixel);
212 fprintf(stderr, "DEBUG: cupsBytesPerLine = %d\n", header->cupsBytesPerLine);
213 fprintf(stderr, "DEBUG: cupsColorOrder = %d\n", header->cupsColorOrder);
214 fprintf(stderr, "DEBUG: cupsColorSpace = %d\n", header->cupsColorSpace);
215 fprintf(stderr, "DEBUG: cupsCompression = %d\n", header->cupsCompression);
216
ef416fc2 217 /*
218 * Register a signal handler to eject the current page if the
219 * job is canceled.
220 */
221
222#ifdef HAVE_SIGSET /* Use System V signals over POSIX to avoid bugs */
223 sigset(SIGTERM, CancelJob);
224#elif defined(HAVE_SIGACTION)
225 memset(&action, 0, sizeof(action));
226
227 sigemptyset(&action.sa_mask);
228 action.sa_handler = CancelJob;
229 sigaction(SIGTERM, &action, NULL);
230#else
231 signal(SIGTERM, CancelJob);
232#endif /* HAVE_SIGSET */
233
234 switch (ModelNumber)
235 {
236 case DYMO_3x0 :
237 /*
238 * Setup printer/job attributes...
239 */
240
241 length = header->PageSize[1] * header->HWResolution[1] / 72;
242
243 printf("\033L%c%c", length >> 8, length);
244 printf("\033D%c", header->cupsBytesPerLine);
245
246 printf("\033%c", header->cupsCompression + 'c'); /* Darkness */
247 break;
248
249 case ZEBRA_EPL_LINE :
250 /*
251 * Set print rate...
252 */
253
254 if ((choice = ppdFindMarkedChoice(ppd, "zePrintRate")) != NULL &&
255 strcmp(choice->choice, "Default"))
256 printf("\033S%.0f", atof(choice->choice) * 2.0 - 2.0);
257
258 /*
259 * Set darkness...
260 */
261
262 if (header->cupsCompression > 0 && header->cupsCompression <= 100)
263 printf("\033D%d", 7 * header->cupsCompression / 100);
264
265 /*
266 * Set left margin to 0...
267 */
268
269 fputs("\033M01", stdout);
270
271 /*
272 * Start buffered output...
273 */
274
275 fputs("\033B", stdout);
276 break;
277
278 case ZEBRA_EPL_PAGE :
279 /*
280 * Start a new label...
281 */
282
283 puts("");
284 puts("N");
285
286 /*
287 * Set hardware options...
288 */
289
290 if (!strcmp(header->MediaType, "Direct"))
291 puts("OD");
292
293 /*
294 * Set print rate...
295 */
296
297 if ((choice = ppdFindMarkedChoice(ppd, "zePrintRate")) != NULL &&
298 strcmp(choice->choice, "Default"))
299 {
300 float val = atof(choice->choice);
301
302 if (val >= 3.0)
303 printf("S%.0f\n", val);
304 else
305 printf("S%.0f\n", val * 2.0 - 2.0);
306 }
307
308 /*
309 * Set darkness...
310 */
311
312 if (header->cupsCompression > 0 && header->cupsCompression <= 100)
313 printf("D%d\n", 15 * header->cupsCompression / 100);
314
315 /*
316 * Set label size...
317 */
318
319 printf("q%d\n", header->cupsWidth);
320 break;
321
322 case ZEBRA_ZPL :
323 /*
324 * Set darkness...
325 */
326
327 if (header->cupsCompression > 0 && header->cupsCompression <= 100)
328 printf("~SD%02d\n", 30 * header->cupsCompression / 100);
329
330 /*
331 * Start bitmap graphics...
332 */
333
334 printf("~DGR:CUPS.GRF,%d,%d,\n",
335 header->cupsHeight * header->cupsBytesPerLine,
336 header->cupsBytesPerLine);
337
338 /*
339 * Allocate compression buffers...
340 */
341
342 CompBuffer = malloc(2 * header->cupsBytesPerLine + 1);
343 LastBuffer = malloc(header->cupsBytesPerLine);
344 LastSet = 0;
345 break;
346
347 case ZEBRA_CPCL :
348 /*
349 * Start label...
350 */
351
352 printf("! 0 %u %u %u %u\r\n", header->HWResolution[0],
353 header->HWResolution[1], header->cupsHeight,
354 header->NumCopies);
355 break;
356 }
357
358 /*
359 * Allocate memory for a line of graphics...
360 */
361
362 Buffer = malloc(header->cupsBytesPerLine);
363 Feed = 0;
364}
365
366
367/*
368 * 'EndPage()' - Finish a page of graphics.
369 */
370
371void
372EndPage(ppd_file_t *ppd, /* I - PPD file */
373 cups_page_header_t *header) /* I - Page header */
374{
375 int val; /* Option value */
376 ppd_choice_t *choice; /* Marked choice */
377#if defined(HAVE_SIGACTION) && !defined(HAVE_SIGSET)
378 struct sigaction action; /* Actions for POSIX signals */
379#endif /* HAVE_SIGACTION && !HAVE_SIGSET */
380
381
382 switch (ModelNumber)
383 {
384 case DYMO_3x0 :
385 /*
386 * Eject the current page...
387 */
388
389 fputs("\033E", stdout);
390 break;
391
392 case ZEBRA_EPL_LINE :
393 /*
394 * End buffered output, eject the label...
395 */
396
397 fputs("\033E\014", stdout);
398 break;
399
400 case ZEBRA_EPL_PAGE :
401 /*
402 * Print the label...
403 */
404
405 puts("P1");
406 break;
407
408 case ZEBRA_ZPL :
409 if (Canceled)
410 {
411 /*
412 * Cancel bitmap download...
413 */
414
415 puts("~DN");
416 break;
417 }
418
419 /*
420 * Start label...
421 */
422
423 puts("^XA");
424
425 /*
426 * Set print rate...
427 */
428
429 if ((choice = ppdFindMarkedChoice(ppd, "zePrintRate")) != NULL &&
430 strcmp(choice->choice, "Default"))
431 {
432 val = atoi(choice->choice);
433 printf("^PR%d,%d,%d\n", val, val, val);
434 }
435
436 /*
437 * Put label home in default position (0,0)...
438 */
439
440 printf("^LH0,0\n");
441
442 /*
443 * Set media tracking...
444 */
445
446 if (ppdIsMarked(ppd, "zeMediaTracking", "Continuous"))
447 {
448 /*
449 * Add label length command for continuous...
450 */
451
452 printf("^LL%d\n", header->cupsHeight);
453 printf("^MNN\n");
454 }
455 else if (ppdIsMarked(ppd, "zeMediaTracking", "Web"))
456 printf("^MNY\n");
457 else if (ppdIsMarked(ppd, "zeMediaTracking", "Mark"))
458 printf("^MNM\n");
459
460 /*
461 * Set label top
462 */
463
464 if (header->cupsRowStep != 200)
465 printf("^LT%u\n", header->cupsRowStep);
466
467 /*
468 * Set media type...
469 */
470
471 if (!strcmp(header->MediaType, "Thermal"))
472 printf("^MTT\n");
473 else if (!strcmp(header->MediaType, "Direct"))
474 printf("^MTD\n");
475
476 /*
477 * Set print mode...
478 */
479
480 if ((choice = ppdFindMarkedChoice(ppd, "zePrintMode")) != NULL &&
481 strcmp(choice->choice, "Saved"))
482 {
483 printf("^MM");
484
485 if (!strcmp(choice->choice, "Tear"))
486 printf("T,Y\n");
487 else if (!strcmp(choice->choice, "Peel"))
488 printf("P,Y\n");
489 else if (!strcmp(choice->choice, "Rewind"))
490 printf("R,Y\n");
491 else if (!strcmp(choice->choice, "Applicator"))
492 printf("A,Y\n");
493 else
494 printf("C,Y\n");
495 }
496
497 /*
498 * Set tear-off adjust position...
499 */
500
501 if (header->AdvanceDistance != 1000)
502 {
503 if ((int)header->AdvanceDistance < 0)
504 printf("~TA%04d\n", (int)header->AdvanceDistance);
505 else
506 printf("~TA%03d\n", (int)header->AdvanceDistance);
507 }
508
509 /*
510 * Allow for reprinting after an error...
511 */
512
513 if (ppdIsMarked(ppd, "zeErrorReprint", "Always"))
514 printf("^JZY\n");
515 else if (ppdIsMarked(ppd, "zeErrorReprint", "Never"))
516 printf("^JZN\n");
517
518 /*
519 * Print multiple copies
520 */
521
522 if (header->NumCopies > 1)
523 printf("^PQ%d, 0, 0, N\n", header->NumCopies);
524
525 /*
526 * Display the label image...
527 */
528
529 puts("^FO0,0^XGR:CUPS.GRF,1,1^FS");
530
531 /*
532 * End the label and eject...
533 */
534
535 puts("^XZ");
536
537 /*
538 * Free compression buffers...
539 */
540
541 free(CompBuffer);
542 free(LastBuffer);
543 break;
544
545 case ZEBRA_CPCL :
546 /*
547 * Set tear-off adjust position...
548 */
549
550 if (header->AdvanceDistance != 1000)
551 printf("PRESENT-AT %d 1\r\n", (int)header->AdvanceDistance);
552
553 /*
554 * Allow for reprinting after an error...
555 */
556
557 if (ppdIsMarked(ppd, "zeErrorReprint", "Always"))
558 puts("ON-OUT-OF-PAPER WAIT\r");
559 else if (ppdIsMarked(ppd, "zeErrorReprint", "Never"))
560 puts("ON-OUT-OF-PAPER PURGE\r");
561
562 /*
563 * Cut label?
564 */
565
566 if (header->CutMedia)
567 puts("CUT\r");
568
569 /*
570 * Set darkness...
571 */
572
573 if (header->cupsCompression > 0)
574 printf("TONE %u\r\n", 2 * header->cupsCompression);
575
576 /*
577 * Set print rate...
578 */
579
580 if ((choice = ppdFindMarkedChoice(ppd, "zePrintRate")) != NULL &&
581 strcmp(choice->choice, "Default"))
582 {
583 val = atoi(choice->choice);
584 printf("SPEED %d\r\n", val);
585 }
586
587 /*
588 * Print the label...
589 */
590
591 puts("FORM\r");
592 puts("PRINT\r");
593 break;
594 }
595
596 fflush(stdout);
597
598 /*
599 * Unregister the signal handler...
600 */
601
602#ifdef HAVE_SIGSET /* Use System V signals over POSIX to avoid bugs */
603 sigset(SIGTERM, SIG_IGN);
604#elif defined(HAVE_SIGACTION)
605 memset(&action, 0, sizeof(action));
606
607 sigemptyset(&action.sa_mask);
608 action.sa_handler = SIG_IGN;
609 sigaction(SIGTERM, &action, NULL);
610#else
611 signal(SIGTERM, SIG_IGN);
612#endif /* HAVE_SIGSET */
613
614 /*
615 * Free memory...
616 */
617
618 free(Buffer);
619}
620
621
622/*
623 * 'CancelJob()' - Cancel the current job...
624 */
625
626void
627CancelJob(int sig) /* I - Signal */
628{
629 /*
630 * Tell the main loop to stop...
631 */
632
633 (void)sig;
634
635 Canceled = 1;
636}
637
638
639/*
640 * 'OutputLine()' - Output a line of graphics...
641 */
642
643void
644OutputLine(ppd_file_t *ppd, /* I - PPD file */
645 cups_page_header_t *header, /* I - Page header */
646 int y) /* I - Line number */
647{
648 int i; /* Looping var */
649 unsigned char *ptr; /* Pointer into buffer */
ed486911 650 unsigned char *compptr; /* Pointer into compression buffer */
ef416fc2 651 char repeat_char; /* Repeated character */
652 int repeat_count; /* Number of repeated characters */
653 static const char *hex = "0123456789ABCDEF";
654 /* Hex digits */
655
656
657 switch (ModelNumber)
658 {
659 case DYMO_3x0 :
660 /*
661 * See if the line is blank; if not, write it to the printer...
662 */
663
664 if (Buffer[0] ||
665 memcmp(Buffer, Buffer + 1, header->cupsBytesPerLine - 1))
666 {
667 if (Feed)
668 {
669 while (Feed > 255)
670 {
671 printf("\033f\001%c", 255);
672 Feed -= 255;
673 }
674
675 printf("\033f\001%c", Feed);
676 Feed = 0;
677 }
678
679 putchar(0x16);
680 fwrite(Buffer, header->cupsBytesPerLine, 1, stdout);
681 fflush(stdout);
682
683#ifdef __sgi
684 /*
685 * This hack works around a bug in the IRIX serial port driver when
686 * run at high baud rates (e.g. 115200 baud)... This results in
687 * slightly slower label printing, but at least the labels come
688 * out properly.
689 */
690
691 sginap(1);
692#endif /* __sgi */
693 }
694 else
695 Feed ++;
696 break;
697
698 case ZEBRA_EPL_LINE :
699 printf("\033g%03d", header->cupsBytesPerLine);
700 fwrite(Buffer, 1, header->cupsBytesPerLine, stdout);
701 fflush(stdout);
702 break;
703
704 case ZEBRA_EPL_PAGE :
705 if (Buffer[0] || memcmp(Buffer, Buffer + 1, header->cupsBytesPerLine))
706 {
707 printf("GW0,%d,%d,1\n", y, header->cupsBytesPerLine);
708 for (i = header->cupsBytesPerLine, ptr = Buffer; i > 0; i --, ptr ++)
709 putchar(~*ptr);
710 putchar('\n');
711 fflush(stdout);
712 }
713 break;
714
715 case ZEBRA_ZPL :
716 /*
717 * Determine if this row is the same as the previous line.
718 * If so, output a ':' and return...
719 */
720
721 if (LastSet)
722 {
723 if (!memcmp(Buffer, LastBuffer, header->cupsBytesPerLine))
724 {
725 putchar(':');
726 return;
727 }
728 }
729
730 /*
731 * Convert the line to hex digits...
732 */
733
734 for (ptr = Buffer, compptr = CompBuffer, i = header->cupsBytesPerLine;
735 i > 0;
736 i --, ptr ++)
737 {
738 *compptr++ = hex[*ptr >> 4];
739 *compptr++ = hex[*ptr & 15];
740 }
741
742 *compptr = '\0';
743
744 /*
745 * Run-length compress the graphics...
746 */
747
748 for (compptr = CompBuffer, repeat_char = CompBuffer[0], repeat_count = 1;
749 *compptr;
750 compptr ++)
751 if (*compptr == repeat_char)
752 repeat_count ++;
753 else
754 {
755 ZPLCompress(repeat_char, repeat_count);
756 repeat_char = *compptr;
757 repeat_count = 1;
758 }
759
760 if (repeat_char == '0')
761 {
762 /*
763 * Handle 0's on the end of the line...
764 */
765
766 if (repeat_count & 1)
767 putchar('0');
768
769 putchar(',');
770 }
771 else
772 ZPLCompress(repeat_char, repeat_count);
773
774 /*
775 * Save this line for the next round...
776 */
777
778 memcpy(LastBuffer, Buffer, header->cupsBytesPerLine);
779 LastSet = 1;
780 break;
781
782 case ZEBRA_CPCL :
783 if (Buffer[0] || memcmp(Buffer, Buffer + 1, header->cupsBytesPerLine))
784 {
785 printf("CG %u 1 0 %d ", header->cupsBytesPerLine, y);
786 fwrite(Buffer, 1, header->cupsBytesPerLine, stdout);
787 puts("\r");
788 fflush(stdout);
789 }
790 break;
791 }
792}
793
794
795/*
796 * 'ZPLCompress()' - Output a run-length compression sequence.
797 */
798
799void
800ZPLCompress(char repeat_char, /* I - Character to repeat */
801 int repeat_count) /* I - Number of repeated characters */
802{
803 if (repeat_count > 1)
804 {
805 /*
806 * Print as many z's as possible - they are the largest denomination
807 * representing 400 characters (zC stands for 400 adjacent C's)
808 */
809
810 while (repeat_count >= 400)
811 {
812 putchar('z');
813 repeat_count -= 400;
814 }
815
816 /*
817 * Then print 'g' through 'y' as multiples of 20 characters...
818 */
819
820 if (repeat_count >= 20)
821 {
822 putchar('f' + repeat_count / 20);
823 repeat_count %= 20;
824 }
825
826 /*
827 * Finally, print 'G' through 'Y' as 1 through 19 characters...
828 */
829
830 if (repeat_count > 0)
831 putchar('F' + repeat_count);
832 }
833
834 /*
835 * Then the character to be repeated...
836 */
837
838 putchar(repeat_char);
839}
840
841
842/*
843 * 'main()' - Main entry and processing of driver.
844 */
845
846int /* O - Exit status */
847main(int argc, /* I - Number of command-line arguments */
848 char *argv[]) /* I - Command-line arguments */
849{
850 int fd; /* File descriptor */
851 cups_raster_t *ras; /* Raster stream for printing */
852 cups_page_header_t header; /* Page header from file */
853 int y; /* Current line */
854 ppd_file_t *ppd; /* PPD file */
855 int num_options; /* Number of options */
856 cups_option_t *options; /* Options */
857
858
859 /*
860 * Make sure status messages are not buffered...
861 */
862
863 setbuf(stderr, NULL);
864
865 /*
866 * Check command-line...
867 */
868
869 if (argc < 6 || argc > 7)
870 {
871 /*
872 * We don't have the correct number of arguments; write an error message
873 * and return.
874 */
875
f7faf1f5 876 fputs("ERROR: rastertodymo job-id user title copies options [file]\n", stderr);
ef416fc2 877 return (1);
878 }
879
880 /*
881 * Open the page stream...
882 */
883
884 if (argc == 7)
885 {
886 if ((fd = open(argv[6], O_RDONLY)) == -1)
887 {
888 perror("ERROR: Unable to open raster file - ");
889 sleep(1);
890 return (1);
891 }
892 }
893 else
894 fd = 0;
895
896 ras = cupsRasterOpen(fd, CUPS_RASTER_READ);
897
898 /*
899 * Open the PPD file and apply options...
900 */
901
902 num_options = cupsParseOptions(argv[5], 0, &options);
903
904 if ((ppd = ppdOpenFile(getenv("PPD"))) != NULL)
905 {
906 ppdMarkDefaults(ppd);
907 cupsMarkOptions(ppd, num_options, options);
908 }
909
910 /*
911 * Initialize the print device...
912 */
913
914 Setup(ppd);
915
916 /*
917 * Process pages as needed...
918 */
919
920 Page = 0;
921 Canceled = 0;
922
923 while (cupsRasterReadHeader(ras, &header))
924 {
925 /*
926 * Write a status message with the page number and number of copies.
927 */
928
929 Page ++;
930
931 fprintf(stderr, "PAGE: %d 1\n", Page);
932
933 /*
934 * Start the page...
935 */
936
937 StartPage(ppd, &header);
938
939 /*
940 * Loop for each line on the page...
941 */
942
943 for (y = 0; y < header.cupsHeight && !Canceled; y ++)
944 {
945 /*
946 * Let the user know how far we have progressed...
947 */
948
949 if ((y & 15) == 0)
950 fprintf(stderr, "INFO: Printing page %d, %d%% complete...\n", Page,
951 100 * y / header.cupsHeight);
952
953 /*
954 * Read a line of graphics...
955 */
956
957 if (cupsRasterReadPixels(ras, Buffer, header.cupsBytesPerLine) < 1)
958 break;
959
960 /*
961 * Write it to the printer...
962 */
963
964 OutputLine(ppd, &header, y);
965 }
966
967 /*
968 * Eject the page...
969 */
970
971 EndPage(ppd, &header);
972
973 if (Canceled)
974 break;
975 }
976
977 /*
978 * Close the raster stream...
979 */
980
981 cupsRasterClose(ras);
982 if (fd != 0)
983 close(fd);
984
985 /*
986 * Close the PPD file and free the options...
987 */
988
989 ppdClose(ppd);
990 cupsFreeOptions(num_options, options);
991
992 /*
993 * If no pages were printed, send an error message...
994 */
995
996 if (Page == 0)
997 fputs("ERROR: No pages found!\n", stderr);
998 else
999 fputs("INFO: Ready to print.\n", stderr);
1000
1001 return (Page == 0);
1002}
1003
1004
1005/*
f7faf1f5 1006 * End of "$Id: rastertolabel.c 5665 2006-06-16 00:59:10Z mike $".
ef416fc2 1007 */