]>
Commit | Line | Data |
---|---|---|
74456259 | 1 | /* |
c9d3f842 | 2 | * "$Id$" |
74456259 | 3 | * |
725dbff8 | 4 | * Label printer filter for the Common UNIX Printing System (CUPS). |
74456259 | 5 | * |
24c1b5ce | 6 | * Copyright 2001-2006 by Easy Software Products. |
74456259 | 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 | |
c9d3f842 | 18 | * Hollywood, Maryland 20636 USA |
74456259 | 19 | * |
9639c4de | 20 | * Voice: (301) 373-9600 |
74456259 | 21 | * EMail: cups-info@cups.org |
22 | * WWW: http://www.cups.org | |
23 | * | |
dab1a4d8 | 24 | * This file is subject to the Apple OS-Developed Software exception. |
25 | * | |
74456259 | 26 | * Contents: |
27 | * | |
28 | * Setup() - Prepare the printer for printing. | |
29 | * StartPage() - Start a page of graphics. | |
30 | * EndPage() - Finish a page of graphics. | |
74456259 | 31 | * CancelJob() - Cancel the current job... |
74456259 | 32 | * OutputLine() - Output a line of graphics. |
0de32e05 | 33 | * PCLCompress() - Output a PCL (mode 3) compressed line. |
6c5fbfa1 | 34 | * ZPLCompress() - Output a run-length compression sequence. |
74456259 | 35 | * main() - Main entry and processing of driver. |
36 | */ | |
37 | ||
38 | /* | |
39 | * Include necessary headers... | |
40 | */ | |
41 | ||
42 | #include <cups/cups.h> | |
43 | #include <cups/string.h> | |
44 | #include "raster.h" | |
45 | #include <stdlib.h> | |
46 | #include <unistd.h> | |
47 | #include <fcntl.h> | |
48 | #include <signal.h> | |
49 | ||
50 | ||
725dbff8 | 51 | /* |
0de32e05 | 52 | * This driver filter currently supports Dymo, Intellitech, and Zebra |
53 | * label printers. | |
725dbff8 | 54 | * |
55 | * The Dymo portion of the driver has been tested with the 300, 330, | |
0de32e05 | 56 | * and 330 Turbo label printers; it may also work with other models. |
725dbff8 | 57 | * The Dymo printers support printing at 136, 203, and 300 DPI. |
58 | * | |
0de32e05 | 59 | * The Intellitech portion of the driver has been tested with the |
60 | * Intellibar 408, 412, and 808 and supports their PCL variant. | |
61 | * | |
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. | |
725dbff8 | 66 | */ |
67 | ||
68 | /* | |
69 | * Model number constants... | |
70 | */ | |
71 | ||
72 | #define DYMO_3x0 0 /* Dymo Labelwriter 300/330/330 Turbo */ | |
73 | ||
ea19a116 | 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 */ | |
7379b1c7 | 77 | #define ZEBRA_CPCL 0x13 /* Zebra CPCL-based printers */ |
725dbff8 | 78 | |
0de32e05 | 79 | #define INTELLITECH_PCL 0x20 /* Intellitech PCL-based printers */ |
80 | ||
725dbff8 | 81 | |
74456259 | 82 | /* |
83 | * Globals... | |
84 | */ | |
85 | ||
86 | unsigned char *Buffer; /* Output buffer */ | |
0de32e05 | 87 | unsigned char *CompBuffer; /* Compression buffer */ |
6c5fbfa1 | 88 | unsigned char *LastBuffer; /* Last buffer */ |
89 | int LastSet; /* Number of repeat characters */ | |
725dbff8 | 90 | int ModelNumber, /* cupsModelNumber attribute */ |
91 | Page, /* Current page */ | |
92 | Feed, /* Number of lines to skip */ | |
ea19a116 | 93 | Canceled; /* Non-zero if job is canceled */ |
74456259 | 94 | |
95 | ||
96 | /* | |
97 | * Prototypes... | |
98 | */ | |
99 | ||
6c5fbfa1 | 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); | |
74456259 | 103 | void CancelJob(int sig); |
6c5fbfa1 | 104 | void OutputLine(ppd_file_t *ppd, cups_page_header_t *header, int y); |
0de32e05 | 105 | void PCLCompress(unsigned char *line, int length); |
6c5fbfa1 | 106 | void ZPLCompress(char repeat_char, int repeat_count); |
74456259 | 107 | |
108 | ||
109 | /* | |
110 | * 'Setup()' - Prepare the printer for printing. | |
111 | */ | |
112 | ||
113 | void | |
6c5fbfa1 | 114 | Setup(ppd_file_t *ppd) /* I - PPD file */ |
74456259 | 115 | { |
725dbff8 | 116 | int i; /* Looping var */ |
74456259 | 117 | |
118 | ||
119 | /* | |
725dbff8 | 120 | * Get the model number from the PPD file... |
74456259 | 121 | */ |
122 | ||
6c5fbfa1 | 123 | if (ppd) |
725dbff8 | 124 | ModelNumber = ppd->model_number; |
c67094f2 | 125 | |
126 | /* | |
725dbff8 | 127 | * Initialize based on the model number... |
c67094f2 | 128 | */ |
129 | ||
725dbff8 | 130 | switch (ModelNumber) |
131 | { | |
132 | case DYMO_3x0 : | |
133 | /* | |
134 | * Clear any remaining data... | |
135 | */ | |
136 | ||
137 | for (i = 0; i < 100; i ++) | |
138 | putchar(0x1b); | |
139 | ||
140 | /* | |
141 | * Reset the printer... | |
142 | */ | |
143 | ||
144 | fputs("\033@", stdout); | |
145 | break; | |
146 | ||
ea19a116 | 147 | case ZEBRA_EPL_LINE : |
148 | break; | |
149 | ||
150 | case ZEBRA_EPL_PAGE : | |
151 | break; | |
152 | ||
725dbff8 | 153 | case ZEBRA_ZPL : |
725dbff8 | 154 | break; |
7379b1c7 | 155 | |
156 | case ZEBRA_CPCL : | |
157 | break; | |
0de32e05 | 158 | |
159 | case INTELLITECH_PCL : | |
160 | /* | |
161 | * Send a PCL reset sequence. | |
162 | */ | |
163 | ||
164 | putchar(0x1b); | |
165 | putchar('E'); | |
166 | break; | |
725dbff8 | 167 | } |
74456259 | 168 | } |
169 | ||
170 | ||
171 | /* | |
172 | * 'StartPage()' - Start a page of graphics. | |
173 | */ | |
174 | ||
175 | void | |
4e070bd9 | 176 | StartPage(ppd_file_t *ppd, /* I - PPD file */ |
6c5fbfa1 | 177 | cups_page_header_t *header) /* I - Page header */ |
74456259 | 178 | { |
6f110ff2 | 179 | ppd_choice_t *choice; /* Marked choice */ |
180 | int length; /* Actual label length */ | |
74456259 | 181 | #if defined(HAVE_SIGACTION) && !defined(HAVE_SIGSET) |
182 | struct sigaction action; /* Actions for POSIX signals */ | |
183 | #endif /* HAVE_SIGACTION && !HAVE_SIGSET */ | |
184 | ||
185 | ||
4e070bd9 | 186 | /* |
187 | * Show page device dictionary... | |
188 | */ | |
189 | ||
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); | |
195 | ||
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], | |
210 | header->Margins[1]); | |
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); | |
0de32e05 | 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); | |
4e070bd9 | 236 | |
74456259 | 237 | /* |
238 | * Register a signal handler to eject the current page if the | |
ea19a116 | 239 | * job is canceled. |
74456259 | 240 | */ |
241 | ||
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)); | |
246 | ||
247 | sigemptyset(&action.sa_mask); | |
248 | action.sa_handler = CancelJob; | |
249 | sigaction(SIGTERM, &action, NULL); | |
250 | #else | |
251 | signal(SIGTERM, CancelJob); | |
252 | #endif /* HAVE_SIGSET */ | |
253 | ||
725dbff8 | 254 | switch (ModelNumber) |
255 | { | |
256 | case DYMO_3x0 : | |
257 | /* | |
258 | * Setup printer/job attributes... | |
259 | */ | |
260 | ||
261 | length = header->PageSize[1] * header->HWResolution[1] / 72; | |
262 | ||
263 | printf("\033L%c%c", length >> 8, length); | |
264 | printf("\033D%c", header->cupsBytesPerLine); | |
265 | ||
266 | printf("\033%c", header->cupsCompression + 'c'); /* Darkness */ | |
267 | break; | |
74456259 | 268 | |
ea19a116 | 269 | case ZEBRA_EPL_LINE : |
6f110ff2 | 270 | /* |
271 | * Set print rate... | |
272 | */ | |
273 | ||
274 | if ((choice = ppdFindMarkedChoice(ppd, "zePrintRate")) != NULL && | |
275 | strcmp(choice->choice, "Default")) | |
276 | printf("\033S%.0f", atof(choice->choice) * 2.0 - 2.0); | |
277 | ||
ea19a116 | 278 | /* |
279 | * Set darkness... | |
280 | */ | |
281 | ||
6f110ff2 | 282 | if (header->cupsCompression > 0 && header->cupsCompression <= 100) |
283 | printf("\033D%d", 7 * header->cupsCompression / 100); | |
284 | ||
285 | /* | |
286 | * Set left margin to 0... | |
287 | */ | |
288 | ||
289 | fputs("\033M01", stdout); | |
ea19a116 | 290 | |
291 | /* | |
292 | * Start buffered output... | |
293 | */ | |
294 | ||
6f110ff2 | 295 | fputs("\033B", stdout); |
ea19a116 | 296 | break; |
297 | ||
298 | case ZEBRA_EPL_PAGE : | |
6f110ff2 | 299 | /* |
300 | * Start a new label... | |
301 | */ | |
302 | ||
303 | puts(""); | |
304 | puts("N"); | |
305 | ||
306 | /* | |
307 | * Set hardware options... | |
308 | */ | |
309 | ||
310 | if (!strcmp(header->MediaType, "Direct")) | |
311 | puts("OD"); | |
312 | ||
313 | /* | |
314 | * Set print rate... | |
315 | */ | |
316 | ||
317 | if ((choice = ppdFindMarkedChoice(ppd, "zePrintRate")) != NULL && | |
318 | strcmp(choice->choice, "Default")) | |
319 | { | |
320 | float val = atof(choice->choice); | |
321 | ||
322 | if (val >= 3.0) | |
323 | printf("S%.0f\n", val); | |
324 | else | |
325 | printf("S%.0f\n", val * 2.0 - 2.0); | |
326 | } | |
327 | ||
ea19a116 | 328 | /* |
329 | * Set darkness... | |
330 | */ | |
331 | ||
6f110ff2 | 332 | if (header->cupsCompression > 0 && header->cupsCompression <= 100) |
333 | printf("D%d\n", 15 * header->cupsCompression / 100); | |
ea19a116 | 334 | |
335 | /* | |
336 | * Set label size... | |
337 | */ | |
338 | ||
339 | printf("q%d\n", header->cupsWidth); | |
340 | break; | |
341 | ||
725dbff8 | 342 | case ZEBRA_ZPL : |
725dbff8 | 343 | /* |
344 | * Set darkness... | |
345 | */ | |
9a12ff91 | 346 | |
6f110ff2 | 347 | if (header->cupsCompression > 0 && header->cupsCompression <= 100) |
6c5fbfa1 | 348 | printf("~SD%02d\n", 30 * header->cupsCompression / 100); |
74456259 | 349 | |
725dbff8 | 350 | /* |
351 | * Start bitmap graphics... | |
352 | */ | |
353 | ||
354 | printf("~DGR:CUPS.GRF,%d,%d,\n", | |
355 | header->cupsHeight * header->cupsBytesPerLine, | |
356 | header->cupsBytesPerLine); | |
6c5fbfa1 | 357 | |
358 | /* | |
359 | * Allocate compression buffers... | |
360 | */ | |
361 | ||
362 | CompBuffer = malloc(2 * header->cupsBytesPerLine + 1); | |
363 | LastBuffer = malloc(header->cupsBytesPerLine); | |
364 | LastSet = 0; | |
725dbff8 | 365 | break; |
7379b1c7 | 366 | |
367 | case ZEBRA_CPCL : | |
368 | /* | |
369 | * Start label... | |
370 | */ | |
371 | ||
11bead89 | 372 | printf("! 0 %u %u %u %u\r\n", header->HWResolution[0], |
7379b1c7 | 373 | header->HWResolution[1], header->cupsHeight, |
374 | header->NumCopies); | |
199a033e | 375 | printf("PAGE-WIDTH %d\r\n", header->cupsWidth); |
376 | printf("PAGE-HEIGHT %d\r\n", header->cupsWidth); | |
7379b1c7 | 377 | break; |
0de32e05 | 378 | |
379 | case INTELLITECH_PCL : | |
380 | /* | |
381 | * Set the media size... | |
382 | */ | |
383 | ||
384 | printf("\033&l6D\033&k12H"); /* Set 6 LPI, 10 CPI */ | |
385 | printf("\033&l0O"); /* Set portrait orientation */ | |
386 | ||
387 | switch (header->PageSize[1]) | |
388 | { | |
389 | case 540 : /* Monarch Envelope */ | |
390 | printf("\033&l80A"); /* Set page size */ | |
391 | break; | |
392 | ||
393 | case 624 : /* DL Envelope */ | |
394 | printf("\033&l90A"); /* Set page size */ | |
395 | break; | |
396 | ||
397 | case 649 : /* C5 Envelope */ | |
398 | printf("\033&l91A"); /* Set page size */ | |
399 | break; | |
400 | ||
401 | case 684 : /* COM-10 Envelope */ | |
402 | printf("\033&l81A"); /* Set page size */ | |
403 | break; | |
404 | ||
405 | case 756 : /* Executive */ | |
406 | printf("\033&l1A"); /* Set page size */ | |
407 | break; | |
408 | ||
409 | case 792 : /* Letter */ | |
410 | printf("\033&l2A"); /* Set page size */ | |
411 | break; | |
412 | ||
413 | case 842 : /* A4 */ | |
414 | printf("\033&l26A"); /* Set page size */ | |
415 | break; | |
416 | ||
417 | case 1008 : /* Legal */ | |
418 | printf("\033&l3A"); /* Set page size */ | |
419 | break; | |
420 | ||
421 | default : /* Custom size */ | |
422 | printf("\033!f%dZ", header->PageSize[1] * 300 / 72); | |
423 | break; | |
424 | } | |
425 | ||
426 | printf("\033&l%dP", /* Set page length */ | |
427 | header->PageSize[1] / 12); | |
428 | printf("\033&l0E"); /* Set top margin to 0 */ | |
429 | printf("\033&l%dX", header->NumCopies); | |
430 | /* Set number copies */ | |
431 | printf("\033&l0L"); /* Turn off perforation skip */ | |
432 | ||
433 | /* | |
434 | * Print settings... | |
435 | */ | |
436 | ||
437 | if (Page == 1) | |
438 | { | |
439 | if (header->cupsRowFeed) /* inPrintRate */ | |
440 | printf("\033!p%dS", header->cupsRowFeed); | |
441 | ||
442 | if (header->cupsCompression != ~0) | |
443 | /* inPrintDensity */ | |
444 | printf("\033&d%dA", 30 * header->cupsCompression / 100 - 15); | |
445 | ||
f80f7af1 | 446 | if ((choice = ppdFindMarkedChoice(ppd, "inPrintMode")) != NULL) |
447 | { | |
448 | if (!strcmp(choice->choice, "Standard")) | |
449 | fputs("\033!p0M", stdout); | |
450 | else if (!strcmp(choice->choice, "Tear")) | |
451 | { | |
452 | fputs("\033!p1M", stdout); | |
453 | ||
454 | if (header->cupsRowCount) /* inTearInterval */ | |
455 | printf("\033!n%dT", header->cupsRowCount); | |
456 | } | |
457 | else | |
458 | { | |
459 | fputs("\033!p2M", stdout); | |
460 | ||
461 | if (header->cupsRowStep) /* inCutInterval */ | |
462 | printf("\033!n%dC", header->cupsRowStep); | |
463 | } | |
464 | } | |
0de32e05 | 465 | } |
466 | ||
467 | /* | |
468 | * Setup graphics... | |
469 | */ | |
470 | ||
471 | printf("\033*t%dR", header->HWResolution[0]); | |
472 | /* Set resolution */ | |
473 | ||
474 | printf("\033*r%dS", header->cupsWidth); | |
475 | /* Set width */ | |
476 | printf("\033*r%dT", header->cupsHeight); | |
477 | /* Set height */ | |
478 | ||
479 | printf("\033&a0H"); /* Set horizontal position */ | |
480 | printf("\033&a0V"); /* Set vertical position */ | |
481 | printf("\033*r1A"); /* Start graphics */ | |
482 | printf("\033*b3M"); /* Set compression */ | |
483 | ||
484 | /* | |
485 | * Allocate compression buffers... | |
486 | */ | |
487 | ||
488 | CompBuffer = malloc(2 * header->cupsBytesPerLine + 1); | |
489 | LastBuffer = malloc(header->cupsBytesPerLine); | |
490 | LastSet = 0; | |
491 | break; | |
725dbff8 | 492 | } |
74456259 | 493 | |
494 | /* | |
495 | * Allocate memory for a line of graphics... | |
496 | */ | |
497 | ||
498 | Buffer = malloc(header->cupsBytesPerLine); | |
499 | Feed = 0; | |
500 | } | |
501 | ||
502 | ||
503 | /* | |
504 | * 'EndPage()' - Finish a page of graphics. | |
505 | */ | |
506 | ||
507 | void | |
6c5fbfa1 | 508 | EndPage(ppd_file_t *ppd, /* I - PPD file */ |
509 | cups_page_header_t *header) /* I - Page header */ | |
74456259 | 510 | { |
6c5fbfa1 | 511 | int val; /* Option value */ |
512 | ppd_choice_t *choice; /* Marked choice */ | |
74456259 | 513 | #if defined(HAVE_SIGACTION) && !defined(HAVE_SIGSET) |
725dbff8 | 514 | struct sigaction action; /* Actions for POSIX signals */ |
74456259 | 515 | #endif /* HAVE_SIGACTION && !HAVE_SIGSET */ |
516 | ||
517 | ||
725dbff8 | 518 | switch (ModelNumber) |
519 | { | |
520 | case DYMO_3x0 : | |
521 | /* | |
522 | * Eject the current page... | |
523 | */ | |
524 | ||
525 | fputs("\033E", stdout); | |
ea19a116 | 526 | break; |
74456259 | 527 | |
ea19a116 | 528 | case ZEBRA_EPL_LINE : |
529 | /* | |
530 | * End buffered output, eject the label... | |
531 | */ | |
532 | ||
6f110ff2 | 533 | fputs("\033E\014", stdout); |
ea19a116 | 534 | break; |
535 | ||
536 | case ZEBRA_EPL_PAGE : | |
537 | /* | |
538 | * Print the label... | |
539 | */ | |
540 | ||
541 | puts("P1"); | |
725dbff8 | 542 | break; |
543 | ||
544 | case ZEBRA_ZPL : | |
ea19a116 | 545 | if (Canceled) |
725dbff8 | 546 | { |
547 | /* | |
548 | * Cancel bitmap download... | |
549 | */ | |
550 | ||
551 | puts("~DN"); | |
552 | break; | |
553 | } | |
554 | ||
555 | /* | |
6c5fbfa1 | 556 | * Start label... |
725dbff8 | 557 | */ |
74456259 | 558 | |
725dbff8 | 559 | puts("^XA"); |
725dbff8 | 560 | |
561 | /* | |
6c5fbfa1 | 562 | * Set print rate... |
725dbff8 | 563 | */ |
564 | ||
6c5fbfa1 | 565 | if ((choice = ppdFindMarkedChoice(ppd, "zePrintRate")) != NULL && |
566 | strcmp(choice->choice, "Default")) | |
567 | { | |
568 | val = atoi(choice->choice); | |
569 | printf("^PR%d,%d,%d\n", val, val, val); | |
570 | } | |
571 | ||
572 | /* | |
573 | * Put label home in default position (0,0)... | |
574 | */ | |
575 | ||
576 | printf("^LH0,0\n"); | |
577 | ||
578 | /* | |
579 | * Set media tracking... | |
580 | */ | |
581 | ||
582 | if (ppdIsMarked(ppd, "zeMediaTracking", "Continuous")) | |
583 | { | |
584 | /* | |
585 | * Add label length command for continuous... | |
586 | */ | |
587 | ||
588 | printf("^LL%d\n", header->cupsHeight); | |
589 | printf("^MNN\n"); | |
590 | } | |
591 | else if (ppdIsMarked(ppd, "zeMediaTracking", "Web")) | |
592 | printf("^MNY\n"); | |
593 | else if (ppdIsMarked(ppd, "zeMediaTracking", "Mark")) | |
594 | printf("^MNM\n"); | |
595 | ||
596 | /* | |
597 | * Set label top | |
598 | */ | |
599 | ||
600 | if (header->cupsRowStep != 200) | |
601 | printf("^LT%u\n", header->cupsRowStep); | |
602 | ||
603 | /* | |
604 | * Set media type... | |
605 | */ | |
606 | ||
607 | if (!strcmp(header->MediaType, "Thermal")) | |
608 | printf("^MTT\n"); | |
609 | else if (!strcmp(header->MediaType, "Direct")) | |
610 | printf("^MTD\n"); | |
611 | ||
612 | /* | |
613 | * Set print mode... | |
614 | */ | |
615 | ||
616 | if ((choice = ppdFindMarkedChoice(ppd, "zePrintMode")) != NULL && | |
617 | strcmp(choice->choice, "Saved")) | |
618 | { | |
619 | printf("^MM"); | |
620 | ||
621 | if (!strcmp(choice->choice, "Tear")) | |
622 | printf("T,Y\n"); | |
623 | else if (!strcmp(choice->choice, "Peel")) | |
624 | printf("P,Y\n"); | |
625 | else if (!strcmp(choice->choice, "Rewind")) | |
626 | printf("R,Y\n"); | |
627 | else if (!strcmp(choice->choice, "Applicator")) | |
628 | printf("A,Y\n"); | |
629 | else | |
630 | printf("C,Y\n"); | |
631 | } | |
632 | ||
633 | /* | |
634 | * Set tear-off adjust position... | |
635 | */ | |
636 | ||
637 | if (header->AdvanceDistance != 1000) | |
638 | { | |
639 | if ((int)header->AdvanceDistance < 0) | |
640 | printf("~TA%04d\n", (int)header->AdvanceDistance); | |
641 | else | |
642 | printf("~TA%03d\n", (int)header->AdvanceDistance); | |
643 | } | |
644 | ||
645 | /* | |
646 | * Allow for reprinting after an error... | |
647 | */ | |
648 | ||
649 | if (ppdIsMarked(ppd, "zeErrorReprint", "Always")) | |
650 | printf("^JZY\n"); | |
651 | else if (ppdIsMarked(ppd, "zeErrorReprint", "Never")) | |
652 | printf("^JZN\n"); | |
653 | ||
654 | /* | |
655 | * Print multiple copies | |
656 | */ | |
657 | ||
658 | if (header->NumCopies > 1) | |
659 | printf("^PQ%d, 0, 0, N\n", header->NumCopies); | |
725dbff8 | 660 | |
661 | /* | |
662 | * Display the label image... | |
663 | */ | |
664 | ||
6c5fbfa1 | 665 | puts("^FO0,0^XGR:CUPS.GRF,1,1^FS"); |
725dbff8 | 666 | |
667 | /* | |
668 | * End the label and eject... | |
669 | */ | |
670 | ||
671 | puts("^XZ"); | |
6c5fbfa1 | 672 | |
673 | /* | |
674 | * Free compression buffers... | |
675 | */ | |
676 | ||
677 | free(CompBuffer); | |
678 | free(LastBuffer); | |
725dbff8 | 679 | break; |
7379b1c7 | 680 | |
681 | case ZEBRA_CPCL : | |
682 | /* | |
683 | * Set tear-off adjust position... | |
684 | */ | |
685 | ||
11bead89 | 686 | if (header->AdvanceDistance != 1000) |
7379b1c7 | 687 | printf("PRESENT-AT %d 1\r\n", (int)header->AdvanceDistance); |
688 | ||
689 | /* | |
690 | * Allow for reprinting after an error... | |
691 | */ | |
692 | ||
693 | if (ppdIsMarked(ppd, "zeErrorReprint", "Always")) | |
694 | puts("ON-OUT-OF-PAPER WAIT\r"); | |
695 | else if (ppdIsMarked(ppd, "zeErrorReprint", "Never")) | |
696 | puts("ON-OUT-OF-PAPER PURGE\r"); | |
697 | ||
698 | /* | |
699 | * Cut label? | |
700 | */ | |
701 | ||
702 | if (header->CutMedia) | |
703 | puts("CUT\r"); | |
704 | ||
705 | /* | |
706 | * Set darkness... | |
707 | */ | |
708 | ||
709 | if (header->cupsCompression > 0) | |
11bead89 | 710 | printf("TONE %u\r\n", 2 * header->cupsCompression); |
7379b1c7 | 711 | |
712 | /* | |
713 | * Set print rate... | |
714 | */ | |
715 | ||
716 | if ((choice = ppdFindMarkedChoice(ppd, "zePrintRate")) != NULL && | |
717 | strcmp(choice->choice, "Default")) | |
718 | { | |
719 | val = atoi(choice->choice); | |
720 | printf("SPEED %d\r\n", val); | |
721 | } | |
722 | ||
723 | /* | |
724 | * Print the label... | |
725 | */ | |
726 | ||
199a033e | 727 | if ((choice = ppdFindMarkedChoice(ppd, "zeMediaTracking")) == NULL || |
728 | strcmp(choice->choice, "Continuous")) | |
729 | puts("FORM\r"); | |
730 | ||
7379b1c7 | 731 | puts("PRINT\r"); |
732 | break; | |
0de32e05 | 733 | |
734 | case INTELLITECH_PCL : | |
735 | printf("\033*rB"); /* End GFX */ | |
736 | printf("\014"); /* Eject current page */ | |
737 | break; | |
725dbff8 | 738 | } |
74456259 | 739 | |
ea19a116 | 740 | fflush(stdout); |
741 | ||
74456259 | 742 | /* |
743 | * Unregister the signal handler... | |
744 | */ | |
745 | ||
746 | #ifdef HAVE_SIGSET /* Use System V signals over POSIX to avoid bugs */ | |
747 | sigset(SIGTERM, SIG_IGN); | |
748 | #elif defined(HAVE_SIGACTION) | |
749 | memset(&action, 0, sizeof(action)); | |
750 | ||
751 | sigemptyset(&action.sa_mask); | |
752 | action.sa_handler = SIG_IGN; | |
753 | sigaction(SIGTERM, &action, NULL); | |
754 | #else | |
755 | signal(SIGTERM, SIG_IGN); | |
756 | #endif /* HAVE_SIGSET */ | |
757 | ||
758 | /* | |
759 | * Free memory... | |
760 | */ | |
761 | ||
762 | free(Buffer); | |
763 | } | |
764 | ||
765 | ||
766 | /* | |
767 | * 'CancelJob()' - Cancel the current job... | |
768 | */ | |
769 | ||
770 | void | |
771 | CancelJob(int sig) /* I - Signal */ | |
772 | { | |
725dbff8 | 773 | /* |
774 | * Tell the main loop to stop... | |
775 | */ | |
74456259 | 776 | |
777 | (void)sig; | |
778 | ||
ea19a116 | 779 | Canceled = 1; |
725dbff8 | 780 | } |
74456259 | 781 | |
74456259 | 782 | |
725dbff8 | 783 | /* |
784 | * 'OutputLine()' - Output a line of graphics... | |
785 | */ | |
786 | ||
787 | void | |
6c5fbfa1 | 788 | OutputLine(ppd_file_t *ppd, /* I - PPD file */ |
789 | cups_page_header_t *header, /* I - Page header */ | |
ea19a116 | 790 | int y) /* I - Line number */ |
725dbff8 | 791 | { |
792 | int i; /* Looping var */ | |
793 | unsigned char *ptr; /* Pointer into buffer */ | |
ddc1a5f9 | 794 | unsigned char *compptr; /* Pointer into compression buffer */ |
6c5fbfa1 | 795 | char repeat_char; /* Repeated character */ |
796 | int repeat_count; /* Number of repeated characters */ | |
797 | static const char *hex = "0123456789ABCDEF"; | |
798 | /* Hex digits */ | |
725dbff8 | 799 | |
74456259 | 800 | |
725dbff8 | 801 | switch (ModelNumber) |
802 | { | |
803 | case DYMO_3x0 : | |
804 | /* | |
805 | * See if the line is blank; if not, write it to the printer... | |
806 | */ | |
807 | ||
808 | if (Buffer[0] || | |
809 | memcmp(Buffer, Buffer + 1, header->cupsBytesPerLine - 1)) | |
810 | { | |
811 | if (Feed) | |
812 | { | |
813 | while (Feed > 255) | |
814 | { | |
815 | printf("\033f\001%c", 255); | |
816 | Feed -= 255; | |
817 | } | |
818 | ||
819 | printf("\033f\001%c", Feed); | |
820 | Feed = 0; | |
821 | } | |
74456259 | 822 | |
725dbff8 | 823 | putchar(0x16); |
824 | fwrite(Buffer, header->cupsBytesPerLine, 1, stdout); | |
825 | fflush(stdout); | |
826 | ||
827 | #ifdef __sgi | |
828 | /* | |
829 | * This hack works around a bug in the IRIX serial port driver when | |
830 | * run at high baud rates (e.g. 115200 baud)... This results in | |
831 | * slightly slower label printing, but at least the labels come | |
832 | * out properly. | |
833 | */ | |
834 | ||
835 | sginap(1); | |
836 | #endif /* __sgi */ | |
837 | } | |
838 | else | |
839 | Feed ++; | |
840 | break; | |
841 | ||
ea19a116 | 842 | case ZEBRA_EPL_LINE : |
6f110ff2 | 843 | printf("\033g%03d", header->cupsBytesPerLine); |
ea19a116 | 844 | fwrite(Buffer, 1, header->cupsBytesPerLine, stdout); |
845 | fflush(stdout); | |
846 | break; | |
847 | ||
848 | case ZEBRA_EPL_PAGE : | |
6f110ff2 | 849 | if (Buffer[0] || memcmp(Buffer, Buffer + 1, header->cupsBytesPerLine)) |
850 | { | |
851 | printf("GW0,%d,%d,1\n", y, header->cupsBytesPerLine); | |
852 | for (i = header->cupsBytesPerLine, ptr = Buffer; i > 0; i --, ptr ++) | |
853 | putchar(~*ptr); | |
854 | putchar('\n'); | |
855 | fflush(stdout); | |
856 | } | |
ea19a116 | 857 | break; |
858 | ||
725dbff8 | 859 | case ZEBRA_ZPL : |
6c5fbfa1 | 860 | /* |
861 | * Determine if this row is the same as the previous line. | |
862 | * If so, output a ':' and return... | |
863 | */ | |
864 | ||
865 | if (LastSet) | |
866 | { | |
867 | if (!memcmp(Buffer, LastBuffer, header->cupsBytesPerLine)) | |
725dbff8 | 868 | { |
6c5fbfa1 | 869 | putchar(':'); |
870 | return; | |
725dbff8 | 871 | } |
6c5fbfa1 | 872 | } |
873 | ||
874 | /* | |
875 | * Convert the line to hex digits... | |
876 | */ | |
877 | ||
878 | for (ptr = Buffer, compptr = CompBuffer, i = header->cupsBytesPerLine; | |
879 | i > 0; | |
880 | i --, ptr ++) | |
881 | { | |
882 | *compptr++ = hex[*ptr >> 4]; | |
883 | *compptr++ = hex[*ptr & 15]; | |
884 | } | |
885 | ||
886 | *compptr = '\0'; | |
887 | ||
888 | /* | |
889 | * Run-length compress the graphics... | |
890 | */ | |
891 | ||
a24a1989 | 892 | for (compptr = CompBuffer + 1, repeat_char = CompBuffer[0], repeat_count = 1; |
6c5fbfa1 | 893 | *compptr; |
894 | compptr ++) | |
895 | if (*compptr == repeat_char) | |
896 | repeat_count ++; | |
725dbff8 | 897 | else |
6c5fbfa1 | 898 | { |
899 | ZPLCompress(repeat_char, repeat_count); | |
900 | repeat_char = *compptr; | |
901 | repeat_count = 1; | |
902 | } | |
903 | ||
904 | if (repeat_char == '0') | |
905 | { | |
906 | /* | |
907 | * Handle 0's on the end of the line... | |
908 | */ | |
725dbff8 | 909 | |
6c5fbfa1 | 910 | if (repeat_count & 1) |
a24a1989 | 911 | { |
912 | repeat_count --; | |
6c5fbfa1 | 913 | putchar('0'); |
a24a1989 | 914 | } |
6c5fbfa1 | 915 | |
a24a1989 | 916 | if (repeat_count > 0) |
917 | putchar(','); | |
6c5fbfa1 | 918 | } |
919 | else | |
920 | ZPLCompress(repeat_char, repeat_count); | |
921 | ||
a24a1989 | 922 | fflush(stdout); |
923 | ||
6c5fbfa1 | 924 | /* |
925 | * Save this line for the next round... | |
926 | */ | |
927 | ||
928 | memcpy(LastBuffer, Buffer, header->cupsBytesPerLine); | |
929 | LastSet = 1; | |
725dbff8 | 930 | break; |
7379b1c7 | 931 | |
932 | case ZEBRA_CPCL : | |
11bead89 | 933 | if (Buffer[0] || memcmp(Buffer, Buffer + 1, header->cupsBytesPerLine)) |
934 | { | |
935 | printf("CG %u 1 0 %d ", header->cupsBytesPerLine, y); | |
936 | fwrite(Buffer, 1, header->cupsBytesPerLine, stdout); | |
937 | puts("\r"); | |
938 | fflush(stdout); | |
7379b1c7 | 939 | } |
7379b1c7 | 940 | break; |
0de32e05 | 941 | |
942 | case INTELLITECH_PCL : | |
943 | if (Buffer[0] || | |
944 | memcmp(Buffer, Buffer + 1, header->cupsBytesPerLine - 1)) | |
945 | { | |
946 | if (Feed) | |
947 | { | |
948 | printf("\033*b%dY", Feed); | |
949 | Feed = 0; | |
950 | LastSet = 0; | |
951 | } | |
952 | ||
953 | PCLCompress(Buffer, header->cupsBytesPerLine); | |
954 | } | |
955 | else | |
956 | Feed ++; | |
957 | break; | |
725dbff8 | 958 | } |
74456259 | 959 | } |
960 | ||
961 | ||
0de32e05 | 962 | /* |
963 | * 'PCLCompress()' - Output a PCL (mode 3) compressed line. | |
964 | */ | |
965 | ||
966 | void | |
967 | PCLCompress(unsigned char *line, /* I - Line to compress */ | |
968 | int length) /* I - Length of line */ | |
969 | { | |
970 | unsigned char *line_ptr, /* Current byte pointer */ | |
971 | *line_end, /* End-of-line byte pointer */ | |
972 | *comp_ptr, /* Pointer into compression buffer */ | |
973 | *start, /* Start of compression sequence */ | |
974 | *seed; /* Seed buffer pointer */ | |
975 | int count, /* Count of bytes for output */ | |
976 | offset; /* Offset of bytes for output */ | |
977 | ||
978 | ||
979 | /* | |
980 | * Do delta-row compression... | |
981 | */ | |
982 | ||
983 | line_ptr = line; | |
984 | line_end = line + length; | |
985 | ||
986 | comp_ptr = CompBuffer; | |
987 | seed = LastBuffer; | |
988 | ||
989 | while (line_ptr < line_end) | |
990 | { | |
991 | /* | |
992 | * Find the next non-matching sequence... | |
993 | */ | |
994 | ||
995 | start = line_ptr; | |
996 | ||
997 | if (!LastSet) | |
998 | { | |
999 | /* | |
1000 | * The seed buffer is invalid, so do the next 8 bytes, max... | |
1001 | */ | |
1002 | ||
1003 | offset = 0; | |
1004 | ||
1005 | if ((count = line_end - line_ptr) > 8) | |
1006 | count = 8; | |
1007 | ||
1008 | line_ptr += count; | |
1009 | } | |
1010 | else | |
1011 | { | |
1012 | /* | |
1013 | * The seed buffer is valid, so compare against it... | |
1014 | */ | |
1015 | ||
1016 | while (*line_ptr == *seed && | |
1017 | line_ptr < line_end) | |
1018 | { | |
1019 | line_ptr ++; | |
1020 | seed ++; | |
1021 | } | |
1022 | ||
1023 | if (line_ptr == line_end) | |
1024 | break; | |
1025 | ||
1026 | offset = line_ptr - start; | |
1027 | ||
1028 | /* | |
1029 | * Find up to 8 non-matching bytes... | |
1030 | */ | |
1031 | ||
1032 | start = line_ptr; | |
1033 | count = 0; | |
1034 | while (*line_ptr != *seed && | |
1035 | line_ptr < line_end && | |
1036 | count < 8) | |
1037 | { | |
1038 | line_ptr ++; | |
1039 | seed ++; | |
1040 | count ++; | |
1041 | } | |
1042 | } | |
1043 | ||
1044 | /* | |
1045 | * Place mode 3 compression data in the buffer; see HP manuals | |
1046 | * for details... | |
1047 | */ | |
1048 | ||
1049 | if (offset >= 31) | |
1050 | { | |
1051 | /* | |
1052 | * Output multi-byte offset... | |
1053 | */ | |
1054 | ||
1055 | *comp_ptr++ = ((count - 1) << 5) | 31; | |
1056 | ||
1057 | offset -= 31; | |
1058 | while (offset >= 255) | |
1059 | { | |
1060 | *comp_ptr++ = 255; | |
1061 | offset -= 255; | |
1062 | } | |
1063 | ||
1064 | *comp_ptr++ = offset; | |
1065 | } | |
1066 | else | |
1067 | { | |
1068 | /* | |
1069 | * Output single-byte offset... | |
1070 | */ | |
1071 | ||
1072 | *comp_ptr++ = ((count - 1) << 5) | offset; | |
1073 | } | |
1074 | ||
1075 | memcpy(comp_ptr, start, count); | |
1076 | comp_ptr += count; | |
1077 | } | |
1078 | ||
1079 | line_ptr = CompBuffer; | |
1080 | line_end = comp_ptr; | |
1081 | ||
1082 | /* | |
1083 | * Set the length of the data and write it... | |
1084 | */ | |
1085 | ||
1086 | printf("\033*b%dW", comp_ptr - CompBuffer); | |
1087 | fwrite(CompBuffer, comp_ptr - CompBuffer, 1, stdout); | |
1088 | ||
1089 | /* | |
1090 | * Save this line as a "seed" buffer for the next... | |
1091 | */ | |
1092 | ||
1093 | memcpy(LastBuffer, line, length); | |
1094 | LastSet = 1; | |
1095 | } | |
1096 | ||
1097 | ||
6c5fbfa1 | 1098 | /* |
1099 | * 'ZPLCompress()' - Output a run-length compression sequence. | |
1100 | */ | |
1101 | ||
1102 | void | |
1103 | ZPLCompress(char repeat_char, /* I - Character to repeat */ | |
1104 | int repeat_count) /* I - Number of repeated characters */ | |
1105 | { | |
1106 | if (repeat_count > 1) | |
1107 | { | |
1108 | /* | |
1109 | * Print as many z's as possible - they are the largest denomination | |
1110 | * representing 400 characters (zC stands for 400 adjacent C's) | |
1111 | */ | |
1112 | ||
1113 | while (repeat_count >= 400) | |
1114 | { | |
1115 | putchar('z'); | |
1116 | repeat_count -= 400; | |
1117 | } | |
1118 | ||
1119 | /* | |
1120 | * Then print 'g' through 'y' as multiples of 20 characters... | |
1121 | */ | |
1122 | ||
1123 | if (repeat_count >= 20) | |
1124 | { | |
1125 | putchar('f' + repeat_count / 20); | |
1126 | repeat_count %= 20; | |
1127 | } | |
1128 | ||
1129 | /* | |
1130 | * Finally, print 'G' through 'Y' as 1 through 19 characters... | |
1131 | */ | |
1132 | ||
1133 | if (repeat_count > 0) | |
1134 | putchar('F' + repeat_count); | |
1135 | } | |
1136 | ||
1137 | /* | |
1138 | * Then the character to be repeated... | |
1139 | */ | |
1140 | ||
1141 | putchar(repeat_char); | |
1142 | } | |
1143 | ||
1144 | ||
74456259 | 1145 | /* |
1146 | * 'main()' - Main entry and processing of driver. | |
1147 | */ | |
1148 | ||
725dbff8 | 1149 | int /* O - Exit status */ |
1150 | main(int argc, /* I - Number of command-line arguments */ | |
1151 | char *argv[]) /* I - Command-line arguments */ | |
74456259 | 1152 | { |
725dbff8 | 1153 | int fd; /* File descriptor */ |
1154 | cups_raster_t *ras; /* Raster stream for printing */ | |
1155 | cups_page_header_t header; /* Page header from file */ | |
1156 | int y; /* Current line */ | |
6c5fbfa1 | 1157 | ppd_file_t *ppd; /* PPD file */ |
1158 | int num_options; /* Number of options */ | |
1159 | cups_option_t *options; /* Options */ | |
74456259 | 1160 | |
1161 | ||
1162 | /* | |
1163 | * Make sure status messages are not buffered... | |
1164 | */ | |
1165 | ||
1166 | setbuf(stderr, NULL); | |
1167 | ||
1168 | /* | |
1169 | * Check command-line... | |
1170 | */ | |
1171 | ||
1172 | if (argc < 6 || argc > 7) | |
1173 | { | |
1174 | /* | |
1175 | * We don't have the correct number of arguments; write an error message | |
1176 | * and return. | |
1177 | */ | |
1178 | ||
0de32e05 | 1179 | fputs("ERROR: rastertolabel job-id user title copies options [file]\n", stderr); |
74456259 | 1180 | return (1); |
1181 | } | |
1182 | ||
1183 | /* | |
1184 | * Open the page stream... | |
1185 | */ | |
1186 | ||
1187 | if (argc == 7) | |
1188 | { | |
725dbff8 | 1189 | if ((fd = open(argv[6], O_RDONLY)) == -1) |
74456259 | 1190 | { |
1191 | perror("ERROR: Unable to open raster file - "); | |
1192 | sleep(1); | |
1193 | return (1); | |
1194 | } | |
1195 | } | |
1196 | else | |
2e32fcdb | 1197 | fd = 0; |
74456259 | 1198 | |
2e32fcdb | 1199 | ras = cupsRasterOpen(fd, CUPS_RASTER_READ); |
74456259 | 1200 | |
6c5fbfa1 | 1201 | /* |
1202 | * Open the PPD file and apply options... | |
1203 | */ | |
1204 | ||
1205 | num_options = cupsParseOptions(argv[5], 0, &options); | |
1206 | ||
1207 | if ((ppd = ppdOpenFile(getenv("PPD"))) != NULL) | |
1208 | { | |
1209 | ppdMarkDefaults(ppd); | |
1210 | cupsMarkOptions(ppd, num_options, options); | |
1211 | } | |
1212 | ||
74456259 | 1213 | /* |
1214 | * Initialize the print device... | |
1215 | */ | |
1216 | ||
6c5fbfa1 | 1217 | Setup(ppd); |
74456259 | 1218 | |
1219 | /* | |
1220 | * Process pages as needed... | |
1221 | */ | |
1222 | ||
725dbff8 | 1223 | Page = 0; |
ea19a116 | 1224 | Canceled = 0; |
74456259 | 1225 | |
1226 | while (cupsRasterReadHeader(ras, &header)) | |
1227 | { | |
1228 | /* | |
1229 | * Write a status message with the page number and number of copies. | |
1230 | */ | |
1231 | ||
1232 | Page ++; | |
1233 | ||
1234 | fprintf(stderr, "PAGE: %d 1\n", Page); | |
1235 | ||
1236 | /* | |
1237 | * Start the page... | |
1238 | */ | |
1239 | ||
6c5fbfa1 | 1240 | StartPage(ppd, &header); |
74456259 | 1241 | |
1242 | /* | |
1243 | * Loop for each line on the page... | |
1244 | */ | |
1245 | ||
ea19a116 | 1246 | for (y = 0; y < header.cupsHeight && !Canceled; y ++) |
74456259 | 1247 | { |
1248 | /* | |
1249 | * Let the user know how far we have progressed... | |
1250 | */ | |
1251 | ||
1252 | if ((y & 15) == 0) | |
1253 | fprintf(stderr, "INFO: Printing page %d, %d%% complete...\n", Page, | |
1254 | 100 * y / header.cupsHeight); | |
1255 | ||
1256 | /* | |
1257 | * Read a line of graphics... | |
1258 | */ | |
1259 | ||
1260 | if (cupsRasterReadPixels(ras, Buffer, header.cupsBytesPerLine) < 1) | |
1261 | break; | |
1262 | ||
1263 | /* | |
725dbff8 | 1264 | * Write it to the printer... |
74456259 | 1265 | */ |
1266 | ||
6c5fbfa1 | 1267 | OutputLine(ppd, &header, y); |
74456259 | 1268 | } |
1269 | ||
1270 | /* | |
1271 | * Eject the page... | |
1272 | */ | |
1273 | ||
6c5fbfa1 | 1274 | EndPage(ppd, &header); |
725dbff8 | 1275 | |
ea19a116 | 1276 | if (Canceled) |
725dbff8 | 1277 | break; |
74456259 | 1278 | } |
1279 | ||
1280 | /* | |
1281 | * Close the raster stream... | |
1282 | */ | |
1283 | ||
1284 | cupsRasterClose(ras); | |
725dbff8 | 1285 | if (fd != 0) |
2e32fcdb | 1286 | close(fd); |
74456259 | 1287 | |
6c5fbfa1 | 1288 | /* |
1289 | * Close the PPD file and free the options... | |
1290 | */ | |
1291 | ||
1292 | ppdClose(ppd); | |
1293 | cupsFreeOptions(num_options, options); | |
1294 | ||
74456259 | 1295 | /* |
1296 | * If no pages were printed, send an error message... | |
1297 | */ | |
1298 | ||
1299 | if (Page == 0) | |
1300 | fputs("ERROR: No pages found!\n", stderr); | |
1301 | else | |
725dbff8 | 1302 | fputs("INFO: Ready to print.\n", stderr); |
74456259 | 1303 | |
1304 | return (Page == 0); | |
1305 | } | |
1306 | ||
1307 | ||
1308 | /* | |
c9d3f842 | 1309 | * End of "$Id$". |
74456259 | 1310 | */ |