Debian Codegraph @

src/main/print-dpl.c

raw symbols SCIP
1 /*
2 *
3 * Print plug-in Datamax-O'Neil DPL driver for Gutenprint.
4 *
5 * Copyright 1997-2000 Michael Sweet ([email protected]),
6 * Robert Krawitz ([email protected]) and
7 * Dave Hill ([email protected])
8 *
9 * Copyright 2016 Steve Letter ([email protected])
10 *
11 * This program is free software; you can redistribute it and/or modify it
12 * under the terms of the GNU General Public License as published by the Free
13 * Software Foundation; either version 2 of the License, or (at your option)
14 * any later version.
15 *
16 * This program is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
18 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19 * for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program. If not, see <https://www.gnu.org/licenses/>.
23 */
24
25 /*
26 * This file must include only standard C header files. The core code must
27 * compile on generic platforms that don't support glib, gimp, gtk, etc.
28 */
29
30 #ifdef HAVE_CONFIG_H
31 #include <config.h>
32 #endif
33 #include <gutenprint/gutenprint.h>
34 #include <gutenprint/gutenprint-intl-internal.h>
35 #include "gutenprint-internal.h"
36 #include "dither-impl.h"
37 #include <stdio.h>
38 #include <string.h>
39
40 #define DEBUG
41 #define DPL_DEBUG_DISABLE_BLANKLINE_REMOVAL
42
43 /*
44 * Local functions...
45 */
46 static void dpl_pcx (stp_vars_t *, unsigned char *, int, int);
47 static int dpl_get_multiplier (const stp_vars_t * v);
48
49 #ifndef MAX
50 #define MAX(a, b) ((a) > (b) ? (a) : (b))
51 #endif /* !MAX */
52
53 typedef struct
54 {
55 int height;
56 int orientation;
57 int label_separator;
58 unsigned int h_offset;
59 unsigned int v_offset;
60 int darkness;
61 int speed;
62 int present;
63 } dpl_privdata_t;
64
65 /*
66 * Generic define for a name/value set
67 */
68
69 typedef struct
70 {
71 const char *dpl_name;
72 const char *dpl_text;
73 int dpl_code;
74 int p0;
75 int p1;
76 } dpl_t;
77
78
79 #define DPL_RES_150_150 1
80 #define DPL_RES_203_203 2
81 #define DPL_RES_300_300 4
82 #define DPL_RES_400_400 8
83 #define DPL_RES_600_600 16
84
85 static const dpl_t dpl_resolutions[] = {
86 {"600dpi", N_("600x600 DPI"), DPL_RES_600_600, 600, 600},
87 {"400dpi", N_("400x400 DPI"), DPL_RES_400_400, 400, 400},
88 {"300dpi", N_("300x300 DPI"), DPL_RES_300_300, 300, 300},
89 {"203dpi", N_("203x203 DPI"), DPL_RES_203_203, 203, 203},
90 {"150dpi", N_("150x150 DPI"), DPL_RES_150_150, 150, 150},
91 };
92
93 #define NUM_RESOLUTIONS (sizeof(dpl_resolutions) / sizeof (dpl_t))
94
95 static const dpl_t dpl_speeds[] = {
96 {"A", N_("1.0 IPS"), 'A'},
97 {"B", N_("1.5 IPS"), 'B'},
98 {"C", N_("2.0 IPS"), 'C'},
99 {"D", N_("2.5 IPS"), 'D'},
100 {"E", N_("3.0 IPS"), 'E'},
101 {"F", N_("3.5 IPS"), 'F'},
102 {"G", N_("4.0 IPS"), 'G'},
103 {"H", N_("4.5 IPS"), 'H'},
104 {"I", N_("5.0 IPS"), 'I'},
105 {"J", N_("5.5 IPS"), 'J'},
106 {"K", N_("6.0 IPS"), 'K'},
107 {"L", N_("6.5 IPS"), 'L'},
108 {"M", N_("7.0 IPS"), 'M'},
109 {"N", N_("7.5 IPS"), 'N'},
110 {"O", N_("8.0 IPS"), 'O'},
111 {"P", N_("8.5 IPS"), 'P'},
112 {"Q", N_("9.0 IPS"), 'Q'},
113 {"R", N_("9.5 IPS"), 'R'},
114 {"S", N_("10.0 IPS"), 'S'},
115 {"T", N_("10.5 IPS"), 'T'},
116 {"U", N_("11.0 IPS"), 'U'},
117 {"V", N_("11.5 IPS"), 'V'},
118 {"W", N_("12.0 IPS"), 'W'},
119 };
120
121 #define NUM_SPEEDS (sizeof(dpl_speeds) / sizeof (dpl_t))
122
123 /*
124 * Printer capability data
125 */
126
127 typedef struct
128 {
129 int model;
130 unsigned int custom_max_width;
131 unsigned int custom_max_height;
132 unsigned int custom_min_width;
133 unsigned int custom_min_height;
134 int resolutions;
135 int max_resolution;
136 int resolution_adjust;
137 char max_speed;
138 char min_speed;
139 char default_speed;
140 } dpl_cap_t;
141
142 static const dpl_cap_t dpl_model_capabilities[] = {
143 /* Datamax-O'Neil Thermal DPL printers */
144 {10017, /* I Class Mark II 203 DPI */
145 4 * 72, 99 * 72, /* Max paper size */
146 1, 1, /* Min paper size */
147 DPL_RES_203_203,
148 DPL_RES_203_203,
149 DPL_RES_203_203,
150 'W',
151 'C',
152 'O',
153 },
154 /* Datamax-O'Neil Thermal DPL printers */
155 {10018, /* I Class Mark II 300 DPI */
156 4 * 72, 99 * 72, /* Max paper size */
157 1, 1, /* Min paper size */
158 DPL_RES_150_150 | DPL_RES_300_300, /* Resolutions */
159 DPL_RES_300_300,
160 DPL_RES_203_203,
161 'S',
162 'C',
163 'O',
164 },
165 /* Datamax-O'Neil Thermal DPL printers */
166 {10020, /* I Class Mark II 600 DPI */
167 4 * 72, 99 * 72, /* Max paper size */
168 1, 1, /* Min paper size */
169 /* for future use
170 DPL_RES_150_150 | DPL_RES_203_203 | DPL_RES_300_300 | DPL_RES_600_600, */
171 DPL_RES_300_300 | DPL_RES_600_600, /* Resolutions */
172 DPL_RES_600_600,
173 DPL_RES_300_300,
174 'K',
175 'C',
176 'G',
177 },
178 /* Datamax-O'Neil Thermal DPL printers */
179 {10021, /* E Class Mark III Basic 203 DPI*/
180 4 * 72, 99 * 72, /* Max paper size */
181 1, 1, /* Min paper size */
182 DPL_RES_203_203, /* Resolutions */
183 DPL_RES_203_203,
184 DPL_RES_203_203,
185 'G',
186 'C',
187 'E',
188 },
189 /* Datamax-O'Neil Thermal DPL printers */
190 {10022, /* E Class Mark III Basic 300 DPI*/
191 4 * 72, 99 * 72, /* Max paper size */
192 1, 1, /* Min paper size */
193 DPL_RES_300_300, /* Resolutions */
194 DPL_RES_300_300,
195 DPL_RES_300_300,
196 'G',
197 'C',
198 'E',
199 },
200 /* Datamax-O'Neil Thermal DPL printers */
201 {10023, /* E Class Mark III Advanced 203 DPI*/
202 4 * 72, 99 * 72, /* Max paper size */
203 1, 1, /* Min paper size */
204 DPL_RES_203_203, /* Resolutions */
205 DPL_RES_203_203,
206 DPL_RES_203_203,
207 'I',
208 'C',
209 'E',
210 },
211 /* Datamax-O'Neil Thermal DPL printers */
212 {10024, /* E Class Mark III Advanced 300 DPI*/
213 4 * 72, 99 * 72, /* Max paper size */
214 1, 1, /* Min paper size */
215 DPL_RES_300_300, /* Resolutions */
216 DPL_RES_300_300,
217 DPL_RES_300_300,
218 'I',
219 'C',
220 'G',
221 },
222 /* Datamax-O'Neil Thermal DPL printers */
223 {10025, /* E Class Mark III Pro 203 DPI*/
224 4 * 72, 99 * 72, /* Max paper size */
225 1, 1, /* Min paper size */
226 DPL_RES_203_203, /* Resolutions */
227 DPL_RES_203_203,
228 DPL_RES_203_203,
229 'K',
230 'C',
231 'G',
232 },
233 /* Datamax-O'Neil Thermal DPL printers */
234 {10026, /* E Class Mark III Pro 300 DPI*/
235 4 * 72, 99 * 72, /* Max paper size */
236 1, 1, /* Min paper size */
237 DPL_RES_300_300, /* Resolutions */
238 DPL_RES_300_300,
239 DPL_RES_300_300,
240 'I',
241 'C',
242 'G',
243 },
244 /* Datamax-O'Neil Thermal DPL printers */
245 {10027, /* E Class Mark III ProPlus 203 DPI*/
246 4 * 72, 99 * 72, /* Max paper size */
247 1, 1, /* Min paper size */
248 DPL_RES_203_203, /* Resolutions */
249 DPL_RES_203_203,
250 DPL_RES_203_203,
251 'K',
252 'C',
253 'G',
254 },
255 /* Datamax-O'Neil Thermal DPL printers */
256 {10028, /* E Class Mark III ProPlus 300 DPI*/
257 4 * 72, 99 * 72, /* Max paper size */
258 1, 1, /* Min paper size */
259 DPL_RES_300_300, /* Resolutions */
260 DPL_RES_300_300,
261 DPL_RES_300_300,
262 'I',
263 'C',
264 'G',
265 },
266 /* Datamax-O'Neil Thermal DPL printers */
267 {10029, /* RL3e */
268 3 * 72, 99 * 72, /* Max paper size */
269 1, 1, /* Min paper size */
270 DPL_RES_203_203, /* Resolutions */
271 DPL_RES_203_203,
272 DPL_RES_203_203,
273 'G',
274 'A',
275 'E',
276 },
277 /* Datamax-O'Neil Thermal DPL printers */
278 {10030, /* RL4e */
279 4 * 72, 99 * 72, /* Max paper size */
280 1, 1, /* Min paper size */
281 DPL_RES_203_203, /* Resolutions */
282 DPL_RES_203_203,
283 DPL_RES_203_203,
284 'G',
285 'A',
286 'E',
287 },
288 /* Datamax-O'Neil Thermal DPL printers */
289 {10031, /* H4212 */
290 4 * 72, 99 * 72, /* Max paper size */
291 1, 1, /* Min paper size */
292 DPL_RES_203_203, /* Resolutions */
293 DPL_RES_203_203, /* Max Resolution */
294 DPL_RES_203_203, /* Resolution Adjust */
295 'W', /* Maximum IPS */
296 'C', /* Minimum IPS */
297 'O', /* Default IPS */
298 },
299 /* Datamax-O'Neil Thermal DPL printers */
300 {10032, /* H4212X */
301 4 * 72, 99 * 72, /* Max paper size */
302 1, 1, /* Min paper size */
303 DPL_RES_203_203, /* Resolutions */
304 DPL_RES_203_203, /* Max Resolution */
305 DPL_RES_203_203, /* Resolution Adjust */
306 'W', /* Maximum IPS */
307 'C', /* Minimum IPS */
308 'O', /* Default IPS */
309 },
310 /* Datamax-O'Neil Thermal DPL printers */
311 {10033, /* H4310 */
312 4 * 72, 99 * 72, /* Max paper size */
313 1, 1, /* Min paper size */
314 DPL_RES_150_150 | DPL_RES_300_300, /* Resolutions */
315 DPL_RES_300_300, /* Max Resolution */
316 DPL_RES_203_203, /* Resolution Adjust */
317 'S', /* Maximum IPS */
318 'C', /* Minimum IPS */
319 'O', /* Default IPS */
320 },
321 /* Datamax-O'Neil Thermal DPL printers */
322 {10034, /* H4310X */
323 4 * 72, 99 * 72, /* Max paper size */
324 1, 1, /* Min paper size */
325 DPL_RES_150_150 | DPL_RES_300_300, /* Resolutions */
326 DPL_RES_300_300, /* Max Resolution */
327 DPL_RES_203_203, /* Resolution Adjust */
328 'S', /* Maximum IPS */
329 'C', /* Minimum IPS */
330 'O', /* Default IPS */
331 },
332 /* Datamax-O'Neil Thermal DPL printers */
333 {10035, /* H4408 */
334 4 * 72, 99 * 72, /* Max paper size */
335 1, 1, /* Min paper size */
336 DPL_RES_400_400 | DPL_RES_203_203, /* Resolutions */
337 DPL_RES_203_203, /* Max Resolution */
338 DPL_RES_203_203, /* Resolution Adjust */
339 'O', /* Maximum IPS */
340 'C', /* Minimum IPS */
341 'G', /* Default IPS */
342 },
343 /* Datamax-O'Neil Thermal DPL printers */
344 {10036, /* H4606 */
345 4 * 72, 99 * 72, /* Max paper size */
346 1, 1, /* Min paper size */
347 DPL_RES_300_300 | DPL_RES_600_600, /* Resolutions */
348 DPL_RES_600_600, /* Max Resolution */
349 DPL_RES_300_300, /* Resolution Adjust */
350 'K', /* Maximum IPS */
351 'C', /* Minimum IPS */
352 'G', /* Default IPS */
353 },
354 /* Datamax-O'Neil Thermal DPL printers */
355 {10037, /* H4606X */
356 4 * 72, 99 * 72, /* Max paper size */
357 1, 1, /* Min paper size */
358 DPL_RES_300_300 | DPL_RES_600_600, /* Resolutions */
359 DPL_RES_600_600, /* Max Resolution */
360 DPL_RES_300_300, /* Resolution Adjust */
361 'K', /* Maximum IPS */
362 'C', /* Minimum IPS */
363 'G', /* Default IPS */
364 },
365 /* Datamax-O'Neil Thermal DPL printers */
366 {10038, /* H6210 */
367 6 * 72, 99 * 72, /* Max paper size */
368 1, 1, /* Min paper size */
369 DPL_RES_203_203, /* Resolutions */
370 DPL_RES_203_203, /* Max Resolution */
371 DPL_RES_203_203, /* Resolution Adjust */
372 'S', /* Maximum IPS */
373 'C', /* Minimum IPS */
374 'O', /* Default IPS */
375 },
376 /* Datamax-O'Neil Thermal DPL printers */
377 {10039, /* H6210X */
378 6 * 72, 99 * 72, /* Max paper size */
379 1, 1, /* Min paper size */
380 DPL_RES_203_203, /* Resolutions */
381 DPL_RES_203_203, /* Max Resolution */
382 DPL_RES_203_203, /* Resolution Adjust */
383 'S', /* Maximum IPS */
384 'C', /* Minimum IPS */
385 'O', /* Default IPS */
386 },
387 /* Datamax-O'Neil Thermal DPL printers */
388 {10040, /* H6212 */
389 6 * 72, 99 * 72, /* Max paper size */
390 1, 1, /* Min paper size */
391 DPL_RES_203_203, /* Resolutions */
392 DPL_RES_203_203, /* Max Resolution */
393 DPL_RES_203_203, /* Resolution Adjust */
394 'W', /* Maximum IPS */
395 'C', /* Minimum IPS */
396 'O', /* Default IPS */
397 },
398 /* Datamax-O'Neil Thermal DPL printers */
399 {10041, /* H6212X */
400 6 * 72, 99 * 72, /* Max paper size */
401 1, 1, /* Min paper size */
402 DPL_RES_203_203, /* Resolutions */
403 DPL_RES_203_203, /* Max Resolution */
404 DPL_RES_203_203, /* Resolution Adjust */
405 'W', /* Maximum IPS */
406 'C', /* Minimum IPS */
407 'O', /* Default IPS */
408 },
409 /* Datamax-O'Neil Thermal DPL printers */
410 {10042, /* H6308 */
411 6 * 72, 99 * 72, /* Max paper size */
412 1, 1, /* Min paper size */
413 DPL_RES_150_150 | DPL_RES_300_300, /* Resolutions */
414 DPL_RES_300_300, /* Max Resolution */
415 DPL_RES_203_203, /* Resolution Adjust */
416 'O', /* Maximum IPS */
417 'C', /* Minimum IPS */
418 'G', /* Default IPS */
419 },
420 /* Datamax-O'Neil Thermal DPL printers */
421 {10043, /* H6310X */
422 6 * 72, 99 * 72, /* Max paper size */
423 1, 1, /* Min paper size */
424 DPL_RES_150_150 | DPL_RES_300_300, /* Resolutions */
425 DPL_RES_300_300, /* Max Resolution */
426 DPL_RES_203_203, /* Resolution Adjust */
427 'S', /* Maximum IPS */
428 'C', /* Minimum IPS */
429 'O', /* Default IPS */
430 },
431 /* Datamax-O'Neil Thermal DPL printers */
432 {10044, /* H8308 */
433 8.5 * 72, 99 * 72, /* Max paper size */
434 1, 1, /* Min paper size */
435 DPL_RES_150_150 | DPL_RES_300_300, /* Resolutions */
436 DPL_RES_300_300, /* Max Resolution */
437 DPL_RES_203_203, /* Resolution Adjust */
438 'O', /* Maximum IPS */
439 'C', /* Minimum IPS */
440 'G', /* Default IPS */
441 },
442 /* Datamax-O'Neil Thermal DPL printers */
443 {10045, /* H8308X */
444 8.5 * 72, 99 * 72, /* Max paper size */
445 1, 1, /* Min paper size */
446 DPL_RES_150_150 | DPL_RES_300_300, /* Resolutions */
447 DPL_RES_300_300, /* Max Resolution */
448 DPL_RES_203_203, /* Resolution Adjust */
449 'O', /* Maximum IPS */
450 'C', /* Minimum IPS */
451 'G', /* Default IPS */
452 },
453 /* Honeywell Thermal DPL printers */
454 {10046, /* RP2 */
455 2 * 72, 99 * 72, /* Max paper size */
456 1, 1, /* Min paper size */
457 DPL_RES_203_203, /* Resolutions */
458 DPL_RES_203_203,
459 DPL_RES_203_203,
460 'I',
461 'A',
462 'E',
463 },
464 /* Honeywell Thermal DPL printers */
465 {10047, /* RP4 */
466 4 * 72, 99 * 72, /* Max paper size */
467 1, 1, /* Min paper size */
468 DPL_RES_203_203, /* Resolutions */
469 DPL_RES_203_203,
470 DPL_RES_203_203,
471 'I',
472 'A',
473 'E',
474 },
475 };
476
477 static const stp_parameter_t the_parameters[] = {
478 {
479 "PageSize", N_("Page Size"), "Color=No,Category=Basic Printer Setup",
480 N_("Size of the paper being printed to"),
481 STP_PARAMETER_TYPE_STRING_LIST, STP_PARAMETER_CLASS_CORE,
482 STP_PARAMETER_LEVEL_BASIC, 1, 1, STP_CHANNEL_NONE, 1, 0},
483 {
484 "Resolution", N_("Resolution"), "Color=No,Category=Basic Printer Setup",
485 N_("Resolution of the print"),
486 STP_PARAMETER_TYPE_STRING_LIST, STP_PARAMETER_CLASS_FEATURE,
487 STP_PARAMETER_LEVEL_BASIC, 1, 1, STP_CHANNEL_NONE, 1, 0},
488 {
489 "PrintingMode", N_("Printing Mode"), "Color=Yes,Category=Core Parameter",
490 N_("Printing Output Mode"),
491 STP_PARAMETER_TYPE_STRING_LIST, STP_PARAMETER_CLASS_CORE,
492 STP_PARAMETER_LEVEL_BASIC, 1, 1, STP_CHANNEL_NONE, 1, 0
493 },
494 #ifdef FIXME /* Orientation not available for graphics, need
495 * rotation routine in this driver */
496 {
497 "Orientation", N_("Orientation"), "Color=No,Category=Basic Printer Setup",
498 N_("Orientation, Portrait, Landscape, Upside Down, Seascape"),
499 STP_PARAMETER_TYPE_STRING_LIST, STP_PARAMETER_CLASS_FEATURE,
500 STP_PARAMETER_LEVEL_BASIC, 1, 1, STP_CHANNEL_NONE, 1, 0
501 },
502 #endif
503 {
504 "LabelSeparator", N_("Media Index Type"),
505 "Color=No,Category=Basic Printer Setup",
506 N_("Gap, Notch, Hole, Black Mark, Continuous"),
507 STP_PARAMETER_TYPE_STRING_LIST, STP_PARAMETER_CLASS_FEATURE,
508 STP_PARAMETER_LEVEL_BASIC, 1, 1, STP_CHANNEL_NONE, 1, 0,
509 },
510 {
511 "Darkness", N_("Darkness"), "Color=No,Category=Basic Printer Setup",
512 N_("Darkness Adjust, from 0 to 30"),
513 STP_PARAMETER_TYPE_INT, STP_PARAMETER_CLASS_FEATURE,
514 STP_PARAMETER_LEVEL_BASIC, 0, 1, STP_CHANNEL_NONE, 1, 0},
515 {
516 "Speed", N_("Print Speed"), "Color=No,Category=Basic Printer Setup",
517 N_("Speed Adjust"),
518 STP_PARAMETER_TYPE_STRING_LIST, STP_PARAMETER_CLASS_FEATURE,
519 STP_PARAMETER_LEVEL_BASIC, 1, 1, STP_CHANNEL_NONE, 0, 0},
520 };
521
522 static const unsigned int the_parameter_count =
523 sizeof (the_parameters) / sizeof (const stp_parameter_t);
524
525 typedef struct
526 {
527 const stp_parameter_t param;
528 double min;
529 double max;
530 double defval;
531 int color_only;
532 } float_param_t;
533
534 static const float_param_t float_parameters[] = {
535 {
536 {
537 "HorizOffset", N_("Horizontal Offset"),
538 "Color=No,Category=Basic Output Adjustment",
539 N_("Adjust horizontal position"),
540 STP_PARAMETER_TYPE_DOUBLE, STP_PARAMETER_CLASS_OUTPUT,
541 STP_PARAMETER_LEVEL_ADVANCED3, 1, 1, STP_CHANNEL_NONE, 1, 0,
542 }, 0.0, 4.0, 0.0, 0},
543 {
544 {
545 "VertOffset", N_("Vertical Offset"),
546 "Color=No,Category=Basic Output Adjustment",
547 N_("Adjust vertical position"),
548 STP_PARAMETER_TYPE_DOUBLE, STP_PARAMETER_CLASS_OUTPUT,
549 STP_PARAMETER_LEVEL_ADVANCED3, 1, 1, STP_CHANNEL_NONE, 1, 0,
550 }, 0.0, 10.0, 0.0, 0},
551 {
552 {
553 "Present", N_("Present Distance"),
554 "Color=No,Category=Basic Output Adjustment",
555 N_("Presnt Distance, 0.0 advances the default."),
556 STP_PARAMETER_TYPE_DOUBLE, STP_PARAMETER_CLASS_FEATURE,
557 STP_PARAMETER_LEVEL_BASIC, 1, 1, STP_CHANNEL_NONE, 1, 0,
558 }, 0.0, 10.0, 0.0, 0},
559 };
560
561 static const unsigned int float_parameter_count =
562 sizeof (float_parameters) / sizeof (const float_param_t);
563
564 /*
565 * Convert a value into it's option name
566 */
567
568 static const char *
569 dpl_val_to_string (const stp_vars_t *v,
570 int code, /* I: Code */
571 const dpl_t * options, /* I: Options */
572 int num_options) /* I: Num options */
573 {
574
575 int i;
576 const char *string = NULL;
577
578 /*
579 * Look up the code in the table and convert to the string.
580 */
581
582 for (i = 0; i < num_options; i++)
583 {
584 if (code == options[i].dpl_code)
585 {
586 string = options[i].dpl_name;
587 break;
588 }
589 }
590
591 stp_dprintf (STP_DBG_DPL, v, "Code: %d, String: %s\n", code, string);
592
593 return (string);
594 }
595
596 static const char *
597 dpl_val_to_text (const stp_vars_t *v,
598 int code, /* I: Code */
599 const dpl_t * options, /* I: Options */
600 int num_options) /* I: Num options */
601 {
602
603 int i;
604 const char *string = "<null>";
605
606 /*
607 * Look up the code in the table and convert to the string.
608 */
609
610 for (i = 0; i < num_options; i++)
611 {
612 if (code == options[i].dpl_code)
613 {
614 string = gettext (options[i].dpl_text);
615 break;
616 }
617 }
618
619 stp_dprintf (STP_DBG_DPL, v, "Code: %d, String: %s\n", code, string);
620
621 return (string);
622 }
623
624 /*
625 * dpl_get_model_capabilities() - Return struct of model capabilities
626 */
627
628 static const dpl_cap_t * /* O: Capabilities */
629 dpl_get_model_capabilities (const stp_vars_t *v) /* I: Model */
630 {
631 int i;
632 int model = stp_get_model_id(v);
633 int models = sizeof (dpl_model_capabilities) / sizeof (dpl_cap_t);
634 for (i = 0; i < models; i++)
635 {
636 if (dpl_model_capabilities[i].model == model)
637 {
638 return &(dpl_model_capabilities[i]);
639 }
640 }
641 stp_eprintf (v, "dpl: model %d not found in capabilities list.\n", model);
642 return &(dpl_model_capabilities[0]);
643 }
644
645 /*
646 * Determine the current resolution
647 */
648
649 static void
650 dpl_describe_resolution (const stp_vars_t * v, stp_resolution_t *x, stp_resolution_t *y)
651 {
652 unsigned int i;
653 const char *resolution = stp_get_string_parameter (v, "Resolution");
654
655 *x = -1;
656 *y = -1;
657 if (resolution)
658 {
659 for (i = 0; i < NUM_RESOLUTIONS; i++)
660 {
661 if (!strcmp (resolution, dpl_resolutions[i].dpl_name))
662 {
663 *x = dpl_resolutions[i].p0;
664 *y = dpl_resolutions[i].p1;
665 }
666 }
667 }
668 if (*x != *y) {
669 if (*x > *y) {
670 *y = *x;
671 } else {
672 *x = *y;
673 }
674 }
675 }
676
677 int
678 dpl_get_multiplier (const stp_vars_t * v)
679 {
680 stp_resolution_t x, y;
681 int multiplier;
682 unsigned int i;
683 int max_dpi = 0;
684
685 const dpl_cap_t *caps = dpl_get_model_capabilities (v);
686
687 for (i = 0; i < NUM_RESOLUTIONS; i++)
688 {
689 if (caps->max_resolution == dpl_resolutions[i].dpl_code)
690 {
691 max_dpi = dpl_resolutions[i].p0;
692 }
693 }
694
695 // XXX error if max_dpi is 0?
696
697 dpl_describe_resolution (v, &x, &y);
698
699 if (x == max_dpi)
700 multiplier = 1;
701 else
702 multiplier = 2;
703
704 return multiplier;
705 }
706
707 #ifdef FIXME
708 /*
709 * Orientation support - modes available
710 * Note that the internal names MUST match those in cups/genppd.c else the
711 * PPD files will not be generated correctly
712 */
713
714 static const stp_param_string_t orientation_types[] = {
715 {"Portrait", N_("Portrait")},
716 {"Landscape", N_("Landscape")},
717 {"UpsideDown", N_("Reverse Portrait")},
718 {"Seascape", N_("Reverse Landscape")},
719 };
720
721 #define NUM_ORIENTATION (sizeof (orientation_types) / sizeof (stp_param_string_t))
722 #endif
723
724 /*
725 * Label Separator Support for D-O printers, modes available
726 */
727
728 static const stp_param_string_t label_separator_types[] = {
729 {"IGNORE", N_("Printer Setting")},
730 {"GAP", N_("Gap")},
731 {"NOTCH", N_("Notch")},
732 {"HOLE", N_("Hole")},
733 {"MARK", N_("Black Mark")},
734 {"CONTINUOUS", N_("Continuous")},
735 };
736
737 #define NUM_LABEL_SEPARATOR (sizeof (label_separator_types) / sizeof (stp_param_string_t))
738
739 /*
740 * 'dpl_papersize_valid()' - Is the paper size valid for this printer.
741 */
742
743 static int
744 dpl_papersize_valid (const stp_vars_t *v, const stp_papersize_t * pt)
745 {
746 const dpl_cap_t *caps = dpl_get_model_capabilities (v);
747 unsigned int pwidth = pt->width;
748 unsigned int pheight = pt->height;
749
750 /*
751 * Is it a valid name?
752 */
753
754 if (strlen (pt->name) <= 0)
755 return (0);
756
757 /*
758 * We are allowed custom paper sizes. Check that the size is within
759 * limits. Check that the name contains d-o if this is the
760 * Datamax O'Neil label printer and not custom paper
761 */
762
763 if (pwidth <= caps->custom_max_width &&
764 pheight <= caps->custom_max_height &&
765 (pheight >= caps->custom_min_height || pheight == 0) &&
766 (pwidth >= caps->custom_min_width || pwidth == 0))
767 {
768 if (strcmp (pt->name, "Custom"))
769 {
770 if (NULL != strstr (pt->name, "d-o"))
771 {
772 return (1);
773 }
774 else
775 {
776 return (0);
777 }
778 }
779 }
780
781 return (0);
782 }
783
784 /*
785 * 'dpl_parameters()' - Return the parameter values for the given parameter.
786 */
787
788 static stp_parameter_list_t
789 dpl_list_parameters (const stp_vars_t * v)
790 {
791 stp_parameter_list_t *ret;
792 unsigned int i;
793 (void)v;
794
795 ret = stp_parameter_list_create ();
796 for (i = 0; i < the_parameter_count; i++)
797 stp_parameter_list_add_param (ret, &(the_parameters[i]));
798 for (i = 0; i < float_parameter_count; i++)
799 stp_parameter_list_add_param (ret, &(float_parameters[i].param));
800 return ret;
801 }
802
803 static void
804 dpl_parameters (const stp_vars_t * v, const char *name,
805 stp_parameter_t * description)
806 {
807 int model = stp_get_model_id (v);
808 unsigned int i;
809 const dpl_cap_t *caps;
810 description->p_type = STP_PARAMETER_TYPE_INVALID;
811
812 if (name == NULL)
813 return;
814
815 stp_dprintf (STP_DBG_DPL, v, "dpl_parameters(): Name = %s\n", name);
816
817 caps = dpl_get_model_capabilities (v);
818
819 stp_dprintf (STP_DBG_DPL, v, "Printer model = %d\n", model);
820 stp_dprintf (STP_DBG_DPL, v, "PageWidth = %d, PageHeight = %d\n",
821 caps->custom_max_width, caps->custom_max_height);
822 stp_dprintf (STP_DBG_DPL, v, "MinPageWidth = %d, MinPageHeight = %d\n",
823 caps->custom_min_width, caps->custom_min_height);
824 stp_dprintf (STP_DBG_DPL, v, "Resolutions: %d\n", caps->resolutions);
825
826 for (i = 0; i < the_parameter_count; i++)
827 if (strcmp (name, the_parameters[i].name) == 0)
828 {
829 stp_fill_parameter_settings (description, &(the_parameters[i]));
830 break;
831 }
832 description->deflt.str = NULL;
833
834 for (i = 0; i < float_parameter_count; i++)
835 if (strcmp (name, float_parameters[i].param.name) == 0)
836 {
837 stp_fill_parameter_settings (description,
838 &(float_parameters[i].param));
839 description->deflt.dbl = float_parameters[i].defval;
840 description->bounds.dbl.upper = float_parameters[i].max;
841 description->bounds.dbl.lower = float_parameters[i].min;
842 break;
843 }
844
845 if (strcmp (name, "PageSize") == 0)
846 {
847 const stp_papersize_list_t *paper_sizes =
848 stpi_get_papersize_list_named("labels", "");
849 const stp_papersize_list_item_t *ptli =
850 stpi_papersize_list_get_start(paper_sizes);
851 description->bounds.str = stp_string_list_create ();
852 while (ptli)
853 {
854 const stp_papersize_t *pt = stpi_paperlist_item_get_data(ptli);
855 if (strlen (pt->name) > 0 && dpl_papersize_valid (v, pt))
856 stp_string_list_add_string(description->bounds.str,
857 pt->name, gettext(pt->text));
858 ptli = stpi_paperlist_item_next(ptli);
859 }
860 description->deflt.str =
861 stp_string_list_param (description->bounds.str, 0)->name;
862 }
863 else if (strcmp (name, "Resolution") == 0)
864 {
865 description->bounds.str = stp_string_list_create ();
866 description->deflt.str =
867 dpl_val_to_string (v, caps->max_resolution, dpl_resolutions,
868 NUM_RESOLUTIONS);
869 for (i = 0; i < NUM_RESOLUTIONS; i++)
870 if (caps->resolutions & dpl_resolutions[i].dpl_code)
871 {
872 stp_string_list_add_string
873 (description->bounds.str,
874 dpl_val_to_string (v, dpl_resolutions[i].dpl_code,
875 dpl_resolutions, NUM_RESOLUTIONS),
876 dpl_val_to_text (v, dpl_resolutions[i].dpl_code,
877 dpl_resolutions, NUM_RESOLUTIONS));
878 }
879 }
880 else if (strcmp(name, "PrintingMode") == 0)
881 {
882 description->bounds.str = stp_string_list_create();
883 stp_string_list_add_string
884 (description->bounds.str, "BW", _("Black and White"));
885 description->deflt.str =
886 stp_string_list_param(description->bounds.str, 0)->name;
887 }
888 #ifdef FIXME
889 else if (strcmp (name, "Orientation") == 0)
890 {
891 description->bounds.str = stp_string_list_create ();
892 description->deflt.str = orientation_types[0].name;
893 for (i = 0; i < NUM_ORIENTATION; i++)
894 {
895 stp_string_list_add_string (description->bounds.str,
896 orientation_types[i].name,
897 gettext (orientation_types[i].text));
898 }
899 }
900 #endif
901 else if (strcmp (name, "LabelSeparator") == 0)
902 {
903 description->bounds.str = stp_string_list_create ();
904 description->deflt.str = label_separator_types[0].name;
905 for (i = 0; i < NUM_LABEL_SEPARATOR; i++)
906 {
907 stp_string_list_add_string (description->bounds.str,
908 label_separator_types[i].name,
909 gettext (label_separator_types[i].
910 text));
911 }
912 }
913 else if (strcmp (name, "Darkness") == 0)
914 {
915 description->deflt.integer = -1;
916 description->bounds.integer.lower = 0;
917 description->bounds.integer.upper = 30;
918 }
919 else if (strcmp (name, "Speed") == 0)
920 {
921 description->bounds.str = stp_string_list_create ();
922 stp_string_list_add_string (description->bounds.str, "None",
923 _("Use Current Setting"));
924 stp_string_list_add_string (description->bounds.str, "Default",
925 _("Use Default Setting"));
926 description->deflt.str = "None";
927 for (i = 0; i < NUM_SPEEDS; i++)
928 {
929 stp_string_list_add_string (description->bounds.str,
930 dpl_speeds[i].dpl_name,
931 gettext (dpl_speeds[i].
932 dpl_text));
933 }
934 }
935 else if (strcmp (name, "HorizOffset") == 0 ||
936 strcmp (name, "VertOffset") == 0 || strcmp (name, "Present") == 0)
937 {
938 description->is_active = 1;
939 }
940 }
941
942
943 /*
944 * 'dpl_imageable_area()' - Return the imageable area of the page.
945 */
946 static void
947 internal_imageable_area (const stp_vars_t * v, /* I */
948 stp_dimension_t *left, /* O - Left position in points */
949 stp_dimension_t *right, /* O - Right position in points */
950 stp_dimension_t *bottom, /* O - Bottom position in points */
951 stp_dimension_t *top) /* O - Top position in points */
952 {
953 stp_dimension_t width, height; /* Size of page */
954
955 stp_default_media_size (v, &width, &height);
956
957 *left = 0;
958 *right = width;
959 *top = 0;
960 *bottom = height;
961 }
962
963 static void
964 dpl_imageable_area (const stp_vars_t * v, /* I */
965 stp_dimension_t *left, /* O - Left position in points */
966 stp_dimension_t *right, /* O - Right position in points */
967 stp_dimension_t *bottom, /* O - Bottom position in points */
968 stp_dimension_t *top) /* O - Top position in points */
969 {
970 internal_imageable_area (v, left, right, bottom, top);
971 }
972
973 static void
974 dpl_limit (const stp_vars_t * v, /* I */
975 stp_dimension_t *width, stp_dimension_t *height, stp_dimension_t *min_width, stp_dimension_t *min_height)
976 {
977 const dpl_cap_t *caps = dpl_get_model_capabilities (v);
978 *width = caps->custom_max_width;
979 *height = caps->custom_max_height;
980 *min_width = caps->custom_min_width;
981 *min_height = caps->custom_min_height;
982 }
983
984 static const char *
985 dpl_describe_output (const stp_vars_t * v)
986 {
987 (void)v;
988 return "Grayscale";
989 }
990
991 static const stp_papersize_t *
992 dpl_describe_papersize(const stp_vars_t *v, const char *name)
993 {
994 (void)v;
995 return stpi_get_listed_papersize(name, "labels");
996 }
997
998 static void
999 pcx_header (stp_vars_t * v, stp_image_t * image)
1000 {
1001 unsigned short height;
1002 unsigned short right;
1003 unsigned short top; /* y = 0 is at bottom */
1004 unsigned short bytes;
1005 short xdpi;
1006 stp_resolution_t r_xdpi;
1007 stp_resolution_t *xdpi_p = (&r_xdpi);
1008 short ydpi;
1009 stp_resolution_t r_ydpi;
1010 stp_resolution_t *ydpi_p = (&r_ydpi);
1011 int n;
1012 const short zero = 0;
1013
1014 stp_putc (10, v); /* Signature */
1015 stp_putc (5, v); /* Version */
1016 stp_putc (1, v); /* RLE encoding */
1017 stp_putc (1, v); /* bits per pixel */
1018
1019 /* Get resolutions */
1020 dpl_describe_resolution (v, xdpi_p, ydpi_p);
1021
1022 xdpi = (short) r_xdpi;
1023 ydpi = (short) r_ydpi;
1024
1025 bytes = (xdpi * 4 + 7 ) / 8; /* must be an even number */
1026 if (bytes != (bytes & 0xfffe))
1027 bytes++;
1028
1029 height = stp_image_height (image);
1030
1031 /*
1032 * Convert image size to printer resolution and setup the page for printing...
1033 */
1034
1035 right = 4 * xdpi - 1;
1036 top = height - 1;
1037
1038 /* send image start and end positions */
1039 stp_zfwrite ((const char *) &zero, 2, 1, v);
1040 stp_zfwrite ((const char *) &zero, 2, 1, v);
1041 stp_zfwrite ((const char *) &right, 2, 1, v);
1042 stp_zfwrite ((const char *) &top, 2, 1, v);
1043
1044 /* send resolutions */
1045 stp_zfwrite ((const char *) &xdpi, 2, 1, v);
1046 stp_zfwrite ((const char *) &ydpi, 2, 1, v);
1047
1048 /* send palette and reserved byte */
1049 for (n = 0; n < 3; n++)
1050 stp_putc (0, v);
1051 for (n = 0; n < 45; n++)
1052 stp_putc (0xff, v);
1053 stp_putc (0, v);
1054
1055 stp_putc (1, v); /* number of planes, monochrome */
1056
1057 stp_zfwrite ((const char *) &bytes, 2, 1, v);
1058
1059 stp_putc (1, v); /* monochrome */
1060 stp_putc (0, v);
1061
1062 stp_putc (0, v); /* imagee size */
1063 stp_putc (0, v);
1064 stp_putc (0, v);
1065 stp_putc (0, v);
1066
1067 for (n = 0; n < 54; n++)
1068 stp_putc (0, v); /* padding */
1069 }
1070
1071 /*
1072 * 'dpl_print()' - Print an image to an HP printer.
1073 */
1074
1075 static void
1076 dpl_printfunc (stp_vars_t * v, int height)
1077 {
1078 unsigned char *black = stp_dither_get_channel (v, STP_ECOLOR_K, 0);
1079
1080 dpl_pcx (v, black, (height + 7) / 8, 1);
1081 }
1082
1083 static double
1084 get_double_param (stp_vars_t * v, const char *param)
1085 {
1086 if (param && stp_check_float_parameter (v, param, STP_PARAMETER_ACTIVE))
1087 return stp_get_float_parameter (v, param);
1088 else
1089 return 1.0;
1090 }
1091
1092 static int
1093 dpl_do_print (stp_vars_t * v, stp_image_t * image)
1094 {
1095 dpl_privdata_t privdata;
1096 int status = 1;
1097 #ifdef FIXME
1098 const char *orientation_mode = stp_get_string_parameter (v, "Orientation");
1099 #endif
1100 const char *label_separator_mode =
1101 stp_get_string_parameter (v, "LabelSeparator");
1102 double h_offset = get_double_param (v, "HorizOffset");
1103 double v_offset = get_double_param (v, "VertOffset");
1104 double present = get_double_param (v, "Present");
1105 int y; /* Looping vars */
1106 stp_resolution_t xdpi, ydpi; /* Resolution */
1107 int multiplier;
1108 unsigned char *black; /* Black bitmap data */
1109 unsigned zero_mask;
1110 int image_height;
1111 int image_width;
1112 const dpl_cap_t *caps = dpl_get_model_capabilities (v);
1113 const char *speed = stp_get_string_parameter(v, "Speed");
1114
1115 if (!stp_verify (v))
1116 {
1117 stp_eprintf (v, "Print options not verified; cannot print.\n");
1118 return 0;
1119 }
1120
1121 /*
1122 * Setup a read-only pixel region for the entire image...
1123 */
1124
1125 stp_image_init (image);
1126
1127 stp_set_string_parameter (v, "ColorCorrection", "None");
1128 #ifdef TESTING
1129 stp_set_float_parameter (v, "Brightness", 1.0);
1130 stp_set_float_parameter (v, "Contrast", 1.0);
1131 stp_set_float_parameter (v, "Gamma", 1.0);
1132 #endif
1133 /*
1134 * Figure out the output resolution...
1135 */
1136
1137 dpl_describe_resolution (v, &xdpi, &ydpi);
1138
1139 stp_dprintf (STP_DBG_DPL, v, "dpl: resolution=%dx%d\n", (int) xdpi, (int) ydpi);
1140 if (xdpi <= 0 || ydpi <= 0)
1141 {
1142 stp_eprintf (v, "No resolution found; cannot print.\n");
1143 return 0;
1144 }
1145
1146 image_height = stp_image_height (image);
1147 image_width = stp_image_width (image);
1148
1149 #ifdef FIXME
1150 privdata.orientation = 0;
1151 if ((strncmp (orientation_mode, "Landscape", 9) == 0))
1152 privdata.orientation = 1;
1153 else if ((strncmp (orientation_mode, "UpsideDown", 10) == 0))
1154 privdata.orientation = 2;
1155 else if ((strncmp (orientation_mode, "Seascape", 8) == 0))
1156 privdata.orientation = 3;
1157 #endif
1158
1159 /*
1160 * Label Separator mode
1161 */
1162 privdata.label_separator = 0;
1163 if ((strncmp (label_separator_mode, "GAP", 3) == 0))
1164 privdata.label_separator = 1;
1165 else if ((strncmp (label_separator_mode, "NOTCH", 5) == 0))
1166 privdata.label_separator = 1;
1167 else if ((strncmp (label_separator_mode, "HOLE", 4) == 0))
1168 privdata.label_separator = 1;
1169 else if ((strncmp (label_separator_mode, "MARK", 4) == 0))
1170 privdata.label_separator = 2;
1171 else if ((strncmp (label_separator_mode, "CONTINUOUS", 10) == 0))
1172 privdata.label_separator = 3;
1173
1174 /*
1175 * Print Offsets
1176 */
1177 privdata.h_offset = (int) (h_offset * 100); /* in 0.01 of an inch */
1178 privdata.v_offset = (int) (v_offset * 100); /* in 0.01 of an inch */
1179
1180 privdata.present = (int) (present * 100.0); /* in 0.01 of an inch */
1181
1182 /*
1183 * Darkness Mode
1184 */
1185 if (-1 != (privdata.darkness = stp_get_int_parameter (v, "Darkness")))
1186 {
1187 if (0 == privdata.darkness)
1188 {
1189 privdata.darkness = 10; /* default */
1190 }
1191 }
1192
1193 /*
1194 * Speed Mode
1195 */
1196 privdata.speed = 0;
1197 if (0 != strcmp("None", speed))
1198 {
1199 if (0 == strcmp("Default", speed))
1200 {
1201 privdata.speed = (int) caps->default_speed;
1202 }
1203 else
1204 {
1205 unsigned int i;
1206 for (i = 0; i < NUM_SPEEDS; i++)
1207 {
1208 if (0 == strcmp(dpl_speeds[i].dpl_name, speed))
1209 {
1210 privdata.speed = dpl_speeds[i].dpl_code;
1211 break;
1212 }
1213 }
1214 if (caps->min_speed > (char) (privdata.speed))
1215 {
1216 privdata.speed = caps->min_speed;
1217 }
1218 else
1219 {
1220 if (caps->max_speed < (char) (privdata.speed))
1221 {
1222 privdata.speed = caps->max_speed;
1223 }
1224 }
1225 }
1226 }
1227
1228 /* workaround for printer bug */
1229 for (y=0; y<64; y++)
1230 stp_putc (0, v);
1231
1232 /*
1233 * Send DPL initialization commands...
1234 */
1235 stp_puts ("\002n\r", v); /* set Imperial units */
1236
1237 /* Max page length */
1238 if (image_height / ydpi > 4)
1239 {
1240 stp_zprintf (v, "\002M%04i\r",
1241 300 * image_height / ((int) ydpi) + (3 * privdata.v_offset));
1242 }
1243 else
1244 {
1245 stp_zprintf (v, "\002M%04i\r", 1200 + (3 * privdata.v_offset));
1246 }
1247 /* set Label Width */
1248 stp_zprintf (v, "\002KcLW%04i\r",
1249 100 * image_width / ((int) xdpi) + privdata.h_offset);
1250 if (0 != privdata.label_separator)
1251 {
1252 if (1 == privdata.label_separator)
1253 {
1254 stp_puts ("\002e\r", v); /* edge mode */
1255 }
1256 else if (2 == privdata.label_separator)
1257 {
1258 stp_puts ("\002r\r", v); /* Mark mode */
1259 }
1260 else
1261 {
1262 stp_zprintf (v, "\002c%04i\r", 100 * /* Continuous mode */
1263 image_height / ((int) ydpi) + privdata.v_offset);
1264 }
1265 }
1266 if (privdata.darkness > -1)
1267 {
1268 stp_zprintf (v, "\002KZH%02i\r", privdata.darkness);
1269 }
1270 if (privdata.speed > 0)
1271 {
1272 stp_zprintf (v, "\002KZP%c\r", privdata.speed);
1273 }
1274 stp_zprintf (v, "\002Kf%04i\r", privdata.present);
1275 stp_puts ("\002IDPcups0\r", v); /* Save PCX file */
1276 pcx_header (v, image);
1277
1278
1279 stp_dprintf (STP_DBG_DPL, v, "Normal init\n");
1280
1281 /*
1282 * Allocate memory for the raster data...
1283 */
1284
1285 black = stp_malloc ((image_width + 7) / 8);
1286
1287 stp_set_string_parameter (v, "STPIOutputType", "Grayscale");
1288
1289 /* set up for very fast dithering as default */
1290 stp_set_string_parameter (v, "DitherAlgorithm", "VeryFast");
1291
1292 stp_dither_init (v, image, image_width, xdpi, ydpi);
1293
1294 stp_dither_add_channel (v, black, STP_ECOLOR_K, 0);
1295 stp_channel_set_black_channel (v, STP_ECOLOR_K);
1296
1297 stp_channel_set_density_adjustment (v, STP_ECOLOR_K, 0,
1298 get_double_param (v, "BlackDensity") *
1299 1);
1300
1301 (void) stp_color_init (v, image, 65536);
1302
1303 stp_allocate_component_data (v, "Driver", NULL, NULL, &privdata);
1304
1305 for (y = 0; y < image_height; y++)
1306 {
1307 if (stp_color_get_row (v, image, y, &zero_mask))
1308 {
1309 status = 2;
1310 break;
1311 }
1312 stp_dither (v, y, 0, 0, NULL);
1313 dpl_printfunc (v, image_width);
1314 }
1315
1316 stp_puts ("\r\002L\r", v); /* enter Label Formatting mode */
1317 multiplier = dpl_get_multiplier (v); /* dot multiplier */
1318 stp_zprintf (v, "D%1i%1i\r", multiplier, multiplier);
1319 stp_puts ("R0000\r", v); /* 0 offset, offset handled below */
1320 stp_puts ("A2\r", v); /* transparent mode */
1321 /* load graphic */
1322 stp_zprintf (v, "1Y11000%04i%04icups0\r", privdata.v_offset,
1323 privdata.h_offset);
1324 stp_puts ("Q0001\r", v); /* one label */
1325 stp_puts ("E\r", v); /* print now */
1326 stp_puts ("\002xDGcups0\r", v); /* delete graphic */
1327 #if 0
1328 stp_puts ("\002zD\r", v); /* reclaim space */
1329 #endif
1330
1331 stp_image_conclude (image);
1332
1333 /*
1334 * Cleanup...
1335 */
1336
1337 if (black != NULL)
1338 stp_free (black);
1339
1340 return status;
1341 }
1342
1343 static int
1344 dpl_print (const stp_vars_t * v, stp_image_t * image)
1345 {
1346 int status;
1347 stp_vars_t *nv = stp_vars_create_copy (v);
1348 stp_prune_inactive_options (nv);
1349 status = dpl_do_print (nv, image);
1350 stp_vars_destroy (nv);
1351 return status;
1352 }
1353
1354 static const stp_printfuncs_t print_dpl_printfuncs = {
1355 dpl_list_parameters,
1356 dpl_parameters,
1357 stp_default_media_size,
1358 dpl_imageable_area,
1359 dpl_imageable_area,
1360 dpl_limit,
1361 dpl_print,
1362 dpl_describe_resolution,
1363 dpl_describe_output,
1364 stp_verify_printer_params,
1365 NULL,
1366 NULL,
1367 NULL,
1368 dpl_describe_papersize
1369 };
1370
1371
1372 static void
1373 dpl_pcx (stp_vars_t * v, /* I - Print file or command */
1374 unsigned char *short_line, /* I - Output bitmap data */
1375 int height, /* I - Height of bitmap data */
1376 int last_plane) /* I - True if this is the last plane */
1377 {
1378 unsigned char *line;
1379 unsigned char *data;
1380 unsigned char stored;
1381 int add_bytes = 0;
1382 int count = 0;
1383 int in = 0;
1384 int out = 0;
1385 stp_resolution_t xdpi, ydpi;
1386 const dpl_cap_t *caps = dpl_get_model_capabilities (v);
1387 unsigned int i;
1388 int max_dpi = 0;
1389 int dpi_adjust = 0;
1390 (void)last_plane;
1391
1392 /* Each line has to be 4 inches long */
1393 dpl_describe_resolution (v, &xdpi, &ydpi);
1394
1395 for (i = 0; i < NUM_RESOLUTIONS; i++)
1396 {
1397 if (caps->max_resolution == dpl_resolutions[i].dpl_code)
1398 {
1399 max_dpi = dpl_resolutions[i].p0;
1400 }
1401 if (caps->resolution_adjust == dpl_resolutions[i].dpl_code)
1402 {
1403 dpi_adjust = dpl_resolutions[i].p0;
1404 }
1405 }
1406
1407 // XXX check to see if max_dpi or dpi_adjust == 0?
1408
1409 if (xdpi == max_dpi)
1410 {
1411 add_bytes = ((xdpi * 4) + 7) / 8 - height;
1412 }
1413 else
1414 {
1415 add_bytes = ((dpi_adjust * 4) + 7) / 8 - height;
1416 }
1417
1418 /* allocate 4 inch input buffer */
1419 line = (unsigned char *) stp_malloc (height + add_bytes);
1420 /* allocate output buffer, worst case */
1421 data = (unsigned char *) stp_malloc ((height + add_bytes) * 2);
1422
1423 /* invert data, cups makes white 1 and black 0, printer wants the opposite */
1424 for (in = 0; in < height; in++)
1425 {
1426 line[in] = 0xff ^ short_line[in];
1427 }
1428
1429 /* pad to 4 inches */
1430 for (in = height; in < (height + add_bytes); in++)
1431 {
1432 line[in] = 0xff;
1433 }
1434
1435 in = 0;
1436 while (in < (height + add_bytes))
1437 {
1438 stored = line[in]; /* save the value */
1439 for (count = 1; in + count < (height + add_bytes) && line[in + count] == stored && count < 63; count++); /* count the run */
1440
1441 /* test to see if we need to make a run of one because the data value
1442 has the two top bits set and see if we actually have a run */
1443 if (stored > 191 || count > 1)
1444 {
1445 data[out++] = count | 0xc0; /* mask to indicate a run */
1446 data[out++] = stored; /* output the value */
1447 }
1448 else /* not a run */
1449 {
1450 data[out++] = stored; /* output the value */
1451 }
1452 in += count;
1453 }
1454 stp_zfwrite ((const char *) data, out, 1, v);
1455 stp_free (line);
1456 stp_free (data);
1457 }
1458
1459
1460 static stp_family_t print_dpl_module_data = {
1461 &print_dpl_printfuncs,
1462 NULL
1463 };
1464
1465
1466 static int
1467 print_dpl_module_init (void)
1468 {
1469 return stpi_family_register (print_dpl_module_data.printer_list);
1470 }
1471
1472
1473 static int
1474 print_dpl_module_exit (void)
1475 {
1476 return stpi_family_unregister (print_dpl_module_data.printer_list);
1477 }
1478
1479
1480 /* Module header */
1481 #define stp_module_version print_dpl_LTX_stp_module_version
1482 #define stp_module_data print_dpl_LTX_stp_module_data
1483
1484 stp_module_version_t stp_module_version = { 0, 0 };
1485
1486 stp_module_t stp_module_data = {
1487 "dpl",
1488 VERSION,
1489 "DPL family driver",
1490 STP_MODULE_CLASS_FAMILY,
1491 NULL,
1492 print_dpl_module_init,
1493 print_dpl_module_exit,
1494 (void *) &print_dpl_module_data
1495 };