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