Debian Codegraph @

src/main/print-canon.c

raw symbols SCIP
1 /*
2 *
3 * Print plug-in CANON BJL driver for the GIMP.
4 *
5 * Copyright 1997-2000 Michael Sweet ([email protected]),
6 * Robert Krawitz ([email protected]) and
7 * Andy Thaller ([email protected])
8 *
9 * Copyright (c) 2006 - 2007 Sascha Sommer ([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 /*
31 * Large parts of this file (mainly the ink handling) is based on
32 * print-escp2.c -- refer to README.new-printer on how to adjust the colors
33 * for a certain model.
34 */
35
36 /* TODO-LIST
37 *
38 * * adjust the colors of all supported models
39 *
40 */
41 #ifdef HAVE_CONFIG_H
42 #include <config.h>
43 #endif
44 #include <gutenprint/gutenprint.h>
45 #include "gutenprint-internal.h"
46 #include <gutenprint/gutenprint-intl-internal.h>
47 #include <string.h>
48 #include <stdio.h>
49 #if defined(HAVE_VARARGS_H) && !defined(HAVE_STDARG_H)
50 #include <varargs.h>
51 #else
52 #include <stdarg.h>
53 #endif
54 #ifdef HAVE_LIMITS_H
55 #include <limits.h>
56 #endif
57 #include <math.h>
58
59 #include "print-canon.h"
60
61 #ifndef MIN
62 # define MIN(a,b) (((a)<(b)) ? (a) : (b))
63 #endif /* !MIN */
64 #ifndef MAX
65 # define MAX(a, b) ((a) > (b) ? (a) : (b))
66 #endif /* !MAX */
67
68 /* 5 3-level pixels into 1 byte */
69 static int
70 pack_pixels(unsigned char* buf,int len)
71 {
72 int read_pos = 0;
73 int write_pos = 0;
74 int shift = 6;
75 while(read_pos < len)
76 {
77 /* read 5pixels at 2 bit */
78 unsigned short value = buf[read_pos] << 8;
79 if(read_pos+1 < len)
80 value += buf[read_pos + 1];
81 if(shift) /*6,4,2,0*/
82 value >>= shift;
83 /* write 8bit value representing the 10 bit pixel combination */
84 buf[write_pos] = tentoeight[value & 1023];
85 ++write_pos;
86 if(shift == 0)
87 {
88 shift = 6;
89 read_pos += 2;
90 }
91 else
92 {
93 shift -= 2;
94 ++read_pos;
95 }
96 }
97 return write_pos;
98 }
99
100 /* 3 4-bit-per-pixel 5-level pixels into 1 byte */
101 static int
102 pack_pixels3_5(unsigned char* buf,int len)
103 {
104 int read_pos = 0;
105 int write_pos = 0;
106 int shift = 4;
107 while(read_pos < len)
108 {
109 /* read 3pixels at 4 bit */
110 unsigned short value = buf[read_pos] << 8;
111 if(read_pos+1 < len)
112 value += buf[read_pos + 1];
113 if(shift) /*4,0*/
114 value >>= shift;
115 /* write 8bit value representing the 12 bit pixel combination */
116 buf[write_pos] = twelve2eight[value & 4095];
117 ++write_pos;
118 if(shift == 0)
119 {
120 shift = 4;
121 read_pos += 2;
122 }
123 else
124 {
125 shift -= 4;
126 ++read_pos;
127 }
128 }
129 return write_pos;
130 }
131
132 /* 3 4-bit-per-pixel 6-level pixels into 1 byte */
133 static int
134 pack_pixels3_6(unsigned char* buf,int len)
135 {
136 int read_pos = 0;
137 int write_pos = 0;
138 int shift = 4;
139 while(read_pos < len)
140 {
141 /* read 3pixels at 4 bit */
142 unsigned short value = buf[read_pos] << 8;
143 if(read_pos+1 < len)
144 value += buf[read_pos + 1];
145 if(shift) /*4,0*/
146 value >>= shift;
147 /* write 8bit value representing the 12 bit pixel combination */
148 buf[write_pos] = twelve2eight2[value & 4095];
149 ++write_pos;
150 if(shift == 0)
151 {
152 shift = 4;
153 read_pos += 2;
154 }
155 else
156 {
157 shift -= 4;
158 ++read_pos;
159 }
160 }
161 return write_pos;
162 }
163
164 /* model peculiarities */
165 #define CANON_CAP_MSB_FIRST 0x02ul /* how to send data */
166 #define CANON_CAP_a 0x04ul
167 #define CANON_CAP_b 0x08ul
168 #define CANON_CAP_q 0x10ul
169 #define CANON_CAP_m 0x20ul
170 #define CANON_CAP_d 0x40ul
171 #define CANON_CAP_t 0x80ul
172 #define CANON_CAP_c 0x100ul
173 #define CANON_CAP_p 0x200ul
174 #define CANON_CAP_l 0x400ul
175 #define CANON_CAP_r 0x800ul
176 #define CANON_CAP_g 0x1000ul
177 #define CANON_CAP_px 0x2000ul
178 #define CANON_CAP_rr 0x4000ul
179 #define CANON_CAP_I 0x8000ul
180 #define CANON_CAP_T 0x10000ul /* cartridge selection for PIXMA printers with Black and Color carts */
181 #define CANON_CAP_P 0x20000ul /* related to media type selection */
182 #define CANON_CAP_DUPLEX 0x40000ul /* duplex printing */
183 #define CANON_CAP_XML 0x80000ul /* use of XML at start and end of print data */
184 #define CANON_CAP_CARTRIDGE 0x100000ul /* not sure of this yet */
185 #define CANON_CAP_M 0x200000ul /* not sure of this yet */
186 #define CANON_CAP_S 0x400000ul /* not sure of this yet */
187 #define CANON_CAP_cart 0x800000ul /* BJC printers with Color, Black, Photo options */
188 #define CANON_CAP_BORDERLESS 0x1000000ul /* borderless (fullbleed) printing */
189 #define CANON_CAP_NOBLACK 0x2000000ul /* no Black cartridge selection */
190 #define CANON_CAP_v 0x4000000ul /* not sure of this yet */
191 #define CANON_CAP_w 0x8000000ul /* related to media type selection */
192 #define CANON_CAP_s 0x10000000ul /* not sure of this yet: duplex-related? */
193 #define CANON_CAP_u 0x20000000ul /* not sure of this yet: duplex-related? */
194
195 #define CANON_CAP_STD0 (CANON_CAP_b|CANON_CAP_c|CANON_CAP_d|\
196 CANON_CAP_l|CANON_CAP_q|CANON_CAP_t)
197
198 #define CANON_CAP_STD1 (CANON_CAP_b|CANON_CAP_c|CANON_CAP_d|CANON_CAP_l|\
199 CANON_CAP_m|CANON_CAP_p|CANON_CAP_q|CANON_CAP_t)
200
201 #include "canon-inks.h"
202 #include "canon-modes.h"
203 #include "canon-media.h"
204 #include "canon-media-mode.h"
205 #include "canon-printers.h"
206
207 typedef struct {
208 char name;
209 const canon_ink_t* props;
210 unsigned char* buf;
211 unsigned char* comp_buf_offset;
212 unsigned int buf_length;
213 unsigned int delay;
214 } canon_channel_t;
215
216 typedef struct
217 {
218 const canon_mode_t* mode;
219 const canon_slot_t* slot;
220 const canon_paper_t *pt;
221 /* cartridge selection for CANON_CAP_T and CANON_CAP_cart */
222 const char *ink_set;
223 const canon_modeuse_t* modeuse;
224 /* final inks used for output, after selection process completed */
225 unsigned int used_inks;
226 int num_channels;
227 int quality;
228 canon_channel_t* channels;
229 char* channel_order;
230 const canon_cap_t *caps;
231 unsigned char *comp_buf;
232 unsigned char *fold_buf;
233 int delay_max;
234 unsigned int buf_length_max;
235 int length;
236 int out_width;
237 int out_height;
238 int page_width;
239 int page_height;
240 int top;
241 int left;
242 int emptylines;
243 int ncolors; /* number of colors to print with */
244 int physical_xdpi, nozzle_ydpi, stepper_ydpi;
245 int nozzles; /* count of inkjets for one pass */
246 int nozzle_separation;
247 int horizontal_passes;
248 int vertical_passes;
249 int vertical_oversample;
250 int *head_offset;
251 int last_pass_offset;
252 int bidirectional; /* tells us if we are allowed to print bidirectional */
253 int direction; /* stores the last direction of the print head */
254 int weave_bits[4];
255 const char *duplex_str;
256 int is_first_page;
257 double cd_inner_radius;
258 double cd_outer_radius;
259 } canon_privdata_t;
260
261 static const canon_modeuse_t* select_media_modes(stp_vars_t *v, const canon_paper_t* media_type,const canon_modeuselist_t* mlist);
262 static int compare_mode_valid(stp_vars_t *v,const canon_mode_t* mode,const canon_modeuse_t* muse, const canon_modeuselist_t* mlist);
263 static const canon_mode_t* suitable_mode_monochrome(stp_vars_t *v,const canon_modeuse_t* muse,const canon_cap_t *caps,int quality,const char *duplex_mode);
264 static const canon_mode_t* find_first_matching_mode_monochrome(stp_vars_t *v,const canon_modeuse_t* muse,const canon_cap_t *caps,const char *duplex_mode);
265 static const canon_mode_t* find_first_matching_mode(stp_vars_t *v,const canon_modeuse_t* muse,const canon_cap_t *caps,const char *duplex_mode);
266 static const canon_mode_t* suitable_mode_color(stp_vars_t *v,const canon_modeuse_t* muse,const canon_cap_t *caps,int quality,const char *duplex_mode);
267 static const canon_mode_t* find_first_matching_mode_color(stp_vars_t *v,const canon_modeuse_t* muse,const canon_cap_t *caps,const char *duplex_mode);
268 static const canon_mode_t* suitable_mode_photo(stp_vars_t *v,const canon_modeuse_t* muse,const canon_cap_t *caps,int quality,const char *duplex_mode);
269 static const canon_mode_t* find_first_matching_mode_photo(stp_vars_t *v,const canon_modeuse_t* muse,const canon_cap_t *caps,const char *duplex_mode);
270 #if 0
271 static const canon_mode_t* suitable_mode_general(stp_vars_t *v,const canon_modeuse_t* muse,const canon_cap_t *caps,int quality,const char *duplex_mode);
272 #endif
273 static const char* find_ink_type(stp_vars_t *v,const canon_mode_t* mode,const char *printing_mode);
274 static const canon_mode_t* canon_check_current_mode(stp_vars_t *v);
275
276 static void canon_write_line(stp_vars_t *v);
277
278 static void canon_advance_paper(stp_vars_t *, int);
279 static void canon_flush_pass(stp_vars_t *, int, int);
280 static void canon_write_multiraster(stp_vars_t *v,canon_privdata_t* pd,int y);
281
282 static void fix_papersize(unsigned char arg_ESCP_1, int *paper_width, int *paper_length);
283
284 static const stp_parameter_t the_parameters[] =
285 {
286 {
287 "PageSize", N_("Page Size"), "Color=No,Category=Basic Printer Setup",
288 N_("Size of the paper being printed to"),
289 STP_PARAMETER_TYPE_STRING_LIST, STP_PARAMETER_CLASS_CORE,
290 STP_PARAMETER_LEVEL_BASIC, 1, 1, STP_CHANNEL_NONE, 1, 0
291 },
292 {
293 "MediaType", N_("Media Type"), "Color=Yes,Category=Basic Printer Setup",
294 N_("Type of media (plain paper, photo paper, etc.)"),
295 STP_PARAMETER_TYPE_STRING_LIST, STP_PARAMETER_CLASS_FEATURE,
296 STP_PARAMETER_LEVEL_BASIC, 1, 1, STP_CHANNEL_NONE, 1, 0
297 },
298 {
299 "InputSlot", N_("Media Source"), "Color=No,Category=Basic Printer Setup",
300 N_("Source (input slot) of the media"),
301 STP_PARAMETER_TYPE_STRING_LIST, STP_PARAMETER_CLASS_FEATURE,
302 STP_PARAMETER_LEVEL_BASIC, 1, 1, STP_CHANNEL_NONE, 1, 0
303 },
304 {
305 "CassetteTray", N_("Cassette Tray"), "Color=No,Category=Basic Printer Setup",
306 N_("Tray selection for cassette media source"),
307 STP_PARAMETER_TYPE_STRING_LIST, STP_PARAMETER_CLASS_FEATURE,
308 STP_PARAMETER_LEVEL_BASIC, 1, 1, STP_CHANNEL_NONE, 1, 0
309 },
310 {
311 "CDInnerRadius", N_("CD Hub Size"), "Color=No,Category=Basic Printer Setup",
312 N_("Print only outside of the hub of the CD, or all the way to the hole"),
313 STP_PARAMETER_TYPE_STRING_LIST, STP_PARAMETER_CLASS_FEATURE,
314 STP_PARAMETER_LEVEL_BASIC, 1, 1, STP_CHANNEL_NONE, 1, 0
315 },
316 {
317 "CDOuterDiameter", N_("CD Size (Custom)"), "Color=No,Category=Basic Printer Setup",
318 N_("Variable adjustment for the outer diameter of CD"),
319 STP_PARAMETER_TYPE_DIMENSION, STP_PARAMETER_CLASS_FEATURE,
320 STP_PARAMETER_LEVEL_ADVANCED, 1, 1, STP_CHANNEL_NONE, 1, 0
321 },
322 {
323 "CDInnerDiameter", N_("CD Hub Size (Custom)"), "Color=No,Category=Basic Printer Setup",
324 N_("Variable adjustment to the inner hub of the CD"),
325 STP_PARAMETER_TYPE_DIMENSION, STP_PARAMETER_CLASS_FEATURE,
326 STP_PARAMETER_LEVEL_ADVANCED, 1, 1, STP_CHANNEL_NONE, 1, 0
327 },
328 {
329 "CDXAdjustment", N_("CD Horizontal Fine Adjustment"), "Color=No,Category=Advanced Printer Setup",
330 N_("Fine adjustment to horizontal position for CD printing"),
331 STP_PARAMETER_TYPE_DIMENSION, STP_PARAMETER_CLASS_FEATURE,
332 STP_PARAMETER_LEVEL_ADVANCED, 1, 1, STP_CHANNEL_NONE, 1, 0
333 },
334 {
335 "CDYAdjustment", N_("CD Vertical Fine Adjustment"), "Color=No,Category=Advanced Printer Setup",
336 N_("Fine adjustment to horizontal position for CD printing"),
337 STP_PARAMETER_TYPE_DIMENSION, STP_PARAMETER_CLASS_FEATURE,
338 STP_PARAMETER_LEVEL_ADVANCED, 1, 1, STP_CHANNEL_NONE, 1, 0
339 },
340 {
341 "Resolution", N_("Resolution"), "Color=Yes,Category=Basic Printer Setup",
342 N_("Resolution and quality of the print"),
343 STP_PARAMETER_TYPE_STRING_LIST, STP_PARAMETER_CLASS_FEATURE,
344 STP_PARAMETER_LEVEL_BASIC, 1, 1, STP_CHANNEL_NONE, 1, 0
345 },
346 /*
347 * Don't check this parameter. We may offer different settings for
348 * different ink sets, but we need to be able to handle settings from PPD
349 * files that don't have constraints set up.
350 */
351 {
352 "InkType", N_("Ink Type"), "Color=Yes,Category=Advanced Printer Setup",
353 N_("Type of ink in the printer"),
354 STP_PARAMETER_TYPE_STRING_LIST, STP_PARAMETER_CLASS_FEATURE,
355 STP_PARAMETER_LEVEL_BASIC, 1, 1, STP_CHANNEL_NONE, 0, 0
356 },
357 {
358 "InkChannels", N_("Ink Channels"), "Color=Yes,Category=Advanced Printer Functionality",
359 N_("Ink Channels"),
360 STP_PARAMETER_TYPE_INT, STP_PARAMETER_CLASS_FEATURE,
361 STP_PARAMETER_LEVEL_INTERNAL, 0, 0, STP_CHANNEL_NONE, 0, 0
362 },
363 /*
364 * Don't check this parameter. We may offer different settings for
365 * different ink sets, but we need to be able to handle settings from PPD
366 * files that don't have constraints set up.
367 */
368 {
369 "PrintingMode", N_("Printing Mode"), "Color=Yes,Category=Core Parameter",
370 N_("Printing Output Mode"),
371 STP_PARAMETER_TYPE_STRING_LIST, STP_PARAMETER_CLASS_CORE,
372 STP_PARAMETER_LEVEL_BASIC, 1, 1, STP_CHANNEL_NONE, 0, 0
373 },
374 /*
375 * Don't check this parameter. We may offer different settings for
376 * different ink sets, but we need to be able to handle settings from PPD
377 * files that don't have constraints set up.
378 */
379 {
380 "InkSet", N_("Ink Set"), "Color=Yes,Category=Basic Printer Setup",
381 N_("Type of inkset in the printer"),
382 STP_PARAMETER_TYPE_STRING_LIST, STP_PARAMETER_CLASS_FEATURE,
383 STP_PARAMETER_LEVEL_BASIC, 1, 1, STP_CHANNEL_NONE, 0, 0
384 },
385 {
386 "FullBleed", N_("Borderless"), "Color=No,Category=Basic Printer Setup",
387 N_("Print without borders"),
388 STP_PARAMETER_TYPE_BOOLEAN, STP_PARAMETER_CLASS_FEATURE,
389 STP_PARAMETER_LEVEL_BASIC, 1, 1, STP_CHANNEL_NONE, 1, 0
390 },
391 {
392 "Duplex", N_("Double-Sided Printing"), "Color=No,Category=Basic Printer Setup",
393 N_("Duplex/Tumble Setting"),
394 STP_PARAMETER_TYPE_STRING_LIST, STP_PARAMETER_CLASS_FEATURE,
395 STP_PARAMETER_LEVEL_BASIC, 1, 1, STP_CHANNEL_NONE, 1, 0
396 },
397 {
398 "Quality", N_("Print Quality"), "Color=Yes,Category=Basic Output Adjustment",
399 N_("Print Quality"),
400 STP_PARAMETER_TYPE_STRING_LIST, STP_PARAMETER_CLASS_FEATURE,
401 STP_PARAMETER_LEVEL_BASIC, 1, 1, STP_CHANNEL_NONE, 0, 0
402 },
403 {
404 "Orientation", N_("Orientation"), "Color=No,Category=Basic Printer Setup",
405 N_("Orientation, Portrait, Landscape, Upside Down, Seascape"),
406 STP_PARAMETER_TYPE_STRING_LIST, STP_PARAMETER_CLASS_FEATURE,
407 STP_PARAMETER_LEVEL_BASIC, 1, 1, STP_CHANNEL_NONE, 1, 0,
408 },
409 };
410
411 static const unsigned int the_parameter_count =
412 sizeof(the_parameters) / sizeof(const stp_parameter_t);
413
414 typedef struct
415 {
416 const stp_parameter_t param;
417 double min;
418 double max;
419 double defval;
420 int color_only;
421 } float_param_t;
422
423 static const float_param_t float_parameters[] =
424 {
425 {
426 {
427 "CyanDensity", N_("Cyan Density"), "Color=Yes,Category=Output Level Adjustment",
428 N_("Adjust the cyan density"),
429 STP_PARAMETER_TYPE_DOUBLE, STP_PARAMETER_CLASS_OUTPUT,
430 STP_PARAMETER_LEVEL_ADVANCED, 0, 1, 1, 1, 0
431 }, 0.0, 2.0, 1.0, 1
432 },
433 {
434 {
435 "MagentaDensity", N_("Magenta Density"), "Color=Yes,Category=Output Level Adjustment",
436 N_("Adjust the magenta density"),
437 STP_PARAMETER_TYPE_DOUBLE, STP_PARAMETER_CLASS_OUTPUT,
438 STP_PARAMETER_LEVEL_ADVANCED, 0, 1, 2, 1, 0
439 }, 0.0, 2.0, 1.0, 1
440 },
441 {
442 {
443 "YellowDensity", N_("Yellow Density"), "Color=Yes,Category=Output Level Adjustment",
444 N_("Adjust the yellow density"),
445 STP_PARAMETER_TYPE_DOUBLE, STP_PARAMETER_CLASS_OUTPUT,
446 STP_PARAMETER_LEVEL_ADVANCED, 0, 1, 3, 1, 0
447 }, 0.0, 2.0, 1.0, 1
448 },
449 {
450 {
451 "BlackDensity", N_("Black Density"), "Color=Yes,Category=Output Level Adjustment",
452 N_("Adjust the black density"),
453 STP_PARAMETER_TYPE_DOUBLE, STP_PARAMETER_CLASS_OUTPUT,
454 STP_PARAMETER_LEVEL_ADVANCED, 0, 1, 0, 1, 0
455 }, 0.0, 2.0, 1.0, 1
456 },
457 {
458 {
459 "LightCyanTrans", N_("Light Cyan Transition"), "Color=Yes,Category=Advanced Ink Adjustment",
460 N_("Light Cyan Transition"),
461 STP_PARAMETER_TYPE_DOUBLE, STP_PARAMETER_CLASS_OUTPUT,
462 STP_PARAMETER_LEVEL_ADVANCED4, 0, 1, STP_CHANNEL_NONE, 1, 0
463 }, 0.0, 5.0, 1.0, 1
464 },
465 {
466 {
467 "LightMagentaTrans", N_("Light Magenta Transition"), "Color=Yes,Category=Advanced Ink Adjustment",
468 N_("Light Magenta Transition"),
469 STP_PARAMETER_TYPE_DOUBLE, STP_PARAMETER_CLASS_OUTPUT,
470 STP_PARAMETER_LEVEL_ADVANCED4, 0, 1, STP_CHANNEL_NONE, 1, 0
471 }, 0.0, 5.0, 1.0, 1
472 },
473 {
474 {
475 "LightYellowTrans", N_("Light Yellow Transition"), "Color=Yes,Category=Advanced Ink Adjustment",
476 N_("Light Yellow Transition"),
477 STP_PARAMETER_TYPE_DOUBLE, STP_PARAMETER_CLASS_OUTPUT,
478 STP_PARAMETER_LEVEL_ADVANCED4, 0, 1, STP_CHANNEL_NONE, 1, 0
479 }, 0.0, 5.0, 1.0, 1
480 },
481 };
482
483 static const unsigned int float_parameter_count =
484 sizeof(float_parameters) / sizeof(const float_param_t);
485
486 /*
487 * Duplex support - modes available
488 * Note that the internal names MUST match those in cups/genppd.c else the
489 * PPD files will not be generated correctly
490 */
491
492 static const stp_param_string_t duplex_types[] =
493 {
494 { "None", N_ ("Off") },
495 { "DuplexNoTumble", N_ ("Long Edge (Standard)") },
496 { "DuplexTumble", N_ ("Short Edge (Flip)") }
497 };
498 #define NUM_DUPLEX (sizeof (duplex_types) / sizeof (stp_param_string_t))
499
500 /*
501 * Orientation support - modes available
502 * Note that the internal names MUST match those in cups/genppd.c else the
503 * PPD files will not be generated correctly
504 */
505
506 static const stp_param_string_t orientation_types[] = {
507 {"Portrait", N_("Portrait")},
508 {"Landscape", N_("Landscape")},
509 {"UpsideDown", N_("Reverse Portrait")},
510 {"Seascape", N_("Reverse Landscape")},
511 };
512 #define NUM_ORIENTATION (sizeof (orientation_types) / sizeof (stp_param_string_t))
513
514 static const canon_paper_t *
515 get_media_type(const canon_cap_t* caps,const char *name)
516 {
517 int i;
518 if (name && caps->paperlist)
519 {
520 for (i = 0; i < caps->paperlist->count; i++)
521 {
522 /* translate paper_t.name */
523 if (!strcmp(name, caps->paperlist->papers[i].name))
524 return &(caps->paperlist->papers[i]);
525 }
526 return &(caps->paperlist->papers[0]);
527 }
528 return NULL;
529 }
530
531 static const char* canon_families[] = {
532 "", /* the old BJC printers */
533 "S", /* 1 */
534 "i", /* 2 */
535 "PIXMA iP", /* 3 */
536 "PIXMA iX", /* 4 */
537 "PIXMA MP", /* 5 */
538 "PIXUS", /* 6 */
539 "PIXMA Pro", /* 7 */
540 "PIXMA MG", /* 8 */
541 "PIXMA MX", /* 9 */
542 "SELPHY DS", /* 10 */
543 "PIXMA mini",/* 11 */
544 "PIXMA E", /* 12 */
545 "PIXMA P", /* 13 */
546 "MAXIFY iB", /* 14 */
547 "MAXIFY MB", /* 15 */
548 "PIXMA MPC", /* 16 */
549 "PIXMA G", /* 17 */
550 "PIXMA TS", /* 18 */
551 "PIXMA TR", /* 19 */
552 "PIXMA XK", /* 20 */
553 "PIXMA GM", /* 21 */
554 };
555
556 /* canon model ids look like the following
557 FFMMMMMM
558 FF: family is the offset in the canon_families struct
559 MMMMMM: model nr
560 */
561 static char* canon_get_printername(const stp_vars_t* v)
562 {
563 unsigned int model = stp_get_model_id(v);
564 unsigned int family = model / 1000000;
565 unsigned int nr = model - family * 1000000;
566 char* name;
567 size_t len;
568 if(family >= sizeof(canon_families) / sizeof(canon_families[0])){
569 stp_eprintf(v,"canon_get_printername: no family %i using default BJC\n", family);
570 family = 0;
571 }
572 len = strlen(canon_families[family]) + 7; /* max model nr. + terminating 0 */
573 name = stp_zalloc(len);
574 snprintf(name,len,"%s%u",canon_families[family],nr);
575 stp_dprintf(STP_DBG_CANON, v,"canon_get_printername: current printer name: %s\n", name);
576 return name;
577 }
578
579 static const canon_cap_t * canon_get_model_capabilities(const stp_vars_t*v)
580 {
581 int i;
582 char* name = canon_get_printername(v);
583 int models= sizeof(canon_model_capabilities) / sizeof(canon_cap_t);
584 for (i=0; i<models; i++) {
585 if (!strcmp(canon_model_capabilities[i].name,name)) {
586 stp_free(name);
587 return &(canon_model_capabilities[i]);
588 }
589 }
590 stp_eprintf(v,"canon: model %s not found in capabilities list=> using default\n",name);
591 stp_free(name);
592 return &(canon_model_capabilities[0]);
593 }
594
595 static const canon_slot_t *
596 canon_source_type(const char *name, const canon_cap_t * caps)
597 {
598 if(name){
599 int i;
600 for(i=0; i<caps->slotlist->count; i++){
601 if( !strcmp(name,caps->slotlist->slots[i].name))
602 return &(caps->slotlist->slots[i]);
603 }
604 }
605 return &(caps->slotlist->slots[0]);
606 }
607
608 /* function returns the current set printmode (specified by resolution) */
609 /* if no mode is set the default mode will be returned */
610 static const canon_mode_t* canon_get_current_mode(const stp_vars_t *v){
611 #if 0
612 const char* input_slot = stp_get_string_parameter(v, "InputSlot");
613 const char *quality = stp_get_string_parameter(v, "Quality");
614 #endif
615 const char *resolution = stp_get_string_parameter(v, "Resolution");
616 const canon_cap_t * caps = canon_get_model_capabilities(v);
617 const canon_mode_t* mode = NULL;
618 const char *ink_type = stp_get_string_parameter(v, "InkType");/*debug*/
619 const char *ink_set = stp_get_string_parameter(v, "InkSet");/*debug*/
620 int i;
621
622 stp_dprintf(STP_DBG_CANON, v,"Entered canon_get_current_mode\n");
623
624 if (ink_set)
625 stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint: InkSet value (high priority): '%s'\n",ink_set);
626 else
627 stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint: InkSet value is NULL\n");
628
629 if (ink_type)
630 stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint: InkType value (low priority): '%s'\n",ink_type);
631 else
632 stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint: InkType value is NULL\n");
633
634 if(resolution){
635 for(i=0;i<caps->modelist->count;i++){
636 if(!strcmp(resolution,caps->modelist->modes[i].name)){
637 mode = &caps->modelist->modes[i];
638 break;
639 }
640 }
641 }
642 #if 0
643 if(!mode)
644 mode = &caps->modelist->modes[caps->modelist->default_mode];
645 #endif
646
647 #if 0
648 if(quality && strcmp(quality, "None") == 0)
649 quality = "Standard";
650
651 if(quality && !strcmp(quality,"Standard")){
652 return &caps->modelist->modes[caps->modelist->default_mode];
653 }
654 #endif
655
656 #if 0
657 /* only some modes can print to cd */
658 if(input_slot && !strcmp(input_slot,"CD") && !(mode->flags & MODE_FLAG_CD)){
659 for(i=0;i<caps->modelist->count;i++){
660 if(caps->modelist->modes[i].flags & MODE_FLAG_CD){
661 mode = &caps->modelist->modes[i];
662 break;
663 }
664 }
665 }
666 #endif
667
668 stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint: current mode is '%s'\n",resolution ? resolution : "(null)");
669
670 return mode;
671 }
672
673 const canon_modeuse_t* select_media_modes(stp_vars_t *v, const canon_paper_t* media_type,const canon_modeuselist_t* mlist){
674 const canon_modeuse_t* muse = NULL;
675 int i;
676 for(i=0;i<mlist->count;i++){
677 if(!strcmp(media_type->name,mlist->modeuses[i].name)){
678 muse = &mlist->modeuses[i];
679 stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint: mode searching: assigned media '%s'\n",mlist->name);
680 break;
681 }
682 }
683 return muse;
684 }
685
686 int compare_mode_valid(stp_vars_t *v,const canon_mode_t* mode,const canon_modeuse_t* muse, const canon_modeuselist_t* mlist){
687 int i=0;
688 int modecheck=1;
689 stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint: mode searching: assigned mode-media '%s'\n",mlist->name);
690 while (muse->mode_name_list[i]!=NULL){
691 if(!strcmp(mode->name,muse->mode_name_list[i])){
692 modecheck=0;
693 break;
694 }
695 i++;
696 }
697 return modecheck;
698 }
699
700 const canon_mode_t* suitable_mode_monochrome(stp_vars_t *v,const canon_modeuse_t* muse,const canon_cap_t *caps,int quality,const char *duplex_mode) {
701 const canon_mode_t* mode=NULL;
702 int i=0;
703 int j;
704 int modefound=0;
705
706 stp_dprintf(STP_DBG_CANON, v,"DEBUG: Entered suitable_mode_monochrome\n");
707
708 while ((muse->mode_name_list[i]!=NULL) && (modefound != 1)){
709 for(j=0;j<caps->modelist->count;j++){
710 if(!strcmp(muse->mode_name_list[i],caps->modelist->modes[j].name)){/* find right place in canon-modes list */
711 if ( (muse->use_flags & INKSET_BLACK_MODEREPL) ) {
712 /* only look at modes with MODE_FLAG_BLACK if INKSET_BLACK_MODEREPL is in force */
713 if ( (caps->modelist->modes[j].quality >= quality) && (caps->modelist->modes[j].flags & MODE_FLAG_BLACK) ){
714 /* keep setting the mode until lowest matching quality is found */
715 if ( (duplex_mode && strncmp(duplex_mode,"Duplex",6)) || !(muse->use_flags & DUPLEX_SUPPORT) || !(caps->modelist->modes[j].flags & MODE_FLAG_NODUPLEX) ) {
716 /* duplex check -- rare for monochrome, cannot remember any such case */
717 mode = &caps->modelist->modes[j];
718 modefound=1;
719 }
720 }
721 break; /* go to next mode in muse list */
722 }
723 else { /* no special replacement modes for black inkset */
724 if ( (caps->modelist->modes[j].quality >= quality) ){
725 /* keep setting the mode until lowest matching quality is found */
726 if ( (duplex_mode && strncmp(duplex_mode,"Duplex",6)) || !(muse->use_flags & DUPLEX_SUPPORT) || !(caps->modelist->modes[j].flags & MODE_FLAG_NODUPLEX) ) {
727 /* duplex check -- rare for monochrome, cannot remember any such case */
728 mode = &caps->modelist->modes[j];
729 modefound=1;
730 }
731 }
732 break; /* go to next mode in muse list */
733 }
734 }
735 }
736 i++;
737 }
738 return mode;
739 }
740
741 const canon_mode_t* find_first_matching_mode_monochrome(stp_vars_t *v,const canon_modeuse_t* muse,const canon_cap_t *caps,const char *duplex_mode) {
742 const canon_mode_t* mode=NULL;
743 /* only look at modes with MODE_FLAG_BLACK if INKSET_BLACK_MODEREPL is in force */
744 int i=0;
745 int modefound=0;
746 int j;
747
748 stp_dprintf(STP_DBG_CANON, v,"DEBUG: Entered find_first_matching_mode_monochrome\n");
749
750 while ( (muse->mode_name_list[i]!=NULL) && (modefound != 1) ) {
751 /* pick first mode with MODE_FLAG_BLACK */
752 for(j=0;j<caps->modelist->count;j++){
753 if(!strcmp(muse->mode_name_list[i],caps->modelist->modes[j].name)){/* find right place in canon-modes list */
754 /* only look at modes with MODE_FLAG_BLACK if INKSET_BLACK_MODEREPL is in force */
755 if ( (caps->modelist->modes[j].flags & MODE_FLAG_BLACK) ) {
756 if ( (duplex_mode && strncmp(duplex_mode,"Duplex",6)) || !(muse->use_flags & DUPLEX_SUPPORT) || !(caps->modelist->modes[j].flags & MODE_FLAG_NODUPLEX) ) {
757 /* duplex check -- rare for monochrome, cannot remember any such case */
758 mode = &caps->modelist->modes[j];
759 modefound=1;
760 stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (find_first_matching_mode_monochrome): picked monochrome mode (%s)\n",mode->name);
761 }
762 }
763 break; /* go to next mode in muse list */
764 }
765 }
766 i++;
767 }
768 return mode;
769 }
770
771 const canon_mode_t* find_first_matching_mode(stp_vars_t *v,const canon_modeuse_t* muse,const canon_cap_t *caps,const char *duplex_mode) {
772 const canon_mode_t* mode=NULL;
773 int i=0;
774 int modefound=0;
775 int j;
776
777 stp_dprintf(STP_DBG_CANON, v,"DEBUG: Entered find_first_matching_mode\n");
778
779 while ( (muse->mode_name_list[i]!=NULL) && (modefound != 1) ) {
780 for(j=0;j<caps->modelist->count;j++){
781 if(!strcmp(muse->mode_name_list[i],caps->modelist->modes[j].name)){/* find right place in canon-modes list */
782 if ( (duplex_mode && strncmp(duplex_mode,"Duplex",6)) || !(muse->use_flags & DUPLEX_SUPPORT) || !(caps->modelist->modes[j].flags & MODE_FLAG_NODUPLEX) ) {
783 /* duplex check */
784 mode = &caps->modelist->modes[j];
785 modefound=1;
786 stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (find_first_matching_mode): picked mode without inkset limitation (%s)\n",mode->name);
787 }
788 break; /* go to next mode in muse list */
789 }
790 }
791 i++;
792 }
793 return mode;
794 }
795
796 const canon_mode_t* suitable_mode_color(stp_vars_t *v,const canon_modeuse_t* muse,const canon_cap_t *caps,int quality,const char *duplex_mode) {
797 const canon_mode_t* mode=NULL;
798 int i=0;
799 int j;
800 int modefound=0;
801
802 stp_dprintf(STP_DBG_CANON, v,"DEBUG: Entered suitable_mode_color\n");
803
804 while ((muse->mode_name_list[i]!=NULL) && (modefound != 1)){
805 for(j=0;j<caps->modelist->count;j++){
806 if(!strcmp(muse->mode_name_list[i],caps->modelist->modes[j].name)){/* find right place in canon-modes list */
807 if ( (muse->use_flags & INKSET_COLOR_MODEREPL) ) {
808 /* only look at modes with MODE_FLAG_COLOR if INKSET_COLOR_MODEREPL is in force */
809 if ( (caps->modelist->modes[j].quality >= quality) && (caps->modelist->modes[j].flags & MODE_FLAG_COLOR) ) {
810 /* keep setting the mode until lowest matching quality is found */
811 if ( (duplex_mode && strncmp(duplex_mode,"Duplex",6)) || !(muse->use_flags & DUPLEX_SUPPORT) || !(caps->modelist->modes[j].flags & MODE_FLAG_NODUPLEX) ) {
812 /* duplex check */
813 mode = &caps->modelist->modes[j];
814 stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (suitable_mode_color): picked mode with special replacement inkset (%s)\n",mode->name);
815 modefound=1;
816 }
817 }
818 break; /* go to next mode in muse list */
819 }
820 else { /* no special replacement modes for color inkset */
821 if ( (caps->modelist->modes[j].quality >= quality) ){
822 /* keep setting the mode until lowest matching quality is found */
823 if ( (duplex_mode && strncmp(duplex_mode,"Duplex",6)) || !(muse->use_flags & DUPLEX_SUPPORT) || !(caps->modelist->modes[j].flags & MODE_FLAG_NODUPLEX) ) {
824 /* duplex check */
825 mode = &caps->modelist->modes[j];
826 stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (suitable_mode_color): picked mode without any special replacement inkset (%s)\n",mode->name);
827 modefound=1;
828 }
829 }
830 break; /* go to next mode in muse list */
831 }
832 }
833 }
834 i++;
835 }
836 return mode;
837 }
838
839 const canon_mode_t* find_first_matching_mode_color(stp_vars_t *v,const canon_modeuse_t* muse,const canon_cap_t *caps,const char *duplex_mode) {
840 const canon_mode_t* mode=NULL;
841 /* only look at modes with MODE_FLAG_COLOR if INKSET_COLOR_MODEREPL is in force */
842 int i=0;
843 int modefound=0;
844 int j;
845
846 stp_dprintf(STP_DBG_CANON, v,"DEBUG: Entered find_first_matching_mode_color\n");
847
848 while ( (muse->mode_name_list[i]!=NULL) && (modefound != 1) ) {
849 /* pick first mode with MODE_FLAG_COLOR */
850 for(j=0;j<caps->modelist->count;j++){
851 if(!strcmp(muse->mode_name_list[i],caps->modelist->modes[j].name)){/* find right place in canon-modes list */
852 /* only look at modes with MODE_FLAG_COLOR if INKSET_COLOR_MODEREPL is in force */
853 if ( (caps->modelist->modes[j].flags & MODE_FLAG_COLOR) ) {
854 if ( (duplex_mode && strncmp(duplex_mode,"Duplex",6)) || !(muse->use_flags & DUPLEX_SUPPORT) || !(caps->modelist->modes[j].flags & MODE_FLAG_NODUPLEX) ) {
855 /* duplex check */
856 mode = &caps->modelist->modes[j];
857 stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (find_first_matching_mode_color): picked first mode with special replacement inkset (%s)\n",mode->name);
858 modefound=1;
859 }
860 }
861 break; /* go to next mode in muse list */
862 }
863 }
864 i++;
865 }
866 return mode;
867 }
868
869 const canon_mode_t* suitable_mode_photo(stp_vars_t *v,const canon_modeuse_t* muse,const canon_cap_t *caps,int quality,const char *duplex_mode) {
870 const canon_mode_t* mode=NULL;
871 int i=0;
872 int j;
873 int modefound=0;
874
875 stp_dprintf(STP_DBG_CANON, v,"DEBUG: Entered suitable_mode_photo\n");
876
877 while ((muse->mode_name_list[i]!=NULL) && (modefound != 1)){
878 for(j=0;j<caps->modelist->count;j++){
879 if(!strcmp(muse->mode_name_list[i],caps->modelist->modes[j].name)){/* find right place in canon-modes list */
880 if ( (muse->use_flags & INKSET_PHOTO_MODEREPL) ) {
881 /* only look at modes with MODE_FLAG_PHOTO if INKSET_PHOTO_MODEREPL is in force */
882 if ( (caps->modelist->modes[j].quality >= quality) && (caps->modelist->modes[j].flags & MODE_FLAG_PHOTO) ) {
883 /* keep setting the mode until lowest matching quality is found */
884 if ( (duplex_mode && strncmp(duplex_mode,"Duplex",6)) || !(muse->use_flags & DUPLEX_SUPPORT) || !(caps->modelist->modes[j].flags & MODE_FLAG_NODUPLEX) ) {
885 /* duplex check */
886 mode = &caps->modelist->modes[j];
887 stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (suitable_mode_photo): picked first mode with special replacement inkset (%s)\n",mode->name);
888 modefound=1;
889 }
890 }
891 break; /* go to next mode in muse list */
892 }
893 else { /* if no special replacement modes for photo inkset */
894 if ( (caps->modelist->modes[j].quality >= quality) ){
895 /* keep setting the mode until lowest matching quality is found */
896 if ( (duplex_mode && strncmp(duplex_mode,"Duplex",6)) || !(muse->use_flags & DUPLEX_SUPPORT) || !(caps->modelist->modes[j].flags & MODE_FLAG_NODUPLEX) ) {
897 /* duplex check */
898 mode = &caps->modelist->modes[j];
899 stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (suitable_mode_photo): picked first mode with photo inkset (%s)\n",mode->name);
900 modefound=1;
901 }
902 }
903 break; /* go to next mode in muse list */
904 }
905 }
906 }
907 i++;
908 }
909 return mode;
910 }
911
912 const canon_mode_t* find_first_matching_mode_photo(stp_vars_t *v,const canon_modeuse_t* muse,const canon_cap_t *caps,const char *duplex_mode) {
913 const canon_mode_t* mode=NULL;
914 /* only look at modes with MODE_FLAG_PHOTO if INKSET_PHOTO_MODEREPL is in force */
915 int i=0;
916 int modefound=0;
917 int j;
918
919 stp_dprintf(STP_DBG_CANON, v,"DEBUG: Entered find_first_matching_mode_photo\n");
920
921 while ( (muse->mode_name_list[i]!=NULL) && (modefound != 1) ) {
922 /* pick first mode with MODE_FLAG_PHOTO */
923 for(j=0;j<caps->modelist->count;j++){
924 if(!strcmp(muse->mode_name_list[i],caps->modelist->modes[j].name)){/* find right place in canon-modes list */
925 /* only look at modes with MODE_FLAG_PHOTO if INKSET_PHOTO_MODEREPL is in force */
926 if ( (caps->modelist->modes[j].flags & MODE_FLAG_PHOTO) ) {
927 if ( (duplex_mode && strncmp(duplex_mode,"Duplex",6)) || !(muse->use_flags & DUPLEX_SUPPORT) || !(caps->modelist->modes[j].flags & MODE_FLAG_NODUPLEX) ) {
928 /* duplex check */
929 mode = &caps->modelist->modes[j];
930 stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (find_first_matching_mode_photo): picked first mode with photo inkset (%s)\n",mode->name);
931 modefound=1;
932 }
933 }
934 break; /* go to next mode in muse list */
935 }
936 }
937 i++;
938 }
939 return mode;
940 }
941
942 #if 0
943 const canon_mode_t* suitable_mode_general(stp_vars_t *v,const canon_modeuse_t* muse,const canon_cap_t *caps,int quality,const char *duplex_mode) {
944 const canon_mode_t* mode=NULL;
945 int i=0;
946 int j;
947 int modefound=0;
948
949 stp_dprintf(STP_DBG_CANON, v,"DEBUG: Entered suitable_mode_general\n");
950
951
952 while ((muse->mode_name_list[i]!=NULL) && (modefound != 1)){
953 for(j=0;j<caps->modelist->count;j++){
954 if(!strcmp(muse->mode_name_list[i],caps->modelist->modes[j].name)){/* find right place in canon-modes list */
955 if ( (caps->modelist->modes[j].quality >= quality) ) {
956 /* keep setting the mode until lowest matching quality is found */
957 if ( (duplex_mode && strncmp(duplex_mode,"Duplex",6)) || !(muse->use_flags & DUPLEX_SUPPORT) || !(caps->modelist->modes[j].flags & MODE_FLAG_NODUPLEX) ) {
958 /* duplex check */
959 mode = &caps->modelist->modes[j];
960 stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (suitable_mode_general): picked first mode with lowest matching quality (%s)\n",mode->name);
961 modefound=1;
962 }
963 }
964 break; /* go to next mode in muse list */
965 }
966 }
967 i++;
968 }
969 return mode;
970 }
971 #endif
972
973 const char* find_ink_type(stp_vars_t *v,const canon_mode_t* mode,const char *printing_mode) {
974 unsigned int i,inkfound;
975 const char *ink_type = stp_get_string_parameter(v, "InkType");
976
977 stp_dprintf(STP_DBG_CANON, v,"DEBUG: Entered find_ink_type\n");
978
979 /* if InkType does not match that of mode, change InkType to match it */
980 /* choose highest color as default, as there is only one option for Black */
981 /* if InkType does not match that of mode, change InkType to match it */
982 /* choose highest color as default, as there is only one option for Black */
983 if (printing_mode && !strcmp(printing_mode,"BW")) {
984 stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (InkSet:Both): InkType changed to %u (%s)\n",CANON_INK_K, "Gray");
985 stp_set_string_parameter(v, "InkType", "Gray");
986 ink_type = stp_get_string_parameter(v, "InkType");
987 } else {
988 inkfound=0;
989 stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (InkSet:Both): InkType of mode %s is currently set as %s\n",mode->name,ink_type);
990 for(i=0;i<sizeof(canon_inktypes)/sizeof(canon_inktypes[0]);i++){
991 if (mode->ink_types & canon_inktypes[i].ink_type) { /* a mode can have several ink_types: must compare with ink_type if set */
992 if ( !(strcmp(ink_type,canon_inktypes[i].name))) {
993 inkfound=1;
994 stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (InkSet:Both): InkType match found %i(%s)\n",canon_inktypes[i].ink_type,canon_inktypes[i].name);
995 stp_set_string_parameter(v, "InkType", canon_inktypes[i].name);
996 ink_type = stp_get_string_parameter(v, "InkType");
997 break;
998 }
999 }
1000 }
1001 /* if no match found choose first available inkset */
1002 if (inkfound==0) {
1003 for(i=0;i<sizeof(canon_inktypes)/sizeof(canon_inktypes[0]);i++){
1004 if (mode->ink_types & canon_inktypes[i].ink_type) { /* a mode can have several ink_types: must compare with ink_type if set */
1005 if ((!ink_type) || (strcmp(ink_type,canon_inktypes[i].name))) { /* if InkType does not match selected mode ink type*/
1006 stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (InkSet:Both): No match found---InkType changed to %i(%s)\n",canon_inktypes[i].ink_type,canon_inktypes[i].name);
1007 stp_set_string_parameter(v, "InkType", canon_inktypes[i].name);
1008 ink_type = stp_get_string_parameter(v, "InkType");
1009 inkfound=1; /* set */
1010 break;
1011 }
1012 }
1013 }
1014 }
1015 }
1016 return ink_type;
1017 }
1018
1019 /* function checks printmode (specified by resolution) */
1020 /* and substitutes a mode if needed. NULL is returned for now */
1021 const canon_mode_t* canon_check_current_mode(stp_vars_t *v){
1022 #if 0
1023 const char* input_slot = stp_get_string_parameter(v, "InputSlot");
1024 const char *quality = stp_get_string_parameter(v, "Quality");
1025 #endif
1026 const char *resolution = stp_get_string_parameter(v, "Resolution");
1027 const char *ink_set = stp_get_string_parameter(v, "InkSet");
1028 const char *duplex_mode = stp_get_string_parameter(v, "Duplex");
1029 const char *ink_type = stp_get_string_parameter(v, "InkType");
1030 const char *printing_mode = stp_get_string_parameter(v, "PrintingMode");
1031 const canon_cap_t * caps = canon_get_model_capabilities(v);
1032 const canon_mode_t* mode = NULL;
1033 const canon_modeuselist_t* mlist = caps->modeuselist;
1034 const canon_modeuse_t* muse = NULL;
1035 const canon_paper_t* media_type = get_media_type(caps,stp_get_string_parameter(v, "MediaType"));
1036 unsigned int i,j;
1037 int modecheck, quality, modefound;
1038 #if 0
1039 int inkfound;
1040 #endif
1041
1042 stp_dprintf(STP_DBG_CANON, v,"Entered canon_check_current_mode: got PrintingMode %s\n",printing_mode);
1043
1044 /* Logic: priority of options
1045 1. Media --- always present for final selection.
1046 2. InkSet (cartridge selection) --- optional as only some printers offer this.
1047 3. PrintingMode --- for printers which have K-only monochrome modes can choose BW.
1048 4. Duplex --- for printers that have special duplex modes need to skip non-duplex modes.
1049 5. InkType --- suggestion only, since modes are tied to ink types in most Canon printers.
1050 6. Quality --- suggestion, based on initially-selected mode.
1051 7. Mode --- once chosen, InkType is selected based on quality, inkset, printing mode.
1052 */
1053
1054 /*
1055 canon-mode-media:
1056 INKSET_BLACK_SUPPORT: media type supports black-only cartridge
1057 INKSET_COLOR_SUPPORT: media type supports color-only cartridge
1058 INKSET_BLACK_MODEREPL: media type has special modes for black-only cartridge
1059 INKSET_COLOR_MODEREPL: media type has special modes for black-only cartridge
1060 INKSET_PHOTO_SUPPORT: media type supports special photo cartridge
1061 DUPLEX_MODEREPL: media type has (a) special mode(s) for duplex
1062 canon-modes.h:
1063 MODE_FLAG_BLACK: mode can be used for supporting black-only cartridge
1064 MODE_FLAG_COLOR: mode can be used for supporting color-only cartridge
1065 MODE_FLAG_PHOTO: mode can be used for supporting photo cartridge
1066 MODE_FLAG_NOPDUPLEX: mode cannot be used for duplex, must be skipped
1067 */
1068
1069 if(resolution){
1070 stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint: check_current_mode --- (Initial) Resolution already known: '%s'\n",resolution);
1071 for(i=0;i<caps->modelist->count;i++){
1072 if(!strcmp(resolution,caps->modelist->modes[i].name)){
1073 mode = &caps->modelist->modes[i];
1074 break;
1075 }
1076 }
1077 }
1078 else {
1079 stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint: check_current_mode --- (Initial) Resolution not yet known \n");
1080 }
1081
1082 if (ink_set)
1083 stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint: (Initial) InkSet value (high priority): '%s'\n",ink_set);
1084 else
1085 stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint: (Initial) InkSet value is NULL\n");
1086
1087 if (ink_type)
1088 stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint: (Initial) InkType value (low priority): '%s'\n",ink_type);
1089 else
1090 stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint: (Initial) InkType value is NULL\n");
1091
1092 /* beginning of mode replacement code */
1093 if (media_type && resolution && mode) {
1094 stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint: check_current_mode --- Resolution, Media, Mode all known \n");
1095 stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint: media type selected: '%s'\n",media_type->name);
1096 stp_dprintf(STP_DBG_CANON, v,"DEBUG: (Initial) Gutenprint: mode initially active: '%s'\n",mode->name);
1097
1098 /* scroll through modeuse list to find media */
1099 muse = select_media_modes(v,media_type,mlist);
1100
1101 /* now scroll through to find if the mode is in the modeuses list */
1102 modecheck=compare_mode_valid(v,mode,muse,mlist);
1103
1104 stp_dprintf(STP_DBG_CANON, v,"DEBUG: (mode replacement) Gutenprint: modecheck value: '%i'\n",modecheck);
1105
1106 /* if we did not find a valid mode, need to replace it */
1107 if (modecheck!=0) {
1108
1109 stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (check_current_mode): no suitable mode exists, need to find a mode\n");
1110
1111 quality = mode->quality;
1112 /* Black InkSet */
1113 if (ink_set && !strcmp(ink_set,"Black")) {
1114 stp_set_string_parameter(v, "PrintingMode","BW");
1115 printing_mode = stp_get_string_parameter(v, "PrintingMode");
1116 if (!(mode->ink_types & CANON_INK_K)) {
1117
1118 /* need a new mode:
1119 loop through modes in muse list searching for a matching inktype, comparing quality
1120 */
1121 mode=suitable_mode_monochrome(v,muse,caps,quality,duplex_mode);
1122 if (!mode)
1123 modefound=0;
1124 else
1125 modefound=1;
1126
1127 if (modefound == 0) { /* still did not find a mode: pick first one for that media matching the InkSet limitation */
1128 if ( (muse->use_flags & INKSET_BLACK_MODEREPL) ) {
1129 mode=find_first_matching_mode_monochrome(v,muse,caps,duplex_mode);
1130 }
1131 else { /* no special replacement modes for black inkset */
1132 mode=find_first_matching_mode(v,muse,caps,duplex_mode);
1133 stp_dprintf(STP_DBG_CANON, v,"Gutenprint (check_current_mode): Ink set is set to CANON_INK_K but did no special conditions, so first match taken: '%s'\n",mode->name);
1134 }
1135 }
1136 if (!mode)
1137 modefound=0;
1138 else
1139 modefound=1;
1140
1141 /* set InkType for the mode found */
1142 for(i=0;i<sizeof(canon_inktypes)/sizeof(canon_inktypes[0]);i++){
1143 if (mode->ink_types & canon_inktypes[i].ink_type) {
1144 if (strcmp(ink_type,canon_inktypes[i].name)) { /* if InkType does not match selected mode ink type*/
1145 stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (InkSet:Black): InkType changed to %i(%s)\n",canon_inktypes[i].ink_type,canon_inktypes[i].name);
1146 stp_set_string_parameter(v, "InkType", canon_inktypes[i].name);
1147 ink_type = stp_get_string_parameter(v, "InkType");
1148 break;
1149 }
1150 }
1151 }
1152 }
1153 else {
1154 /* mode is fine */
1155 /* matched expected K inkset, but need to check if Duplex matches, and if not, get a new mode with right inkset */
1156 mode=suitable_mode_monochrome(v,muse,caps,quality,duplex_mode);
1157 stp_dprintf(STP_DBG_CANON, v,"Gutenprint (check_current_mode): Ink set is set to CANON_INK_K and mode already fits (but need to check for duplex condition): '%s'\n",mode->name);
1158 if (!mode)
1159 modefound=0;
1160 else
1161 modefound=1;
1162
1163 if (modefound == 0) { /* still did not find a mode: pick first one for that media matching the InkSet limitation */
1164 if ( (muse->use_flags & INKSET_BLACK_MODEREPL) ) {
1165 mode=find_first_matching_mode_monochrome(v,muse,caps,duplex_mode);
1166 stp_dprintf(STP_DBG_CANON, v,"Gutenprint (check_current_mode): Ink set is set to CANON_INK_K, pick first one matching condition for black mode replacement: '%s'\n",mode->name);
1167 }
1168 else { /* no special replacement modes for black inkset */
1169 mode=find_first_matching_mode(v,muse,caps,duplex_mode);
1170 stp_dprintf(STP_DBG_CANON, v,"Gutenprint (check_current_mode): Ink set is set to CANON_INK_K, pick first one matching condition without mode replacement needed: '%s'\n",mode->name);
1171 }
1172 }
1173
1174 ink_type=find_ink_type(v,mode,printing_mode);
1175 #if 0
1176 /* if InkType does not match that of mode, change InkType to match it */
1177 /* choose highest color as default, as there is only one option for Black */
1178 /* if InkType does not match that of mode, change InkType to match it */
1179 /* choose highest color as default, as there is only one option for Black */
1180 if (printing_mode && !strcmp(printing_mode,"BW")) {
1181 stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (InkSet:Black): InkType changed to %u (%s)\n",CANON_INK_K, "Gray");
1182 stp_set_string_parameter(v, "InkType", "Gray");
1183 ink_type = stp_get_string_parameter(v, "InkType");
1184 } else {
1185 inkfound=0;
1186 stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (InkSet:Black): InkType of mode %s is currently set as %s\n",mode->name,ink_type);
1187 for(i=0;i<sizeof(canon_inktypes)/sizeof(canon_inktypes[0]);i++){
1188 if (mode->ink_types & canon_inktypes[i].ink_type) { /* a mode can have several ink_types: must compare with ink_type if set */
1189 if ( !(strcmp(ink_type,canon_inktypes[i].name))) {
1190 inkfound=1;
1191 stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (InkSet:Black): InkType match found %i(%s)\n",canon_inktypes[i].ink_type,canon_inktypes[i].name);
1192 stp_set_string_parameter(v, "InkType", canon_inktypes[i].name);
1193 ink_type = stp_get_string_parameter(v, "InkType");
1194 break;
1195 }
1196 }
1197 }
1198 /* if no match found choose first available inkset */
1199 if (inkfound==0) {
1200 for(i=0;i<sizeof(canon_inktypes)/sizeof(canon_inktypes[0]);i++){
1201 if (mode->ink_types & canon_inktypes[i].ink_type) { /* a mode can have several ink_types: must compare with ink_type if set */
1202 if ((!ink_type) || (strcmp(ink_type,canon_inktypes[i].name))) { /* if InkType does not match selected mode ink type*/
1203 stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (InkSet:Black): No match found---InkType changed to %i(%s)\n",canon_inktypes[i].ink_type,canon_inktypes[i].name);
1204 stp_set_string_parameter(v, "InkType", canon_inktypes[i].name);
1205 ink_type = stp_get_string_parameter(v, "InkType");
1206 inkfound=1; /* set */
1207 break;
1208 }
1209 }
1210 }
1211 }
1212 }
1213 #endif
1214
1215 #if 0
1216 /* set InkType for the mode found */
1217 for(i=0;i<sizeof(canon_inktypes)/sizeof(canon_inktypes[0]);i++){
1218 if (mode->ink_types & canon_inktypes[i].ink_type) {
1219 if (strcmp(ink_type,canon_inktypes[i].name)) { /* if InkType does not match selected mode ink type*/
1220 stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (InkSet:Black): InkType changed to %i(%s)\n",canon_inktypes[i].ink_type,canon_inktypes[i].name);
1221 stp_set_string_parameter(v, "InkType", canon_inktypes[i].name);
1222 ink_type = stp_get_string_parameter(v, "InkType");
1223 break;
1224 }
1225 }
1226 }
1227 #endif
1228
1229 }
1230 } /* End of Black Inkset */
1231 /*-------------------------------------------------------------------------------------------------*/
1232 /* Color InkSet */
1233 /* Added limitation: "Color" for BJC corresponds to "Both" on other types */
1234 else if ( (ink_set && !strcmp(ink_set,"Color")) && (caps->features & CANON_CAP_T) ) {
1235 stp_set_string_parameter(v, "PrintingMode","Color");
1236 printing_mode = stp_get_string_parameter(v, "PrintingMode");
1237 if (!(mode->ink_types & CANON_INK_CMY)) {
1238 stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (InkSet:Color): inkset incorrect for Color cartridge---need new mode\n");
1239 /* need a new mode
1240 loop through modes in muse list searching for a matching inktype, comparing quality
1241 */
1242 mode=suitable_mode_color(v,muse,caps,quality,duplex_mode);
1243 if (!mode)
1244 modefound=0;
1245 else
1246 modefound=1;
1247
1248 if (modefound == 0) { /* still did not find a mode: pick first one for that media */
1249 if ( (muse->use_flags & INKSET_COLOR_MODEREPL) ) {
1250 mode=find_first_matching_mode_color(v,muse,caps,duplex_mode);
1251 stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (InkSet:Color): Decided on first matching mode for color inkset (%s)\n",mode->name);
1252 }
1253 else { /* no special replacement modes for color inkset */
1254 mode=find_first_matching_mode(v,muse,caps,duplex_mode);
1255 stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (InkSet:Color): Decided on first matching mode with no special replacement modes for color inkset (%s)\n",mode->name);
1256 }
1257 }
1258 if (!mode)
1259 modefound=0;
1260 else
1261 modefound=1;
1262
1263 ink_type=find_ink_type(v,mode,printing_mode);
1264 #if 0
1265 /* if InkType does not match that of mode, change InkType to match it */
1266 /* choose highest color as default, as there is only one option for Black */
1267 /* if InkType does not match that of mode, change InkType to match it */
1268 /* choose highest color as default, as there is only one option for Black */
1269 if (printing_mode && !strcmp(printing_mode,"BW")) {
1270 stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (InkSet:Color): InkType changed to %u (%s)\n",CANON_INK_K, "Gray");
1271 stp_set_string_parameter(v, "InkType", "Gray");
1272 ink_type = stp_get_string_parameter(v, "InkType");
1273 } else {
1274 inkfound=0;
1275 stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (InkSet:Color): InkType of mode %s is currently set as %s\n",mode->name,ink_type);
1276 for(i=0;i<sizeof(canon_inktypes)/sizeof(canon_inktypes[0]);i++){
1277 if (mode->ink_types & canon_inktypes[i].ink_type) { /* a mode can have several ink_types: must compare with ink_type if set */
1278 if ( !(strcmp(ink_type,canon_inktypes[i].name))) {
1279 inkfound=1;
1280 stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (InkSet:Color): InkType match found %i(%s)\n",canon_inktypes[i].ink_type,canon_inktypes[i].name);
1281 stp_set_string_parameter(v, "InkType", canon_inktypes[i].name);
1282 ink_type = stp_get_string_parameter(v, "InkType");
1283 break;
1284 }
1285 }
1286 }
1287 /* if no match found choose first available inkset */
1288 if (inkfound==0) {
1289 for(i=0;i<sizeof(canon_inktypes)/sizeof(canon_inktypes[0]);i++){
1290 if (mode->ink_types & canon_inktypes[i].ink_type) { /* a mode can have several ink_types: must compare with ink_type if set */
1291 if ((!ink_type) || (strcmp(ink_type,canon_inktypes[i].name))) { /* if InkType does not match selected mode ink type*/
1292 stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (InkSet:Both): No match found---InkType changed to %i(%s)\n",canon_inktypes[i].ink_type,canon_inktypes[i].name);
1293 stp_set_string_parameter(v, "InkType", canon_inktypes[i].name);
1294 ink_type = stp_get_string_parameter(v, "InkType");
1295 inkfound=1; /* set */
1296 break;
1297 }
1298 }
1299 }
1300 }
1301 }
1302 #endif
1303 #if 0
1304 /* set InkType for the mode found */
1305 for(i=0;i<sizeof(canon_inktypes)/sizeof(canon_inktypes[0]);i++){
1306 if (mode->ink_types & canon_inktypes[i].ink_type) {
1307 if (strcmp(ink_type,canon_inktypes[i].name)) { /* if InkType does not match selected mode ink type*/
1308 stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (InkSet:Color): InkType changed to %i(%s)\n",canon_inktypes[i].ink_type,canon_inktypes[i].name);
1309 stp_set_string_parameter(v, "InkType", canon_inktypes[i].name);
1310 ink_type = stp_get_string_parameter(v, "InkType");
1311 break;
1312 }
1313 }
1314 }
1315 #endif
1316
1317 }
1318 else {
1319 /* mode is fine */
1320 /* matched expected RGB inkset, but need to check if Duplex matches, and if not, get a new mode with right inkset */
1321 stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (InkSet:Color): inkset OK but need to check other parameters\n");
1322 mode=suitable_mode_color(v,muse,caps,quality,duplex_mode);
1323 if (!mode)
1324 modefound=0;
1325 else
1326 modefound=1;
1327
1328 if (modefound == 0) { /* still did not find a mode: pick first one for that media */
1329 if ( (muse->use_flags & INKSET_COLOR_MODEREPL) ) {
1330 mode=find_first_matching_mode_color(v,muse,caps,duplex_mode);
1331 stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (InkSet:Color): Decided on first matching mode for color inkset (%s)\n",mode->name);
1332 }
1333 else { /* no special replacement modes for color inkset */
1334 mode=find_first_matching_mode(v,muse,caps,duplex_mode);
1335 stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (InkSet:Color): Decided on first matching mode with no special replacement modes for color inkset (%s)\n",mode->name);
1336 }
1337 }
1338 if (!mode)
1339 modefound=0;
1340 else
1341 modefound=1;
1342
1343 ink_type=find_ink_type(v,mode,printing_mode);
1344 #if 0
1345 /* if InkType does not match that of mode, change InkType to match it */
1346 /* choose highest color as default, as there is only one option for Black */
1347 /* if InkType does not match that of mode, change InkType to match it */
1348 /* choose highest color as default, as there is only one option for Black */
1349 if (printing_mode && !strcmp(printing_mode,"BW")) {
1350 stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (InkSet:Color): InkType changed to %u (%s)\n",CANON_INK_K, "Gray");
1351 stp_set_string_parameter(v, "InkType", "Gray");
1352 ink_type = stp_get_string_parameter(v, "InkType");
1353 } else {
1354 inkfound=0;
1355 stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (InkSet:Color): InkType of mode %s is currently set as %s\n",mode->name,ink_type);
1356 for(i=0;i<sizeof(canon_inktypes)/sizeof(canon_inktypes[0]);i++){
1357 if (mode->ink_types & canon_inktypes[i].ink_type) { /* a mode can have several ink_types: must compare with ink_type if set */
1358 if ( !(strcmp(ink_type,canon_inktypes[i].name))) {
1359 inkfound=1;
1360 stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (InkSet:Color): InkType match found %i(%s)\n",canon_inktypes[i].ink_type,canon_inktypes[i].name);
1361 stp_set_string_parameter(v, "InkType", canon_inktypes[i].name);
1362 ink_type = stp_get_string_parameter(v, "InkType");
1363 break;
1364 }
1365 }
1366 }
1367 /* if no match found choose first available inkset */
1368 if (inkfound==0) {
1369 for(i=0;i<sizeof(canon_inktypes)/sizeof(canon_inktypes[0]);i++){
1370 if (mode->ink_types & canon_inktypes[i].ink_type) { /* a mode can have several ink_types: must compare with ink_type if set */
1371 if ((!ink_type) || (strcmp(ink_type,canon_inktypes[i].name))) { /* if InkType does not match selected mode ink type*/
1372 stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (InkSet:Color): No match found---InkType changed to %i(%s)\n",canon_inktypes[i].ink_type,canon_inktypes[i].name);
1373 stp_set_string_parameter(v, "InkType", canon_inktypes[i].name);
1374 ink_type = stp_get_string_parameter(v, "InkType");
1375 inkfound=1; /* set */
1376 break;
1377 }
1378 }
1379 }
1380 }
1381 }
1382 #endif
1383 #if 0
1384 /* set InkType for the mode found */
1385 for(i=0;i<sizeof(canon_inktypes)/sizeof(canon_inktypes[0]);i++){
1386 if (mode->ink_types & canon_inktypes[i].ink_type) {
1387 if (strcmp(ink_type,canon_inktypes[i].name)) { /* if InkType does not match selected mode ink type*/
1388 stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (InkSet:Color): InkType changed to %i(%s)\n",canon_inktypes[i].ink_type,canon_inktypes[i].name);
1389 stp_set_string_parameter(v, "InkType", canon_inktypes[i].name);
1390 ink_type = stp_get_string_parameter(v, "InkType");
1391 break;
1392 }
1393 }
1394 }
1395 #endif
1396
1397 }
1398 } /* end of Color InkSet */
1399 /*-------------------------------------------------------------------------------------------------*/
1400 /* Photo cartridge selection: only use modes that support it */
1401 else if (ink_set && !strcmp(ink_set,"Photo")) {
1402 /* Photo cartridge printing does not seem to have any monochrome option */
1403 stp_set_string_parameter(v, "PrintingMode","Color");
1404 printing_mode = stp_get_string_parameter(v, "PrintingMode");
1405 /* need to match photo cartridge mode flag */
1406 if (!(mode->flags & MODE_FLAG_PHOTO)) {
1407 /* need a new mode
1408 loop through modes in muse list searching for a matching inkset, comparing quality
1409 */
1410 mode=suitable_mode_photo(v,muse,caps,quality,duplex_mode);
1411 if (!mode)
1412 modefound=0;
1413 else
1414 modefound=1;
1415
1416 if (modefound == 0) { /* still did not find a mode: pick first one for that media */
1417 if ( (muse->use_flags & INKSET_PHOTO_MODEREPL) ) {
1418 mode=find_first_matching_mode_photo(v,muse,caps,duplex_mode);
1419 }
1420 else { /* no special replacement modes for photo inkset */
1421 mode=find_first_matching_mode(v,muse,caps,duplex_mode);
1422 }
1423 }
1424 if (!mode)
1425 modefound=0;
1426 else
1427 modefound=1;
1428
1429 ink_type=find_ink_type(v,mode,printing_mode);
1430 #if 0
1431 /* if InkType does not match that of mode, change InkType to match it */
1432 /* choose highest color as default, as there is only one option for Black */
1433 /* if InkType does not match that of mode, change InkType to match it */
1434 /* choose highest color as default, as there is only one option for Black */
1435 if (printing_mode && !strcmp(printing_mode,"BW")) {
1436 stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (InkSet:Both): InkType changed to %u (%s)\n",CANON_INK_K, "Gray");
1437 stp_set_string_parameter(v, "InkType", "Gray");
1438 ink_type = stp_get_string_parameter(v, "InkType");
1439 } else {
1440 inkfound=0;
1441 stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (InkSet:Both): InkType of mode %s is currently set as %s\n",mode->name,ink_type);
1442 for(i=0;i<sizeof(canon_inktypes)/sizeof(canon_inktypes[0]);i++){
1443 if (mode->ink_types & canon_inktypes[i].ink_type) { /* a mode can have several ink_types: must compare with ink_type if set */
1444 if ( !(strcmp(ink_type,canon_inktypes[i].name))) {
1445 inkfound=1;
1446 stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (InkSet:Both): InkType match found %i(%s)\n",canon_inktypes[i].ink_type,canon_inktypes[i].name);
1447 stp_set_string_parameter(v, "InkType", canon_inktypes[i].name);
1448 ink_type = stp_get_string_parameter(v, "InkType");
1449 break;
1450 }
1451 }
1452 }
1453 /* if no match found choose first available inkset */
1454 if (inkfound==0) {
1455 for(i=0;i<sizeof(canon_inktypes)/sizeof(canon_inktypes[0]);i++){
1456 if (mode->ink_types & canon_inktypes[i].ink_type) { /* a mode can have several ink_types: must compare with ink_type if set */
1457 if ((!ink_type) || (strcmp(ink_type,canon_inktypes[i].name))) { /* if InkType does not match selected mode ink type*/
1458 stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (InkSet:Both): No match found---InkType changed to %i(%s)\n",canon_inktypes[i].ink_type,canon_inktypes[i].name);
1459 stp_set_string_parameter(v, "InkType", canon_inktypes[i].name);
1460 ink_type = stp_get_string_parameter(v, "InkType");
1461 inkfound=1; /* set */
1462 break;
1463 }
1464 }
1465 }
1466 }
1467 }
1468 #endif
1469 #if 0
1470 /* set InkType for the mode found */
1471 for(i=0;i<sizeof(canon_inktypes)/sizeof(canon_inktypes[0]);i++){
1472 if (mode->ink_types & canon_inktypes[i].ink_type) {
1473 if (strcmp(ink_type,canon_inktypes[i].name)) { /* if InkType does not match selected mode ink type*/
1474 stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (InkSet:Color): InkType changed to %i(%s)\n",canon_inktypes[i].ink_type,canon_inktypes[i].name);
1475 stp_set_string_parameter(v, "InkType", canon_inktypes[i].name);
1476 ink_type = stp_get_string_parameter(v, "InkType");
1477 break;
1478 }
1479 }
1480 }
1481 #endif
1482
1483 }
1484 else {
1485 /* mode is fine */
1486 /* matched expected inkset, but need to check if Duplex matches, and if not, get a new mode with right inkset */
1487 mode=suitable_mode_photo(v,muse,caps,quality,duplex_mode);
1488 if (!mode)
1489 modefound=0;
1490 else
1491 modefound=1;
1492
1493 if (modefound == 0) { /* still did not find a mode: pick first one for that media */
1494 if ( (muse->use_flags & INKSET_PHOTO_MODEREPL) ) {
1495 mode=find_first_matching_mode_photo(v,muse,caps,duplex_mode);
1496 }
1497 else { /* no special replacement modes for photo inkset */
1498 mode=find_first_matching_mode(v,muse,caps,duplex_mode);
1499 }
1500 }
1501 if (!mode)
1502 modefound=0;
1503 else
1504 modefound=1;
1505
1506 ink_type=find_ink_type(v,mode,printing_mode);
1507 #if 0
1508 /* if InkType does not match that of mode, change InkType to match it */
1509 /* choose highest color as default, as there is only one option for Black */
1510 /* if InkType does not match that of mode, change InkType to match it */
1511 /* choose highest color as default, as there is only one option for Black */
1512 if (printing_mode && !strcmp(printing_mode,"BW")) {
1513 stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (InkSet:Both): InkType changed to %u (%s)\n",CANON_INK_K, "Gray");
1514 stp_set_string_parameter(v, "InkType", "Gray");
1515 ink_type = stp_get_string_parameter(v, "InkType");
1516 } else {
1517 inkfound=0;
1518 stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (InkSet:Both): InkType of mode %s is currently set as %s\n",mode->name,ink_type);
1519 for(i=0;i<sizeof(canon_inktypes)/sizeof(canon_inktypes[0]);i++){
1520 if (mode->ink_types & canon_inktypes[i].ink_type) { /* a mode can have several ink_types: must compare with ink_type if set */
1521 if ( !(strcmp(ink_type,canon_inktypes[i].name))) {
1522 inkfound=1;
1523 stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (InkSet:Both): InkType match found %i(%s)\n",canon_inktypes[i].ink_type,canon_inktypes[i].name);
1524 stp_set_string_parameter(v, "InkType", canon_inktypes[i].name);
1525 ink_type = stp_get_string_parameter(v, "InkType");
1526 break;
1527 }
1528 }
1529 }
1530 /* if no match found choose first available inkset */
1531 if (inkfound==0) {
1532 for(i=0;i<sizeof(canon_inktypes)/sizeof(canon_inktypes[0]);i++){
1533 if (mode->ink_types & canon_inktypes[i].ink_type) { /* a mode can have several ink_types: must compare with ink_type if set */
1534 if ((!ink_type) || (strcmp(ink_type,canon_inktypes[i].name))) { /* if InkType does not match selected mode ink type*/
1535 stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (InkSet:Both): No match found---InkType changed to %i(%s)\n",canon_inktypes[i].ink_type,canon_inktypes[i].name);
1536 stp_set_string_parameter(v, "InkType", canon_inktypes[i].name);
1537 ink_type = stp_get_string_parameter(v, "InkType");
1538 inkfound=1; /* set */
1539 break;
1540 }
1541 }
1542 }
1543 }
1544 }
1545 #endif
1546 #if 0
1547 /* set InkType for the mode found */
1548 for(i=0;i<sizeof(canon_inktypes)/sizeof(canon_inktypes[0]);i++){
1549 if (mode->ink_types & canon_inktypes[i].ink_type) {
1550 if (strcmp(ink_type,canon_inktypes[i].name)) { /* if InkType does not match selected mode ink type*/
1551 stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (InkSet:Color): InkType changed to %i(%s)\n",canon_inktypes[i].ink_type,canon_inktypes[i].name);
1552 stp_set_string_parameter(v, "InkType", canon_inktypes[i].name);
1553 ink_type = stp_get_string_parameter(v, "InkType");
1554 break;
1555 }
1556 }
1557 }
1558
1559 #endif
1560
1561 }
1562 } /* end of Photo Inkset */
1563 /*-------------------------------------------------------------------------------------------------*/
1564 /* no restrictions for InkSet "Both" (non-BJC) or "Color" (BJC) or if no InkSet set yet --- do not worry about InkSet at all */
1565 else {
1566 if (printing_mode && !strcmp(printing_mode,"Color")) {
1567 stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (InkSet:Both) PrintingMode Color\n");
1568 /* must skip K-only inksets if they exist: they only exist if the option "BW" is also declared but we cannot check if an option exists or not */
1569 i=0;
1570 quality = mode->quality;
1571 modefound=0;
1572 while ( (muse->mode_name_list[i]!=NULL) && (modefound != 1) ) {
1573 for(j=0;j<caps->modelist->count;j++){
1574 if(!strcmp(muse->mode_name_list[i],caps->modelist->modes[j].name)){/* find right place in canon-modes list */
1575 if ( (caps->modelist->modes[j].quality >= quality) ) {
1576 if ( (duplex_mode && strncmp(duplex_mode,"Duplex",6)) || !(muse->use_flags & DUPLEX_SUPPORT) || !(caps->modelist->modes[j].flags & MODE_FLAG_NODUPLEX) ) {
1577 /* duplex check */
1578 if (caps->modelist->modes[j].ink_types > CANON_INK_K) {
1579 mode = &caps->modelist->modes[j];
1580 stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (check_current_mode, Both/Color, printmode color): picked first mode with color inkset (%s)\n",mode->name);
1581 modefound=1;
1582 }
1583 }
1584 }
1585 break; /* go to next mode in muse list */
1586 }
1587 }
1588 i++;
1589 }
1590 }
1591 else if (printing_mode && !strcmp(printing_mode,"BW")) {
1592 stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (InkSet:Both) PrintingMode BW\n");
1593 /* need to find K-only inksets: they must exist since we declared the printer to have this capability! */
1594 i=0;
1595 quality = mode->quality;
1596 modefound=0;
1597 while ( (muse->mode_name_list[i]!=NULL) && (modefound != 1) ) {
1598 for(j=0;j<caps->modelist->count;j++){
1599 if(!strcmp(muse->mode_name_list[i],caps->modelist->modes[j].name)){/* find right place in canon-modes list */
1600 if ( (caps->modelist->modes[j].quality >= quality) ) {
1601 if ( (duplex_mode && strncmp(duplex_mode,"Duplex",6)) || !(muse->use_flags & DUPLEX_SUPPORT) || !(caps->modelist->modes[j].flags & MODE_FLAG_NODUPLEX) ) {
1602 /* duplex check */
1603 if (caps->modelist->modes[j].ink_types & CANON_INK_K) { /* AND means support for CANON_IN_K is included */
1604 mode = &caps->modelist->modes[j];
1605 stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (check_current_mode, Both/Color, printmode BW): picked first mode with mono inkset (%s)\n",mode->name);
1606 modefound=1;
1607 }
1608 }
1609 }
1610 break; /* go to next mode in muse list */
1611 }
1612 }
1613 i++;
1614 }
1615 }
1616 else { /* no restriction from PrintingMode if not set yet */
1617 stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (InkSet:Both) PrintingMode not set yet\n");
1618 /* if mode is not a matching duplex mode, need to find a new one */
1619 i=0;
1620 quality = mode->quality;
1621 modefound=0;
1622 while ( (muse->mode_name_list[i]!=NULL) && (modefound != 1) ) {
1623 for(j=0;j<caps->modelist->count;j++){
1624 if(!strcmp(muse->mode_name_list[i],caps->modelist->modes[j].name)){/* find right place in canon-modes list */
1625 if ( (caps->modelist->modes[j].quality >= quality) ) {
1626 if ( !(duplex_mode) || !(muse->use_flags & DUPLEX_SUPPORT) || !(caps->modelist->modes[j].flags & MODE_FLAG_NODUPLEX) ) {
1627 /* duplex check */
1628 mode = &caps->modelist->modes[j];
1629 stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (check_current_mode, Both/Color, printmode unset): picked first mode with quality match (%s)\n",mode->name);
1630 modefound=1;
1631 }
1632 }
1633 break; /* go to next mode in muse list */
1634 }
1635 }
1636 i++;
1637 }
1638 }
1639 /* if no mode was found yet, repeat with no restrictions --- since some media may not allow PrintingMode to be what was selected */
1640 if (modefound==0) {
1641 i=0;
1642 quality = mode->quality;
1643 while ( (muse->mode_name_list[i]!=NULL) && (modefound != 1) ) {
1644 for(j=0;j<caps->modelist->count;j++){
1645 if(!strcmp(muse->mode_name_list[i],caps->modelist->modes[j].name)){/* find right place in canon-modes list */
1646 if ( (caps->modelist->modes[j].quality >= quality) ) {
1647 if ( (duplex_mode && strncmp(duplex_mode,"Duplex",6)) || !(muse->use_flags & DUPLEX_SUPPORT) || !(caps->modelist->modes[j].flags & MODE_FLAG_NODUPLEX) ) {
1648 /* duplex check */
1649 mode = &caps->modelist->modes[j];
1650 stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (check_current_mode, Both/Color, no printmode): picked first mode with quality match (%s)\n",mode->name);
1651 modefound=1;
1652 /* set PrintingMode to whatever the mode is capable of */
1653 if (caps->modelist->modes[j].ink_types > CANON_INK_K) {
1654 stp_set_string_parameter(v,"PrintingMode","Color");
1655 printing_mode = stp_get_string_parameter(v, "PrintingMode");
1656 stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (InkSet:Both) PrintingMode set to Color\n");
1657 } else {
1658 stp_set_string_parameter(v,"PrintingMode","BW");
1659 printing_mode = stp_get_string_parameter(v, "PrintingMode");
1660 stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (InkSet:Both) PrintingMode set to BW\n");
1661 }
1662 }
1663 }
1664 break; /* go to next mode in muse list */
1665 }
1666 }
1667 i++;
1668 }
1669 }
1670
1671 ink_type=find_ink_type(v,mode,printing_mode);
1672 #if 0
1673 /* if InkType does not match that of mode, change InkType to match it */
1674 /* choose highest color as default, as there is only one option for Black */
1675 /* if InkType does not match that of mode, change InkType to match it */
1676 /* choose highest color as default, as there is only one option for Black */
1677 if (printing_mode && !strcmp(printing_mode,"BW")) {
1678 stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (InkSet:Both): InkType changed to %u (%s)\n",CANON_INK_K, "Gray");
1679 stp_set_string_parameter(v, "InkType", "Gray");
1680 ink_type = stp_get_string_parameter(v, "InkType");
1681 } else {
1682 inkfound=0;
1683 stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (InkSet:Both): InkType of mode %s is currently set as %s\n",mode->name,ink_type);
1684 for(i=0;i<sizeof(canon_inktypes)/sizeof(canon_inktypes[0]);i++){
1685 if (mode->ink_types & canon_inktypes[i].ink_type) { /* a mode can have several ink_types: must compare with ink_type if set */
1686 if ( !(strcmp(ink_type,canon_inktypes[i].name))) {
1687 inkfound=1;
1688 stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (InkSet:Both): InkType match found %i(%s)\n",canon_inktypes[i].ink_type,canon_inktypes[i].name);
1689 stp_set_string_parameter(v, "InkType", canon_inktypes[i].name);
1690 ink_type = stp_get_string_parameter(v, "InkType");
1691 break;
1692 }
1693 }
1694 }
1695 /* if no match found choose first available inkset */
1696 if (inkfound==0) {
1697 for(i=0;i<sizeof(canon_inktypes)/sizeof(canon_inktypes[0]);i++){
1698 if (mode->ink_types & canon_inktypes[i].ink_type) { /* a mode can have several ink_types: must compare with ink_type if set */
1699 if ((!ink_type) || (strcmp(ink_type,canon_inktypes[i].name))) { /* if InkType does not match selected mode ink type*/
1700 stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (InkSet:Both): No match found---choosing first available. InkType changed to %i(%s)\n",canon_inktypes[i].ink_type,canon_inktypes[i].name);
1701 stp_set_string_parameter(v, "InkType", canon_inktypes[i].name);
1702 ink_type = stp_get_string_parameter(v, "InkType");
1703 inkfound=1; /* set */
1704 break;
1705 }
1706 }
1707 }
1708 }
1709 }
1710 #endif
1711
1712 /* end of cartridge option block */
1713
1714 stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint: mode searching: replaced mode with: '%s'\n",mode->name);
1715
1716 #if 0
1717 /* set InkType for the mode decided upon */
1718 for(i=0;i<sizeof(canon_inktypes)/sizeof(canon_inktypes[0]);i++){
1719 if (mode->ink_types & canon_inktypes[i].ink_type) {
1720 if (strcmp(ink_type,canon_inktypes[i].name)) {
1721 stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (Mode found): InkType changed to %i(%s)\n",canon_inktypes[i].ink_type,canon_inktypes[i].name);
1722 stp_set_string_parameter(v, "InkType", canon_inktypes[i].name);
1723 ink_type = stp_get_string_parameter(v, "InkType");
1724 break;
1725 }
1726 }
1727 }
1728 #endif
1729
1730 }
1731 }
1732 /* -------------------------------------- modecheck returned 0 for compare_mode_valid ------------------------------------------*/
1733 else { /* we did find the mode in the list for media, so it should take precedence over other settings, as it is more specific. */
1734
1735 stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (check_current_mode): mode exists, need to check for consistency (%s)\n",mode->name);
1736 quality = mode->quality;
1737 /* Black InkSet */
1738 if (ink_set && !strcmp(ink_set,"Black")) {
1739 stp_set_string_parameter(v, "PrintingMode","BW");
1740 printing_mode = stp_get_string_parameter(v, "PrintingMode");
1741 if (!(mode->ink_types & CANON_INK_K)) {
1742 /* need a new mode:
1743 loop through modes in muse list searching for a matching inktype, comparing quality
1744 */
1745 mode=suitable_mode_monochrome(v,muse,caps,quality,duplex_mode);
1746 if (!mode)
1747 modefound=0;
1748 else
1749 modefound=1;
1750
1751 if (modefound == 0) { /* still did not find a mode: pick first one for that media */
1752 if ( (muse->use_flags & INKSET_BLACK_MODEREPL) ) {
1753 mode=find_first_matching_mode_monochrome(v,muse,caps,duplex_mode);
1754 }
1755 else { /* no special replacement modes for black inkset */
1756 mode=find_first_matching_mode(v,muse,caps,duplex_mode);
1757 }
1758 }
1759 if (!mode)
1760 modefound=0;
1761 else
1762 modefound=1;
1763
1764 ink_type=find_ink_type(v,mode,printing_mode);
1765 #if 0
1766 /* if InkType does not match that of mode, change InkType to match it */
1767 /* choose highest color as default, as there is only one option for Black */
1768 /* if InkType does not match that of mode, change InkType to match it */
1769 /* choose highest color as default, as there is only one option for Black */
1770 if (printing_mode && !strcmp(printing_mode,"BW")) {
1771 stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (InkSet:Both): InkType changed to %u (%s)\n",CANON_INK_K, "Gray");
1772 stp_set_string_parameter(v, "InkType", "Gray");
1773 ink_type = stp_get_string_parameter(v, "InkType");
1774 } else {
1775 inkfound=0;
1776 stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (InkSet:Both): InkType of mode %s is currently set as %s\n",mode->name,ink_type);
1777 for(i=0;i<sizeof(canon_inktypes)/sizeof(canon_inktypes[0]);i++){
1778 if (mode->ink_types & canon_inktypes[i].ink_type) { /* a mode can have several ink_types: must compare with ink_type if set */
1779 if ( !(strcmp(ink_type,canon_inktypes[i].name))) {
1780 inkfound=1;
1781 stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (InkSet:Both): InkType match found %i(%s)\n",canon_inktypes[i].ink_type,canon_inktypes[i].name);
1782 stp_set_string_parameter(v, "InkType", canon_inktypes[i].name);
1783 ink_type = stp_get_string_parameter(v, "InkType");
1784 break;
1785 }
1786 }
1787 }
1788 /* if no match found choose first available inkset */
1789 if (inkfound==0) {
1790 for(i=0;i<sizeof(canon_inktypes)/sizeof(canon_inktypes[0]);i++){
1791 if (mode->ink_types & canon_inktypes[i].ink_type) { /* a mode can have several ink_types: must compare with ink_type if set */
1792 if ((!ink_type) || (strcmp(ink_type,canon_inktypes[i].name))) { /* if InkType does not match selected mode ink type*/
1793 stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (InkSet:Both): No match found---InkType changed to %i(%s)\n",canon_inktypes[i].ink_type,canon_inktypes[i].name);
1794 stp_set_string_parameter(v, "InkType", canon_inktypes[i].name);
1795 ink_type = stp_get_string_parameter(v, "InkType");
1796 inkfound=1; /* set */
1797 break;
1798 }
1799 }
1800 }
1801 }
1802 }
1803 #endif
1804 #if 0
1805 /* set InkType for the mode found */
1806 for(i=0;i<sizeof(canon_inktypes)/sizeof(canon_inktypes[0]);i++){
1807 if (mode->ink_types & canon_inktypes[i].ink_type) {
1808 if (strcmp(ink_type,canon_inktypes[i].name)) { /* if InkType does not match selected mode ink type*/
1809 stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (InkSet:Black): InkType changed to %i(%s)\n",canon_inktypes[i].ink_type,canon_inktypes[i].name);
1810 stp_set_string_parameter(v, "InkType", canon_inktypes[i].name);
1811 ink_type = stp_get_string_parameter(v, "InkType");
1812 break;
1813 }
1814 }
1815 }
1816 #endif
1817
1818 }
1819 else {
1820 /* mode is fine */
1821 /* matched expected K inkset, but need to check if Duplex matches, and if not, get a new mode with right inkset */
1822 mode=suitable_mode_monochrome(v,muse,caps,quality,duplex_mode);
1823 if (!mode)
1824 modefound=0;
1825 else
1826 modefound=1;
1827
1828 if (modefound == 0) { /* still did not find a mode: pick first one for that media */
1829 if ( (muse->use_flags & INKSET_BLACK_MODEREPL) ) {
1830 mode=find_first_matching_mode_monochrome(v,muse,caps,duplex_mode);
1831 }
1832 else { /* no special replacement modes for black inkset */
1833 mode=find_first_matching_mode(v,muse,caps,duplex_mode);
1834 }
1835 }
1836 if (!mode)
1837 modefound=0;
1838 else
1839 modefound=1;
1840
1841 ink_type=find_ink_type(v,mode,printing_mode);
1842 #if 0
1843 /* if InkType does not match that of mode, change InkType to match it */
1844 /* choose highest color as default, as there is only one option for Black */
1845 /* if InkType does not match that of mode, change InkType to match it */
1846 /* choose highest color as default, as there is only one option for Black */
1847 if (printing_mode && !strcmp(printing_mode,"BW")) {
1848 stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (InkSet:Both): InkType changed to %u (%s)\n",CANON_INK_K, "Gray");
1849 stp_set_string_parameter(v, "InkType", "Gray");
1850 ink_type = stp_get_string_parameter(v, "InkType");
1851 } else {
1852 inkfound=0;
1853 stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (InkSet:Both): InkType of mode %s is currently set as %s\n",mode->name,ink_type);
1854 for(i=0;i<sizeof(canon_inktypes)/sizeof(canon_inktypes[0]);i++){
1855 if (mode->ink_types & canon_inktypes[i].ink_type) { /* a mode can have several ink_types: must compare with ink_type if set */
1856 if ( !(strcmp(ink_type,canon_inktypes[i].name))) {
1857 inkfound=1;
1858 stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (InkSet:Both): InkType match found %i(%s)\n",canon_inktypes[i].ink_type,canon_inktypes[i].name);
1859 stp_set_string_parameter(v, "InkType", canon_inktypes[i].name);
1860 ink_type = stp_get_string_parameter(v, "InkType");
1861 break;
1862 }
1863 }
1864 }
1865 /* if no match found choose first available inkset */
1866 if (inkfound==0) {
1867 for(i=0;i<sizeof(canon_inktypes)/sizeof(canon_inktypes[0]);i++){
1868 if (mode->ink_types & canon_inktypes[i].ink_type) { /* a mode can have several ink_types: must compare with ink_type if set */
1869 if ((!ink_type) || (strcmp(ink_type,canon_inktypes[i].name))) { /* if InkType does not match selected mode ink type*/
1870 stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (InkSet:Both): No match found---InkType changed to %i(%s)\n",canon_inktypes[i].ink_type,canon_inktypes[i].name);
1871 stp_set_string_parameter(v, "InkType", canon_inktypes[i].name);
1872 ink_type = stp_get_string_parameter(v, "InkType");
1873 inkfound=1; /* set */
1874 break;
1875 }
1876 }
1877 }
1878 }
1879 }
1880 #endif
1881 #if 0
1882 /* set InkType for the mode found */
1883 for(i=0;i<sizeof(canon_inktypes)/sizeof(canon_inktypes[0]);i++){
1884 if (mode->ink_types & canon_inktypes[i].ink_type) {
1885 if (strcmp(ink_type,canon_inktypes[i].name)) { /* if InkType does not match selected mode ink type*/
1886 stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (InkSet:Black): InkType changed to %i(%s)\n",canon_inktypes[i].ink_type,canon_inktypes[i].name);
1887 stp_set_string_parameter(v, "InkType", canon_inktypes[i].name);
1888 ink_type = stp_get_string_parameter(v, "InkType");
1889 break;
1890 }
1891 }
1892 }
1893 #endif
1894
1895 }
1896 } /* End of Black Inkset */
1897 /*-------------------------------------------------------------------------------------------------*/
1898 /* InkSet Color */
1899 else if ( (ink_set && !strcmp(ink_set,"Color")) && (caps->features & CANON_CAP_T) ) {
1900 stp_set_string_parameter(v, "PrintingMode","Color");
1901 printing_mode = stp_get_string_parameter(v, "PrintingMode");
1902 if (!(mode->ink_types & CANON_INK_CMY)) { /* Color InkSet */
1903 stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (InkSet:Color): inkset incorrect for Color cartridge---need new mode\n");
1904 /* need a new mode
1905 loop through modes in muse list searching for a matching inktype, comparing quality
1906 */
1907 mode=suitable_mode_color(v,muse,caps,quality,duplex_mode);
1908
1909 if (!mode)
1910 modefound=0;
1911 else
1912 modefound=1;
1913
1914 if (modefound == 0) { /* still did not find a mode: pick first one for that media */
1915 if ( (muse->use_flags & INKSET_COLOR_MODEREPL) ) {
1916 mode=find_first_matching_mode_monochrome(v,muse,caps,duplex_mode);
1917 stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (InkSet:Color): Decided on first matching mode for color inkset (%s)\n",mode->name);
1918 }
1919 else { /* no special replacement modes for color inkset */
1920 mode=find_first_matching_mode(v,muse,caps,duplex_mode);
1921 stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (InkSet:Color): Decided on first matching mode with no special replacement modes for color inkset (%s)\n",mode->name);
1922 }
1923 }
1924 if (!mode)
1925 modefound=0;
1926 else
1927 modefound=1;
1928
1929 ink_type=find_ink_type(v,mode,printing_mode);
1930 #if 0
1931 /* if InkType does not match that of mode, change InkType to match it */
1932 /* choose highest color as default, as there is only one option for Black */
1933 /* if InkType does not match that of mode, change InkType to match it */
1934 /* choose highest color as default, as there is only one option for Black */
1935 if (printing_mode && !strcmp(printing_mode,"BW")) {
1936 stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (InkSet:Both): InkType changed to %u (%s)\n",CANON_INK_K, "Gray");
1937 stp_set_string_parameter(v, "InkType", "Gray");
1938 ink_type = stp_get_string_parameter(v, "InkType");
1939 } else {
1940 inkfound=0;
1941 stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (InkSet:Both): InkType of mode %s is currently set as %s\n",mode->name,ink_type);
1942 for(i=0;i<sizeof(canon_inktypes)/sizeof(canon_inktypes[0]);i++){
1943 if (mode->ink_types & canon_inktypes[i].ink_type) { /* a mode can have several ink_types: must compare with ink_type if set */
1944 if ( !(strcmp(ink_type,canon_inktypes[i].name))) {
1945 inkfound=1;
1946 stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (InkSet:Both): InkType match found %i(%s)\n",canon_inktypes[i].ink_type,canon_inktypes[i].name);
1947 stp_set_string_parameter(v, "InkType", canon_inktypes[i].name);
1948 ink_type = stp_get_string_parameter(v, "InkType");
1949 break;
1950 }
1951 }
1952 }
1953 /* if no match found choose first available inkset */
1954 if (inkfound==0) {
1955 for(i=0;i<sizeof(canon_inktypes)/sizeof(canon_inktypes[0]);i++){
1956 if (mode->ink_types & canon_inktypes[i].ink_type) { /* a mode can have several ink_types: must compare with ink_type if set */
1957 if ((!ink_type) || (strcmp(ink_type,canon_inktypes[i].name))) { /* if InkType does not match selected mode ink type*/
1958 stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (InkSet:Both): No match found---InkType changed to %i(%s)\n",canon_inktypes[i].ink_type,canon_inktypes[i].name);
1959 stp_set_string_parameter(v, "InkType", canon_inktypes[i].name);
1960 ink_type = stp_get_string_parameter(v, "InkType");
1961 inkfound=1; /* set */
1962 break;
1963 }
1964 }
1965 }
1966 }
1967 }
1968 #endif
1969 #if 0
1970 /* set InkType for the mode found */
1971 for(i=0;i<sizeof(canon_inktypes)/sizeof(canon_inktypes[0]);i++){
1972 if (mode->ink_types & canon_inktypes[i].ink_type) {
1973 if (strcmp(ink_type,canon_inktypes[i].name)) { /* if InkType does not match selected mode ink type*/
1974 stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (InkSet:Color): InkType changed to %i(%s)\n",canon_inktypes[i].ink_type,canon_inktypes[i].name);
1975 stp_set_string_parameter(v, "InkType", canon_inktypes[i].name);
1976 ink_type = stp_get_string_parameter(v, "InkType");
1977 break;
1978 }
1979 }
1980 }
1981 #endif
1982
1983 }
1984 else {
1985 /* mode is fine */
1986 /* matched expected RGB inkset, but need to check if Duplex matches, and if not, get a new mode with right inkset */
1987 stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (InkSet:Color): inkset OK but need to check other parameters\n");
1988 mode=suitable_mode_color(v,muse,caps,quality,duplex_mode); /* something wrong here!!! */
1989 stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (InkSet:Color): returned mode for color inkset: %s\n",mode->name);
1990 if (!mode)
1991 modefound=0;
1992 else
1993 modefound=1;
1994
1995 if (modefound == 0) { /* still did not find a mode: pick first one for that media */
1996 if ( (muse->use_flags & INKSET_COLOR_MODEREPL) ) {
1997 mode=find_first_matching_mode_monochrome(v,muse,caps,duplex_mode);
1998 stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (InkSet:Color): Decided on first matching mode for color inkset (%s)\n",mode->name);
1999 }
2000 else { /* no special replacement modes for color inkset */
2001 mode=find_first_matching_mode(v,muse,caps,duplex_mode);
2002 stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (InkSet:Color): Decided on first matching mode with no special replacement modes for color inkset (%s)\n",mode->name);
2003 }
2004 }
2005 if (!mode)
2006 modefound=0;
2007 else
2008 modefound=1;
2009
2010 ink_type=find_ink_type(v,mode,printing_mode);
2011 #if 0
2012 /* if InkType does not match that of mode, change InkType to match it */
2013 /* choose highest color as default, as there is only one option for Black */
2014 /* if InkType does not match that of mode, change InkType to match it */
2015 /* choose highest color as default, as there is only one option for Black */
2016 if (printing_mode && !strcmp(printing_mode,"BW")) {
2017 stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (InkSet:Both): InkType changed to %u (%s)\n",CANON_INK_K, "Gray");
2018 stp_set_string_parameter(v, "InkType", "Gray");
2019 ink_type = stp_get_string_parameter(v, "InkType");
2020 } else {
2021 inkfound=0;
2022 stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (InkSet:Both): InkType of mode %s is currently set as %s\n",mode->name,ink_type);
2023 for(i=0;i<sizeof(canon_inktypes)/sizeof(canon_inktypes[0]);i++){
2024 if (mode->ink_types & canon_inktypes[i].ink_type) { /* a mode can have several ink_types: must compare with ink_type if set */
2025 if ( !(strcmp(ink_type,canon_inktypes[i].name))) {
2026 inkfound=1;
2027 stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (InkSet:Both): InkType match found %i(%s)\n",canon_inktypes[i].ink_type,canon_inktypes[i].name);
2028 stp_set_string_parameter(v, "InkType", canon_inktypes[i].name);
2029 ink_type = stp_get_string_parameter(v, "InkType");
2030 break;
2031 }
2032 }
2033 }
2034 /* if no match found choose first available inkset */
2035 if (inkfound==0) {
2036 for(i=0;i<sizeof(canon_inktypes)/sizeof(canon_inktypes[0]);i++){
2037 if (mode->ink_types & canon_inktypes[i].ink_type) { /* a mode can have several ink_types: must compare with ink_type if set */
2038 if ((!ink_type) || (strcmp(ink_type,canon_inktypes[i].name))) { /* if InkType does not match selected mode ink type*/
2039 stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (InkSet:Both): No match found---InkType changed to %i(%s)\n",canon_inktypes[i].ink_type,canon_inktypes[i].name);
2040 stp_set_string_parameter(v, "InkType", canon_inktypes[i].name);
2041 ink_type = stp_get_string_parameter(v, "InkType");
2042 inkfound=1; /* set */
2043 break;
2044 }
2045 }
2046 }
2047 }
2048 }
2049 #endif
2050 #if 0
2051 /* set InkType for the mode found */
2052 for(i=0;i<sizeof(canon_inktypes)/sizeof(canon_inktypes[0]);i++){
2053 if (mode->ink_types & canon_inktypes[i].ink_type) {
2054 if (strcmp(ink_type,canon_inktypes[i].name)) { /* if InkType does not match selected mode ink type*/
2055 stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (InkSet:Color): InkType changed to %i(%s)\n",canon_inktypes[i].ink_type,canon_inktypes[i].name);
2056 stp_set_string_parameter(v, "InkType", canon_inktypes[i].name);
2057 ink_type = stp_get_string_parameter(v, "InkType");
2058 break;
2059 }
2060 }
2061 }
2062 #endif
2063
2064 }
2065 } /* End of Color Inkset */
2066 /*-------------------------------------------------------------------------------------------------*/
2067 /* Photo cartridge selection: only use modes that support it */
2068 else if (ink_set && !strcmp(ink_set,"Photo")) {
2069 /* Photo cartridge printing does not seem to have any monochrome option */
2070 stp_set_string_parameter(v, "PrintingMode","Color");
2071 printing_mode = stp_get_string_parameter(v, "PrintingMode");
2072 /* need to match photo cartridge mode flag */
2073 if (!(mode->flags & MODE_FLAG_PHOTO)) {
2074 /* need a new mode
2075 loop through modes in muse list searching for a matching inkset, comparing quality
2076 */
2077 mode=suitable_mode_photo(v,muse,caps,quality,duplex_mode);
2078 if (!mode)
2079 modefound=0;
2080 else
2081 modefound=1;
2082
2083 if (modefound == 0) { /* still did not find a mode: pick first one for that media */
2084 if ( (muse->use_flags & INKSET_PHOTO_MODEREPL) ) {
2085 mode=find_first_matching_mode_photo(v,muse,caps,duplex_mode);
2086 }
2087 else { /* no special replacement modes for photo inkset */
2088 mode=find_first_matching_mode(v,muse,caps,duplex_mode);
2089 }
2090 }
2091 if (!mode)
2092 modefound=0;
2093 else
2094 modefound=1;
2095
2096 ink_type=find_ink_type(v,mode,printing_mode);
2097 #if 0
2098 /* if InkType does not match that of mode, change InkType to match it */
2099 /* choose highest color as default, as there is only one option for Black */
2100 /* if InkType does not match that of mode, change InkType to match it */
2101 /* choose highest color as default, as there is only one option for Black */
2102 if (printing_mode && !strcmp(printing_mode,"BW")) {
2103 stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (InkSet:Both): InkType changed to %u (%s)\n",CANON_INK_K, "Gray");
2104 stp_set_string_parameter(v, "InkType", "Gray");
2105 ink_type = stp_get_string_parameter(v, "InkType");
2106 } else {
2107 inkfound=0;
2108 stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (InkSet:Both): InkType of mode %s is currently set as %s\n",mode->name,ink_type);
2109 for(i=0;i<sizeof(canon_inktypes)/sizeof(canon_inktypes[0]);i++){
2110 if (mode->ink_types & canon_inktypes[i].ink_type) { /* a mode can have several ink_types: must compare with ink_type if set */
2111 if ( !(strcmp(ink_type,canon_inktypes[i].name))) {
2112 inkfound=1;
2113 stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (InkSet:Both): InkType match found %i(%s)\n",canon_inktypes[i].ink_type,canon_inktypes[i].name);
2114 stp_set_string_parameter(v, "InkType", canon_inktypes[i].name);
2115 ink_type = stp_get_string_parameter(v, "InkType");
2116 break;
2117 }
2118 }
2119 }
2120 /* if no match found choose first available inkset */
2121 if (inkfound==0) {
2122 for(i=0;i<sizeof(canon_inktypes)/sizeof(canon_inktypes[0]);i++){
2123 if (mode->ink_types & canon_inktypes[i].ink_type) { /* a mode can have several ink_types: must compare with ink_type if set */
2124 if ((!ink_type) || (strcmp(ink_type,canon_inktypes[i].name))) { /* if InkType does not match selected mode ink type*/
2125 stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (InkSet:Both): No match found---InkType changed to %i(%s)\n",canon_inktypes[i].ink_type,canon_inktypes[i].name);
2126 stp_set_string_parameter(v, "InkType", canon_inktypes[i].name);
2127 ink_type = stp_get_string_parameter(v, "InkType");
2128 inkfound=1; /* set */
2129 break;
2130 }
2131 }
2132 }
2133 }
2134 }
2135 #endif
2136 #if 0
2137 /* set InkType for the mode found */
2138 for(i=0;i<sizeof(canon_inktypes)/sizeof(canon_inktypes[0]);i++){
2139 if (mode->ink_types & canon_inktypes[i].ink_type) {
2140 if (strcmp(ink_type,canon_inktypes[i].name)) { /* if InkType does not match selected mode ink type*/
2141 stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (InkSet:Color): InkType changed to %i(%s)\n",canon_inktypes[i].ink_type,canon_inktypes[i].name);
2142 stp_set_string_parameter(v, "InkType", canon_inktypes[i].name);
2143 ink_type = stp_get_string_parameter(v, "InkType");
2144 break;
2145 }
2146 }
2147 }
2148 #endif
2149
2150 }
2151 else {
2152 /* mode is fine */
2153 /* matched expected inkset, but need to check if Duplex matches, and if not, get a new mode with right inkset */
2154 mode=suitable_mode_photo(v,muse,caps,quality,duplex_mode);
2155 if (!mode)
2156 modefound=0;
2157 else
2158 modefound=1;
2159
2160 if (modefound == 0) { /* still did not find a mode: pick first one for that media */
2161 if ( (muse->use_flags & INKSET_PHOTO_MODEREPL) ) {
2162 mode=find_first_matching_mode_photo(v,muse,caps,duplex_mode);
2163 }
2164 else { /* no special replacement modes for photo inkset */
2165 mode=find_first_matching_mode(v,muse,caps,duplex_mode);
2166 }
2167 }
2168 if (!mode)
2169 modefound=0;
2170 else
2171 modefound=1;
2172
2173 ink_type=find_ink_type(v,mode,printing_mode);
2174 #if 0
2175 /* if InkType does not match that of mode, change InkType to match it */
2176 /* choose highest color as default, as there is only one option for Black */
2177 /* if InkType does not match that of mode, change InkType to match it */
2178 /* choose highest color as default, as there is only one option for Black */
2179 if (printing_mode && !strcmp(printing_mode,"BW")) {
2180 stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (InkSet:Both): InkType changed to %u (%s)\n",CANON_INK_K, "Gray");
2181 stp_set_string_parameter(v, "InkType", "Gray");
2182 ink_type = stp_get_string_parameter(v, "InkType");
2183 } else {
2184 inkfound=0;
2185 stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (InkSet:Both): InkType of mode %s is currently set as %s\n",mode->name,ink_type);
2186 for(i=0;i<sizeof(canon_inktypes)/sizeof(canon_inktypes[0]);i++){
2187 if (mode->ink_types & canon_inktypes[i].ink_type) { /* a mode can have several ink_types: must compare with ink_type if set */
2188 if ( !(strcmp(ink_type,canon_inktypes[i].name))) {
2189 inkfound=1;
2190 stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (InkSet:Both): InkType match found %i(%s)\n",canon_inktypes[i].ink_type,canon_inktypes[i].name);
2191 stp_set_string_parameter(v, "InkType", canon_inktypes[i].name);
2192 ink_type = stp_get_string_parameter(v, "InkType");
2193 break;
2194 }
2195 }
2196 }
2197 /* if no match found choose first available inkset */
2198 if (inkfound==0) {
2199 for(i=0;i<sizeof(canon_inktypes)/sizeof(canon_inktypes[0]);i++){
2200 if (mode->ink_types & canon_inktypes[i].ink_type) { /* a mode can have several ink_types: must compare with ink_type if set */
2201 if ((!ink_type) || (strcmp(ink_type,canon_inktypes[i].name))) { /* if InkType does not match selected mode ink type*/
2202 stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (InkSet:Both): No match found---InkType changed to %i(%s)\n",canon_inktypes[i].ink_type,canon_inktypes[i].name);
2203 stp_set_string_parameter(v, "InkType", canon_inktypes[i].name);
2204 ink_type = stp_get_string_parameter(v, "InkType");
2205 inkfound=1; /* set */
2206 break;
2207 }
2208 }
2209 }
2210 }
2211 }
2212 #endif
2213 #if 0
2214 /* set InkType for the mode found */
2215 for(i=0;i<sizeof(canon_inktypes)/sizeof(canon_inktypes[0]);i++){
2216 if (mode->ink_types & canon_inktypes[i].ink_type) {
2217 if (strcmp(ink_type,canon_inktypes[i].name)) { /* if InkType does not match selected mode ink type*/
2218 stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (InkSet:Color): InkType changed to %i(%s)\n",canon_inktypes[i].ink_type,canon_inktypes[i].name);
2219 stp_set_string_parameter(v, "InkType", canon_inktypes[i].name);
2220 ink_type = stp_get_string_parameter(v, "InkType");
2221 break;
2222 }
2223 }
2224 }
2225 #endif
2226
2227 }
2228 } /* end of Photo Inkset */
2229 /*-------------------------------------------------------------------------------------------------*/
2230 /* no restrictions for InkSet "Both" (non-BJC) or "Color" (BJC) or if no InkSet set yet */
2231 else {
2232 if (printing_mode && !strcmp(printing_mode,"Color")) {
2233 stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (InkSet:Both) PrintingMode Color\n");
2234 /* must skip K-only inksets if they exist: they only exist if the option "BW" is also declared but we cannot check if an option exists or not */
2235 i=0;
2236 quality = mode->quality;
2237 modefound=0;
2238 while ( (muse->mode_name_list[i]!=NULL) && (modefound != 1) ) {
2239 for(j=0;j<caps->modelist->count;j++){
2240 if(!strcmp(muse->mode_name_list[i],caps->modelist->modes[j].name)){/* find right place in canon-modes list */
2241 if ( (caps->modelist->modes[j].quality >= quality) ) {
2242 if ( (duplex_mode && strncmp(duplex_mode,"Duplex",6)) || !(muse->use_flags & DUPLEX_SUPPORT) || !(caps->modelist->modes[j].flags & MODE_FLAG_NODUPLEX) ) {
2243 /* duplex check */
2244 if (caps->modelist->modes[j].ink_types > CANON_INK_K) {
2245 if (!strcmp(mode->name,caps->modelist->modes[j].name)) {
2246 mode = &caps->modelist->modes[j];
2247 stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (InkSet:Both) Color: Decided on mode (%s)\n",mode->name);
2248 modefound=1;
2249 }
2250 }
2251 }
2252 }
2253 break; /* go to next mode in muse list */
2254 }
2255 }
2256 i++;
2257 }
2258 }
2259 else if (printing_mode && !strcmp(printing_mode,"BW")) {
2260 stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (InkSet:Both) PrintingMode BW\n");
2261 /* need to find K-only inksets: they must exist since we declared the printer to have this capability! */
2262 i=0;
2263 quality = mode->quality;
2264 modefound=0;
2265 while ( (muse->mode_name_list[i]!=NULL) && (modefound != 1) ) {
2266 for(j=0;j<caps->modelist->count;j++){
2267 if(!strcmp(muse->mode_name_list[i],caps->modelist->modes[j].name)){/* find right place in canon-modes list */
2268 if ( (caps->modelist->modes[j].quality >= quality) ) {
2269 if ( (duplex_mode && strncmp(duplex_mode,"Duplex",6)) || !(muse->use_flags & DUPLEX_SUPPORT) || !(caps->modelist->modes[j].flags & MODE_FLAG_NODUPLEX) ) {
2270 /* duplex check */
2271 if (caps->modelist->modes[j].ink_types & CANON_INK_K) { /* AND means CANON_INK_K is included in the support */
2272 if (!strcmp(mode->name,caps->modelist->modes[j].name)) {
2273 mode = &caps->modelist->modes[j];
2274 stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (InkSet:Both) BW: Decided on mode (%s)\n",mode->name);
2275 modefound=1;
2276 }
2277 }
2278 }
2279 }
2280 break; /* go to next mode in muse list */
2281 }
2282 }
2283 i++;
2284 }
2285 }
2286 else { /* no restriction from PrintingMode if not set yet */
2287 stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (InkSet:Both) PrintingMode not set yet\n");
2288 i=0;
2289 quality = mode->quality;
2290 modefound=0;
2291 while ( (muse->mode_name_list[i]!=NULL) && (modefound != 1) ) {
2292 for(j=0;j<caps->modelist->count;j++){
2293 if(!strcmp(muse->mode_name_list[i],caps->modelist->modes[j].name)){/* find right place in canon-modes list */
2294 if ( (caps->modelist->modes[j].quality >= quality) ) {
2295 if ( (duplex_mode && strncmp(duplex_mode,"Duplex",6)) || !(muse->use_flags & DUPLEX_SUPPORT) || !(caps->modelist->modes[j].flags & MODE_FLAG_NODUPLEX) ) {
2296 /* duplex check */
2297 if (!strcmp(mode->name,caps->modelist->modes[j].name)) {
2298 mode = &caps->modelist->modes[j];
2299 stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (InkSet:Both) PrintingMode not set yet: Decided on first matching mode with quality match (%s)\n",mode->name);
2300 modefound=1;
2301 }
2302 }
2303 }
2304 break; /* go to next mode in muse list */
2305 }
2306 }
2307 i++;
2308 }
2309 }
2310 /* if no mode was found yet, repeat with no restrictions --- since some media may not allow PrintingMode to be what was selected */
2311 if (modefound==0) {
2312 i=0;
2313 quality = mode->quality;
2314 while ( (muse->mode_name_list[i]!=NULL) && (modefound != 1) ) {
2315 for(j=0;j<caps->modelist->count;j++){
2316 if(!strcmp(muse->mode_name_list[i],caps->modelist->modes[j].name)){/* find right place in canon-modes list */
2317 if ( (caps->modelist->modes[j].quality >= quality) ) {
2318 if ( (duplex_mode && strncmp(duplex_mode,"Duplex",6)) || !(muse->use_flags & DUPLEX_SUPPORT) || !(caps->modelist->modes[j].flags & MODE_FLAG_NODUPLEX) ) {
2319 /* duplex check */
2320 mode = &caps->modelist->modes[j];
2321 stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (InkSet:Both) No mode previously found---catch-all: Decided on first matching mode (%s)\n",mode->name);
2322 modefound=1;
2323 /* set PrintingMode to whatever the mode is capable of */
2324 if (caps->modelist->modes[j].ink_types > CANON_INK_K){
2325 stp_set_string_parameter(v,"PrintingMode","Color");
2326 printing_mode = stp_get_string_parameter(v, "PrintingMode");
2327 stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (InkSet:Both) PrintingMode set to Color\n");
2328 } else {
2329 stp_set_string_parameter(v,"PrintingMode","BW");
2330 printing_mode = stp_get_string_parameter(v, "PrintingMode");
2331 stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (InkSet:Both) PrintingMode set to BW\n");
2332 }
2333 }
2334 }
2335 break; /* go to next mode in muse list */
2336 }
2337 }
2338 i++;
2339 }
2340 }
2341
2342 ink_type=find_ink_type(v,mode,printing_mode);
2343 #if 0
2344 /* if InkType does not match that of mode, change InkType to match it */
2345 /* choose highest color as default, as there is only one option for Black */
2346 /* if InkType does not match that of mode, change InkType to match it */
2347 /* choose highest color as default, as there is only one option for Black */
2348 if (printing_mode && !strcmp(printing_mode,"BW")) {
2349 stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (InkSet:Both): InkType changed to %u (%s)\n",CANON_INK_K, "Gray");
2350 stp_set_string_parameter(v, "InkType", "Gray");
2351 ink_type = stp_get_string_parameter(v, "InkType");
2352 } else {
2353 inkfound=0;
2354 stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (InkSet:Both): InkType of mode %s is currently set as %s\n",mode->name,ink_type);
2355 for(i=0;i<sizeof(canon_inktypes)/sizeof(canon_inktypes[0]);i++){
2356 if (mode->ink_types & canon_inktypes[i].ink_type) { /* a mode can have several ink_types: must compare with ink_type if set */
2357 if ( !(strcmp(ink_type,canon_inktypes[i].name))) {
2358 inkfound=1;
2359 stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (InkSet:Both): InkType match found %i(%s)\n",canon_inktypes[i].ink_type,canon_inktypes[i].name);
2360 stp_set_string_parameter(v, "InkType", canon_inktypes[i].name);
2361 ink_type = stp_get_string_parameter(v, "InkType");
2362 break;
2363 }
2364 }
2365 }
2366 /* if no match found choose first available inkset */
2367 if (inkfound==0) {
2368 for(i=0;i<sizeof(canon_inktypes)/sizeof(canon_inktypes[0]);i++){
2369 if (mode->ink_types & canon_inktypes[i].ink_type) { /* a mode can have several ink_types: must compare with ink_type if set */
2370 if ((!ink_type) || (strcmp(ink_type,canon_inktypes[i].name))) { /* if InkType does not match selected mode ink type*/
2371 stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (InkSet:Both): No match found---choosing first available. InkType changed to %i(%s)\n",canon_inktypes[i].ink_type,canon_inktypes[i].name);
2372 stp_set_string_parameter(v, "InkType", canon_inktypes[i].name);
2373 ink_type = stp_get_string_parameter(v, "InkType");
2374 inkfound=1; /* set */
2375 break;
2376 }
2377 }
2378 }
2379 }
2380 }
2381 #endif
2382 }
2383 }
2384 }
2385 /* end of mode replacement code */
2386
2387
2388 #if 0
2389 if(quality && strcmp(quality, "None") == 0)
2390 quality = "Standard";
2391
2392 if(quality && !strcmp(quality,"Standard")){
2393 return &caps->modelist->modes[caps->modelist->default_mode];
2394 }
2395 #endif
2396
2397 #if 0
2398 /* only some modes can print to cd */
2399 if(input_slot && !strcmp(input_slot,"CD") && !(mode->flags & MODE_FLAG_CD)){
2400 for(i=0;i<caps->modelist->count;i++){
2401 if(caps->modelist->modes[i].flags & MODE_FLAG_CD){
2402 mode = &caps->modelist->modes[i];
2403 break;
2404 }
2405 }
2406 }
2407 #endif
2408
2409
2410 if (mode) {
2411 stp_set_string_parameter(v, "Resolution",mode->text); /* check_current_mode checks resolution! */
2412 stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint: check_current_mode --- updated Resolution: '%s'\n",mode->name);
2413 }
2414
2415 if (mode) {
2416 stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint: check_current_mode --- Final returned mode: '%s'\n",mode->name);
2417 }
2418 else {
2419 stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint: check_current_mode --- Final returned mode is NULL \n");
2420 }
2421
2422 /* set PrintingMode in case of Inkset precedence */
2423 if (mode) { /* final mode takes precedence */
2424 if (mode->ink_types == CANON_INK_K)
2425 stp_set_string_parameter(v, "PrintingMode", "BW");
2426 else
2427 stp_set_string_parameter(v, "PrintingMode", "Color");
2428 }
2429 else if (ink_type) { /* mode not yet known, but InkType known. InkSet should have been handled together with InkType above */
2430 if (!strcmp(ink_type,"Gray"))
2431 stp_set_string_parameter(v, "PrintingMode", "BW");
2432 else
2433 stp_set_string_parameter(v, "PrintingMode", "Color");
2434 }
2435
2436 if (printing_mode) {
2437 stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint: Final PrintingMode %s\n",printing_mode);
2438 } else { /* should not happen */
2439 stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint: Final PrintingMode is NULL\n");
2440 }
2441 if (ink_set) {
2442 stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint: Final InkSet value (high priority): '%s'\n",ink_set);
2443 } else {
2444 stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint: Final InkSet value is NULL\n");
2445 }
2446
2447 if (ink_type) {
2448 stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint: Final InkType value (low priority): '%s'\n",ink_type);
2449 } else {
2450 stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint: Final InkType value is NULL\n");
2451 }
2452
2453 return mode;
2454 }
2455
2456 /* function returns the best ink_type for the current mode */
2457 static unsigned int
2458 canon_printhead_colors(const stp_vars_t*v)
2459 {
2460 unsigned int i,j;
2461 const canon_mode_t* mode;
2462 const canon_cap_t * caps = canon_get_model_capabilities(v);
2463 const char *print_mode = stp_get_string_parameter(v, "PrintingMode");
2464 const char *ink_type = stp_get_string_parameter(v, "InkType");
2465 const char *ink_set = stp_get_string_parameter(v, "InkSet");
2466
2467 stp_dprintf(STP_DBG_CANON, v,"Entered canon_printhead_colors: got PrintingMode %s\n",print_mode);
2468
2469 /* if a mode is available, use it. Else mode is NULL */
2470 stp_dprintf(STP_DBG_CANON, v,"Calling get_current_parameter from canon_printhead_colors\n");
2471 mode = canon_get_current_mode(v);
2472
2473 /* get the printing mode again */
2474 print_mode = stp_get_string_parameter(v, "PrintingMode");
2475
2476 /* if the printing mode was already selected as BW, accept it */
2477 if(print_mode && !strcmp(print_mode, "BW") && !(caps->features & CANON_CAP_NOBLACK) ){ /* workaround in case BW is a default */
2478 stp_dprintf(STP_DBG_CANON, v,"(canon_printhead_colors[BW]) Found InkType %u (CANON_INK_K)\n",CANON_INK_K);
2479 stp_dprintf(STP_DBG_CANON, v,"(canon_printhead_colors[BW]) NOBLACK? %lu\n",(caps->features & CANON_CAP_NOBLACK));
2480 return CANON_INK_K;
2481 }
2482 /* alternatively, if the cartridge selection is in force, and black cartridge is selected, accept it */
2483 if(ink_set && !strcmp(ink_set, "Black")){
2484 stp_dprintf(STP_DBG_CANON, v,"(canon_printhead_colors[BW]) Found InkSet black selection\n");
2485 return CANON_INK_K;
2486 }
2487
2488 /* originally finds selected InkType of form: CANON_INK_<inks> */
2489 /* but this is incorrect, since it does not check media or mode */
2490 /* change: deal with mode set and mode not set cases */
2491
2492 /* if mode was already set, then return the ink types for only that mode */
2493
2494 if (mode) {
2495 /* if an inktype selected check what it is */
2496 if(ink_type){
2497 for(i=0;i<sizeof(canon_inktypes)/sizeof(canon_inktypes[0]);i++){
2498 if (mode->ink_types & canon_inktypes[i].ink_type) {
2499 stp_dprintf(STP_DBG_CANON, v,"(canon_printhead_colors[inktype]) Found InkType %i(%s)\n",canon_inktypes[i].ink_type,canon_inktypes[i].name);
2500 return canon_inktypes[i].ink_type;
2501 }
2502 }
2503 }
2504 else {
2505 /* find the matching inks for the mode: chooses the first one found for a mode! */
2506 /* ink types are arranged in decreasing order so those with more meta inks are discovered first */
2507 for(i=0;i<sizeof(canon_inktypes)/sizeof(canon_inktypes[0]);i++){
2508 if(mode->ink_types & canon_inktypes[i].ink_type) {
2509 stp_dprintf(STP_DBG_CANON, v,"(canon_printhead_colors[mode]) Found InkType %i(%s)\n",canon_inktypes[i].ink_type,canon_inktypes[i].name);
2510 return canon_inktypes[i].ink_type;
2511 }
2512 }
2513 }
2514 }
2515 else { /* mode not yet set */
2516 /* if an inktype selected check what it is */
2517 if(ink_type){
2518 for(i=0;i<sizeof(canon_inktypes)/sizeof(canon_inktypes[0]);i++){
2519 if(ink_type && !strcmp(canon_inktypes[i].name,ink_type)) {
2520 stp_dprintf(STP_DBG_CANON, v,"(canon_printhead_colors[inktype]) Found InkType %i(%s)\n",canon_inktypes[i].ink_type,canon_inktypes[i].name);
2521 return canon_inktypes[i].ink_type;
2522 }
2523 }
2524 }
2525 else { /* no ink type selected yet */
2526 stp_dprintf(STP_DBG_CANON, v,"canon_printhead_colors: no mode and no inktype: we have to choose the highest one to return\n");
2527 /* loop through all modes, and return the highest inktype found */
2528 for(i=0;i<sizeof(canon_inktypes)/sizeof(canon_inktypes[0]);i++){
2529 for(j=0;j<caps->modelist->count;j++){
2530 if(caps->modelist->modes[j].ink_types & canon_inktypes[i].ink_type){
2531 stp_dprintf(STP_DBG_CANON, v," highest inktype found --- %s(%s)\n",canon_inktypes[i].name,canon_inktypes[i].text);
2532 return canon_inktypes[i].ink_type;
2533 }
2534 }
2535 }
2536 }
2537
2538 }
2539
2540 /* originally as fallback choose CANON_INK_K */
2541 /* However, some Canon printers do not have monochrome mode at all, only color meta ink modes, like iP6000 series */
2542 #if 0
2543 stp_dprintf(STP_DBG_CANON, v,"(canon_printhead_colors[fall-through]) Returning InkType %i(CANON_INK_K)\n",CANON_INK_K);
2544 return CANON_INK_K;
2545 #endif
2546 /* new fallback: loop through ink type in reverse order, picking first one found, which if CANON_INK_K is supported will be that, else the lowest amount of color */
2547 for(i=((sizeof(canon_inktypes)/sizeof(canon_inktypes[0])));i>0;i--){
2548 for(j=0;j<caps->modelist->count;j++){
2549 if(caps->modelist->modes[j].ink_types & canon_inktypes[i-1].ink_type){
2550 stp_dprintf(STP_DBG_CANON, v," lowest inktype found --- %s(%s)\n",canon_inktypes[i-1].name,canon_inktypes[i-1].text);
2551 return canon_inktypes[i-1].ink_type;
2552 }
2553 }
2554 }
2555
2556 /* if fails until here, return something reasonable in most situations */
2557 return CANON_INK_K;
2558
2559 }
2560
2561 static unsigned char
2562 canon_size_type(const stp_vars_t *v, const canon_cap_t * caps)
2563 {
2564 const stp_papersize_list_t *list = stpi_get_standard_papersize_list();
2565 const stp_papersize_t *pp = stpi_get_papersize_by_size(list,
2566 stp_get_page_height(v),
2567 stp_get_page_width(v));
2568 (void)caps;
2569 stp_dprintf(STP_DBG_CANON, v,"canon: entered canon_size_type\n");
2570
2571 if (pp)
2572 {
2573 const char *name = pp->name;
2574 stp_dprintf(STP_DBG_CANON, v,"canon: in canon_size_type is pp->name: '%s'\n",name);
2575 /* used internally: do not translate */
2576 /* built ins: Japanese driver notation */
2577 if (!strcmp(name,"A5")) return 0x01;
2578 if (!strcmp(name,"A4")) return 0x03;
2579 if (!strcmp(name,"A3")) return 0x05;
2580 if (!strcmp(name,"B5")) return 0x08;
2581 if (!strcmp(name,"B4")) return 0x0a;
2582 if (!strcmp(name,"Letter")) return 0x0d;
2583 if (!strcmp(name,"Legal")) return 0x0f;
2584 if (!strcmp(name,"Tabloid")) return 0x11; /* 11x17 inch */
2585 if (!strcmp(name,"w283h420")) return 0x14; /* Hagaki */
2586 /* if (!strcmp(name,"COM10")) return 0x16;*/
2587 /* if (!strcmp(name,"DL")) return 0x17;*/
2588 if (!strcmp(name,"LetterExtra")) return 0x2a; /* Letter navi --- Letter+ */
2589 if (!strcmp(name,"A4Extra")) return 0x2b; /* A4navi --- A4+ */
2590 if (!strcmp(name,"A3plus")) return 0x2c; /* A3navi --- A3+ (13x19 inch) */
2591 if (!strcmp(name,"w288h144")) return 0x2d; /* 4x2 inch labels */
2592 if (!strcmp(name,"COM10")) return 0x2e; /* US Comm #10 Env */
2593 if (!strcmp(name,"DL")) return 0x2f; /* Euro DL Env */
2594 if (!strcmp(name,"w297h666")) return 0x30; /* Western Env #4 (you4) */
2595 if (!strcmp(name,"w277h538")) return 0x31; /* Western Env #6 (you6) */
2596 if (!strcmp(name,"w252h360J")) return 0x32; /* L --- similar to US 3.5x5 inch size */
2597 if (!strcmp(name,"w360h504J")) return 0x33; /* 2L --- similar to US5x7 inch */
2598 if (!strcmp(name,"w288h432J")) return 0x34; /* KG --- same size as US 4x6 inch */
2599 /* if (!strcmp(name,"CD5Inch")) return 0x35; */ /* CD Custom Tray */
2600 if (!strcmp(name,"w155h257")) return 0x36; /* Japanese Business Card 55mm x 91mm */
2601 if (!strcmp(name,"w360h504")) return 0x37; /* US5x7 inch */
2602 if (!strcmp(name,"w420h567")) return 0x39; /* Oufuku Hagaki --- but should be w567h420 */
2603 if (!strcmp(name,"w340h666")) return 0x3a; /* Japanese Long Env #3 (chou3) */
2604 if (!strcmp(name,"w255h581")) return 0x3b; /* Japanese Long Env #4 (chou4) */
2605 /* if (!strcmp(name,"CD5Inch")) return 0x3f; */ /* CD Tray A */
2606 /* if (!strcmp(name,"CD5Inch")) return 0x40; */ /* CD Tray B */
2607 if (!strcmp(name,"w155h244")) return 0x41; /* Business/Credit Card 54mm x 86mm */
2608
2609 /* Fine Art paper codes */
2610 /* iP6700D, iP7100, iP7500, iP8100, iP8600, iP9910 */
2611 /* iX7000 */
2612 /* MG6100, M6200, MG8100, MG8200 */
2613 /* MX7600 */
2614 /* MP950, MP960, MP970, MP980, MP990 */
2615 /* if (!strcmp(name,"A4")) return 0x42; */ /* FineArt A4 35mm border --- iP7100: gap is 18 */
2616 /* if (!strcmp(name,"A3")) return 0x43; */ /* FineArt A3 35mm border */
2617 /* if (!strcmp(name,"A3plus")) return 0x44; */ /* FineArt A3plus 35mm border */
2618 /* if (!strcmp(name,"Letter")) return 0x45; */ /* FineArt Letter 35mm border */
2619
2620 if (!strcmp(name,"w288h576")) return 0x46; /* US4x8 */
2621 if (!strcmp(name,"w1008h1224J")) return 0x47; /* HanKire --- 14in x 17 inch */
2622 if (!strcmp(name,"720h864J")) return 0x48; /* YonKire --- 10in x 12 inch */
2623 if (!strcmp(name,"c8x10J")) return 0x49; /* RokuKire --- same size as 8x10 inch */
2624
2625 /* if (!strcmp(name,"CD5Inch")) return 0x4a; */ /* CD Tray C */
2626 /* if (!strcmp(name,"CD5Inch")) return 0x4b; */ /* CD Tray D */
2627 /* if (!strcmp(name,"CD5Inch")) return 0x4c; */ /* CD Tray E */
2628
2629 /* Fine Art paper codes */
2630 /* Pro series (9000, 9000 Mk.2, 9500, 9500 Mk.2, PRO-1) */
2631 /* if (!strcmp(name,"A4")) return 0x4d; */ /* FineArt A4 35mm border */
2632 /* if (!strcmp(name,"A3")) return 0x4e; */ /* FineArt A3 35mm border */
2633 /* if (!strcmp(name,"Letter")) return 0x4f; */ /* FineArt Letter 35mm border */
2634 /* if (!strcmp(name,"A3plus")) return 0x50; */ /* FineArt A3plus 35mm border */
2635
2636 /* if (!strcmp(name,"CD5Inch")) return 0x51; */ /* CD Tray F */
2637 if (!strcmp(name,"w288h512")) return 0x52; /* Wide 101.6x180.6mm */
2638 /* w283h566 Wide postcard 100mm x 200mm */
2639
2640 /* media size codes for CD (and other media depending on printer model */
2641
2642 if (!strcmp(name,"CD5Inch")) return 0x53; /* CD Tray G --- arbitrary choice here, modify in ESC (P command */
2643 /* if (!strcmp(name,"CD5Inch")) return 0x56; */ /* CD Tray G-late */
2644 /* if (!strcmp(name,"CD5Inch")) return 0x57; */ /* CD Tray H */
2645
2646 /* Fine Art paper codes */
2647 /* MG6300, MG6500, MG6700, MG7100, MG7500 (only A4), MG6900, MG7700 */
2648 /* iP8700, iX6800 (A3 also) */
2649 /* if (!strcmp(name,"A4")) return 0x58; */ /* FineArt A4 35mm border */
2650 /* if (!strcmp(name,"A3")) return 0x59; */ /* FineArt A3 35mm border */
2651 /* if (!strcmp(name,"Letter")) return 0x5a; */ /* FineArt Letter 35mm border */
2652 /* if (!strcmp(name,"A3plus")) return 0x5d; */ /* FineArt A3plus 35mm border */
2653
2654 /* if (!strcmp(name,"CD5Inch")) return 0x5b; */ /* CD Tray J */
2655 /* if (!strcmp(name,"CD5Inch")) return 0x62; */ /* CD Tray L */
2656
2657 if (!strcmp(name,"A6")) return 0x63;
2658
2659 if (!strcmp(name,"LegalIndia")) return 0x8d; /* Legal (India) */
2660 if (!strcmp(name,"Oficio")) return 0x8e; /* Oficio */
2661 if (!strcmp(name,"M-Oficio")) return 0x8f; /* Mexico Oficio */
2662
2663 if (!strcmp(name,"w612h936")) return 0x90; /* (American) Foolscap */
2664 if (!strcmp(name,"Executive")) return 0x91;
2665
2666 if (!strcmp(name,"C5")) return 0x92; /* C5 Env */
2667 if (!strcmp(name,"Monarch")) return 0x93; /* Monarch Env */
2668
2669 if (!strcmp(name,"B-Oficio")) return 0x94; /* Brazil Oficio */
2670
2671 if (!strcmp(name,"w360h360")) return 0xba; /* square 5x5 inch */
2672
2673 /* custom */
2674
2675 stp_dprintf(STP_DBG_CANON, v,"canon: Unknown paper size '%s' - using custom\n",name);
2676 } else {
2677 stp_dprintf(STP_DBG_CANON, v,"canon: Couldn't look up paper size %fx%f - "
2678 "using custom\n",stp_get_page_height(v), stp_get_page_width(v));
2679 }
2680 return 0;
2681 }
2682
2683 /* fix paper_width and paper_length for known papersizes in ESC (p command */
2684 static void fix_papersize(unsigned char arg_ESCP_1, int *paper_width, int *paper_length){
2685
2686 switch(arg_ESCP_1)
2687 {
2688 case 0x63: *paper_width = 2481; *paper_length = 3497; break;; /* A6 */
2689 case 0x01: *paper_width = 3497; *paper_length = 4961; break;; /* A5 */
2690 case 0x03: *paper_width = 4961; *paper_length = 7016; break;; /* A4 */
2691 case 0x05: *paper_width = 7016; *paper_length = 9922; break;; /* A3 */
2692 case 0x08: *paper_width = 4300; *paper_length = 6071; break;; /* B5 */
2693 case 0x0a: *paper_width = 6071; *paper_length = 8599; break;; /* B4 */
2694 case 0x0d: *paper_width = 5100; *paper_length = 6600; break;; /* Letter */
2695 case 0x0f: *paper_width = 5100; *paper_length = 8400; break;; /* Legal */
2696 case 0x8d: *paper_width = 5079; *paper_length = 8150; break;; /* Legal (India) */
2697 case 0x8e: *paper_width = 5100; *paper_length = 7500; break;; /* Oficio */
2698 case 0x94: *paper_width = 5103; *paper_length = 8386; break;; /* Brazil Oficio */
2699 case 0x8f: *paper_width = 5103; *paper_length = 8056; break;; /* Mexico Oficio */
2700 case 0x90: *paper_width = 5100; *paper_length = 7800; break;; /* (American) Foolscap */
2701 case 0x91: *paper_width = 4352; *paper_length = 6300; break;; /* Executive */
2702 case 0x11: *paper_width = 6600; *paper_length = 10200; break;; /* Tabloid : 11x17" */
2703 /* Letter+, A4+ only seem to be available in shrink-to-fit */
2704 /* case 0x2a: paper_width = ( init->page_width + border_left + border_right ) * unit / 72; break;; */ /* LetterExtra : Letter navi, Letter+ */
2705 /* case 0x2b: paper_width = ( init->page_width + border_left + border_right ) * unit / 72; break;; */ /* A4Extra : A4navi, A4+ */
2706 case 0x2c: *paper_width = 7772; *paper_length = 11410; break;; /* A3Extra : A3navi, A3+ (13x19") */
2707 /* case 0x2d: paper_width = ( init->page_width + border_left + border_right ) * unit / 72; break;; */ /* w288h144 : 4x2" labels */
2708 /* Hagaki media */
2709 case 0x14: *paper_width = 2363; *paper_length = 3497; break;; /* w283h420 : Hagaki */
2710 /* Oufuku Hagaki should be swapped: w567h420, same height as Hagaki */
2711 /* case 0x39: paper_width = 4725; l: 3497 */
2712 /* w420h567 : Oufuku Hagaki */
2713 /* case 0x39: paper_width=(init->page_width + border_left + border_right) * unit / 72; break;;*/ /* leave untouched since orientation wrong */
2714 case 0x52: *paper_width = 2400; *paper_length = 4267; break;; /* w288h512 : Wide101.6x180.6mm */
2715 /* Envelope media */
2716 case 0x16: *paper_width = 2475; *paper_length = 5700; break;; /* COM10 : US Commercial #10 */
2717 case 0x17: *paper_width = 2599; *paper_length = 5197; break;; /* DL : Euro DL */
2718 case 0x2e: *paper_width = 2475; *paper_length = 5700; break;; /* COM10 : US Commercial #10 */
2719 case 0x2f: *paper_width = 2599; *paper_length = 5197; break;; /* DL : Euro DL */
2720 case 0x30: *paper_width = 2481; *paper_length = 5552; break;; /* w297xh666 : Western Env #4 (you4) */
2721 case 0x31: *paper_width = 2155; *paper_length = 4489; break;; /* w277xh538 : Western Env #6 (you6) */
2722 case 0x3a: *paper_width = 2835; *paper_length = 5552; break;; /* w340xh666 : Japanese Long Env #3 (chou3) */
2723 case 0x3b: *paper_width = 2126; *paper_length = 4843; break;; /* w255xh581 : Japanese Long Env #4 (chou4) */
2724 case 0x92: *paper_width = 3827; *paper_length = 5410; break;; /* C5 */
2725 case 0x93: *paper_width = 2325; *paper_length = 4500; break;; /* Monarch */
2726 /* Photo media */
2727 case 0x32: *paper_width = 2103; *paper_length = 3000; break;; /* w252h360 : L --- similar to US 3.5x5" */
2728 case 0x33: *paper_width = 3000; *paper_length = 4205; break;; /* w360h504 : 2L --- similar to US 5x7" */
2729 case 0x37: *paper_width = 3000; *paper_length = 4200; break;; /* w360h504 : US 5x7" */
2730 case 0x34: *paper_width = 2400; *paper_length = 3600; break;; /* w288h432J : KG --- same as US 4x6" */
2731 case 0x46: *paper_width = 2400; *paper_length = 4800; break;; /* w288h576 : US 4x8" */
2732 case 0xba: *paper_width = 3000; *paper_length = 3000; break;; /* w360h360 : square 5x5" */
2733 /* CD media */
2734 case 0x35: *paper_width = 3207; *paper_length = 6041; break;; /* CD5Inch : CD Custom Tray */
2735 case 0x3f: *paper_width = 3378; *paper_length = 6206; break;; /* CD5Inch : CD Tray A */
2736 case 0x40: *paper_width = 3095; *paper_length = 5640; break;; /* CD5Inch : CD Tray B */
2737 case 0x4a: *paper_width = 3095; *paper_length = 5640; break;; /* CD5Inch : CD Tray C */
2738 case 0x4b: *paper_width = 3095; *paper_length = 5640; break;; /* CD5Inch : CD Tray D */
2739 case 0x4c: *paper_width = 4063; *paper_length = 6497; break;; /* CD5Inch : CD Tray E */
2740 case 0x51: *paper_width = 3095; *paper_length = 5730; break;; /* CD5Inch : CD Tray F */
2741 case 0x53: *paper_width = 3095; *paper_length = 6008; break;; /* CD5Inch : CD Tray G */
2742 case 0x56: *paper_width = 3095; *paper_length = 6008; break;; /* CD5Inch : CD Tray G late version */
2743 case 0x57: *paper_width = 3572; *paper_length = 8953; break;; /* CD5Inch : CD Tray H */
2744 case 0x5b: *paper_width = 3071; *paper_length = 5311; break;; /* CD5Inch : CD Tray J */
2745 /* no printer using Tray L yet supported */
2746 /* case 0x62: paper_width = ( init->page_width + border_left + border_right ) * unit / 72; break;; */ /* CD5Inch : CD Tray L */
2747 case 0xbc: *paper_width = 3494; *paper_length = 4928; break;; /* CD5Inch : CD Tray M */
2748 /* Business/Credit Card media */
2749 case 0x36: *paper_width = 1300; *paper_length = 2150; break;; /* w155h257 : Japanese Business Card 55x91mm */
2750 case 0x41: *paper_width = 1276; *paper_length = 2032; break;; /* w155h244 : Business/Credit Card 54x86mm */
2751 /* Fine Art media */
2752 case 0x42: *paper_width = 4961; *paper_length = 7016; break;; /* FineArt A4 35mm border */
2753 case 0x43: *paper_width = 7016; *paper_length = 9922; break;; /* FineArt A3 35mm border */
2754 case 0x44: *paper_width = 7772; *paper_length = 11410; break;; /* FineArt A3+ 35mm border */
2755 case 0x45: *paper_width = 5100; *paper_length = 6600; break;; /* FineArt Letter 35mm border */
2756 case 0x4d: *paper_width = 4961; *paper_length = 7016; break;; /* FineArt A4 35mm border */
2757 case 0x4e: *paper_width = 7016; *paper_length = 9922; break;; /* FineArt A3 35mm border */
2758 case 0x4f: *paper_width = 5100; *paper_length = 6600; break;; /* FineArt Letter 35mm border */
2759 case 0x50: *paper_width = 7772; *paper_length = 11410; break;; /* FineArt A3+ 35mm border */
2760 case 0x58: *paper_width = 4961; *paper_length = 7016; break;; /* FineArt A4 35mm border */
2761 case 0x59: *paper_width = 7016; *paper_length = 9922; break;; /* FineArt A3 35mm border */
2762 case 0x5a: *paper_width = 5100; *paper_length = 6600; break;; /* FineArt Letter 35mm border */
2763 case 0x5d: *paper_width = 7772; *paper_length = 11410; break;; /* FineArt A3+ 35mm border */
2764 /* Other media */
2765 case 0x47: *paper_width = 8400; *paper_length = 10200; break;; /* w1008h1224J : HanKire --- 14x17" */
2766 case 0x48: *paper_width = 6000; *paper_length = 7200; break;; /* 720h864J : YonKire --- 10x12" */
2767 case 0x49: *paper_width = 4800; *paper_length = 6000; break;; /* c8x10J : RokuKire --- same as 8x10" */
2768 /* default */
2769 /* default: paper_width=(init->page_width + border_left + border_right) * unit / 72; break;; */ /* custom */
2770 }
2771 }
2772
2773 static void
2774 canon_describe_resolution(const stp_vars_t *v, stp_resolution_t *x, stp_resolution_t *y)
2775 {
2776 const canon_mode_t* mode = NULL;
2777 const canon_cap_t * caps = canon_get_model_capabilities(v);
2778
2779 /* if mode is not yet set, it remains NULL */
2780 stp_dprintf(STP_DBG_CANON, v,"Calling get_current_parameter from canon_describe_resolution\n");
2781 mode = canon_get_current_mode(v);
2782
2783 if(!mode)
2784 mode = &caps->modelist->modes[caps->modelist->default_mode];
2785
2786 if (mode) {
2787 *x = mode->xdpi;
2788 *y = mode->ydpi;
2789 }
2790 }
2791
2792 static const char *
2793 canon_describe_output(const stp_vars_t *v)
2794 {
2795 unsigned int ink_type = canon_printhead_colors(v);
2796
2797 if(ink_type & CANON_INK_CMYK_MASK)
2798 return "CMYK";
2799 if(ink_type & CANON_INK_CMY_MASK)
2800 return "CMY";
2801 /* Gernot added */
2802 /*if(ink_type & CANON_INK_cmy_MASK)
2803 return "cmy";*/
2804 return "Grayscale";
2805 }
2806
2807 /*
2808 * 'canon_parameters()' - Return the parameter values for the given parameter.
2809 */
2810
2811 static stp_parameter_list_t
2812 canon_list_parameters(const stp_vars_t *v)
2813 {
2814 stp_parameter_list_t *ret = stp_parameter_list_create();
2815 stp_parameter_list_t *tmp_list;
2816
2817 unsigned int i;
2818
2819 /* Set up dithering */
2820 tmp_list = stp_dither_list_parameters(v);
2821 stp_parameter_list_append(ret, tmp_list);
2822 stp_parameter_list_destroy(tmp_list);
2823
2824 for (i = 0; i < the_parameter_count; i++)
2825 stp_parameter_list_add_param(ret, &(the_parameters[i]));
2826 for (i = 0; i < float_parameter_count; i++)
2827 stp_parameter_list_add_param(ret, &(float_parameters[i].param));
2828 return ret;
2829 }
2830
2831 static void
2832 canon_parameters(const stp_vars_t *v, const char *name,
2833 stp_parameter_t *description)
2834 {
2835 unsigned int i;
2836 int j;
2837
2838 const canon_cap_t * caps=
2839 canon_get_model_capabilities(v);
2840 description->p_type = STP_PARAMETER_TYPE_INVALID;
2841
2842 if (name == NULL)
2843 return;
2844
2845 for (i = 0; i < float_parameter_count; i++)
2846 if (strcmp(name, float_parameters[i].param.name) == 0)
2847 {
2848 /* presumably need to return the maximum number of inks the printer can handle */
2849 unsigned int ink_type = canon_printhead_colors(v);
2850
2851 stp_fill_parameter_settings(description,
2852 &(float_parameters[i].param));
2853 description->deflt.dbl = float_parameters[i].defval;
2854 description->bounds.dbl.upper = float_parameters[i].max;
2855 description->bounds.dbl.lower = float_parameters[i].min;
2856 if (ink_type != CANON_INK_K || !float_parameters[i].color_only)
2857 description->is_active = 1;
2858 else
2859 description->is_active = 0;
2860 return;
2861 }
2862
2863 for (i = 0; i < the_parameter_count; i++)
2864 if (strcmp(name, the_parameters[i].name) == 0)
2865 {
2866 stp_fill_parameter_settings(description, &(the_parameters[i]));
2867 break;
2868 }
2869 if (strcmp(name, "PageSize") == 0)
2870 {
2871 const char* input_slot = stp_get_string_parameter(v, "InputSlot");
2872 unsigned int height_limit, width_limit;
2873 description->bounds.str = stp_string_list_create();
2874
2875 width_limit = caps->max_width;
2876 height_limit = caps->max_height;
2877
2878 if(input_slot && !strcmp(input_slot,"CD")){
2879 stp_string_list_add_string
2880 (description->bounds.str, "CD5Inch", _("CD - 5 inch"));
2881 stp_string_list_add_string
2882 (description->bounds.str, "CD3Inch", _("CD - 3 inch"));
2883 stp_string_list_add_string
2884 (description->bounds.str, "CDCustom", _("CD - Custom"));
2885 }else{
2886 const stp_papersize_list_t *paper_sizes =
2887 stpi_get_standard_papersize_list();
2888 const stp_papersize_list_item_t *ptli =
2889 stpi_papersize_list_get_start(paper_sizes);
2890 while (ptli)
2891 {
2892 const stp_papersize_t *pt = stpi_paperlist_item_get_data(ptli);
2893 if (pt->paper_size_type == PAPERSIZE_TYPE_STANDARD ||
2894 pt->paper_size_type == PAPERSIZE_TYPE_ENVELOPE) {
2895 if (strlen(pt->name) > 0 &&
2896 pt->width <= width_limit && pt->height <= height_limit){
2897 stp_string_list_add_string(description->bounds.str,
2898 pt->name, gettext(pt->text));
2899 }
2900 }
2901 ptli = stpi_paperlist_item_next(ptli);
2902 }
2903 }
2904 description->deflt.str =
2905 stp_string_list_param(description->bounds.str, 0)->name;
2906 }
2907 else if (strcmp(name, "CDInnerRadius") == 0 )
2908 {
2909 const char* input_slot = stp_get_string_parameter(v, "InputSlot");
2910 description->bounds.str = stp_string_list_create();
2911 if ( (!input_slot || !strcmp(input_slot,"CD")) &&
2912 (!stp_get_string_parameter(v, "PageSize") ||
2913 strcmp(stp_get_string_parameter(v, "PageSize"), "CDCustom") != 0) )
2914 {
2915 stp_string_list_add_string
2916 (description->bounds.str, "None", _("Normal"));
2917 stp_string_list_add_string
2918 (description->bounds.str, "Small", _("Print To Hub"));
2919 description->deflt.str =
2920 stp_string_list_param(description->bounds.str, 0)->name;
2921 }
2922 else
2923 description->is_active = 0;
2924 }
2925 else if (strcmp(name, "CDInnerDiameter") == 0 )
2926 {
2927 const char* input_slot = stp_get_string_parameter(v, "InputSlot");
2928 description->bounds.dimension.lower = 16 * 10 * 72 / 254;
2929 description->bounds.dimension.upper = 43 * 10 * 72 / 254;
2930 description->deflt.dimension = 43 * 10 * 72 / 254;
2931 if ( (!input_slot || !strcmp(input_slot,"CD")) &&
2932 (!stp_get_string_parameter(v, "PageSize") ||
2933 strcmp(stp_get_string_parameter(v, "PageSize"), "CDCustom") == 0) )
2934 description->is_active = 1;
2935 else
2936 description->is_active = 0;
2937 }
2938 else if (strcmp(name, "CDOuterDiameter") == 0 )
2939 {
2940 const char* input_slot = stp_get_string_parameter(v, "InputSlot");
2941 description->bounds.dimension.lower = 65 * 10 * 72 / 254;
2942 description->bounds.dimension.upper = 120 * 10 * 72 / 254;
2943 description->deflt.dimension = 329;
2944 if ( (!input_slot || !strcmp(input_slot,"CD")) &&
2945 (!stp_get_string_parameter(v, "PageSize") ||
2946 strcmp(stp_get_string_parameter(v, "PageSize"), "CDCustom") == 0) )
2947 description->is_active = 1;
2948 else
2949 description->is_active = 0;
2950 }
2951 else if (strcmp(name, "CDXAdjustment") == 0 ||
2952 strcmp(name, "CDYAdjustment") == 0)
2953 {
2954 const char* input_slot = stp_get_string_parameter(v, "InputSlot");
2955 description->bounds.dimension.lower = -250;
2956 description->bounds.dimension.upper = 250;
2957 description->deflt.dimension = 0;
2958 if (!input_slot || !strcmp(input_slot,"CD"))
2959 description->is_active = 1;
2960 else
2961 description->is_active = 0;
2962 }
2963 else if (strcmp(name, "Resolution") == 0)
2964 {
2965 #if 0
2966 const char* input_slot = stp_get_string_parameter(v, "InputSlot");
2967 #endif
2968 description->bounds.str= stp_string_list_create();
2969 description->deflt.str = NULL;
2970 for(i=0;i<caps->modelist->count;i++){
2971 #if 0
2972 if(!((!input_slot || !strcmp(input_slot,"CD")) && !(caps->modelist->modes[i].flags & MODE_FLAG_CD)))
2973 #endif
2974 stp_string_list_add_string(description->bounds.str,
2975 caps->modelist->modes[i].name, gettext(caps->modelist->modes[i].text));
2976 stp_dprintf(STP_DBG_CANON, v,"supports mode '%s'\n",
2977 caps->modelist->modes[i].name);
2978 if(i == caps->modelist->default_mode)
2979 description->deflt.str=caps->modelist->modes[i].name;
2980 }
2981 }
2982 else if (strcmp(name, "InkType") == 0)
2983 {
2984 const canon_mode_t* mode = NULL;
2985
2986 stp_dprintf(STP_DBG_CANON, v,"Calling get_current_parameter from InkType block in canon_parameters\n");
2987 mode=canon_get_current_mode(v);
2988
2989 description->bounds.str= stp_string_list_create();
2990 if (mode) {
2991 for(i=0;i<sizeof(canon_inktypes)/sizeof(canon_inktypes[0]);i++){
2992 if(mode->ink_types & canon_inktypes[i].ink_type){
2993 stp_string_list_add_string(description->bounds.str,canon_inktypes[i].name,_(canon_inktypes[i].text));
2994 stp_dprintf(STP_DBG_CANON, v," mode known --- Added InkType %s(%s) for mode %s (inktype %u)\n",canon_inktypes[i].name,canon_inktypes[i].text,mode->name,mode->ink_types);
2995 }
2996 }
2997 description->deflt.str = stp_string_list_param(description->bounds.str, 0)->name;
2998 }
2999 /* mode not defined yet --- needed for PPD generation */
3000 else {
3001 for(i=0;i<sizeof(canon_inktypes)/sizeof(canon_inktypes[0]);i++){
3002 for(j=0;j<caps->modelist->count;j++){
3003 if(caps->modelist->modes[j].ink_types & canon_inktypes[i].ink_type){
3004 stp_string_list_add_string(description->bounds.str,canon_inktypes[i].name,_(canon_inktypes[i].text));
3005 stp_dprintf(STP_DBG_CANON, v," no mode --- Added InkType %s(%s) for mode (%s) inktypes %u\n",canon_inktypes[i].name,canon_inktypes[i].text,caps->modelist->modes[j].name,caps->modelist->modes[j].ink_types);
3006 break;
3007 }
3008 }
3009 }
3010 /* default type must be deduced from the default mode */
3011 /* use color if available, so break after first (color) is found, since inkt types ordered with gray last */
3012 for(i=0;i<sizeof(canon_inktypes)/sizeof(canon_inktypes[0]);i++){
3013 if(caps->modelist->modes[caps->modelist->default_mode].ink_types & canon_inktypes[i].ink_type){
3014 description->deflt.str = canon_inktypes[i].name;
3015 break;
3016 }
3017 }
3018 }
3019 /* default type must be deduced from the default mode */
3020 /*description->deflt.str = stp_string_list_param(description->bounds.str, 0)->name;*/
3021 }
3022 else if (strcmp(name, "InkChannels") == 0)
3023 {
3024 unsigned int ink_type = canon_printhead_colors(v);
3025 for(i=0;i<sizeof(canon_inktypes)/sizeof(canon_inktypes[0]);i++){
3026 if(ink_type == canon_inktypes[i].ink_type){
3027 description->deflt.integer = canon_inktypes[i].num_channels;
3028 stp_dprintf(STP_DBG_CANON, v,"Added %d InkChannels\n",canon_inktypes[i].num_channels);
3029 }
3030 }
3031 description->bounds.integer.lower = -1;
3032 description->bounds.integer.upper = -1;
3033 }
3034 else if (strcmp(name, "MediaType") == 0)
3035 {
3036 const canon_paper_t * canon_paper_list = caps->paperlist->papers;
3037 description->bounds.str= stp_string_list_create();
3038 description->deflt.str= canon_paper_list[0].name;
3039
3040 for (i = 0; i < caps->paperlist->count; i ++) {
3041 stp_string_list_add_string(description->bounds.str,
3042 canon_paper_list[i].name,
3043 gettext(canon_paper_list[i].text));
3044
3045 stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint: Added Media Type: '%s'\n",canon_paper_list[i].name);
3046 }
3047 }
3048 else if (strcmp(name, "InputSlot") == 0)
3049 {
3050 const canon_slot_t * canon_slot_list = caps->slotlist->slots;
3051 description->bounds.str= stp_string_list_create();
3052 description->deflt.str= canon_slot_list[0].name;
3053
3054 for (i = 0; i < caps->slotlist->count; i ++)
3055 stp_string_list_add_string(description->bounds.str,
3056 canon_slot_list[i].name,
3057 gettext(canon_slot_list[i].text));
3058 }
3059 else if (strcmp(name, "CassetteTray") == 0)
3060 {
3061 description->bounds.str= stp_string_list_create();
3062 description->is_active = 0;
3063 if (caps->CassetteTray_Opts) {
3064 const char* input_slot = stp_get_string_parameter(v, "InputSlot");
3065 stp_string_list_add_string
3066 (description->bounds.str, "Default", _("Driver-Controlled"));
3067 stp_string_list_add_string
3068 (description->bounds.str, "Upper", _("Upper Tray/Cassette 1"));
3069 stp_string_list_add_string
3070 (description->bounds.str, "Lower", _("Lower Tray/Cassette 2"));
3071 description->deflt.str =
3072 stp_string_list_param(description->bounds.str, 0)->name;
3073 if (!input_slot || !strcmp(input_slot,"Cassette"))
3074 description->is_active = 1;
3075 }
3076 }
3077 else if (strcmp(name, "PrintingMode") == 0)
3078 {
3079 int found_color, found_mono;
3080 const canon_mode_t* mode = NULL;
3081 /* mode remains NULL if not yet set */
3082
3083 stp_dprintf(STP_DBG_CANON, v,"Calling get_current_mode from PrintingMode block in canon_parameter\n");
3084 mode = canon_get_current_mode(v);
3085
3086 /* If mode is not set need to search ink types for all modes and
3087 see whether we have any color there
3088 */
3089
3090 stp_dprintf(STP_DBG_CANON, v,"PrintingMode---entered enumeration block in canon_printers\n");
3091
3092 description->bounds.str = stp_string_list_create();
3093
3094 stp_dprintf(STP_DBG_CANON, v,"PrintingMode---created list\n");
3095
3096 if (mode) {
3097 stp_dprintf(STP_DBG_CANON, v,"PrintingMode: (mode known) what is the current mode inktype value: %i\n",mode->ink_types);
3098 /* e.g., ink_types is 21 = 16 + 4 + 1 */
3099 if (mode->ink_types > 1) {
3100 stp_string_list_add_string
3101 (description->bounds.str, "Color", _("Color"));
3102 stp_dprintf(STP_DBG_CANON, v,"PrintingMode: (mode known) added Color\n");
3103 }
3104 if (mode->ink_types & CANON_INK_K) {
3105 stp_string_list_add_string
3106 (description->bounds.str, "BW", _("Black and White"));
3107 stp_dprintf(STP_DBG_CANON, v,"PrintingMode: (mode known) added BW\n");
3108 }
3109 }
3110 #if 0
3111 /* original code */
3112 if (mode)
3113 if (mode->ink_types != CANON_INK_K) {
3114 stp_string_list_add_string
3115 (description->bounds.str, "Color", _("Color"));
3116 stp_dprintf(STP_DBG_CANON, v,"PrintingMode: (mode known) added Color\n");
3117 }
3118 #endif
3119
3120 else { /* mode not known yet --- needed for PPD generation */
3121 stp_dprintf(STP_DBG_CANON, v,"PrintingMode: entered mode not known conditional block\n");
3122 /* add code to find color inks */
3123 /* default type must be deduced from the default mode */
3124 /* use color if available, so break after first (color) is found, since ink types ordered with gray last */
3125 found_color=0;
3126 for(i=0;i<sizeof(canon_inktypes)/sizeof(canon_inktypes[0]);i++){
3127 for(j=0;j<caps->modelist->count;j++){
3128 if(caps->modelist->modes[j].ink_types > 1){
3129 stp_string_list_add_string
3130 (description->bounds.str, "Color", _("Color"));
3131 found_color=1;
3132 stp_dprintf(STP_DBG_CANON, v,"PrintingMode: (mode not known) added Color\n");
3133 break;
3134 }
3135 }
3136 if (found_color==1)
3137 break;
3138 }
3139 found_mono=0;
3140 for(i=0;i<sizeof(canon_inktypes)/sizeof(canon_inktypes[0]);i++){
3141 for(j=0;j<caps->modelist->count;j++){
3142 if(caps->modelist->modes[j].ink_types & CANON_INK_K){
3143 stp_string_list_add_string
3144 (description->bounds.str, "BW", _("Black and White"));
3145 found_mono=1;
3146 stp_dprintf(STP_DBG_CANON, v,"PrintingMode: (mode not known) added BW\n");
3147 break;
3148 }
3149 }
3150 if (found_mono==1)
3151 break;
3152 }
3153
3154 #if 0
3155 /* ink types for default mode*/
3156 if(caps->modelist->modes[caps->modelist->default_mode].ink_types > 1){
3157 stp_string_list_add_string
3158 (description->bounds.str, "Color", _("Color"));
3159 stp_dprintf(STP_DBG_CANON, v,"PrintingMode: (mode not known) added Color\n");
3160 }
3161 if(caps->modelist->modes[caps->modelist->default_mode].ink_types & CANON_INK_K){
3162 stp_string_list_add_string
3163 (description->bounds.str, "BW", _("Black and White"));
3164 stp_dprintf(STP_DBG_CANON, v,"PrintingMode: (mode not known) added BW\n");
3165 }
3166 #endif
3167 #if 0
3168 /* original code */
3169 stp_string_list_add_string
3170 (description->bounds.str, "BW", _("Black and White"));
3171 stp_dprintf(STP_DBG_CANON, v,"PrintingMode: added BW\n");
3172 #endif
3173 }
3174
3175 /* original code --- fine as is */
3176 description->deflt.str =
3177 stp_string_list_param(description->bounds.str, 0)->name;
3178 }
3179 else if (strcmp(name, "InkSet") == 0)
3180 {
3181 description->bounds.str= stp_string_list_create();
3182 if (caps->features & CANON_CAP_T) {
3183 stp_string_list_add_string
3184 (description->bounds.str, "Both", _("Both"));
3185 if (!(caps->features & CANON_CAP_NOBLACK)) {
3186 stp_string_list_add_string
3187 (description->bounds.str, "Black", _("Black"));
3188 }
3189 stp_string_list_add_string
3190 (description->bounds.str, "Color", _("Color"));
3191 } /* mutually exclusive */
3192 else if (caps->features & CANON_CAP_cart) {
3193 stp_string_list_add_string
3194 (description->bounds.str, "Color", _("Color"));
3195 stp_string_list_add_string
3196 (description->bounds.str, "Black", _("Black"));
3197 stp_string_list_add_string
3198 (description->bounds.str, "Photo", _("Photo"));
3199 } else {
3200 /* make sure to have at least a default value: no choice */
3201 stp_string_list_add_string
3202 (description->bounds.str, "None", _("None"));
3203 }
3204 description->deflt.str =
3205 stp_string_list_param(description->bounds.str, 0)->name;
3206 }
3207 /* Test implementation of borderless printing */
3208 else if (strcmp(name, "FullBleed") == 0)
3209 {
3210 const char* input_slot = stp_get_string_parameter(v, "InputSlot");
3211 if (input_slot && !strcmp(input_slot,"CD"))
3212 description->is_active = 0;
3213 else if (caps->features & CANON_CAP_BORDERLESS)
3214 description->deflt.boolean = 0;
3215 else
3216 description->is_active = 0;
3217 }
3218 else if (strcmp(name, "Duplex") == 0)
3219 {
3220 int offer_duplex=0;
3221
3222 description->bounds.str = stp_string_list_create();
3223
3224 /*
3225 * Don't offer the Duplex/Tumble options if the JobMode parameter is
3226 * set to "Page" Mode.
3227 * "Page" mode is set by the Gimp Plugin, which only outputs one page at a
3228 * time, so Duplex/Tumble is meaningless.
3229 */
3230
3231 if (stp_get_string_parameter(v, "JobMode"))
3232 offer_duplex = strcmp(stp_get_string_parameter(v, "JobMode"), "Page");
3233 else
3234 offer_duplex=1;
3235
3236 if (offer_duplex && (caps->features & CANON_CAP_DUPLEX))
3237 {
3238 description->deflt.str = duplex_types[0].name;
3239 for (i=0; i < NUM_DUPLEX; i++)
3240 {
3241 stp_string_list_add_string(description->bounds.str,
3242 duplex_types[i].name,gettext(duplex_types[i].text));
3243 }
3244 }
3245 else
3246 description->is_active = 0;
3247 }
3248 else if (strcmp(name, "Orientation") == 0)
3249 {
3250 description->bounds.str = stp_string_list_create();
3251 description->deflt.str = orientation_types[0].name;
3252 for (i=0; i < NUM_ORIENTATION; i++)
3253 {
3254 stp_string_list_add_string(description->bounds.str,
3255 orientation_types[i].name,gettext(orientation_types[i].text));
3256 }
3257 }
3258 else if (strcmp(name, "Quality") == 0)
3259 {
3260 #if 0
3261 int has_standard_quality = 0;
3262 #endif
3263 description->bounds.str = stp_string_list_create();
3264 stp_string_list_add_string(description->bounds.str, "None",
3265 _("Manual Control"));
3266 stp_string_list_add_string(description->bounds.str, "Standard",
3267 _("Standard"));
3268 description->deflt.str = "Standard";
3269 }
3270 /* Cartridge selection for those printers that have it */
3271 else if (strcmp(name, "Cartridge") == 0)
3272 {
3273 #if 0
3274 int offer_cartridge_selection = 0;
3275 #endif
3276 description->bounds.str = stp_string_list_create();
3277 stp_string_list_add_string(description->bounds.str, "Both",
3278 _("Both"));
3279 stp_string_list_add_string(description->bounds.str, "Color",
3280 _("Color"));
3281 stp_string_list_add_string(description->bounds.str, "Black",
3282 _("Black"));
3283
3284 /* description->deflt.str = "Both"; */
3285 /* Note: not necessary set cartridge if Mono mode */
3286
3287 if (caps->features & CANON_CAP_CARTRIDGE)
3288 {
3289 description->deflt.str =
3290 stp_string_list_param(description->bounds.str, 0)->name;
3291 }
3292 else
3293 description->is_active = 0;
3294 }
3295
3296 }
3297
3298
3299 /*
3300 * 'canon_imageable_area()' - Return the imageable area of the page.
3301 */
3302
3303 static void
3304 internal_imageable_area(const stp_vars_t *v, /* I */
3305 int use_paper_margins,
3306 int use_maximum_area,
3307 stp_dimension_t *left, /* O - Left position in points */
3308 stp_dimension_t *right, /* O - Right position in points */
3309 stp_dimension_t *bottom, /* O - Bottom position in points */
3310 stp_dimension_t *top) /* O - Top position in points */
3311 {
3312 stp_dimension_t width, length; /* Size of page */
3313 int cd = 0; /* CD selected */
3314 const char *media_size = stp_get_string_parameter(v, "PageSize");
3315 stp_dimension_t left_margin = 0;
3316 stp_dimension_t right_margin = 0;
3317 stp_dimension_t bottom_margin = 0;
3318 stp_dimension_t top_margin = 0;
3319 const stp_papersize_t *pt = NULL;
3320 const char* input_slot = stp_get_string_parameter(v, "InputSlot");
3321
3322 const canon_cap_t * caps= canon_get_model_capabilities(v);
3323
3324 if (media_size)
3325 pt = stp_describe_papersize(v, media_size);
3326
3327 if(input_slot && !strcmp(input_slot,"CD"))
3328 cd = 1;
3329
3330 stp_default_media_size(v, &width, &length);
3331
3332 if (cd) {
3333 /* ignore printer margins for the cd print, margins get adjusted in do_print for now */
3334 if (pt) {
3335 /* move code from do_print here */
3336 }
3337 else {
3338 /* move code from do_print here */
3339 }
3340 }
3341 /* non-CD media */
3342 else {
3343 if (pt && use_paper_margins) {
3344 left_margin = pt->left;
3345 right_margin = pt->right;
3346 bottom_margin = pt->bottom;
3347 top_margin = pt->top;
3348 }
3349 /* limit to printer capabilities---without fullbleed */
3350 left_margin = MAX(left_margin, caps->border_left);
3351 right_margin = MAX(right_margin, caps->border_right);
3352 top_margin = MAX(top_margin, caps->border_top);
3353 bottom_margin = MAX(bottom_margin, caps->border_bottom);
3354 }
3355
3356 /* temporarily limit to non-CD media until page size code moved here from do_print */
3357 /* Note: written below code to handle CD case as well */
3358 if(!cd){
3359 stp_dprintf(STP_DBG_CANON, v,"internal_imageable_area: about to enter the borderless condition block\n");
3360 stp_dprintf(STP_DBG_CANON, v,"internal_imageable_area: is borderless available? %016lx\n",caps->features & CANON_CAP_BORDERLESS);
3361 stp_dprintf(STP_DBG_CANON, v,"internal_imageable_area: is borderless selected? %d\n",stp_get_boolean_parameter(v, "FullBleed"));
3362
3363 if ( (caps->features & CANON_CAP_BORDERLESS) &&
3364 (use_maximum_area || (!cd && stp_get_boolean_parameter(v, "FullBleed")))) {
3365
3366 stp_dprintf(STP_DBG_CANON, v,"internal_imageable_area: entered borderless condition\n");
3367
3368 if (pt) {
3369
3370 stp_dprintf(STP_DBG_CANON, v,"internal_imageable_area: entered pt condition\n");
3371
3372 if (pt->left <= 0 && pt->right <= 0 && pt->top <= 0 && pt->bottom <= 0) {
3373
3374 stp_dprintf(STP_DBG_CANON, v,"internal_imageable_area: entered margin<=0 condition\n");
3375
3376 if (use_paper_margins) {
3377 unsigned width_limit = caps->max_width;
3378 left_margin = -8;
3379 right_margin = -8;
3380 if (width - right_margin - 3 > width_limit)
3381 right_margin = width - width_limit - 3;
3382 top_margin = -6;
3383 bottom_margin = -15;
3384
3385 stp_dprintf(STP_DBG_CANON, v,"internal_imageable_area: use_paper_margins so set margins all to -7\n");
3386
3387 }
3388 else {
3389 left_margin = 0;
3390 right_margin = 0;
3391 top_margin = 0;
3392 bottom_margin = 0;
3393
3394 stp_dprintf(STP_DBG_CANON, v,"internal_imageable_area: does not use paper margins so set margins all to 0\n");
3395
3396 }
3397 }
3398 }
3399 }
3400 }
3401
3402 stp_dprintf(STP_DBG_CANON, v,"internal_imageable_area: left_margin %f\n",left_margin);
3403 stp_dprintf(STP_DBG_CANON, v,"internal_imageable_area: right_margin %f\n",right_margin);
3404 stp_dprintf(STP_DBG_CANON, v,"internal_imageable_area: top_margin %f\n",top_margin);
3405 stp_dprintf(STP_DBG_CANON, v,"internal_imageable_area: bottom_margin %f\n",bottom_margin);
3406
3407 *left = left_margin;
3408 *right = width - right_margin;
3409 *top = top_margin;
3410 *bottom = length - bottom_margin;
3411
3412 stp_dprintf(STP_DBG_CANON, v,"internal_imageable_area: page_left %f\n",*left);
3413 stp_dprintf(STP_DBG_CANON, v,"internal_imageable_area: page_right %f\n",*right);
3414 stp_dprintf(STP_DBG_CANON, v,"internal_imageable_area: page_top %f\n",*top);
3415 stp_dprintf(STP_DBG_CANON, v,"internal_imageable_area: page_bottom %f\n",*bottom);
3416
3417 }
3418
3419 static void
3420 canon_imageable_area(const stp_vars_t *v, /* I */
3421 stp_dimension_t *left, /* O - Left position in points */
3422 stp_dimension_t *right, /* O - Right position in points */
3423 stp_dimension_t *bottom, /* O - Bottom position in points */
3424 stp_dimension_t *top) /* O - Top position in points */
3425 {
3426 internal_imageable_area(v, 1, 0, left, right, bottom, top);
3427 }
3428
3429 static void
3430 canon_maximum_imageable_area(const stp_vars_t *v, /* I */
3431 stp_dimension_t *left, /* O - Left position in points */
3432 stp_dimension_t *right, /* O - Right position in points */
3433 stp_dimension_t *bottom, /* O - Bottom position in points */
3434 stp_dimension_t *top) /* O - Top position in points */
3435 {
3436 internal_imageable_area(v, 1, 1, left, right, bottom, top);
3437 }
3438
3439 static void
3440 canon_limit(const stp_vars_t *v, /* I */
3441 stp_dimension_t *width,
3442 stp_dimension_t *height,
3443 stp_dimension_t *min_width,
3444 stp_dimension_t *min_height)
3445 {
3446 const canon_cap_t * caps=
3447 canon_get_model_capabilities(v);
3448 *width = caps->max_width;
3449 *height = caps->max_height;
3450 *min_width = 1;
3451 *min_height = 1;
3452 }
3453
3454 /*
3455 * 'canon_cmd()' - Sends a command with variable args
3456 */
3457 static void
3458 canon_cmd(const stp_vars_t *v, /* I - the printer */
3459 const char *ini, /* I - 2 bytes start code */
3460 const char cmd, /* I - command code */
3461 int num, /* I - number of arguments */
3462 ... /* I - the args themselves */
3463 )
3464 {
3465 unsigned char *buffer = stp_zalloc(num + 1);
3466 int i;
3467 va_list ap;
3468
3469 if (num)
3470 {
3471 va_start(ap, num);
3472 for (i=0; i<num; i++)
3473 buffer[i]= (unsigned char) va_arg(ap, int);
3474 va_end(ap);
3475 }
3476
3477 stp_zfwrite(ini,2,1,v);
3478 if (cmd)
3479 {
3480 stp_putc(cmd,v);
3481 stp_put16_le(num, v);
3482 if (num)
3483 stp_zfwrite((const char *)buffer,num,1,v);
3484 }
3485 stp_free(buffer);
3486 }
3487
3488 #define PUT(V,WHAT,VAL,RES) stp_dprintf(STP_DBG_CANON,V,"canon: "WHAT \
3489 " is %04x =% 5d = %f\" = %f mm\n",(VAL),(VAL),(VAL)/(1.*RES),(VAL)/(RES/25.4))
3490
3491 #define ESC28 "\033\050"
3492 #define ESC5b "\033\133"
3493 #define ESC40 "\033\100"
3494
3495 static void canon_control_cmd(const stp_vars_t*v,const char* cmd){
3496 canon_cmd(v,ESC5b,0x4b, 2, 0x00,0x1f);
3497 stp_puts("BJLSTART\nControlMode=Common\n",v);
3498 stp_puts(cmd,v);
3499 stp_putc('\n',v);
3500 stp_puts("BJLEND\n",v);
3501 }
3502
3503
3504 /* ESC [K -- -- reset printer:
3505 */
3506 static void
3507 canon_init_resetPrinter(const stp_vars_t *v, const canon_privdata_t *init)
3508 {
3509 if ( init->caps->control_cmdlist ){
3510 int i=0;
3511 while(init->caps->control_cmdlist[i]){
3512 canon_control_cmd(v,init->caps->control_cmdlist[i]);
3513 ++i;
3514 }
3515 }
3516 if(!strcmp(init->slot->name,"CD"))
3517 canon_control_cmd(v,"MediaDetection=ON");
3518 canon_cmd(v,ESC5b,0x4b, 2, 0x00,0x0f);
3519 }
3520
3521 /* ESC ($ -- 0x24 -- cmdSetDuplex --:
3522 */
3523 static void
3524 canon_init_setDuplex(const stp_vars_t *v, const canon_privdata_t *init)
3525 {
3526 if (!(init->caps->features & CANON_CAP_DUPLEX))
3527 return;
3528 if (strncmp(init->duplex_str, "Duplex", 6)) {
3529 if ( !(strcmp(init->caps->name,"i860")) || !(strcmp(init->caps->name,"i865")) || !(strcmp(init->caps->name,"i950")) || !(strcmp(init->caps->name,"i960")) || !(strcmp(init->caps->name,"i990")) ) {
3530 /* i860, i865, i950, i960, i990 use ESC ($ command even for simplex mode */
3531 canon_cmd(v,ESC28,0x24,9,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00);
3532 return;
3533 }
3534 else
3535 return;
3536 }
3537 /* The same command seems to be needed for both Duplex and DuplexTumble
3538 no idea about the meanings of the single bytes */
3539 canon_cmd(v,ESC28,0x24,9,0x01,0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x02);
3540 }
3541
3542 /* ESC (a -- 0x61 -- cmdSetPageMode --:
3543 */
3544 static void
3545 canon_init_setPageMode(const stp_vars_t *v, const canon_privdata_t *init)
3546 {
3547 if (!(init->caps->features & CANON_CAP_a))
3548 return;
3549
3550 if (init->caps->features & CANON_CAP_a)
3551 canon_cmd(v,ESC28,0x61, 1, 0x01);
3552 }
3553
3554 /* ESC (b -- 0x62 -- -- set data compression:
3555 */
3556 static void
3557 canon_init_setDataCompression(const stp_vars_t *v, const canon_privdata_t *init)
3558 {
3559 if (!(init->caps->features & CANON_CAP_b))
3560 return;
3561
3562 canon_cmd(v,ESC28,0x62, 1, 0x01);
3563 }
3564
3565 /* ESC (c -- 0x63 -- cmdSetColor --:
3566 */
3567 static void
3568 canon_init_setColor(const stp_vars_t *v, const canon_privdata_t *init)
3569 {
3570 unsigned char
3571 numargs, arg_63[6];
3572
3573 if (!(init->caps->features & CANON_CAP_c))
3574 return;
3575
3576 numargs = 3;
3577 arg_63[0] = init->caps->model_id << 4; /* MODEL_ID */
3578
3579 switch ( init->caps->model_id ) {
3580
3581 case 0: /* very old 360 dpi series: BJC-800/820 */
3582 break; /* tbd */
3583
3584 case 1: /* 360 dpi series - BJC-4000, BJC-210, BJC-70 and their descendants */
3585 if (init->used_inks == CANON_INK_K)
3586 arg_63[0]|= 0x01; /* PRINT_COLOUR */
3587
3588
3589 // if ( (!strcmp(init->caps->name,"85")) || (!strcmp(init->caps->name,"1000")) ) /* BJC-85, BJC-1000 */
3590 // arg_63[1] = (init->pt) ? init->pt->media_code_c : 0; /* print media type */
3591 // else /* original, not sure which models follow this at all */
3592 arg_63[1] = ((init->pt ? init->pt->media_code_c : 0) << 4) /* PRINT_MEDIA */
3593 + 1; /* hardcode to High quality for now */ /* PRINT_QUALITY */
3594
3595 if (!strcmp(init->caps->name,"2100")) { /* BJC-2100: ESC (c command length is 3 */
3596 if (!strcmp(init->mode->name,"720x360dpi"))
3597 arg_63[1] = 0x00;
3598 else if (!strcmp(init->mode->name,"360x360dpi_draft"))
3599 arg_63[1] = 0x00;
3600 else if (!strcmp(init->mode->name,"180x180dpi"))
3601 arg_63[1] = 0x02;
3602 /* else keep at 01 hard-coded as above - logic unknown */
3603 canon_cmd(v,ESC28,0x63, 3, arg_63[0], arg_63[1], 0x00);
3604 } else /* length 2 in legacy code */
3605 canon_cmd(v,ESC28,0x63, 2, arg_63[0], arg_63[1]);
3606 break;
3607
3608 case 2: /* are any models using this? */
3609 break;
3610
3611 case 3: /* 720 dpi series - BJC-3000 and descendants */
3612 if (init->used_inks == CANON_INK_K)
3613 arg_63[0]|= 0x01; /* colour mode */
3614
3615 arg_63[1] = (init->pt) ? init->pt->media_code_c : 0; /* print media type */
3616
3617 if (!strcmp(init->caps->name,"S200")) /* S200 */
3618 {
3619 if ((init->mode->xdpi == 720) && (init->mode->ydpi == 720 ))
3620 arg_63[2] = 1;
3621 else
3622 arg_63[2] = 4; /* hardcoded: quality 3 (may be 0...4) */
3623 /* bidirectional is controlled via quality: 0..2 is bidi, 3 and 4 uni */
3624 /* not every combination works, no idea about the principle */
3625 if ( (init->mode->xdpi > 360) || (init->mode->ydpi > 360) )
3626 {
3627 numargs = 6;
3628 arg_63[3] = 0x10; arg_63[4] = 6; arg_63[5] = 8; /* arg5 makes a vert. offset for K */
3629 if (init->used_inks == CANON_INK_K)
3630 arg_63[4] = 1;
3631 }
3632 }
3633 else if (!strcmp(init->caps->name,"4550")) /* BJC-4550 */
3634 {
3635 numargs = 3;
3636 arg_63[2] = 0; /* not used in Black and Color, no idea about PhotoColor yet */
3637 arg_63[1] = init->quality; /* hardcode to whatever this means for now; quality, apparently */
3638 }
3639 else
3640 arg_63[2] = init->quality; /* hardcode to whatever this means for now; quality, apparently */
3641
3642 stp_zprintf(v, "\033\050\143");
3643 stp_put16_le(numargs, v);
3644 stp_zfwrite((const char *)arg_63, numargs, 1, v);
3645 break;
3646 }
3647
3648 return;
3649 }
3650
3651 /* ESC (d -- 0x64 -- -- set raster resolution:
3652 */
3653 static void
3654 canon_init_setResolution(const stp_vars_t *v, const canon_privdata_t *init)
3655 {
3656 if (!(init->caps->features & CANON_CAP_d))
3657 return;
3658
3659 if (strcmp(init->caps->name,"S200") || (init->mode->xdpi <= 360))
3660 canon_cmd(v,ESC28,0x64, 4,
3661 (init->mode->ydpi >> 8 ), (init->mode->ydpi & 255),
3662 (init->mode->xdpi >> 8 ), (init->mode->xdpi & 255));
3663 else
3664 if (init->mode->xdpi < 2880)
3665 canon_cmd(v,ESC28,0x64, 4,
3666 (720 >> 8), (720 & 255),
3667 (720 >> 8), (720 & 255));
3668 else
3669 canon_cmd(v,ESC28,0x64, 4,
3670 (720 >> 8), (720 & 255),
3671 (2880 >> 8), (2880 & 255));
3672 }
3673
3674 /* ESC (g -- 0x67 -- cmdSetPageMargins --:
3675 */
3676 static void
3677 canon_init_setPageMargins(const stp_vars_t *v, const canon_privdata_t *init)
3678 {
3679 /* TOFIX: what exactly is to be sent?
3680 * Is it the printable length or the bottom border?
3681 * Is is the printable width or the right border?
3682 */
3683
3684 int minlength= 0;
3685 int minwidth= 0;
3686 int length= init->page_height*5/36;
3687 int width= init->page_width*5/36;
3688
3689 if (!(init->caps->features & CANON_CAP_g))
3690 return;
3691
3692 if (minlength>length) length= minlength;
3693 if (minwidth>width) width= minwidth;
3694
3695 canon_cmd(v,ESC28,0x67, 4, 0,
3696 (unsigned char)(length),1,
3697 (unsigned char)(width));
3698
3699 }
3700
3701 /* ESC (l -- 0x6c -- cmdSetTray --:
3702 */
3703 static void
3704 canon_init_setTray(const stp_vars_t *v, const canon_privdata_t *init)
3705 {
3706 unsigned char
3707 arg_6c_1 = 0x00,
3708 arg_6c_2 = 0x00, /* plain paper */
3709 arg_6c_3 = 0x00; /* special cases like iP7100 to be handled */
3710
3711 if (!(init->caps->features & CANON_CAP_l))
3712 return;
3713
3714 arg_6c_1 = init->caps->model_id << 4;
3715
3716 arg_6c_1|= (init->slot->code & 0x0f);
3717
3718 /* set gap for MP710/740 if thick media selected */
3719 if (!strcmp(init->slot->name,"AutoThick"))
3720 if ( (!strcmp(init->caps->name,"PIXMA MP710")) || (!strcmp(init->caps->name,"PIXMA MP740")) )
3721 arg_6c_3 = 0x10;
3722
3723 switch ( init->caps->model_id ) {
3724 case 0:
3725 break;
3726 case 1:
3727 if (init->pt) arg_6c_2 = ((init->pt ? init->pt->media_code_l : 0) << 4); /* PRINT_MEDIA */
3728 break;
3729 case 2:
3730 break;
3731 case 3:
3732 if (init->pt) arg_6c_2 = init->pt->media_code_l; /* PRINT_MEDIA */
3733 break;
3734 }
3735
3736 /* select between length 2 and 3 byte variations of command */
3737 /*if(init->caps->model_id >= 3)*/
3738 if(init->caps->ESC_l_len == 3)
3739 canon_cmd(v,ESC28,0x6c, 3, arg_6c_1, arg_6c_2, arg_6c_3); /* 3rd arg is "gap" */
3740 else /* else 2 bytes---no other option for now */
3741 canon_cmd(v,ESC28,0x6c, 2, arg_6c_1, arg_6c_2);
3742 }
3743
3744 /* ESC (m -- 0x6d -- -- :
3745 */
3746 static void
3747 canon_init_setPrintMode(const stp_vars_t *v, const canon_privdata_t *init)
3748 {
3749 unsigned char
3750 arg_6d_1 = 0x03, /* color printhead? */
3751 arg_6d_2 = 0x00, /* 00=color 02=b/w */
3752 arg_6d_3 = 0x00, /* only 01 for bjc8200 and S200*/
3753 /* S200:for envelope and t-shirt transfer = 03 */
3754 arg_6d_a = 0x03, /* A4 paper */
3755 arg_6d_b = 0x00;
3756
3757 if (!(init->caps->features & CANON_CAP_m))
3758 return;
3759
3760 arg_6d_a= canon_size_type(v,init->caps);
3761 if (!arg_6d_a)
3762 arg_6d_b= 1;
3763
3764 arg_6d_1= 0x04;
3765
3766 if ((!strcmp(init->caps->name,"7000")) && (init->used_inks == CANON_INK_K || init->used_inks == CANON_INK_CcMmYK || init->used_inks == CANON_INK_CcMmYyK))
3767 arg_6d_1= 0x03;
3768
3769 if (((!strcmp(init->caps->name,"8200") || !strcmp(init->caps->name,"S200")) && init->used_inks == CANON_INK_K) || init->used_inks == CANON_INK_CMYK)
3770 arg_6d_1= 0x02;
3771
3772 if(!strcmp(init->caps->name,"S200") && init->used_inks == CANON_INK_CMY)
3773 arg_6d_1= 0x02;
3774
3775 if (init->used_inks == CANON_INK_K)
3776 arg_6d_2= 0x02;
3777
3778 if (!strcmp(init->caps->name,"8200") || !strcmp(init->caps->name,"S200"))
3779 arg_6d_3= 0x01;
3780
3781 canon_cmd(v,ESC28,0x6d,12, arg_6d_1,
3782 0xff,0xff,0x00,0x00,0x07,0x00,
3783 arg_6d_a,arg_6d_b,arg_6d_2,0x00,arg_6d_3);
3784 }
3785
3786 /* ESC (M -- 0x4d -- -- :
3787 */
3788 static void
3789 canon_init_setESC_M(const stp_vars_t *v, const canon_privdata_t *init)
3790 {
3791 if (!(init->caps->features & CANON_CAP_M))
3792 return;
3793
3794 canon_cmd(v,ESC28,0x4d, 3, 0x00, 0x00, 0x00);
3795 }
3796
3797 /* ESC (p -- 0x70 -- cmdSetPageMargins2 --:
3798 */
3799 static void
3800 canon_init_setPageMargins2(const stp_vars_t *v, canon_privdata_t *init)
3801 {
3802 unsigned char arg_70_1,arg_70_2,arg_70_3,arg_70_4;
3803
3804 int border_left,border_right,border_top,border_bottom;
3805 int border_left2,border_top2;
3806 int border_right2;
3807 int border_bottom2;
3808 int area_right,area_top;
3809 int test_cd; /* variable for activating experimental adjustments */
3810 /* CD tray size adjustments for paper dimensions */
3811 int adjust_tray_custom_length, adjust_tray_custom_width;
3812 int adjust_tray_A_length, adjust_tray_A_width;
3813 int adjust_tray_BCD_length, adjust_tray_BCD_width;
3814 int adjust_tray_E_length, adjust_tray_E_width;
3815 int adjust_tray_F_length, adjust_tray_F_width;
3816 int adjust_tray_G_length, adjust_tray_G_width;
3817 int adjust_tray_H_length, adjust_tray_H_width;
3818 int adjust_tray_J_length, adjust_tray_J_width;
3819 int adjust_tray_L_length, adjust_tray_L_width;
3820 /* CD tray border adjustments */
3821 int adjust_tray_custom_left, adjust_tray_custom_right, adjust_tray_custom_top, adjust_tray_custom_bottom;
3822 int adjust_tray_A_left, adjust_tray_A_right, adjust_tray_A_top, adjust_tray_A_bottom;
3823 int adjust_tray_BCD_left, adjust_tray_BCD_right, adjust_tray_BCD_top, adjust_tray_BCD_bottom;
3824 int adjust_tray_E_left, adjust_tray_E_right, adjust_tray_E_top, adjust_tray_E_bottom;
3825 int adjust_tray_F_left, adjust_tray_F_right, adjust_tray_F_top, adjust_tray_F_bottom;
3826 int adjust_tray_G_left, adjust_tray_G_right, adjust_tray_G_top, adjust_tray_G_bottom;
3827 int adjust_tray_H_left, adjust_tray_H_right, adjust_tray_H_top, adjust_tray_H_bottom;
3828 int adjust_tray_J_left, adjust_tray_J_right, adjust_tray_J_top, adjust_tray_J_bottom;
3829 int adjust_tray_L_left, adjust_tray_L_right, adjust_tray_L_top, adjust_tray_L_bottom;
3830 int paper_width, paper_length;
3831
3832 /* Canon printer firmware requires paper_width (and paper_length?)
3833 to be exact matches in units of 1/600 inch.
3834 To this end, papersize code is used to find the papersize for the
3835 printjob, and paper_width and paper_length set to exact values,
3836 rather than calculated.
3837 */
3838 unsigned char arg_ESCP_1 = (init->pt) ? canon_size_type(v,init->caps) : 0x03; /* default size A4 */
3839 stp_dprintf(STP_DBG_CANON, v,"setPageMargins2: arg_ESCP_1 = '%x'\n",arg_ESCP_1);
3840
3841 /* TOFIX: what exactly is to be sent?
3842 * Is it the printable length or the bottom border?
3843 * Is is the printable width or the right border?
3844 */
3845
3846 int unit = 600;
3847 int printable_width = (init->page_width + 1)*5/6;
3848 int printable_length = (init->page_height + 1)*5/6;
3849
3850 const char* input_slot = stp_get_string_parameter(v, "InputSlot");
3851 int print_cd = (input_slot && (!strcmp(input_slot, "CD")));
3852
3853 stp_dprintf(STP_DBG_CANON, v,"setPageMargins2: print_cd = %d\n",print_cd);
3854
3855 test_cd = 1;
3856 /*
3857 Adjustments for different CD trays:
3858 All based on the following settings:
3859 CANON_CD_X = 176
3860 CANON_CD_Y = 405
3861
3862 Custom:
3863 printable_width = init->page_width + 24;
3864 printable_length = init->page_height + 132;
3865
3866 A:
3867 printable_width = init->page_width + 44;
3868 printable_length = init->page_height + 151;
3869
3870 B/C/D:
3871 printable_width = init->page_width + 10;
3872 printable_length = init->page_height + 84;
3873
3874 E:
3875 printable_width = init->page_width + 127;
3876 printable_length = init->page_height + 186;
3877
3878 F:
3879 printable_width = init->page_width + 10;
3880 printable_length = init->page_height + 95;
3881
3882 G:
3883 printable_width = init->page_width + 10;
3884 printable_length = init->page_height + 127;
3885
3886 H:
3887 printable_width = init->page_width + 68;
3888 printable_length = init->page_height + 481;
3889
3890 J:
3891 printable_width = init->page_width + 8;
3892 printable_length = init->page_height + 44;
3893
3894 L:
3895 printable_width = init->page_width + 10;
3896 printable_length = init->page_height + 263;
3897 */
3898
3899 /* adjust paper dimensions for CD in points */
3900 adjust_tray_custom_length = 132;
3901 adjust_tray_custom_width = 24;
3902 adjust_tray_A_length = 151;
3903 adjust_tray_A_width = 44;
3904 adjust_tray_BCD_length = 84;
3905 adjust_tray_BCD_width = 10;
3906 adjust_tray_E_length = 186;
3907 adjust_tray_E_width = 127;
3908 adjust_tray_F_length = 95;
3909 adjust_tray_F_width = 10; /* 10 calculated, but empirically 11 */
3910 adjust_tray_G_length = 127;
3911 adjust_tray_G_width = 10; /* 10 calculated, but empirically 11 */
3912 adjust_tray_H_length = 481;
3913 adjust_tray_H_width = 68;
3914 adjust_tray_J_length = 44;
3915 adjust_tray_J_width = 8;
3916 adjust_tray_L_length = 263;
3917 adjust_tray_L_width = 10;
3918
3919 /* ensure less than or equal to Windows measurements by border adjustments in points */
3920 adjust_tray_custom_left = 0;
3921 adjust_tray_custom_right = 0;
3922 adjust_tray_custom_top = 0;
3923 adjust_tray_custom_bottom = 0;
3924 adjust_tray_A_left = 0;
3925 adjust_tray_A_right = 0;
3926 adjust_tray_A_top = 0;
3927 adjust_tray_A_bottom = 0;
3928 adjust_tray_BCD_left = 0;
3929 adjust_tray_BCD_right = 0;
3930 adjust_tray_BCD_top = 0;
3931 adjust_tray_BCD_bottom = 0;
3932 adjust_tray_E_left = 0;
3933 adjust_tray_E_right = 0;
3934 adjust_tray_E_top = 0;
3935 adjust_tray_E_bottom = 0;
3936 adjust_tray_F_left = 0;
3937 adjust_tray_F_right = 0;
3938 adjust_tray_F_top = 0;
3939 adjust_tray_F_bottom = 0;
3940 adjust_tray_G_left = 0;
3941 adjust_tray_G_right = 0;
3942 adjust_tray_G_top = 0;
3943 adjust_tray_G_bottom = 0;
3944 adjust_tray_H_left = 0;
3945 adjust_tray_H_right = 0;
3946 adjust_tray_H_top = 0;
3947 adjust_tray_H_bottom = 0;
3948 adjust_tray_J_left = 0;
3949 adjust_tray_J_right = 0;
3950 adjust_tray_J_top = 0;
3951 adjust_tray_J_bottom = 0;
3952 adjust_tray_L_left = 0;
3953 adjust_tray_L_right = 0;
3954 adjust_tray_L_top = 0;
3955 adjust_tray_L_bottom = 0;
3956
3957 if ((print_cd) && test_cd) {
3958 /* test all of the parameters for CD */
3959 stp_dprintf(STP_DBG_CANON, v,"==========Start Test Printout=========='\n");
3960
3961 stp_dprintf(STP_DBG_CANON, v, "Tray Custom original init->page_width (pts): '%d'\n",init->page_width);
3962 stp_dprintf(STP_DBG_CANON, v, "Tray Custom original init->page_height (pts): '%d'\n",init->page_height);
3963 stp_dprintf(STP_DBG_CANON, v, "Tray Custom modified init->page_width (pts): '%d'\n",init->page_width + adjust_tray_custom_width);
3964 stp_dprintf(STP_DBG_CANON, v, "Tray Custom modified init->page_height (pts): '%d'\n",init->page_height + adjust_tray_custom_length);
3965 stp_dprintf(STP_DBG_CANON, v, "Tray Custom printable width (pts): '%d'\n",(init->page_width + adjust_tray_custom_width + 1) * 5 / 6);
3966 stp_dprintf(STP_DBG_CANON, v, "Tray Custom printable length (pts): '%d'\n",(init->page_height + adjust_tray_custom_length + 1) * 5 / 6);
3967 stp_dprintf(STP_DBG_CANON, v, "Tray Custom page_width (1/600): '%d'\n",(init->page_width + adjust_tray_custom_width) * unit / 72);
3968 stp_dprintf(STP_DBG_CANON, v, "Tray Custom page_height (1/600): '%d'\n",(init->page_height + adjust_tray_custom_length) * unit / 72);
3969 stp_dprintf(STP_DBG_CANON, v, "Tray Custom paper_width (1/600): '%d'\n",(init->page_width + adjust_tray_custom_width + 20 + adjust_tray_custom_left + adjust_tray_custom_right) * unit / 72);
3970 stp_dprintf(STP_DBG_CANON, v, "Tray Custom paper_height (1/600): '%d'\n",(init->page_height + adjust_tray_custom_length + 24 + adjust_tray_custom_top + adjust_tray_custom_bottom) * unit / 72);
3971
3972 stp_dprintf(STP_DBG_CANON, v, "Tray A original init->page_width (pts): '%d'\n",init->page_width);
3973 stp_dprintf(STP_DBG_CANON, v, "Tray A original init->page_height (pts): '%d'\n",init->page_height);
3974 stp_dprintf(STP_DBG_CANON, v, "Tray A modified init->page_width (pts): '%d'\n",init->page_width + adjust_tray_A_width);
3975 stp_dprintf(STP_DBG_CANON, v, "Tray A modified init->page_height (pts): '%d'\n",init->page_height + adjust_tray_A_length);
3976 stp_dprintf(STP_DBG_CANON, v, "Tray A printable width (pts): '%d'\n",(init->page_width + adjust_tray_A_width + 1) * 5 / 6);
3977 stp_dprintf(STP_DBG_CANON, v, "Tray A printable length (pts): '%d'\n",(init->page_height + adjust_tray_A_length + 1) * 5 / 6);
3978 stp_dprintf(STP_DBG_CANON, v, "Tray A page_width (1/600): '%d'\n",(init->page_width + adjust_tray_A_width) * unit / 72);
3979 stp_dprintf(STP_DBG_CANON, v, "Tray A page_height (1/600): '%d'\n",(init->page_height + adjust_tray_A_length) * unit / 72);
3980 stp_dprintf(STP_DBG_CANON, v, "Tray A paper_width (1/600): '%d'\n",(init->page_width + adjust_tray_A_width + 20 + adjust_tray_A_left + adjust_tray_A_right ) * unit / 72);
3981 stp_dprintf(STP_DBG_CANON, v, "Tray A paper_height (1/600): '%d'\n",(init->page_height + adjust_tray_A_length + 24 + adjust_tray_A_top + adjust_tray_A_bottom) * unit / 72);
3982
3983 stp_dprintf(STP_DBG_CANON, v, "Tray B/C/D original init->page_width (pts): '%d'\n",init->page_width);
3984 stp_dprintf(STP_DBG_CANON, v, "Tray B/C/D original init->page_height (pts): '%d'\n",init->page_height);
3985 stp_dprintf(STP_DBG_CANON, v, "Tray B/C/D modified init->page_width (pts): '%d'\n",init->page_width + adjust_tray_BCD_width);
3986 stp_dprintf(STP_DBG_CANON, v, "Tray B/C/D modified init->page_height (pts): '%d'\n",init->page_height + adjust_tray_BCD_length);
3987 stp_dprintf(STP_DBG_CANON, v, "Tray B/C/D printable width (pts): '%d'\n",(init->page_width + adjust_tray_BCD_width + 1) * 5 / 6);
3988 stp_dprintf(STP_DBG_CANON, v, "Tray B/C/D printable length (pts): '%d'\n",(init->page_height + adjust_tray_BCD_length + 1) * 5 / 6);
3989 stp_dprintf(STP_DBG_CANON, v, "Tray B/C/D page_width (1/600): '%d'\n",(init->page_width + adjust_tray_BCD_width) * unit / 72);
3990 stp_dprintf(STP_DBG_CANON, v, "Tray B/C/D page_height (1/600): '%d'\n",(init->page_height + adjust_tray_BCD_length) * unit / 72);
3991 stp_dprintf(STP_DBG_CANON, v, "Tray B/C/D paper_width (1/600): '%d'\n",(init->page_width + adjust_tray_BCD_width + 20 + adjust_tray_BCD_left + adjust_tray_BCD_right) * unit / 72);
3992 stp_dprintf(STP_DBG_CANON, v, "Tray B/C/D paper_height (1/600): '%d'\n",(init->page_height + adjust_tray_BCD_length + 24 + adjust_tray_BCD_top + adjust_tray_BCD_bottom) * unit / 72);
3993
3994 stp_dprintf(STP_DBG_CANON, v, "Tray E original init->page_width (pts): '%d'\n",init->page_width);
3995 stp_dprintf(STP_DBG_CANON, v, "Tray E original init->page_height (pts): '%d'\n",init->page_height);
3996 stp_dprintf(STP_DBG_CANON, v, "Tray E modified init->page_width (pts): '%d'\n",init->page_width + adjust_tray_E_width);
3997 stp_dprintf(STP_DBG_CANON, v, "Tray E modified init->page_height (pts): '%d'\n",init->page_height + adjust_tray_E_length);
3998 stp_dprintf(STP_DBG_CANON, v, "Tray E printable width (pts): '%d'\n",(init->page_width + adjust_tray_E_width + 1) * 5 / 6);
3999 stp_dprintf(STP_DBG_CANON, v, "Tray E printable length (pts): '%d'\n",(init->page_height + adjust_tray_E_length + 1) * 5 / 6);
4000 stp_dprintf(STP_DBG_CANON, v, "Tray E page_width (1/600): '%d'\n",(init->page_width + adjust_tray_E_width) * unit / 72);
4001 stp_dprintf(STP_DBG_CANON, v, "Tray E page_height (1/600): '%d'\n",(init->page_height + adjust_tray_E_length) * unit / 72);
4002 stp_dprintf(STP_DBG_CANON, v, "Tray E paper_width (1/600): '%d'\n",(init->page_width + adjust_tray_E_width + 20 + adjust_tray_E_left + adjust_tray_E_right) * unit / 72);
4003 stp_dprintf(STP_DBG_CANON, v, "Tray E paper_height (1/600): '%d'\n",(init->page_height + adjust_tray_E_length + 24 + adjust_tray_E_top + adjust_tray_E_bottom) * unit / 72);
4004
4005 stp_dprintf(STP_DBG_CANON, v, "Tray F original init->page_width (pts): '%d'\n",init->page_width);
4006 stp_dprintf(STP_DBG_CANON, v, "Tray F original init->page_height (pts): '%d'\n",init->page_height);
4007 stp_dprintf(STP_DBG_CANON, v, "Tray F modified init->page_width (pts): '%d'\n",init->page_width + adjust_tray_F_width);
4008 stp_dprintf(STP_DBG_CANON, v, "Tray F modified init->page_height (pts): '%d'\n",init->page_height + adjust_tray_F_length);
4009 stp_dprintf(STP_DBG_CANON, v, "Tray F printable width (pts): '%d'\n",(init->page_width + adjust_tray_F_width + 1) * 5 / 6);
4010 stp_dprintf(STP_DBG_CANON, v, "Tray F printable length (pts): '%d'\n",(init->page_height + adjust_tray_F_length + 1) * 5 / 6);
4011 stp_dprintf(STP_DBG_CANON, v, "Tray F page_width (1/600): '%d'\n",(init->page_width + adjust_tray_F_width) * unit / 72);
4012 stp_dprintf(STP_DBG_CANON, v, "Tray F page_height (1/600): '%d'\n",(init->page_height + adjust_tray_F_length) * unit / 72);
4013 stp_dprintf(STP_DBG_CANON, v, "Tray F paper_width (1/600): '%d'\n",(init->page_width + adjust_tray_F_width + 20 + adjust_tray_F_left + adjust_tray_F_right) * unit / 72);
4014 stp_dprintf(STP_DBG_CANON, v, "Tray F paper_height (1/600): '%d'\n",(init->page_height + adjust_tray_F_length + 24 + adjust_tray_F_top + adjust_tray_F_bottom) * unit / 72);
4015
4016 stp_dprintf(STP_DBG_CANON, v, "Tray G original init->page_width (pts): '%d'\n",init->page_width);
4017 stp_dprintf(STP_DBG_CANON, v, "Tray G original init->page_height (pts): '%d'\n",init->page_height);
4018 stp_dprintf(STP_DBG_CANON, v, "Tray G modified init->page_width (pts): '%d'\n",init->page_width + adjust_tray_G_width);
4019 stp_dprintf(STP_DBG_CANON, v, "Tray G modified init->page_height (pts): '%d'\n",init->page_height + adjust_tray_G_length);
4020 stp_dprintf(STP_DBG_CANON, v, "Tray G printable width (pts): '%d'\n",(init->page_width + adjust_tray_G_width + 1) * 5 / 6);
4021 stp_dprintf(STP_DBG_CANON, v, "Tray G printable length (pts): '%d'\n",(init->page_height + adjust_tray_G_length + 1) * 5 / 6);
4022 stp_dprintf(STP_DBG_CANON, v, "Tray G page_width (1/600): '%d'\n",(init->page_width + adjust_tray_G_width) * unit / 72);
4023 stp_dprintf(STP_DBG_CANON, v, "Tray G page_height (1/600): '%d'\n",(init->page_height + adjust_tray_G_length) * unit / 72);
4024 stp_dprintf(STP_DBG_CANON, v, "Tray G paper_width (1/600): '%d'\n",(init->page_width + adjust_tray_G_width + 20 + adjust_tray_G_left + adjust_tray_G_right) * unit / 72);
4025 stp_dprintf(STP_DBG_CANON, v, "Tray G paper_height (1/600): '%d'\n",(init->page_height + adjust_tray_G_length + 24 + adjust_tray_G_top + adjust_tray_G_bottom) * unit / 72);
4026
4027 stp_dprintf(STP_DBG_CANON, v, "Tray H original init->page_width (pts): '%d'\n",init->page_width);
4028 stp_dprintf(STP_DBG_CANON, v, "Tray H original init->page_height (pts): '%d'\n",init->page_height);
4029 stp_dprintf(STP_DBG_CANON, v, "Tray H modified init->page_width (pts): '%d'\n",init->page_width + adjust_tray_H_width);
4030 stp_dprintf(STP_DBG_CANON, v, "Tray H modified init->page_height (pts): '%d'\n",init->page_height + adjust_tray_H_length);
4031 stp_dprintf(STP_DBG_CANON, v, "Tray H printable width (pts): '%d'\n",(init->page_width + adjust_tray_H_width + 1) * 5 / 6);
4032 stp_dprintf(STP_DBG_CANON, v, "Tray H printable length (pts): '%d'\n",(init->page_height + adjust_tray_H_length + 1) * 5 / 6);
4033 stp_dprintf(STP_DBG_CANON, v, "Tray H page_width (1/600): '%d'\n",(init->page_width + adjust_tray_H_width) * unit / 72);
4034 stp_dprintf(STP_DBG_CANON, v, "Tray H page_height (1/600): '%d'\n",(init->page_height + adjust_tray_H_length) * unit / 72);
4035 stp_dprintf(STP_DBG_CANON, v, "Tray H paper_width (1/600): '%d'\n",(init->page_width + adjust_tray_H_width + 20 + adjust_tray_H_left + adjust_tray_H_right) * unit / 72);
4036 stp_dprintf(STP_DBG_CANON, v, "Tray H paper_height (1/600): '%d'\n",(init->page_height + adjust_tray_H_length + 24 + adjust_tray_H_top + adjust_tray_H_bottom) * unit / 72);
4037
4038 stp_dprintf(STP_DBG_CANON, v, "Tray J original init->page_width (pts): '%d'\n",init->page_width);
4039 stp_dprintf(STP_DBG_CANON, v, "Tray J original init->page_height (pts): '%d'\n",init->page_height);
4040 stp_dprintf(STP_DBG_CANON, v, "Tray J modified init->page_width (pts): '%d'\n",init->page_width + adjust_tray_J_width);
4041 stp_dprintf(STP_DBG_CANON, v, "Tray J modified init->page_height (pts): '%d'\n",init->page_height + adjust_tray_J_length);
4042 stp_dprintf(STP_DBG_CANON, v, "Tray J printable width (pts): '%d'\n",(init->page_width + adjust_tray_J_width + 1) * 5 / 6);
4043 stp_dprintf(STP_DBG_CANON, v, "Tray J printable length (pts): '%d'\n",(init->page_height + adjust_tray_J_length + 1) * 5 / 6);
4044 stp_dprintf(STP_DBG_CANON, v, "Tray J page_width (1/600): '%d'\n",(init->page_width + adjust_tray_J_width) * unit / 72);
4045 stp_dprintf(STP_DBG_CANON, v, "Tray J page_height (1/600): '%d'\n",(init->page_height + adjust_tray_J_length) * unit / 72);
4046 stp_dprintf(STP_DBG_CANON, v, "Tray J paper_width (1/600): '%d'\n",(init->page_width + adjust_tray_J_width + 20 + adjust_tray_J_left + adjust_tray_J_right) * unit / 72);
4047 stp_dprintf(STP_DBG_CANON, v, "Tray J paper_height (1/600): '%d'\n",(init->page_height + adjust_tray_J_length + 24 + adjust_tray_J_top + adjust_tray_J_bottom) * unit / 72);
4048
4049 stp_dprintf(STP_DBG_CANON, v, "Tray L original init->page_width (pts): '%d'\n",init->page_width);
4050 stp_dprintf(STP_DBG_CANON, v, "Tray L original init->page_height (pts): '%d'\n",init->page_height);
4051 stp_dprintf(STP_DBG_CANON, v, "Tray L modified init->page_width (pts): '%d'\n",init->page_width + adjust_tray_L_width);
4052 stp_dprintf(STP_DBG_CANON, v, "Tray L modified init->page_height (pts): '%d'\n",init->page_height + adjust_tray_L_length);
4053 stp_dprintf(STP_DBG_CANON, v, "Tray L printable width (pts): '%d'\n",(init->page_width + adjust_tray_L_width + 1) * 5 / 6);
4054 stp_dprintf(STP_DBG_CANON, v, "Tray L printable length (pts): '%d'\n",(init->page_height + adjust_tray_L_length + 1) * 5 / 6);
4055 stp_dprintf(STP_DBG_CANON, v, "Tray L page_width (1/600): '%d'\n",(init->page_width + adjust_tray_L_width) * unit / 72);
4056 stp_dprintf(STP_DBG_CANON, v, "Tray L page_height (1/600): '%d'\n",(init->page_height + adjust_tray_L_length) * unit / 72);
4057 stp_dprintf(STP_DBG_CANON, v, "Tray L paper_width (1/600): '%d'\n",(init->page_width + adjust_tray_L_width + 20 + adjust_tray_L_left + adjust_tray_L_right) * unit / 72);
4058 stp_dprintf(STP_DBG_CANON, v, "Tray L paper_height (1/600): '%d'\n",(init->page_height + adjust_tray_L_length + 24 + adjust_tray_L_top + adjust_tray_L_bottom) * unit / 72);
4059
4060 stp_dprintf(STP_DBG_CANON, v,"==========End Test Printout=========='\n");
4061 }
4062
4063 /* Tray Custom */
4064 if ( (print_cd) && !(strcmp(init->caps->name,"PIXMA MP710")) && (test_cd==1) ) {
4065
4066 init->page_width +=24;
4067 init->page_height +=132;
4068
4069 stp_dprintf(STP_DBG_CANON, v, "Tray Custom modified init->page_width: '%d'\n",init->page_width);
4070 stp_dprintf(STP_DBG_CANON, v, "Tray Custom modified init->page_height: '%d'\n",init->page_height);
4071
4072 printable_width= (init->page_width+ 1)*5/6;
4073 printable_length= (init->page_height + 1)*5/6;
4074
4075 stp_dprintf(STP_DBG_CANON, v, "Tray Custom modified printable_width: '%d'\n",printable_width);
4076 stp_dprintf(STP_DBG_CANON, v, "Tray Custom modified printable_length: '%d'\n",printable_length);
4077
4078 }
4079
4080 /* Tray A */
4081 if ( (print_cd) && !(strcmp(init->caps->name,"PIXMA iP9910")) && (test_cd==1) ) {
4082
4083 init->page_width +=44;
4084 init->page_height +=151;
4085
4086 stp_dprintf(STP_DBG_CANON, v, "Tray A modified init->page_width: '%d'\n",init->page_width);
4087 stp_dprintf(STP_DBG_CANON, v, "Tray A modified init->page_height: '%d'\n",init->page_height);
4088
4089 printable_width= (init->page_width+ 1)*5/6;
4090 printable_length= (init->page_height + 1)*5/6;
4091
4092 stp_dprintf(STP_DBG_CANON, v, "Tray A modified printable_width: '%d'\n",printable_width);
4093 stp_dprintf(STP_DBG_CANON, v, "Tray A modified printable_length: '%d'\n",printable_length);
4094
4095 }
4096
4097 /* Tray B,C,D */
4098 if ( (print_cd) && !(strcmp(init->caps->name,"PIXMA iP3000")) && (test_cd==1) ) {
4099
4100 init->page_width +=10;
4101 init->page_height +=84;
4102
4103 stp_dprintf(STP_DBG_CANON, v, "Tray B/C/D modified init->page_width: '%d'\n",init->page_width);
4104 stp_dprintf(STP_DBG_CANON, v, "Tray B/C/B modified init->page_height: '%d'\n",init->page_height);
4105
4106 printable_width= (init->page_width+ 1)*5/6;
4107 printable_length= (init->page_height + 1)*5/6;
4108
4109 stp_dprintf(STP_DBG_CANON, v, "Tray B/C/D modified printable_width: '%d'\n",printable_width);
4110 stp_dprintf(STP_DBG_CANON, v, "Tray B/C/D modified printable_length: '%d'\n",printable_length);
4111
4112 }
4113
4114 /* Tray E */
4115 if ( (print_cd) && !(strcmp(init->caps->name,"PIXMA Pro9000")) && (test_cd==1) ) {
4116
4117 init->page_width +=127;
4118 init->page_height +=186;
4119
4120 stp_dprintf(STP_DBG_CANON, v, "Tray E modified init->page_width: '%d'\n",init->page_width);
4121 stp_dprintf(STP_DBG_CANON, v, "Tray E modified init->page_height: '%d'\n",init->page_height);
4122
4123 printable_width= (init->page_width+ 1)*5/6;
4124 printable_length= (init->page_height + 1)*5/6;
4125
4126 stp_dprintf(STP_DBG_CANON, v, "Tray E modified printable_width: '%d'\n",printable_width);
4127 stp_dprintf(STP_DBG_CANON, v, "Tray E modified printable_length: '%d'\n",printable_length);
4128
4129 }
4130
4131 /* Tray F */
4132 if ( (print_cd) && !(strcmp(init->caps->name,"PIXMA iP4500")) && (test_cd==1) ) {
4133 stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint: Tray F init->page_width: '%d'\n",init->page_width);
4134 stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint: Tray F init->page_height: '%d'\n",init->page_height);
4135
4136 stp_dprintf(STP_DBG_CANON, v, "Tray F init->page_width: '%d'\n",init->page_width);
4137 stp_dprintf(STP_DBG_CANON, v, "Tray F init->page_height: '%d'\n",init->page_height);
4138 stp_dprintf(STP_DBG_CANON, v, "Tray F initial printable_width: '%d'\n",printable_width);
4139 stp_dprintf(STP_DBG_CANON, v, "Tray F initial printable_length: '%d'\n",printable_length);
4140
4141 init->page_width +=10;
4142 init->page_height +=95;
4143
4144 stp_dprintf(STP_DBG_CANON, v, "Tray F modified init->page_width: '%d'\n",init->page_width);
4145 stp_dprintf(STP_DBG_CANON, v, "Tray F modified init->page_height: '%d'\n",init->page_height);
4146
4147 printable_width= (init->page_width+ 1)*5/6;
4148 printable_length= (init->page_height + 1)*5/6;
4149
4150 stp_dprintf(STP_DBG_CANON, v, "Tray F modified printable_width: '%d'\n",printable_width);
4151 stp_dprintf(STP_DBG_CANON, v, "Tray F modified printable_length: '%d'\n",printable_length);
4152
4153 stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint: Tray F modified printable_width: '%d'\n",printable_width);
4154 stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint: Tray F modified printable_length: '%d'\n",printable_length);
4155 }
4156
4157 /* Tray G */
4158 if ( (print_cd) && !(strcmp(init->caps->name,"PIXMA iP4700")) && (test_cd==1) ) {
4159
4160 init->page_width +=10;
4161 init->page_height +=127;
4162
4163 stp_dprintf(STP_DBG_CANON, v, "Tray G modified init->page_width: '%d'\n",init->page_width);
4164 stp_dprintf(STP_DBG_CANON, v, "Tray G modified init->page_height: '%d'\n",init->page_height);
4165
4166 printable_width= (init->page_width+ 1)*5/6;
4167 printable_length= (init->page_height + 1)*5/6;
4168
4169 stp_dprintf(STP_DBG_CANON, v, "Tray G modified printable_width: '%d'\n",printable_width);
4170 stp_dprintf(STP_DBG_CANON, v, "Tray G modified printable_length: '%d'\n",printable_length);
4171
4172 }
4173
4174 /* Tray H */
4175 if ( (print_cd) && !(strcmp(init->caps->name,"PIXMA PRO-1")) && (test_cd==1) ) {
4176
4177 init->page_width +=68;
4178 init->page_height +=481;
4179
4180 stp_dprintf(STP_DBG_CANON, v, "Tray H modified init->page_width: '%d'\n",init->page_width);
4181 stp_dprintf(STP_DBG_CANON, v, "Tray H modified init->page_height: '%d'\n",init->page_height);
4182
4183 printable_width= (init->page_width+ 1)*5/6;
4184 printable_length= (init->page_height + 1)*5/6;
4185
4186 stp_dprintf(STP_DBG_CANON, v, "Tray H modified printable_width: '%d'\n",printable_width);
4187 stp_dprintf(STP_DBG_CANON, v, "Tray H modified printable_length: '%d'\n",printable_length);
4188
4189 }
4190
4191 /* Tray J */
4192 if ( (print_cd) && !(strcmp(init->caps->name,"PIXMA iP7200")) && (test_cd==1) ) {
4193
4194 init->page_width +=8;
4195 init->page_height +=44;
4196
4197 stp_dprintf(STP_DBG_CANON, v, "Tray J modified init->page_width: '%d'\n",init->page_width);
4198 stp_dprintf(STP_DBG_CANON, v, "Tray J modified init->page_height: '%d'\n",init->page_height);
4199
4200 printable_width= (init->page_width+ 1)*5/6;
4201 printable_length= (init->page_height + 1)*5/6;
4202
4203 stp_dprintf(STP_DBG_CANON, v, "Tray J modified printable_width: '%d'\n",printable_width);
4204 stp_dprintf(STP_DBG_CANON, v, "Tray J modified printable_length: '%d'\n",printable_length);
4205
4206 }
4207
4208 /* Tray L */
4209 if ( (print_cd) && !(strcmp(init->caps->name,"PIXMA iP8700")) && (test_cd==1) ) {
4210
4211 init->page_width +=10;
4212 init->page_height +=263;
4213
4214 stp_dprintf(STP_DBG_CANON, v, "Tray L modified init->page_width: '%d'\n",init->page_width);
4215 stp_dprintf(STP_DBG_CANON, v, "Tray L modified init->page_height: '%d'\n",init->page_height);
4216
4217 printable_width= (init->page_width+ 1)*5/6;
4218 printable_length= (init->page_height + 1)*5/6;
4219
4220 stp_dprintf(STP_DBG_CANON, v, "Tray L modified printable_width: '%d'\n",printable_width);
4221 stp_dprintf(STP_DBG_CANON, v, "Tray L modified printable_length: '%d'\n",printable_length);
4222
4223 }
4224
4225 /* Tray M - TODO */
4226 /* to add code here */
4227
4228 if ( (init->caps->features & CANON_CAP_BORDERLESS) &&
4229 !(print_cd) && stp_get_boolean_parameter(v, "FullBleed") )
4230 {
4231 stp_dprintf(STP_DBG_CANON, v,"canon_init_setPageMargins2: for borderless set printable length and width to 0\n");
4232 /* set to 0 for borderless */
4233 printable_width = 0;
4234 printable_length = 0;
4235 }
4236
4237 /* arguments for short form of Esc (p command */
4238 arg_70_1= (printable_length >> 8) & 0xff;
4239 arg_70_2= (printable_length) & 0xff;
4240 arg_70_3= (printable_width >> 8) & 0xff;
4241 arg_70_4= (printable_width) & 0xff;
4242
4243
4244 if (!(init->caps->features & CANON_CAP_px) && !(init->caps->features & CANON_CAP_p))
4245 return;
4246
4247 if ((init->caps->features & CANON_CAP_px) ) {
4248 /* workaround for CD writing that uses CANON_CAP_px --- fix with capabilities */
4249 if ( !( input_slot && !(strcmp(input_slot,"CD")) ) || !(strcmp(init->caps->name,"PIXMA iP4500")) || !(strcmp(init->caps->name,"PIXMA iP4600")) || !(strcmp(init->caps->name,"PIXMA iP4700")) || !(strcmp(init->caps->name,"PIXMA iP4800")) || !(strcmp(init->caps->name,"PIXMA iP4900")) || !(strcmp(init->caps->name,"PIXMA iP7200")) || !(strcmp(init->caps->name,"PIXMA MP980")) || !(strcmp(init->caps->name,"PIXMA MP990")) || !(strcmp(init->caps->name,"PIXMA MG5200")) || !(strcmp(init->caps->name,"PIXMA MG5300")) || !(strcmp(init->caps->name,"PIXMA MG6100")) || !(strcmp(init->caps->name,"PIXMA MG6200")) || !(strcmp(init->caps->name,"PIXMA MG6500")) || !(strcmp(init->caps->name,"PIXMA MG6700")) || !(strcmp(init->caps->name,"PIXMA MG7500")) || !(strcmp(init->caps->name,"PIXMA MG7700")) || !(strcmp(init->caps->name,"PIXMA MG8100")) || !(strcmp(init->caps->name,"PIXMA MG8200")) || !(strcmp(init->caps->name,"PIXMA iP9910")) || !(strcmp(init->caps->name,"PIXMA MP710")) || !(strcmp(init->caps->name,"PIXMA iP3000")) || !(strcmp(init->caps->name,"PIXMA Pro9000")) || !(strcmp(init->caps->name,"PIXMA iP8700")) || !(strcmp(init->caps->name,"PIXMA iX6800")) || !(strcmp(init->caps->name,"PIXMA TS8000")) )
4250 /* need to check if iP9910, MP710, iP3000, Pro9000 use Esc (p */
4251 {
4252
4253 /* original borders */
4254 border_left=init->caps->border_left;
4255 border_right=init->caps->border_right;
4256 border_top=init->caps->border_top;
4257 border_bottom=init->caps->border_bottom;
4258
4259 if (print_cd) {
4260 border_top=9;
4261 border_bottom=15; /* was 9 originally */
4262 }
4263
4264 /* modified borders */
4265 border_left2=border_left;
4266 border_top2=border_top;
4267 border_right2=border_right;
4268 border_bottom2=border_bottom;
4269
4270 if ( (print_cd) && !(strcmp(init->caps->name,"PIXMA MP710")) && (test_cd==1) ) {
4271 border_left2 = border_left + adjust_tray_custom_left;
4272 border_right2 = border_right + adjust_tray_custom_right;
4273 border_top2 = border_top + adjust_tray_custom_top;
4274 border_bottom2 = border_bottom + adjust_tray_custom_bottom;
4275 }
4276
4277 if ( (print_cd) && !(strcmp(init->caps->name,"PIXMA iP9910")) && (test_cd==1) ) {
4278 border_left2 = border_left + adjust_tray_A_left;
4279 border_right2 = border_right + adjust_tray_A_right;
4280 border_top2 = border_top + adjust_tray_A_top;
4281 border_bottom2 = border_bottom + adjust_tray_A_bottom;
4282 }
4283
4284 if ( (print_cd) && !(strcmp(init->caps->name,"PIXMA iP3000")) && (test_cd==1) ) {
4285 border_left2 = border_left + adjust_tray_BCD_left;
4286 border_right2 = border_right + adjust_tray_BCD_right;
4287 border_top2 = border_top + adjust_tray_BCD_top;
4288 border_bottom2 = border_bottom + adjust_tray_BCD_bottom;
4289 }
4290
4291 if ( (print_cd) && !(strcmp(init->caps->name,"PIXMA Pro9000")) && (test_cd==1) ) {
4292 border_left2 = border_left + adjust_tray_E_left;
4293 border_right2 = border_right + adjust_tray_E_right;
4294 border_top2 = border_top + adjust_tray_E_top;
4295 border_bottom2 = border_bottom + adjust_tray_E_bottom;
4296 }
4297
4298 if ( (print_cd) && !(strcmp(init->caps->name,"PIXMA iP4500")) && (test_cd==1) ) {
4299 border_left2 = border_left + adjust_tray_F_left;
4300 border_right2 = border_right + adjust_tray_F_right;
4301 border_top2 = border_top + adjust_tray_F_top;
4302 border_bottom2 = border_bottom + adjust_tray_F_bottom;
4303 }
4304
4305 if ( (print_cd) && !(strcmp(init->caps->name,"PIXMA iP4700")) && (test_cd==1) ) {
4306 border_left2 = border_left + adjust_tray_G_left;
4307 border_right2 = border_right + adjust_tray_G_right;
4308 border_top2 = border_top + adjust_tray_G_top;
4309 border_bottom2 = border_bottom + adjust_tray_G_bottom;
4310 }
4311
4312 if ( (print_cd) && !(strcmp(init->caps->name,"PIXMA PRO-1")) && (test_cd==1) ) {
4313 border_left2 = border_left + adjust_tray_H_left;
4314 border_right2 = border_right + adjust_tray_H_right;
4315 border_top2 = border_top + adjust_tray_H_top;
4316 border_bottom2 = border_bottom + adjust_tray_H_bottom;
4317 }
4318
4319 if ( (print_cd) && !(strcmp(init->caps->name,"PIXMA iP7200")) && (test_cd==1) ) {
4320 border_left2 = border_left + adjust_tray_J_left;
4321 border_right2 = border_right + adjust_tray_J_right;
4322 border_top2 = border_top + adjust_tray_J_top;
4323 border_bottom2 = border_bottom + adjust_tray_J_bottom;
4324 }
4325
4326 if ( (print_cd) && !(strcmp(init->caps->name,"PIXMA iP8700")) && (test_cd==1) ) {
4327 border_left2 = border_left + adjust_tray_L_left;
4328 border_right2 = border_right + adjust_tray_L_right;
4329 border_top2 = border_top + adjust_tray_L_top;
4330 border_bottom2 = border_bottom + adjust_tray_L_bottom;
4331 }
4332
4333 /* this does not seem to need adjustment, so use original borders */
4334 area_right = border_left * unit / 72;
4335 area_top = border_top * unit / 72;
4336
4337 if ( (init->caps->features & CANON_CAP_BORDERLESS) &&
4338 !(print_cd) && stp_get_boolean_parameter(v, "FullBleed") ) {
4339 border_left2=-8; /* -8 mini series -6 */
4340 border_right2=-8; /* -8 */
4341 border_top2=-6; /* -6 standard */
4342 border_bottom2=-15; /* -15 standard */
4343 area_right = border_left2 * unit / 72;
4344 area_top = border_top2 * unit / 72;
4345 }
4346
4347 stp_dprintf(STP_DBG_CANON, v,"setPageMargins2: init->page_height = %d\n",init->page_height);
4348 stp_dprintf(STP_DBG_CANON, v,"setPageMargins2: printable_length = %d\n",printable_length);
4349 stp_dprintf(STP_DBG_CANON, v,"setPageMargins2: paper_height = %d\n",(init->page_height + border_top + border_bottom) * unit / 72);
4350
4351
4352 stp_dprintf(STP_DBG_CANON, v, "final init->page_width: '%d'\n",init->page_width);
4353 stp_dprintf(STP_DBG_CANON, v, "final init->page_height: '%d'\n",init->page_height);
4354 stp_dprintf(STP_DBG_CANON, v, "final printable_width: '%d'\n",printable_width);
4355 stp_dprintf(STP_DBG_CANON, v, "final printable_length: '%d'\n",printable_length);
4356
4357 stp_zfwrite(ESC28,2,1,v); /* ESC( */
4358 stp_putc(0x70,v); /* p */
4359 stp_put16_le(46, v); /* len */
4360 /* 0 for borderless, calculated otherwise */
4361 stp_put16_be(printable_length,v); /* printable_length */
4362 stp_put16_be(0,v);
4363 /* 0 for borderless, calculated otherwise */
4364 stp_put16_be(printable_width,v); /* printable_width */
4365 stp_put16_be(0,v);
4366 stp_put32_be(0,v);
4367 stp_put16_be(unit,v);
4368
4369 /* depends on borderless or not: uses modified borders */
4370 stp_put32_be(area_right,v); /* area_right : Windows seems to use 9.6, gutenprint uses 10 */
4371 stp_put32_be(area_top,v); /* area_top : Windows seems to use 8.4, gutenprint uses 15 */
4372
4373 /* calculated depending on borderless or not: uses modified borders */
4374 if ( (init->caps->features & CANON_CAP_BORDERLESS) &&
4375 !(print_cd) && stp_get_boolean_parameter(v, "FullBleed") ) {
4376 /* borderless */
4377 stp_put32_be((init->page_width - border_left2 - border_right2 ) * unit / 72,v); /* area_width */
4378 stp_put32_be((init->page_height - border_top2 - border_bottom2 ) * unit / 72,v); /* area_length */
4379 }
4380 else {
4381 if ( (print_cd) && (test_cd==1) ) { /* bordered for CD */
4382 stp_put32_be(init->page_width * unit / 72,v); /* area_width */
4383 stp_put32_be(init->page_height * unit / 72,v); /* area_length */
4384 }
4385 else { /* bordered non CD media */
4386 stp_put32_be((init->page_width) * unit / 72,v); /* area_width */
4387 stp_put32_be((init->page_height) * unit / 72,v); /* area_length */
4388 }
4389 }
4390
4391 /* 0 under all currently known circumstances */
4392 stp_put32_be(0,v); /* paper_right : Windows also 0 here for all Trays */
4393 stp_put32_be(0,v); /* paper_top : Windows also 0 here for all Trays */
4394
4395 /* standard paper sizes, unchanged for borderless so use
4396 original borders */
4397
4398 /* discovered that paper_width needs to be same as Windows
4399 dimensions for Canon printer firmware to automatically
4400 determine which tray to pull paper from automatically.
4401 */
4402
4403 if ( (init->caps->features & CANON_CAP_BORDERLESS) &&
4404 !(print_cd) && stp_get_boolean_parameter(v, "FullBleed") ) {
4405 /* borderless */
4406 stp_put32_be((init->page_width) * unit / 72,v); /* paper_width */
4407 stp_put32_be((init->page_height) * unit / 72,v); /* paper_length */
4408 }
4409 else {
4410 if ( (print_cd) && (test_cd==1) ) { /* bordered for CD */
4411 paper_width = (init->page_width + border_left2 + border_right2) * unit / 72; /* paper_width */
4412 paper_length = (init->page_height + border_top2 + border_bottom2) * unit / 72; /* paper_length */
4413 fix_papersize(arg_ESCP_1, &paper_width, &paper_length);
4414 stp_put32_be(paper_width,v); /* paper_width */
4415 stp_put32_be(paper_length,v); /* paper_length */
4416 }
4417 else { /* bordered non CD media */
4418 /* set by calculation first, then correct if necessary */
4419 paper_width = (init->page_width + border_left + border_right) * unit / 72; /* paper_width */
4420 paper_length = (init->page_height + border_top + border_bottom) * unit / 72; /* paper_length */
4421 fix_papersize(arg_ESCP_1, &paper_width, &paper_length);
4422 stp_put32_be(paper_width,v); /* paper_width */
4423 stp_put32_be(paper_length,v); /* paper_length */
4424 }
4425 }
4426
4427 return;
4428 }
4429 }
4430 canon_cmd(v,ESC28,0x70, 8,
4431 arg_70_1, arg_70_2, 0x00, 0x00,
4432 arg_70_3, arg_70_4, 0x00, 0x00);
4433 }
4434
4435 /* ESC (P -- 0x50 -- unknown -- :
4436 Seems to set media and page information. Different byte lengths
4437 depending on printer model.
4438 Page rotation option in driver [ESC (v] influences ESC (P command
4439 parameters 5 and 6:
4440 none: 1 0
4441 90 deg: 2 0
4442 180 deg: 1 1
4443 270 deg: 2 1
4444 */
4445 static void
4446 canon_init_setESC_P(const stp_vars_t *v, const canon_privdata_t *init)
4447 {
4448 unsigned char arg_ESCP_1, arg_ESCP_2, arg_ESCP_5, arg_ESCP_6, arg_ESCP_7, arg_ESCP_9;
4449
4450 stp_dimension_t width, length;
4451 /* const char *media_size = stp_get_string_parameter(v, "PageSize");
4452 const stp_papersize_t *pt = NULL; */
4453 const char* orientation_type = stp_get_string_parameter(v, "Orientation");
4454 const char* input_slot = stp_get_string_parameter(v, "InputSlot");
4455 const char* input_tray = stp_get_string_parameter(v, "CassetteTray");
4456 /* const canon_cap_t * caps= canon_get_model_capabilities(v); */
4457 int print_cd = (input_slot && (!strcmp(input_slot, "CD")));
4458 int tray_upper = (input_tray && (!strcmp(input_tray, "Upper")));
4459 int tray_lower = (input_tray && (!strcmp(input_tray, "Lower")));
4460 int tray_user_select;
4461 unsigned char user_ESCP_9;
4462
4463 if(!(init->caps->features & CANON_CAP_P))
4464 return;
4465
4466 /* if (media_size)
4467 pt = stp_describe_papersize(v, media_size); */
4468 stp_default_media_size(v, &width, &length);
4469 if (tray_upper || tray_lower)
4470 tray_user_select=1;
4471 else
4472 tray_user_select=0;
4473 if (tray_upper)
4474 user_ESCP_9=0x01;
4475 else if (tray_lower)
4476 user_ESCP_9=0x02;
4477 else
4478 user_ESCP_9=0x00; /* fall-through setting, but this value is not used */
4479
4480 arg_ESCP_1 = (init->pt) ? canon_size_type(v,init->caps): 0x03; /* media size: set to A4 size as default */
4481 stp_dprintf(STP_DBG_CANON, v,"canon: ESCP (P code read paper size, resulting arg_ESCP_1: '%x'\n",arg_ESCP_1);
4482 arg_ESCP_2 = (init->pt) ? init->pt->media_code_P: 0x00; /* media type: set to plain as default */
4483 arg_ESCP_5 = 0x01; /* default for portrait orientation */
4484 arg_ESCP_6 = 0x00; /* default for portrait orientation */
4485
4486 arg_ESCP_7 = 0x01; /* default - use unknown, with some printers set
4487 to 0x00 for envelope sizes (and other?)
4488 regardless of media type */
4489
4490 if( orientation_type && !strcmp(orientation_type,"Portrait")) { /* none */
4491 arg_ESCP_5 = 0x01;
4492 arg_ESCP_6 = 0x00;
4493 }
4494 else if( orientation_type && !strcmp(orientation_type,"Landscape")) { /* 90 deg */
4495 arg_ESCP_5 = 0x02;
4496 arg_ESCP_6 = 0x00;
4497 }
4498 else if( orientation_type && !strcmp(orientation_type,"UpsideDown")) { /* 180 deg */
4499 arg_ESCP_5 = 0x01;
4500 arg_ESCP_6 = 0x01;
4501 }
4502 else if( orientation_type && !strcmp(orientation_type,"Seascape")) { /* 270 deg */
4503 arg_ESCP_5 = 0x02;
4504 arg_ESCP_6 = 0x01;
4505 }
4506
4507
4508 /* Code for last argument in 9-byte ESC (P printers with and upper and lower tray included in the cassette input source
4509 The intention appears to be to allow printing of photos and non-photo paper without needing to change trays.
4510 Note, envelopes are printed from the lower tray.
4511
4512 Upper tray specification from MG7700 user manual:
4513 Min width: 3.5 inches / 89.0 mm (L size)
4514 Min height: 5 inches / 127.0 mm (L size)
4515 Max width: 7.87 inches / 200.0 mm (marked up to 5 inches)
4516 Max height: 7.28 inches / 184.9 mm
4517
4518 Lower tray specification:
4519 Min width: 3.54 inches / 90.0 mm (takes business envelopes)
4520 Min height: 7.29 inches / 185.0 mm
4521 Max width: 8.5 inches / 215.9 mm
4522 Max height: 14 inches / 355.6 mm
4523
4524 Conditions:
4525 Init: Upper tray
4526 Media:
4527 Hagaki, Photo media --> upper tray
4528 Envelopes (argESCP_2 == 0x08) --> lower tray
4529 Other --> lower tray
4530 Size: Length:
4531 < 7.29 inches (524 pt = 184.85 mm; 525 pt = 185.2 mm ) --> upper tray
4532 >=7.29 inches (524 pt = 184.85 mm; 525 pt = 185.2 mm ) --> lower tray
4533
4534 Printers with this capability:
4535 Code 0xd for cassette (standard cassette code is 0x8)
4536
4537 MG5400
4538 MG6300
4539 MG6500
4540 MG6700
4541 MG6900 - same as MG7700
4542 MG7500
4543 MG7700
4544 iP7200
4545 MX720
4546 MX920
4547 */
4548
4549
4550 if ( !(strcmp(init->caps->name,"PIXMA iP7200")) || !(strcmp(init->caps->name,"PIXMA MG5400")) || !(strcmp(init->caps->name,"PIXMA MG6300")) || !(strcmp(init->caps->name,"PIXMA MG6500")) || !(strcmp(init->caps->name,"PIXMA MG6700")) || !(strcmp(init->caps->name,"PIXMA MG7500")) || !(strcmp(init->caps->name,"PIXMA MG7700")) || !(strcmp(init->caps->name,"PIXMA MX720")) || !(strcmp(init->caps->name,"PIXMA MX920")) ) {
4551 /* default: use upper tray of cassette with two trays, condition check later */
4552 arg_ESCP_9 = 0x01;
4553 }
4554 else if ( !(strcmp(init->caps->name,"PIXMA E400")) || !(strcmp(init->caps->name,"PIXMA E460")) || !(strcmp(init->caps->name,"PIXMA E470")) || !(strcmp(init->caps->name,"PIXMA E480")) || !(strcmp(init->caps->name,"PIXMA E560")) || !(strcmp(init->caps->name,"PIXMA E3100")) || !(strcmp(init->caps->name,"PIXMA TS5000")) || !(strcmp(init->caps->name,"PIXMA TS6000")) || !(strcmp(init->caps->name,"PIXMA TS8000")) || !(strcmp(init->caps->name,"PIXMA G1000")) || !(strcmp(init->caps->name,"PIXMA G4000")) || !(strcmp(init->caps->name,"PIXMA MG2900")) || !(strcmp(init->caps->name,"PIXMA MG3500")) || !(strcmp(init->caps->name,"PIXMA MG3600")) || !(strcmp(init->caps->name,"PIXMA MG5500")) || !(strcmp(init->caps->name,"PIXMA MG5600")) || !(strcmp(init->caps->name,"PIXMA iP110")) || !(strcmp(init->caps->name,"PIXMA iP2800")) || !(strcmp(init->caps->name,"PIXMA iP8700")) || !(strcmp(init->caps->name,"PIXMA iX6800")) || !(strcmp(init->caps->name,"MAXIFY iB4000")) || !(strcmp(init->caps->name,"MAXIFY iB4100")) || !(strcmp(init->caps->name,"MAXIFY MB2000")) || !(strcmp(init->caps->name,"MAXIFY MB2100")) || !(strcmp(init->caps->name,"MAXIFY MB2300")) || !(strcmp(init->caps->name,"MAXIFY MB2700")) || !(strcmp(init->caps->name,"PIXMA MX470")) || !(strcmp(init->caps->name,"PIXMA MX490")) ) {
4555 arg_ESCP_9 = 0xff;
4556 }
4557
4558 else {
4559 arg_ESCP_9 = 0x00;
4560 }
4561
4562 if ( !(strcmp(init->caps->name,"PIXMA E470")) || !(strcmp(init->caps->name,"PIXMA G4000")) || !(strcmp(init->caps->name,"PIXMA TS5000")) || !(strcmp(init->caps->name,"PIXMA TS6000")) || !(strcmp(init->caps->name,"PIXMA TS8000")) ){
4563 /* all envelope sizes it appears, even if media is not Envelope */
4564 /* currently not sure about custom sizes, thus only specify here the known Canon envelope sizes */
4565 switch(arg_ESCP_2)
4566 {
4567 case 0x2e: arg_ESCP_7=0x00; break;; /* US Comm #10 */
4568 case 0x2f: arg_ESCP_7=0x00; break;; /* Euro DL Env */
4569 case 0x30: arg_ESCP_7=0x00; break;; /* Western Env #4 (you4) */
4570 case 0x31: arg_ESCP_7=0x00; break;; /* Western Env #6 (you6) */
4571 case 0x3a: arg_ESCP_7=0x00; break;; /* Japanese Long Env #3 (chou3) */
4572 case 0x3b: arg_ESCP_7=0x00; break;; /* Japanese Long Env #4 (chou4) */
4573 /* new envelopes for some printers added for completeness */
4574 case 0x92: arg_ESCP_7=0x00; break;; /* C5 */
4575 case 0x93: arg_ESCP_7=0x00; break;; /* Monarch */
4576 }
4577 }
4578
4579 /* workaround for CD media */
4580
4581 if ( (arg_ESCP_2 == 0x1f) || ( arg_ESCP_2 == 0x20) ) {
4582 if ( arg_ESCP_1 == 0x53 ) {
4583 /* Tray G as default */
4584 arg_ESCP_1 = 0x53;
4585 /* Custom CD tray */
4586 if ( !(strcmp(init->caps->name,"i865")) || !(strcmp(init->caps->name,"PIXMA MP710")) || !(strcmp(init->caps->name,"PIXMA MP740")) || !(strcmp(init->caps->name,"PIXMA MP900")) ) {
4587 arg_ESCP_1 = 0x35;
4588 }
4589 /* Tray A */
4590 if ( !(strcmp(init->caps->name,"PIXMA iP9910")) ) {
4591 arg_ESCP_1 = 0x3f;
4592 }
4593 /* Tray B */
4594 if ( !(strcmp(init->caps->name,"PIXMA MP750")) || !(strcmp(init->caps->name,"PIXMA MP760")) || !(strcmp(init->caps->name,"PIXMA MP770")) || !(strcmp(init->caps->name,"PIXMA MP780")) || !(strcmp(init->caps->name,"PIXMA MP790")) || !(strcmp(init->caps->name,"PIXMA iP3000")) || !(strcmp(init->caps->name,"PIXMA iP3100")) || !(strcmp(init->caps->name,"PIXMA iP4000")) || !(strcmp(init->caps->name,"PIXMA iP4100")) || !(strcmp(init->caps->name,"PIXMA iP5000")) || !(strcmp(init->caps->name,"PIXMA iP6000")) || !(strcmp(init->caps->name,"PIXMA iP6100")) || !(strcmp(init->caps->name,"PIXMA iP7100")) || !(strcmp(init->caps->name,"PIXMA iP8100")) || !(strcmp(init->caps->name,"PIXMA iP8500")) || !(strcmp(init->caps->name,"PIXMA iP8600")) ) {
4595 arg_ESCP_1 = 0x40;
4596 }
4597 /* Tray C */
4598 if ( !(strcmp(init->caps->name,"PIXMA MP950")) || !(strcmp(init->caps->name,"PIXMA iP4200")) || !(strcmp(init->caps->name,"PIXMA iP5200")) || !(strcmp(init->caps->name,"PIXMA iP6700")) || !(strcmp(init->caps->name,"PIXMA iP7500")) ) {
4599 arg_ESCP_1 = 0x4a;
4600 }
4601 /* Tray D */
4602 if ( !(strcmp(init->caps->name,"PIXMA MP500")) || !(strcmp(init->caps->name,"PIXMA MP530")) || !(strcmp(init->caps->name,"PIXMA MP800")) || !(strcmp(init->caps->name,"PIXMA MP830")) ) {
4603 arg_ESCP_1 = 0x4b;
4604 }
4605 /* Tray E */
4606 if ( !(strcmp(init->caps->name,"PIXMA Pro9000")) || !(strcmp(init->caps->name,"PIXMA Pro9002")) || !(strcmp(init->caps->name,"PIXMA Pro9500")) || !(strcmp(init->caps->name,"PIXMA Pro95002")) ) {
4607 arg_ESCP_1 = 0x4c;
4608 }
4609 /* Tray F */
4610 if ( !(strcmp(init->caps->name,"PIXMA MP600")) || !(strcmp(init->caps->name,"PIXMA MP610")) || !(strcmp(init->caps->name,"PIXMA MP810")) || !(strcmp(init->caps->name,"PIXMA MP960")) || !(strcmp(init->caps->name,"PIXMA MP970")) || !(strcmp(init->caps->name,"PIXMA MX850")) || !(strcmp(init->caps->name,"PIXMA iP4300")) || !(strcmp(init->caps->name,"PIXMA iP4500")) || !(strcmp(init->caps->name,"PIXMA iP5300")) ) {
4611 arg_ESCP_1 = 0x51;
4612 }
4613 /* Tray G from iP4600 onwards */
4614 if ( !(strcmp(init->caps->name,"PIXMA iP4600")) || !(strcmp(init->caps->name,"PIXMA iP4700")) || !(strcmp(init->caps->name,"PIXMA iP4800")) || !(strcmp(init->caps->name,"PIXMA iP4900")) || !(strcmp(init->caps->name,"PIXMA MG5200")) || !(strcmp(init->caps->name,"PIXMA MG5300")) || !(strcmp(init->caps->name,"PIXMA MG6100")) || !(strcmp(init->caps->name,"PIXMA MG6200")) || !(strcmp(init->caps->name,"PIXMA MG8100")) || !(strcmp(init->caps->name,"PIXMA MG8200")) ) {
4615 arg_ESCP_1 = 0x56;
4616 }
4617 /* Tray J from iP7200 onwards */
4618 if ( !(strcmp(init->caps->name,"PIXMA iP7200")) || !(strcmp(init->caps->name,"PIXMA MG5400")) || !(strcmp(init->caps->name,"PIXMA MG6300")) || !(strcmp(init->caps->name,"PIXMA MG6500")) || !(strcmp(init->caps->name,"PIXMA MG6700")) || !(strcmp(init->caps->name,"PIXMA MG7500")) || !(strcmp(init->caps->name,"PIXMA MG7700")) || !(strcmp(init->caps->name,"PIXMA MX920")) ) {
4619 arg_ESCP_1 = 0x5b;
4620 arg_ESCP_9 = 0x00;
4621 }
4622 /* Tray L from iP8700 onwards */
4623 if ( !(strcmp(init->caps->name,"PIXMA iP8700")) ) {
4624 arg_ESCP_1 = 0x62;
4625 }
4626 /* Tray M from TS8000 onwards */
4627 if ( !(strcmp(init->caps->name,"PIXMA TS8000")) ) {
4628 arg_ESCP_1 = 0xbc;
4629 }
4630
4631 }
4632 }
4633 /* 850i: CD Tray custom: none --- no ESC (P */
4634 /* 865i: CD Tray custom: 0x35 */
4635 /* MP500: CD Tray D : 0x4b */
4636 /* MP530: CD Tray D : 0x4b */
4637 /* MP600: CD Tray F : 0x51 */
4638 /* MP610: CD Tray F : 0x51 */
4639 /* MP630: CD Tray G : 0x53 */
4640 /* MP640: CD Tray G : 0x53 */
4641 /* MP700: CD tray custom: none --- no ESC (P */
4642 /* MP710: CD tray custom: 0x35 */
4643 /* MP730: CD tray custom: none --- no ESC (P */
4644 /* MP740: CD tray custom: 0x35 */
4645 /* MP750: CD Tray B : 0x40 */
4646 /* MP760: CD Tray B : 0x40 */
4647 /* MP770: CD Tray B : 0x40 */
4648 /* MP780: CD Tray B : 0x40 */
4649 /* MP790: CD Tray B : 0x40 */
4650 /* MP800: CD Tray D : 0x4b */
4651 /* MP810: CD Tray F : 0x51 */
4652 /* MP830: CD Tray D : 0x4b */
4653 /* MP900: CD Tray custom: 0x35 */
4654 /* MP950: CD Tray C : 0x4a */
4655 /* MP960: CD Tray F : 0x51 */
4656 /* MP970: CD Tray F : 0x51 */
4657 /* MP980: CD Tray G : 0x53 */
4658 /* MP990: CD Tray G : 0x53 */
4659 /* MX850: CD Tray F : 0x51 */
4660 /* MX920: CD Tray J : 0x5b */
4661 /* iP3000: CD Tray B : 0x40 */
4662 /* iP3100: CD Tray B : 0x40 */
4663 /* iP4000: CD Tray B : 0x40 */
4664 /* iP4100: CD Tray B : 0x40 */
4665 /* iP4200: CD Tray C : 0x4a */
4666 /* iP4300: CD Tray F : 0x51 */
4667 /* iP4500: CD Tray F : 0x51 */
4668 /* iP4600: CD Tray G : 0x53 */
4669 /* iP4700: CD Tray G : 0x53 */
4670 /* iP4800: CD Tray G : 0x56 */
4671 /* iP4900: CD Tray G : 0x56 */
4672 /* iP5000: CD Tray B : 0x40 */
4673 /* iP5200: CD Tray C : 0x4a */
4674 /* iP5300: CD Tray F : 0x51 */
4675 /* iP6000D:CD Tray B : 0x40 */
4676 /* iP6100D:CD Tray B : 0x40 */
4677 /* iP6700D:CD Tray C : 0x4a */
4678 /* iP7100: CD Tray B : 0x40 */
4679 /* iP7200: CD Tray J : 0x5b */
4680 /* iP7500: CD Tray C : 0x4a */
4681 /* iP8100: CD Tray B : 0x40 */
4682 /* iP8500 :CD Tray B : 0x40 */
4683 /* iP8600: CD Tray B : 0x40 */
4684 /* iP8700: CD Tray L : 0x62 */
4685 /* iP9910: CD Tray A : 0x3f */
4686 /* MG5200: CD Tray G : 0x56 */
4687 /* MG5300: CD Tray G : 0x56 */
4688 /* MG5400: CD Tray J : 0x5b */
4689 /* MG6100: CD Tray G : 0x56 */
4690 /* MG6200: CD Tray G : 0x56 */
4691 /* MG6300: CD Tray J : 0x5b */
4692 /* MG6500: CD Tray J : 0x5b */
4693 /* MG6700: CD Tray J : 0x5b */
4694 /* MG6900: CD Tray J : 0x5b */
4695 /* MG7500: CD Tray J : 0x5b */
4696 /* MG7700: CD Tray J : 0x5b */
4697 /* MG8100: CD Tray G : 0x56 */
4698 /* MG8200: CD Tray G : 0x56 */
4699 /* pro9000:CD Tray E : 0x4c */
4700 /* pro9000mk2:CD Tray E : 0x4c */
4701 /* pro9500:CD Tray E : 0x4c */
4702 /* pro9500mk2:CD Tray E : 0x4c */
4703 /* PRO-1: CD Tray H : 0x57 */
4704 /* TS8000: CD Tray M : 0xbc */
4705
4706 /* workaround for FineArt media having same size as non-FineArt media */
4707
4708 /* Fine Art paper codes */
4709 /* iP6700D, iP7100, iP7500, iP8100, iP8600, iP9910 */
4710 /* iX7000 */
4711 /* MG6100, M6200, MG8100, MG8200 */
4712 /* MX7600 */
4713 /* MP950, MP960, MP970, MP980, MP990 */
4714 /* if (!strcmp(name,"A4")) return 0x42; */ /* FineArt A4 35mm border --- iP7100: gap is 18 */
4715 /* if (!strcmp(name,"A3")) return 0x43; */ /* FineArt A3 35mm border */
4716 /* if (!strcmp(name,"A3plus")) return 0x44; */ /* FineArt A3plus 35mm border */
4717 /* if (!strcmp(name,"Letter")) return 0x45; */ /* FineArt Letter 35mm border */
4718
4719 /* Fine Art paper codes */
4720 /* Pro series (9000, 9000 Mk.2, 9500, 9500 Mk.2, PRO-1) */
4721 /* if (!strcmp(name,"A4")) return 0x4d; */ /* FineArt A4 35mm border */
4722 /* if (!strcmp(name,"A3")) return 0x4e; */ /* FineArt A3 35mm border */
4723 /* if (!strcmp(name,"A3plus")) return 0x50; */ /* FineArt A3plus 35mm border */
4724 /* if (!strcmp(name,"Letter")) return 0x4f; */ /* FineArt Letter 35mm border */
4725
4726 /* Fine Art paper codes */
4727 /* MG6300, MG6500, MG6700, MG7100, MG7500 */
4728 /* if (!strcmp(name,"A4")) return 0x58; */ /* FineArt A4 35mm border */
4729 /* if (!strcmp(name,"Letter")) return 0x5a; */ /* FineArt Letter 35mm border */
4730
4731 /* Fine Art paper codes */
4732 /* iP8700, iX6800 */
4733 /* if (!strcmp(name,"A4")) return 0x58; */ /* FineArt A4 35mm border */
4734 /* if (!strcmp(name,"A3")) return 0x59; */ /* FineArt A3 35mm border */
4735 /* if (!strcmp(name,"A3plus")) return 0x5d; */ /* FineArt A3plus 35mm border */
4736 /* if (!strcmp(name,"Letter")) return 0x5a; */ /* FineArt Letter 35mm border */
4737
4738
4739 /* iP7100 is an exception needing yet another papersize code */
4740 if ( (arg_ESCP_2 == 0x28) || ( arg_ESCP_2 == 0x29) || (arg_ESCP_2 == 0x2c) || (arg_ESCP_2 == 0x31) ) {
4741 /* A4 FineArt */
4742 if ( arg_ESCP_1 == 0x03 ) {
4743 if ( !(strcmp(init->caps->name,"PIXMA MP950")) || !(strcmp(init->caps->name,"PIXMA MP960")) || !(strcmp(init->caps->name,"PIXMA MP970")) || !(strcmp(init->caps->name,"PIXMA MP980")) || !(strcmp(init->caps->name,"PIXMA MP990")) || !(strcmp(init->caps->name,"PIXMA MX7600")) || !(strcmp(init->caps->name,"PIXMA iP6700")) || !(strcmp(init->caps->name,"PIXMA iP7100")) || !(strcmp(init->caps->name,"PIXMA iP7500")) || !(strcmp(init->caps->name,"PIXMA iP8100")) || !(strcmp(init->caps->name,"PIXMA iP8600")) || !(strcmp(init->caps->name,"PIXMA iP9910")) || !(strcmp(init->caps->name,"PIXMA iX7000")) || !(strcmp(init->caps->name,"PIXMA MG6100")) || !(strcmp(init->caps->name,"PIXMA MG6200")) || !(strcmp(init->caps->name,"PIXMA MG8200")) || !(strcmp(init->caps->name,"PIXMA MG8100")) || !(strcmp(init->caps->name,"PIXMA MG8200")) ) {
4744 arg_ESCP_1 = 0x42;
4745 }
4746 else if ( !(strcmp(init->caps->name,"PIXMA Pro9000")) || !(strcmp(init->caps->name,"PIXMA Pro9002")) || !(strcmp(init->caps->name,"PIXMA Pro9500")) || !(strcmp(init->caps->name,"PIXMA Pro9502")) ) {
4747 arg_ESCP_1 = 0x4d;
4748 }
4749 else if ( !(strcmp(init->caps->name,"PIXMA MG6300")) || !(strcmp(init->caps->name,"PIXMA MG6500")) || !(strcmp(init->caps->name,"PIXMA MG6700")) || !(strcmp(init->caps->name,"PIXMA MG7500")) || !(strcmp(init->caps->name,"PIXMA iP8700")) || !(strcmp(init->caps->name,"PIXMA iX6800")) || !(strcmp(init->caps->name,"PIXMA TS8000")) ) {
4750 arg_ESCP_1 = 0x58;
4751 }
4752 else {
4753 /* default back to non-FineArt */
4754 arg_ESCP_1 = 0x03;
4755 }
4756 }
4757 /* A3 FineArt */
4758 if ( arg_ESCP_1 == 0x05 ) {
4759 if ( !(strcmp(init->caps->name,"PIXMA MP950")) || !(strcmp(init->caps->name,"PIXMA MP960")) || !(strcmp(init->caps->name,"PIXMA MP970")) || !(strcmp(init->caps->name,"PIXMA MP980")) || !(strcmp(init->caps->name,"PIXMA MP990")) || !(strcmp(init->caps->name,"PIXMA MX7600")) || !(strcmp(init->caps->name,"PIXMA iP6700")) || !(strcmp(init->caps->name,"PIXMA iP7100")) || !(strcmp(init->caps->name,"PIXMA iP7500")) || !(strcmp(init->caps->name,"PIXMA iP8100")) || !(strcmp(init->caps->name,"PIXMA iP8600")) || !(strcmp(init->caps->name,"PIXMA iP9910")) || !(strcmp(init->caps->name,"PIXMA iX7000")) || !(strcmp(init->caps->name,"PIXMA MG6100")) || !(strcmp(init->caps->name,"PIXMA MG6200")) || !(strcmp(init->caps->name,"PIXMA MG8200")) || !(strcmp(init->caps->name,"PIXMA MG8100")) || !(strcmp(init->caps->name,"PIXMA MG8200")) ) {
4760 arg_ESCP_1 = 0x43;
4761 }
4762 else if ( !(strcmp(init->caps->name,"PIXMA Pro9000")) || !(strcmp(init->caps->name,"PIXMA Pro9002")) || !(strcmp(init->caps->name,"PIXMA Pro9500")) || !(strcmp(init->caps->name,"PIXMA Pro9502")) ) {
4763 arg_ESCP_1 = 0x4e;
4764 }
4765 #if 0
4766 /* no known papersize code yet, since these printers do not handle A3 */
4767 else if ( !(strcmp(init->caps->name,"PIXMA MG6300")) || !(strcmp(init->caps->name,"PIXMA MG6500")) || !(strcmp(init->caps->name,"PIXMA MG6700")) || !(strcmp(init->caps->name,"PIXMA MG7500")) || !(strcmp(init->caps->name,"PIXMA iP8700")) || !(strcmp(init->caps->name,"PIXMA iX6800")) ) {
4768 arg_ESCP_1 = 0x59;
4769 }
4770 #endif
4771 else {
4772 /* default back to non-FineArt */
4773 arg_ESCP_1 = 0x05;
4774 }
4775 }
4776 /* Letter FineArt */
4777 if ( arg_ESCP_1 == 0x0d ) {
4778 if ( !(strcmp(init->caps->name,"PIXMA MP950")) || !(strcmp(init->caps->name,"PIXMA MP960")) || !(strcmp(init->caps->name,"PIXMA MP970")) || !(strcmp(init->caps->name,"PIXMA MP980")) || !(strcmp(init->caps->name,"PIXMA MP990")) || !(strcmp(init->caps->name,"PIXMA MX7600")) || !(strcmp(init->caps->name,"PIXMA iP6700")) || !(strcmp(init->caps->name,"PIXMA iP7100")) || !(strcmp(init->caps->name,"PIXMA iP7500")) || !(strcmp(init->caps->name,"PIXMA iP8100")) || !(strcmp(init->caps->name,"PIXMA iP8600")) || !(strcmp(init->caps->name,"PIXMA iP9910")) || !(strcmp(init->caps->name,"PIXMA iX7000")) || !(strcmp(init->caps->name,"PIXMA MG6100")) || !(strcmp(init->caps->name,"PIXMA MG6200")) || !(strcmp(init->caps->name,"PIXMA MG8200")) || !(strcmp(init->caps->name,"PIXMA MG8100")) || !(strcmp(init->caps->name,"PIXMA MG8200")) ) {
4779 arg_ESCP_1 = 0x45;
4780 }
4781 else if ( !(strcmp(init->caps->name,"PIXMA Pro9000")) || !(strcmp(init->caps->name,"PIXMA Pro9002")) || !(strcmp(init->caps->name,"PIXMA Pro9500")) || !(strcmp(init->caps->name,"PIXMA Pro9502")) ) {
4782 arg_ESCP_1 = 0x4f;
4783 }
4784 else if ( !(strcmp(init->caps->name,"PIXMA MG6300")) || !(strcmp(init->caps->name,"PIXMA MG6500")) || !(strcmp(init->caps->name,"PIXMA MG6700")) || !(strcmp(init->caps->name,"PIXMA MG7500")) || !(strcmp(init->caps->name,"PIXMA iP8700")) || !(strcmp(init->caps->name,"PIXMA iX6800")) || !(strcmp(init->caps->name,"PIXMA TS8000")) ) {
4785 arg_ESCP_1 = 0x5a;
4786 }
4787 else {
4788 /* default back to non-FineArt */
4789 arg_ESCP_1 = 0x0d;
4790 }
4791 }
4792 /* A3plus FineArt */
4793 if ( arg_ESCP_1 == 0x2c ) {
4794 if ( !(strcmp(init->caps->name,"PIXMA MP950")) || !(strcmp(init->caps->name,"PIXMA MP960")) || !(strcmp(init->caps->name,"PIXMA MP970")) || !(strcmp(init->caps->name,"PIXMA MP980")) || !(strcmp(init->caps->name,"PIXMA MP990")) || !(strcmp(init->caps->name,"PIXMA MX7600")) || !(strcmp(init->caps->name,"PIXMA iP6700")) || !(strcmp(init->caps->name,"PIXMA iP7100")) || !(strcmp(init->caps->name,"PIXMA iP7500")) || !(strcmp(init->caps->name,"PIXMA iP8100")) || !(strcmp(init->caps->name,"PIXMA iP8600")) || !(strcmp(init->caps->name,"PIXMA iP9910")) || !(strcmp(init->caps->name,"PIXMA iX7000")) || !(strcmp(init->caps->name,"PIXMA MG6100")) || !(strcmp(init->caps->name,"PIXMA MG6200")) || !(strcmp(init->caps->name,"PIXMA MG8200")) || !(strcmp(init->caps->name,"PIXMA MG8100")) || !(strcmp(init->caps->name,"PIXMA MG8200")) ) {
4795 arg_ESCP_1 = 0x44;
4796 }
4797 else if ( !(strcmp(init->caps->name,"PIXMA Pro9000")) || !(strcmp(init->caps->name,"PIXMA Pro9002")) || !(strcmp(init->caps->name,"PIXMA Pro9500")) || !(strcmp(init->caps->name,"PIXMA Pro9502")) ) {
4798 arg_ESCP_1 = 0x50;
4799 }
4800 #if 0
4801 else if ( !(strcmp(init->caps->name,"PIXMA iP8700")) || !(strcmp(init->caps->name,"PIXMA iX6800")) ) {
4802 arg_ESCP_1 = 0x5d;
4803 }
4804 #endif
4805 else {
4806 /* default back to non-FineArt */
4807 arg_ESCP_1 = 0x2c;
4808 }
4809 }
4810 }
4811
4812 /* workaround for media type based differences in 9-parameter ESC (P commands */
4813 /* These printers use 0x02 (lower tray) usually and for envelopes, 0x01 (upper tray) with various Hagaki/Photo media, and 0x00 with CD media */
4814 if ( !(strcmp(init->caps->name,"PIXMA iP7200")) || !(strcmp(init->caps->name,"PIXMA MG5400")) || !(strcmp(init->caps->name,"PIXMA MG6300")) || !(strcmp(init->caps->name,"PIXMA MG6500")) || !(strcmp(init->caps->name,"PIXMA MG6700")) || !(strcmp(init->caps->name,"PIXMA MG7500")) || !(strcmp(init->caps->name,"PIXMA MG7700")) || !(strcmp(init->caps->name,"PIXMA MX720")) || !(strcmp(init->caps->name,"PIXMA MX920")) ) {
4815 if (tray_user_select && !print_cd)
4816 arg_ESCP_9=user_ESCP_9;
4817 else {
4818 switch(arg_ESCP_2)
4819 {
4820 /* Hagaki media */
4821 case 0x07: arg_ESCP_9=0x01; break;;
4822 case 0x14: arg_ESCP_9=0x01; break;; /* not used with any of these models */
4823 case 0x1b: arg_ESCP_9=0x01; break;;
4824 case 0x36: arg_ESCP_9=0x01; break;;
4825 case 0x38: arg_ESCP_9=0x01; break;;
4826 case 0x46: arg_ESCP_9=0x01; break;;
4827 case 0x47: arg_ESCP_9=0x01; break;;
4828 case 0x48: arg_ESCP_9=0x01; break;;
4829 /* Photo media here */
4830 case 0x32: arg_ESCP_9=0x01; break;;
4831 case 0x33: arg_ESCP_9=0x01; break;;
4832 case 0x3f: arg_ESCP_9=0x01; break;;
4833 case 0x2a: arg_ESCP_9=0x01; break;;
4834 case 0x16: arg_ESCP_9=0x01; break;;
4835 case 0x44: arg_ESCP_9=0x01; break;; /* MG6700, MG7500 only, instead of 0x16 */
4836 case 0x1c: arg_ESCP_9=0x01; break;;
4837 case 0x24: arg_ESCP_9=0x01; break;;
4838 /* Envelope media */
4839 case 0x08: arg_ESCP_9=0x02; break;;
4840 /* CD media */
4841 case 0x1f: arg_ESCP_9=0x00; break;;
4842 case 0x20: arg_ESCP_9=0x00; break;;
4843 /* other media default to lower tray */
4844 default: arg_ESCP_9=0x02; break;;
4845 }
4846
4847 /* condition for length to use lower tray: 7.29 in equals 524-525 points */
4848 if ( (arg_ESCP_9 == 0x01) && ( length > 524 ) ) {
4849 arg_ESCP_9=0x02;
4850 }
4851
4852 /* even if user does not select correct CD media type, set appropriately */
4853 if (print_cd)
4854 arg_ESCP_9=0x00;
4855 }
4856 }
4857
4858 /* MG6700, MG7500, TS8000 uses 0xff with CD media tray */
4859 if ( !(strcmp(init->caps->name,"PIXMA MG6700")) || !(strcmp(init->caps->name,"PIXMA MG7500")) || !(strcmp(init->caps->name,"PIXMA TS8000")) ) {
4860 if (tray_user_select && !print_cd)
4861 arg_ESCP_9=user_ESCP_9;
4862 else {
4863 switch(arg_ESCP_2)
4864 {
4865 /* CD media */
4866 case 0x1f: arg_ESCP_9=0xff; break;;
4867 case 0x20: arg_ESCP_9=0xff; break;;
4868 }
4869
4870 /* even if user does not select correct CD media type, set appropriately */
4871 if (print_cd)
4872 arg_ESCP_9=0x00;
4873 }
4874 }
4875
4876 if ( init->caps->ESC_P_len == 9 ) /* support for new devices from October 2012. */
4877 {/* the 4th of the 6 bytes is the media type. 2nd byte is media size. Both read from canon-media array. */
4878
4879 if ( !(strcmp(init->caps->name,"PIXMA MG7700")) ) {
4880 /* output with 3 extra 0s at the end */
4881 canon_cmd( v,ESC28,0x50,12,0x00,arg_ESCP_1,0x00,arg_ESCP_2,arg_ESCP_5,arg_ESCP_6,arg_ESCP_7,0x00,arg_ESCP_9,0x00,0x00,0x00 );
4882 }
4883 else {
4884
4885 /* arg_ESCP_1 = 0x03; */ /* A4 size */
4886 /* arg_ESCP_2 = 0x00; */ /* plain media */
4887 /* size media tray */
4888 canon_cmd( v,ESC28,0x50,9,0x00,arg_ESCP_1,0x00,arg_ESCP_2,arg_ESCP_5,arg_ESCP_6,arg_ESCP_7,0x00,arg_ESCP_9 );
4889
4890 }
4891 }
4892 else if ( init->caps->ESC_P_len == 8 ) /* support for new devices from 2012. */
4893 {/* the 4th of the 6 bytes is the media type. 2nd byte is media size. Both read from canon-media array. */
4894
4895 /* arg_ESCP_1 = 0x03; */ /* A4 size */
4896 /* arg_ESCP_2 = 0x00; */ /* plain media */
4897 /* size media */
4898 canon_cmd( v,ESC28,0x50,8,0x00,arg_ESCP_1,0x00,arg_ESCP_2,arg_ESCP_5,arg_ESCP_6,arg_ESCP_7,0x00 );
4899 }
4900 else if ( init->caps->ESC_P_len == 6 ) /* first devices with XML header and ender */
4901 {/* the 4th of the 6 bytes is the media type. 2nd byte is media size. Both read from canon-media array. */
4902
4903 /* arg_ESCP_1 = 0x03; */ /* A4 size */
4904 /* arg_ESCP_2 = 0x00; */ /* plain media */
4905 /* size media */
4906 canon_cmd( v,ESC28,0x50,6,0x00,arg_ESCP_1,0x00,arg_ESCP_2,arg_ESCP_5,arg_ESCP_6 );
4907 }
4908 else if ( init->caps->ESC_P_len == 4 ) {/* 4 bytes */
4909 /* size media */
4910 canon_cmd( v,ESC28,0x50,4,0x00,arg_ESCP_1,0x00,arg_ESCP_2 );
4911 }
4912 else if ( init->caps->ESC_P_len == 2 ) {
4913 /* 2 bytes only */
4914 canon_cmd( v,ESC28,0x50,2,0x00,arg_ESCP_1 );
4915 }
4916 else /* error in definition */
4917 stp_dprintf(STP_DBG_CANON, v,"SEVERE BUG IN print-canon.c::canon_init_setESC_P() "
4918 "ESC_P_len=%d!!\n",init->caps->ESC_P_len);
4919 }
4920
4921 /* ESC (s -- 0x73 -- :
4922 used in some newer printers for duplex pages except last one.
4923 When capability available, used for non-tumble and tumble (unlike Esc (u which is non-tumble only)
4924 Limitation: outputs on every page */
4925 static void
4926 canon_init_setESC_s(const stp_vars_t *v, const canon_privdata_t *init)
4927 {
4928 if (!(init->caps->features & CANON_CAP_DUPLEX))
4929 return;
4930 if (!(init->caps->features & CANON_CAP_s))
4931 return;
4932
4933 canon_cmd(v,ESC28,0x73, 1, 0x00);
4934 }
4935
4936 /* ESC (S -- 0x53 -- unknown -- :
4937 Required by iP90/iP90v and iP100 printers.
4938 */
4939 static void
4940 canon_init_setESC_S(const stp_vars_t *v, const canon_privdata_t *init)
4941 {
4942 unsigned char arg_ESCS_01,arg_ESCS_04,arg_ESCS_09,arg_ESCS_11;
4943
4944 if (!(init->caps->features & CANON_CAP_S))
4945 return;
4946
4947 if (!(init->mode->flags & MODE_FLAG_S))
4948 return;
4949
4950 /* iP90 defaults: based on non-photo media */
4951 arg_ESCS_01 = 0x01;
4952 arg_ESCS_04 = 0xff;
4953 arg_ESCS_09 = 0x1a;
4954 arg_ESCS_11 = 0x68;
4955
4956 /* hard-coded for different media, color and quality settings */
4957 /* iP90 bytes 1,4,9 and 11 vary */
4958 if ( !(strcmp(init->caps->name,"PIXMA iP90")) ) {
4959 if ( !strcmp(init->mode->name,"600x600dpi_high2") || !strcmp(init->mode->name,"600x600dpi_high4") ) {
4960 /* if inkset is color then set special bytes, else leave default.
4961 Note: in this case the mode only has CMYK, mono is a different mode.
4962 */
4963 if (init->used_inks == CANON_INK_CMYK) {
4964 arg_ESCS_01 = 0xc1;
4965 arg_ESCS_04 = 0xf1;
4966 arg_ESCS_09 = 0x50;
4967 arg_ESCS_11 = 0x28;
4968 }
4969 } else if ( !strcmp(init->mode->name,"300x300dpi_draft") ) {
4970 /* set regardless of inkset */
4971 arg_ESCS_09 = 0x02;
4972 arg_ESCS_11 = 0x08;
4973 } else if ( !strcmp(init->mode->name,"600x600dpi_draft2") ) {
4974 /* if inkset is color then set special bytes, else leave default */
4975 if (init->used_inks == CANON_INK_CMYK) {
4976 arg_ESCS_09 = 0x0a;
4977 arg_ESCS_11 = 0x28;
4978 }
4979 } else if ( !strcmp(init->mode->name,"600x600dpi_photohigh") || !strcmp(init->mode->name,"600x600dpi_photo") || !strcmp(init->mode->name,"600x600dpi_photodraft") ) {
4980 /* almost all photo media need (same) changes from defaults */
4981 /* exception: "600x600dpi_photohigh2" no ESC (S command */
4982 /* exception: "600x600dpi_tshirt" no ESC (S command */
4983 arg_ESCS_01 = 0xc1;
4984 arg_ESCS_04 = 0xf0;
4985 arg_ESCS_09 = 0x50;
4986 arg_ESCS_11 = 0x28;
4987 }
4988 }
4989 else if ( !(strcmp(init->caps->name,"PIXMA iP100")) ) {
4990 /* iP100 bytes 9 and 11 vary */
4991 if ( !strcmp(init->mode->name,"300x300dpi_draft") ) {
4992 /* set regardless of inkset */
4993 arg_ESCS_09 = 0x02;
4994 arg_ESCS_11 = 0x08;
4995 } else if ( !strcmp(init->mode->name,"600x600dpi_photohigh2") || !strcmp(init->mode->name,"600x600dpi_photohigh") || !strcmp(init->mode->name,"600x600dpi_photo2") || !strcmp(init->mode->name,"600x600dpi_photo") || !strcmp(init->mode->name,"600x600dpi_tshirt") ) {
4996 /* all photo media need (same) changes from defaults */
4997 arg_ESCS_09 = 0x0a;
4998 arg_ESCS_11 = 0x28;
4999 }
5000 }
5001
5002 canon_cmd(v,ESC28,0x53,54,arg_ESCS_01,0x02,0xff,arg_ESCS_04,0x41,0x02,0x00,0x01,arg_ESCS_09,0x00,arg_ESCS_11,0x00,0x01,0x01,0x03,0x02,0x01,0x01,0x01,0x03,0x02,0x00,0x07,0x06,0x02,0x01,0x02,0x04,0x04,0x04,0x05,0x06,0x08,0x08,0x08,0x0a,0x0a,0x09,0x00,0x03,0x02,0x01,0x01,0x01,0x01,0x01,0x06,0x02,0x02,0x02,0x03,0x04,0x05,0x06);
5003
5004 }
5005
5006 /* ESC (T -- 0x54 -- setCartridge -- :
5007 */
5008 static void
5009 canon_init_setCartridge(const stp_vars_t *v, const canon_privdata_t *init)
5010 {
5011 const char *ink_set;
5012
5013 if (!(init->caps->features & CANON_CAP_T))
5014 return;
5015
5016 ink_set = stp_get_string_parameter(v, "InkSet");
5017
5018 if (ink_set && !(strcmp(ink_set,"Both"))) {
5019 if ( !(strcmp(init->caps->name,"PIXMA iP90")) || !(strcmp(init->caps->name,"PIXMA iP100")) || !(strcmp(init->caps->name,"PIXMA iP110")) ) {
5020 canon_cmd(v,ESC28,0x54,3,0x02,0x00,0x00); /* default for iP90, iP100, iP110 */
5021 }
5022 else if ( !(strcmp(init->caps->name,"PIXMA iP6210")) ) {
5023 canon_cmd(v,ESC28,0x54,3,0x03,0x06,0x06); /* default for iP6210D, iP6220D, iP6310D */
5024 /* both: 0x3 0x6 0x6 */
5025 /* color: 0x3 0x1 0x1 */
5026 }
5027 else {
5028 canon_cmd(v,ESC28,0x54,3,0x03,0x04,0x04); /* default: both cartridges */
5029 }
5030 }
5031 else if (ink_set && !(strcmp(ink_set,"Black"))) {
5032 if ( !(strcmp(init->caps->name,"PIXMA iP90")) || !(strcmp(init->caps->name,"PIXMA iP100")) || !(strcmp(init->caps->name,"PIXMA iP110")) ) {
5033 canon_cmd(v,ESC28,0x54,3,0x02,0x00,0x00); /* default for iP90, iP100, iP110 */
5034 }
5035 else if ( !(strcmp(init->caps->name,"PIXMA iP6210")) ) {
5036 canon_cmd(v,ESC28,0x54,3,0x03,0x06,0x06); /* default for iP6210D, iP6220D, iP6310D */
5037 /* both: 0x3 0x6 0x6 */
5038 /* color: 0x3 0x1 0x1 */
5039 /* workaround since does not have black option */
5040 }
5041 else {
5042 canon_cmd(v,ESC28,0x54,3,0x03,0x02,0x02); /* default: black cartridge */
5043 }
5044 }
5045 else if (ink_set && !(strcmp(ink_set,"Color"))) {
5046 if ( !(strcmp(init->caps->name,"PIXMA iP90")) || !(strcmp(init->caps->name,"PIXMA iP100")) || !(strcmp(init->caps->name,"PIXMA iP110")) ) {
5047 canon_cmd(v,ESC28,0x54,3,0x02,0x00,0x01); /* composite for iP90, iP100, iP110 */
5048 /* black save : 2 1 0 for selected plain (600dpi std) modes, rest remain 2 0 0 */
5049 /* composite black: 2 0 1 for selected plain (600dpi std & draft) modes, rest remain 2 0 0 */
5050 /* both above set : AND of bytes above */
5051 }
5052 else if ( !(strcmp(init->caps->name,"PIXMA iP6210")) ) {
5053 canon_cmd(v,ESC28,0x54,3,0x03,0x01,0x01); /* default for iP6210D, iP6220D, iP6310D */
5054 /* both: 0x3 0x6 0x6 */
5055 /* color: 0x3 0x1 0x1 */
5056 }
5057 else {
5058 canon_cmd(v,ESC28,0x54,3,0x03,0x01,0x01); /* default: color cartridges */
5059 }
5060 }
5061 else {
5062 canon_cmd(v,ESC28,0x54,3,0x03,0x04,0x04); /* default: both cartridges */
5063 }
5064 }
5065
5066 /* ESC (q -- 0x71 -- setPageID -- :
5067 */
5068 static void
5069 canon_init_setPageID(const stp_vars_t *v, const canon_privdata_t *init)
5070 {
5071 if (!(init->caps->features & CANON_CAP_q))
5072 return;
5073
5074 canon_cmd(v,ESC28,0x71, 1, 0x01);
5075 }
5076
5077 /* ESC (r -- 0x72 -- -- :
5078 */
5079 static void
5080 canon_init_setX72(const stp_vars_t *v, const canon_privdata_t *init)
5081 {
5082 if ( !( (init->caps->features & CANON_CAP_r)
5083 || (init->caps->features & CANON_CAP_rr) ) )
5084 return;
5085
5086 if ( (init->caps->features & CANON_CAP_r)
5087 || (init->caps->features & CANON_CAP_rr) )
5088 if (init->caps->ESC_r_arg != 0) /* only output arg if non-zero */
5089 canon_cmd(v,ESC28,0x72, 1, init->caps->ESC_r_arg); /* whatever for - 8200/S200 need it */
5090 if (init->caps->features & CANON_CAP_rr) {
5091 if ( !(strcmp(init->caps->name,"S200")) ) {
5092 canon_cmd(v,ESC28,0x72, 3, 0x63, 1, 0); /* whatever for - S200 needs it */
5093 /* probably to set the print direction of the head */
5094 }
5095 else if ( !(strcmp(init->caps->name,"S820")) || !(strcmp(init->caps->name,"S900")) || !(strcmp(init->caps->name,"S9000")) || !(strcmp(init->caps->name,"i950")) || !(strcmp(init->caps->name,"i960")) || !(strcmp(init->caps->name,"i9100")) || !(strcmp(init->caps->name,"i9900")) || !(strcmp(init->caps->name,"PIXMA iP7100")) || !(strcmp(init->caps->name,"PIXMA iP8100")) || !(strcmp(init->caps->name,"PIXMA iP8500")) || !(strcmp(init->caps->name,"PIXMA iP8600")) || !(strcmp(init->caps->name,"PIXMA iP9910")) || !(strcmp(init->caps->name,"PIXMA MP900")) || !(strcmp(init->caps->name,"PIXMA Pro9000")) || !(strcmp(init->caps->name,"PIXMA Pro9002")) || !(strcmp(init->caps->name,"PIXMA Pro9500")) || !(strcmp(init->caps->name,"PIXMA Pro9502")) ) {
5096 canon_cmd(v,ESC28,0x72, 2, 0x62, 0); /* 2 bytes */
5097 }
5098 /* CD mode only */
5099 else if ( (init->mode->flags & MODE_FLAG_CD) && (!(strcmp(init->caps->name,"PIXMA iP4600")) || !(strcmp(init->caps->name,"PIXMA iP4700")) || !(strcmp(init->caps->name,"PIXMA MP980")) || !(strcmp(init->caps->name,"PIXMA MP990")) ) ) {
5100 canon_cmd(v,ESC28,0x72, 1, 0x65);
5101 }
5102 /* CD mode only */
5103 else if ( (init->mode->flags & MODE_FLAG_CD) && ( !(strcmp(init->caps->name,"PIXMA iP4800")) || !(strcmp(init->caps->name,"PIXMA MG6100")) || !(strcmp(init->caps->name,"PIXMA MG8100")) ) ) {
5104 canon_cmd(v,ESC28,0x72, 1, 0x68);
5105 }
5106 /* CD mode only -- no ESC (r at all otherwise */
5107 else if ( (init->mode->flags & MODE_FLAG_CD) && ( !(strcmp(init->caps->name,"PIXMA iP4900")) || !(strcmp(init->caps->name,"PIXMA MG5200")) || !(strcmp(init->caps->name,"PIXMA MG5300")) || !(strcmp(init->caps->name,"PIXMA MG6200")) || !(strcmp(init->caps->name,"PIXMA MG8200")) || !(strcmp(init->caps->name,"PIXMA TS8000")) ) ) {
5108 canon_cmd(v,ESC28,0x72, 1, 0x68); /* same as above case? */
5109 }
5110 /* other cases here */
5111 }
5112 }
5113
5114 /* ESC (r -- 0x72 -- ??? set direction ??? -- :
5115 only works if quality = 01 (S200) */
5116 static void
5117 canon_set_X72(const stp_vars_t *v, int x72arg)
5118 {
5119 canon_cmd(v,ESC28,0x72, 3, 0x63, x72arg, 0);
5120 }
5121
5122 /* ESC (t -- 0x74 -- cmdSetImage --:
5123 */
5124 static void
5125 canon_init_setImage(const stp_vars_t *v, const canon_privdata_t *init)
5126 {
5127 unsigned char
5128 arg_74_1 = 0x01, /* 1 bit per pixel */
5129 arg_74_2 = 0x00, /* */
5130 arg_74_3 = 0x01; /* 01 <= 360 dpi 09 >= 720 dpi */
5131
5132 if (!(init->caps->features & CANON_CAP_t))
5133 return;
5134
5135 if(init->mode->flags & MODE_FLAG_EXTENDED_T) /*code requires extended mode settings*/
5136 {
5137 unsigned int i;
5138 unsigned int length = init->mode->num_inks*3 + 3;
5139 unsigned char* buf = stp_zalloc(length);
5140 buf[0]=0x80;
5141 if(init->mode->flags & MODE_FLAG_PRO){
5142 buf[1]=0x90; /* was 0x10, but this should probably be 0x90 */
5143 buf[2]=0x4;
5144 }else if(init->mode->flags & MODE_FLAG_IP8500){
5145 buf[1]=0x00;
5146 buf[2]=0x01;
5147 }else if(init->mode->flags & MODE_FLAG_MP130){
5148 buf[1]=0x04;
5149 buf[2]=0x01;
5150 }else if(init->mode->flags & MODE_FLAG_MP360){
5151 buf[1]=0x84;
5152 buf[2]=0x01;
5153 }else{
5154 buf[1]=0x80;
5155 buf[2]=0x01;
5156 }
5157 for(i=0;i<init->mode->num_inks;i++){
5158 if(init->mode->inks[i].channel != 0){ /* 0 means ink is used in gutenprint for sub-channel setup but not intended for printer */
5159 if(init->mode->inks[i].ink->flags & INK_FLAG_5pixel_in_1byte)
5160 buf[3+i*3+0]=(1<<5)|init->mode->inks[i].ink->bits; /*info*/
5161 /*else if(init->mode->inks[i].ink->flags & INK_FLAG_lowresmode)
5162 {
5163 buf[3+i*3+1]=0x01;
5164 buf[3+i*3+0]=init->mode->inks[i].ink->bits;
5165 }*/
5166 else if(init->mode->inks[i].ink->flags & INK_FLAG_3pixel5level_in_1byte)
5167 buf[3+i*3+0]=(1<<5)|init->mode->inks[i].ink->bits; /*info*/
5168 else if(init->mode->inks[i].ink->flags & INK_FLAG_3pixel6level_in_1byte)
5169 buf[3+i*3+0]=(1<<5)|init->mode->inks[i].ink->bits; /*info*/
5170 else
5171 buf[3+i*3+0]=init->mode->inks[i].ink->bits;
5172
5173 /* workaround for now on the 4-4 inkset and others */
5174 /*if (init->mode->inks[i].ink->bits == 4)
5175 buf[3+i*3+2] = 0x04;*/
5176 /*else if (init->mode->inks[i].ink->bits == 2)
5177 buf[3+i*3+2] = 0x04;*/
5178 /*else if (init->mode->inks[i].ink->bits == 1)
5179 buf[3+i*3+2] = 0x02;*/
5180 /*else*/ /* normal operation */
5181 buf[3+i*3+2]= init->mode->inks[i].ink->numsizes+1;/*level*/
5182 /*else
5183 buf[3+i*3+2] = 0x00;*/
5184 /* this should show that there is an error */
5185 }
5186 }
5187 stp_zfwrite(ESC28,2,1,v);
5188 stp_putc(0x74,v);
5189 stp_put16_le(length,v);
5190 stp_zfwrite((char*)buf,length,1,v);
5191 stp_free(buf);
5192 return;
5193 }
5194
5195 /* other models mostly hardcoded stuff not really understood ;( */
5196 if (!strcmp(init->caps->name,"S200")) /* 1 bit per pixel (arg 4,7,10,13); */
5197 /* 2 level per pixel (arg 6,9,12,15) for each color */
5198 /* though we print only 1bit/pixel - but this is how */
5199 /* the windows driver works */
5200 {
5201 canon_cmd(v,ESC28,0x74, 30, 0x80, 4, 1, 1, 0, 2, 1, 0, 2, 1, 0, 2, 1, 0, 2,\
5202 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
5203 return;
5204 }
5205
5206 if (init->mode->xdpi==1440) arg_74_2= 0x04;
5207 if (init->mode->ydpi>=720) arg_74_3= 0x09;
5208
5209 if (init->mode->inks[0].ink->bits>1) {
5210 arg_74_1= 0x02;
5211 arg_74_2= 0x80;
5212 arg_74_3= 0x09; /* default for most media */
5213 /* FIXME: (Gernot) below must be corrected I think, since CMY is
5214 not a function of the cartridge but of the driver selection of
5215 which logical inks get sent to the printer. So here the
5216 printers that use this should be enumerated, rather than a
5217 generic condition based on CANON_INK_CMY */
5218 if (init->used_inks == CANON_INK_CMY) arg_74_3= 0x02; /* for BC-06 cartridge!!! */
5219 /* example of better way: for BJC-3000 series */
5220 if ( !strcmp(init->caps->name,"3000") || !strcmp(init->caps->name,"4300")) {
5221 /* but if photo cartridge selection, set differently again */
5222 if (init->mode->flags & MODE_FLAG_PHOTO)
5223 arg_74_3= 0x0a;
5224 /* T-Shirt (3), Backprint Film (3) or Transparencies (2) */
5225 else if ((init->pt->media_code_c==2) || (init->pt->media_code_c==3))
5226 arg_74_3= 0x01;
5227 else
5228 /* other media */
5229 arg_74_3= 0x09; /* return to default after broken code above */
5230 }
5231 if ( (!strcmp(init->caps->name,"2000")) || (!strcmp(init->caps->name,"2100")) ) {
5232 /* but if photo cartridge selection, set differently again */
5233 if (init->mode->flags & MODE_FLAG_PHOTO)
5234 arg_74_3= 0x0a;
5235 else
5236 /* other media */
5237 arg_74_3= 0x09; /* return to default after broken code above */
5238 }
5239
5240 }
5241
5242 /* workaround for the bjc8200 in 6color mode - not really understood */
5243 if (!strcmp(init->caps->name,"8200")) {
5244 if (init->used_inks == CANON_INK_CcMmYK) {
5245 arg_74_1= 0xff;
5246 arg_74_2= 0x90;
5247 arg_74_3= 0x04;
5248 if (init->mode->ydpi>600) arg_74_3= 0x09;
5249 } else {
5250 arg_74_1= 0x01;
5251 arg_74_2= 0x00;
5252 arg_74_3= 0x01;
5253 if (init->mode->ydpi>600) arg_74_3= 0x09;
5254 }
5255 }
5256
5257 canon_cmd(v,ESC28,0x74, 3, arg_74_1, arg_74_2, arg_74_3);
5258 }
5259
5260 /* ESC (I (J (L
5261 */
5262 static void
5263 canon_init_setMultiRaster(const stp_vars_t *v, const canon_privdata_t *init){
5264
5265 int i; /* introduced for channel counting */
5266 char* raster_channel_order; /* introduced for channel counting */
5267
5268 if(!(init->caps->features & CANON_CAP_I))
5269 return;
5270
5271 canon_cmd(v,ESC28,0x49, 1, 0x1); /* enable MultiLine Raster? */
5272 /* canon_cmd(v,ESC28,0x4a, 1, init->caps->raster_lines_per_block); */
5273 canon_cmd(v,ESC28,0x4a, 1, init->mode->raster_lines_per_block); /* set number of lines per raster block */
5274
5275 /* set the color sequence */
5276 stp_zfwrite("\033(L", 3, 1, v);
5277 stp_put16_le(init->num_channels, v);
5278 /* add an exception here to add 0x60 of cmy channels for those printers/modes that require it */
5279 /* Note: 2017-06-28 this section needs revision, many printers not entered here, thus modes either not supported or incorrectly output */
5280 raster_channel_order=init->channel_order;
5281 if ( !(strcmp(init->caps->name,"PIXMA E3100")) || !(strcmp(init->caps->name,"PIXMA MP140")) || !(strcmp(init->caps->name,"PIXMA MP150")) || !(strcmp(init->caps->name,"PIXMA MP160")) || !(strcmp(init->caps->name,"PIXMA MP170")) || !(strcmp(init->caps->name,"PIXMA MP180")) || !(strcmp(init->caps->name,"PIXMA MP190")) || !(strcmp(init->caps->name,"PIXMA MP210")) || !(strcmp(init->caps->name,"PIXMA MP220")) || !(strcmp(init->caps->name,"PIXMA MP240")) || !(strcmp(init->caps->name,"PIXMA MP250")) || !(strcmp(init->caps->name,"PIXMA MP270")) || !(strcmp(init->caps->name,"PIXMA MP280")) || !(strcmp(init->caps->name,"PIXMA MP450")) || !(strcmp(init->caps->name,"PIXMA MP460")) || !(strcmp(init->caps->name,"PIXMA MP470")) || !(strcmp(init->caps->name,"PIXMA MP480")) || !(strcmp(init->caps->name,"PIXMA MP490")) || !(strcmp(init->caps->name,"PIXMA MP495")) || !(strcmp(init->caps->name,"PIXMA MX300")) || !(strcmp(init->caps->name,"PIXMA MX310")) || !(strcmp(init->caps->name,"PIXMA MX330")) || !(strcmp(init->caps->name,"PIXMA MX340")) || !(strcmp(init->caps->name,"PIXMA MX350")) || !(strcmp(init->caps->name,"PIXMA MX360")) || !(strcmp(init->caps->name,"PIXMA MX370")) || !(strcmp(init->caps->name,"PIXMA MX410")) || !(strcmp(init->caps->name,"PIXMA MX510")) || !(strcmp(init->caps->name,"PIXMA MX520")) || !(strcmp(init->caps->name,"PIXMA iP2700")) || !(strcmp(init->caps->name,"PIXMA MG2100")) || !(strcmp(init->caps->name,"PIXMA MG2400")) || !(strcmp(init->caps->name,"PIXMA MG2500")) || !(strcmp(init->caps->name,"PIXMA MG3500")) || !(strcmp(init->caps->name,"PIXMA MG3600")) || !(strcmp(init->caps->name,"PIXMA G1000")) || !(strcmp(init->caps->name,"PIXMA G4000")) )
5282 {
5283 /* if cmy there, add 0x60 to each --- all modes using cmy require it */
5284 for(i=0;i<init->num_channels;i++){
5285 switch(init->channel_order[i]){
5286 case 'c':raster_channel_order[i]+=0x60; break;;
5287 case 'm':raster_channel_order[i]+=0x60; break;;
5288 case 'y':raster_channel_order[i]+=0x60; break;;
5289 }
5290 }
5291 /* Gernot: debug */
5292 /* if CMY there, add 0x80 to each to change to cmy+0x60 */
5293 /* for(i=0;i<init->num_channels;i++){
5294 switch(init->channel_order[i]){
5295 case 'C':raster_channel_order[i]+=0x80; break;;
5296 case 'M':raster_channel_order[i]+=0x80; break;;
5297 case 'Y':raster_channel_order[i]+=0x80; break;;
5298 }
5299 }*/
5300 stp_zfwrite((const char *)raster_channel_order,init->num_channels, 1, v);
5301 }
5302 /* note these names are from canon-printers.h, only separate driver strings are required */
5303 else if ( !(strcmp(init->caps->name,"PIXMA iP6210")) ) {
5304 /* if cmy there, add 0x60 to each --- only some modes using cmy require it */
5305 /* case one: all modes with only cmy */
5306 if (init->num_channels==3) {
5307 for(i=0;i<init->num_channels;i++){
5308 switch(init->channel_order[i]){
5309 case 'c':raster_channel_order[i]+=0x60; break;;
5310 case 'm':raster_channel_order[i]+=0x60; break;;
5311 case 'y':raster_channel_order[i]+=0x60; break;;
5312 }
5313 }
5314 }
5315 /* case two: CMYcmy modes, but not CMYkcm modes */
5316 else if ( (init->num_channels==6) && (init->used_inks==CANON_INK_CMY) ) {
5317 for(i=0;i<init->num_channels;i++){
5318 switch(init->channel_order[i]){
5319 case 'c':raster_channel_order[i]+=0x60; break;;
5320 case 'm':raster_channel_order[i]+=0x60; break;;
5321 case 'y':raster_channel_order[i]+=0x60; break;;
5322 }
5323 }
5324 }
5325 /* case three: CMYkm modes with 0x80 to subtract from all inks with 2 or 8 bits */
5326 else if ( (init->num_channels==6) && (init->used_inks==CANON_INK_CcMmYK) && ((init->mode->inks[0].ink->bits==2) || (init->mode->inks[0].ink->bits==8)) ) {
5327 for(i=0;i<init->num_channels;i++){
5328 switch(init->channel_order[i]){
5329 case 'C':raster_channel_order[i]+=0x80; break;;
5330 case 'M':raster_channel_order[i]+=0x80; break;;
5331 case 'Y':raster_channel_order[i]+=0x80; break;;
5332 case 'c':raster_channel_order[i]+=0x80; break;;
5333 case 'm':raster_channel_order[i]+=0x80; break;;
5334 case 'k':raster_channel_order[i]+=0x80; break;;
5335 }
5336 }
5337 }
5338 stp_zfwrite((const char *)raster_channel_order,init->num_channels, 1, v);
5339 }
5340 else
5341 {
5342 stp_zfwrite((const char *)init->channel_order,init->num_channels, 1, v);
5343 }
5344 }
5345
5346 /* ESC (u -- 0x75 -- even pages duplex for long side only -- */
5347 static void
5348 canon_init_setESC_u(const stp_vars_t *v, const canon_privdata_t *init)
5349 {
5350 if (!(init->caps->features & CANON_CAP_DUPLEX))
5351 return;
5352
5353 canon_cmd( v,ESC28,0x75, 1, 0x01 );
5354 }
5355
5356 /* ESC (v -- 0x76 -- */
5357 /* page rotation in Windows driver settings: */
5358 /* none: 0x0 */
5359 /* 90 deg: 0x1 */
5360 /* 180 deg: 0x2 */
5361 /* 270 deg: 0x3 */
5362 /* also influences ESC (P command parameters 5 and 6 */
5363 /* none: 1 0 */
5364 /* 90 deg: 2 0 */
5365 /* 180 deg: 1 1 */
5366 /* 270 deg: 2 1 */
5367 static void
5368 canon_init_setESC_v(const stp_vars_t *v, const canon_privdata_t *init)
5369 {
5370 const char *orientation_type =stp_get_string_parameter(v, "Orientation");
5371 unsigned char arg_ESCv_1 = 0x00;
5372
5373 if (!(init->caps->features & CANON_CAP_v))
5374 return;
5375
5376 if( orientation_type && !strcmp(orientation_type,"Portrait")) /* none */
5377 arg_ESCv_1 = 0x00;
5378 else if( orientation_type && !strcmp(orientation_type,"Landscape")) /* 90 deg */
5379 arg_ESCv_1 = 0x01;
5380 else if( orientation_type && !strcmp(orientation_type,"UpsideDown")) /* 180 deg */
5381 arg_ESCv_1 = 0x02;
5382 else if( orientation_type && !strcmp(orientation_type,"Seascape")) /* 270 deg */
5383 arg_ESCv_1 = 0x03;
5384
5385 canon_cmd( v,ESC28,0x76, 1, arg_ESCv_1 );
5386 }
5387
5388 /* ESC (w -- 0x77 -- :
5389 Unknown.
5390 new September 2015, currently only 1 byte.
5391 */
5392 static void
5393 canon_init_setESC_w(const stp_vars_t *v, const canon_privdata_t *init)
5394 {
5395 unsigned char arg_ESCw_1;
5396 if (!(init->caps->features & CANON_CAP_w))
5397 return;
5398
5399 arg_ESCw_1 = (init->pt) ? init->pt->media_code_w: 0x00;
5400 canon_cmd( v,ESC28,0x77, 1, arg_ESCw_1 );
5401 }
5402
5403 static void
5404 canon_init_printer(const stp_vars_t *v, canon_privdata_t *init)
5405 {
5406 unsigned int mytop;
5407 int page_number = stp_get_int_parameter(v, "PageNumber");
5408 const char *duplex_mode = stp_get_string_parameter(v, "Duplex");
5409 /* init printer */
5410 if (init->is_first_page) {
5411 canon_init_resetPrinter(v,init); /* ESC [K */
5412 canon_init_setESC_M(v,init); /* ESC (M */
5413 canon_init_setDuplex(v,init); /* ESC ($ */
5414 }
5415 canon_init_setPageMode(v,init); /* ESC (a */
5416 canon_init_setDataCompression(v,init); /* ESC (b */
5417 canon_init_setPageID(v,init); /* ESC (q */
5418 canon_init_setPrintMode(v,init); /* ESC (m */
5419 canon_init_setResolution(v,init); /* ESC (d */
5420 canon_init_setImage(v,init); /* ESC (t */
5421 canon_init_setColor(v,init); /* ESC (c */
5422 canon_init_setPageMargins(v,init); /* ESC (g */
5423 canon_init_setPageMargins2(v,init); /* ESC (p */
5424 canon_init_setESC_P(v,init); /* ESC (P */
5425 canon_init_setCartridge(v,init); /* ESC (T */
5426 canon_init_setESC_S(v,init); /* ESC (S */
5427 canon_init_setTray(v,init); /* ESC (l */
5428 canon_init_setX72(v,init); /* ESC (r */
5429 canon_init_setESC_v(v,init); /* ESC (v */
5430 if (init->is_first_page)
5431 canon_init_setESC_w(v,init); /* ESC (w */
5432 if((page_number & 1) && duplex_mode && !strcmp(duplex_mode,"DuplexNoTumble"))
5433 canon_init_setESC_u(v,init); /* ESC (u 0x1 */
5434 if(duplex_mode)
5435 canon_init_setESC_s(v,init); /* ESC (s 0x0 */
5436 canon_init_setMultiRaster(v,init); /* ESC (I (J (L */
5437
5438 /* some linefeeds */
5439
5440 mytop= (init->top*init->mode->ydpi)/72;
5441
5442 if(init->caps->features & CANON_CAP_I)
5443 /* mytop /= init->caps->raster_lines_per_block; */
5444 mytop /= init->mode->raster_lines_per_block;
5445
5446 if(mytop)
5447 canon_cmd(v,ESC28,0x65, 2, (mytop >> 8 ),(mytop & 255));
5448 }
5449
5450 static void
5451 canon_deinit_printer(const stp_vars_t *v, const canon_privdata_t *init)
5452 {
5453 /* eject page */
5454 stp_putc(0x0c,v);
5455
5456 /* say goodbye */
5457 canon_cmd(v,ESC28,0x62,1,0);
5458 if (init->caps->features & CANON_CAP_a)
5459 canon_cmd(v,ESC28,0x61, 1, 0);
5460 }
5461
5462 static int
5463 canon_start_job(const stp_vars_t *v, stp_image_t *image)
5464 {
5465 const canon_cap_t * caps = canon_get_model_capabilities(v);
5466 (void)image;
5467
5468 /* output XML for iP2700 and other devices */
5469 if (caps->features & CANON_CAP_XML) {
5470 int length=strlen(prexml_iP2700); /* 680 */
5471 stp_zfwrite((const char*)prexml_iP2700,length,1,v);
5472 }
5473 return 1;
5474 }
5475
5476 static int
5477 canon_end_job(const stp_vars_t *v, stp_image_t *image)
5478 {
5479 const canon_cap_t * caps = canon_get_model_capabilities(v);
5480 (void)image;
5481
5482 canon_cmd(v,ESC40,0,0);
5483 /* output XML for iP2700 and other devices */
5484 if (caps->features & CANON_CAP_XML) {
5485 int length=strlen(postxml_iP2700); /* 263 */
5486 stp_zfwrite((const char*)postxml_iP2700,length,1,v);
5487 }
5488 return 1;
5489 }
5490
5491 /*
5492 * 'advance_buffer()' - Move (num) lines of length (len) down one line
5493 * and sets first line to 0s
5494 * accepts NULL pointers as buf
5495 * !!! buf must contain more than (num) lines !!!
5496 * also sets first line to 0s if num<1
5497 */
5498 static void
5499 canon_advance_buffer(unsigned char *buf, int len, int num)
5500 {
5501 if (!buf || !len) return;
5502 if (num>0) memmove(buf+len,buf,len*num);
5503 memset(buf,0,len);
5504 }
5505
5506 static void
5507 canon_printfunc(stp_vars_t *v)
5508 {
5509 int i;
5510 canon_privdata_t *pd = (canon_privdata_t *) stp_get_component_data(v, "Driver");
5511 canon_write_line(v);
5512 for (i = 0; i < pd->num_channels ; i++)
5513 canon_advance_buffer(pd->channels[i].buf, pd->length, pd->channels[i].delay);
5514
5515 }
5516
5517 static double
5518 get_double_param(stp_vars_t *v, const char *param)
5519 {
5520 if (param && stp_check_float_parameter(v, param, STP_PARAMETER_ACTIVE))
5521 return stp_get_float_parameter(v, param);
5522 else
5523 return 1.0;
5524 }
5525
5526
5527
5528 static void
5529 set_mask(unsigned char *cd_mask, int x_center, int scaled_x_where,
5530 int limit, int expansion, int invert)
5531 {
5532 int clear_val = invert ? 255 : 0;
5533 int set_val = invert ? 0 : 255;
5534 int bytesize = 8 / expansion;
5535 int byteextra = bytesize - 1;
5536 int first_x_on = x_center - scaled_x_where;
5537 int first_x_off = x_center + scaled_x_where;
5538 if (first_x_on < 0)
5539 first_x_on = 0;
5540 if (first_x_on > limit)
5541 first_x_on = limit;
5542 if (first_x_off < 0)
5543 first_x_off = 0;
5544 if (first_x_off > limit)
5545 first_x_off = limit;
5546 first_x_on += byteextra;
5547 if (first_x_off > (first_x_on - byteextra))
5548 {
5549 int first_x_on_byte = first_x_on / bytesize;
5550 int first_x_on_mod = expansion * (byteextra - (first_x_on % bytesize));
5551 int first_x_on_extra = ((1 << first_x_on_mod) - 1) ^ clear_val;
5552 int first_x_off_byte = first_x_off / bytesize;
5553 int first_x_off_mod = expansion * (byteextra - (first_x_off % bytesize));
5554 int first_x_off_extra = ((1 << 8) - (1 << first_x_off_mod)) ^ clear_val;
5555 if (first_x_off_byte < first_x_on_byte)
5556 {
5557 /* This can happen, if 6 or fewer points are turned on */
5558 cd_mask[first_x_on_byte] = first_x_on_extra & first_x_off_extra;
5559 }
5560 else
5561 {
5562 if (first_x_on_extra != clear_val)
5563
5564 cd_mask[first_x_on_byte - 1] = first_x_on_extra;
5565 if (first_x_off_byte > first_x_on_byte)
5566 memset(cd_mask + first_x_on_byte, set_val,
5567 first_x_off_byte - first_x_on_byte);
5568 if (first_x_off_extra != clear_val)
5569 cd_mask[first_x_off_byte] = first_x_off_extra;
5570 }
5571 }
5572 }
5573
5574
5575 /* get delay settings for the specified color and mode */
5576 static int canon_get_delay(canon_privdata_t* privdata,char color){
5577 int i=0;
5578 int delay = 0;
5579 const canon_delay_t* delaylist = privdata->mode->delay;
5580
5581 while(delaylist && delaylist[i].color){
5582 if(delaylist[i].color == color){
5583 delay = delaylist[i].delay;
5584 break;
5585 }
5586 ++i;
5587 }
5588 if(delay > privdata->delay_max)
5589 privdata->delay_max = delay;
5590 return delay;
5591 }
5592
5593
5594 /* add a single channel to the dither engine */
5595 static int canon_setup_channel(stp_vars_t *v,canon_privdata_t* privdata,int channel,int subchannel,const canon_inkset_t* ink,stp_shade_t** shades){
5596 if(ink->channel && ink->density > 0.0){
5597 int delay = canon_get_delay(privdata,ink->channel);
5598 canon_channel_t* current;
5599 stp_dprintf(STP_DBG_CANON, v, "canon_setup_channel: (start) privdata->num_channels %d\n", privdata->num_channels);
5600 stp_dprintf(STP_DBG_CANON, v, "canon_setup_channel: (start) privdata->channel_order %s\n", privdata->channel_order);
5601
5602 /* create a new channel */
5603 privdata->channels = stp_realloc(privdata->channels,sizeof(canon_channel_t) * (privdata->num_channels + 1));
5604 privdata->channel_order = stp_realloc(privdata->channel_order,privdata->num_channels + 2);
5605 /* update channel order */
5606 privdata->channel_order[privdata->num_channels]=ink->channel;
5607 stp_dprintf(STP_DBG_CANON, v, "canon_setup_channel: ink->channel %c\n", ink->channel);
5608 privdata->channel_order[privdata->num_channels+1]='\0';
5609 stp_dprintf(STP_DBG_CANON, v, "canon_setup_channel: (terminated)privdata->channel_order %s\n", privdata->channel_order);
5610 current = &(privdata->channels[privdata->num_channels]);
5611 ++privdata->num_channels;
5612 /* fill ink properties */
5613 current->name = ink->channel;
5614 stp_dprintf(STP_DBG_CANON, v, "canon_setup_channel: current->name %c\n", current->name);
5615 current->props = ink->ink;
5616 current->delay = delay;
5617 /* calculate buffer length */
5618 current->buf_length = ((privdata->length * current->props->bits)+1)*(delay + 1);
5619 /* update maximum buffer length */
5620 if(current->buf_length > privdata->buf_length_max)
5621 privdata->buf_length_max = current->buf_length;
5622 /* allocate buffer for the raster data */
5623 current->buf = stp_zalloc(current->buf_length + 1);
5624 /* add channel to the dither engine */
5625 stp_dither_add_channel(v, current->buf , channel , subchannel);
5626
5627 /* add shades to the shades array */
5628 *shades = stp_realloc(*shades,(subchannel + 1) * sizeof(stp_shade_t));
5629 /* move previous shades up one position as set_inks_full expects the subchannels first */
5630 if(subchannel)
5631 memmove(*shades + 1,*shades,sizeof(stp_shade_t) * subchannel);
5632 (*shades)[0].value = ink->density;
5633 stp_dprintf(STP_DBG_CANON, v, "canon_setup_channel: ink->density %.3f\n", ink->density);
5634 (*shades)[0].numsizes = ink->ink->numsizes;
5635 /* test for 4-4 inket with 8 levels spaced every 2nd */
5636 /*if (ink->ink->bits == 4)
5637 (*shades)[0].numsizes = 8;*/
5638
5639 (*shades)[0].dot_sizes = ink->ink->dot_sizes;
5640 return 1;
5641 }
5642 return 0;
5643 }
5644
5645
5646
5647
5648
5649 /* setup the dither channels */
5650 static void canon_setup_channels(stp_vars_t *v,canon_privdata_t* privdata){
5651 /* (in gutenprint notation) => KCMY, 1230 => CMYK etc. */
5652 const char default_channel_order[STP_NCOLORS] = {0,1,2,3};
5653 /* codes for the primary channels */
5654 const char primary[STP_NCOLORS] = {'K','C','M','Y',};
5655 /* codes for the subchannels */
5656 const char secondary[STP_NCOLORS] = {'k','c','m','y'};
5657 /* names of the density adjustment controls */
5658 const char *primary_density_control[STP_NCOLORS] = {"BlackDensity","CyanDensity","MagentaDensity","YellowDensity"};
5659 const char *secondary_density_control[STP_NCOLORS] = {NULL,"LightCyanTrans","LightMagentaTrans","LightYellowTrans"};
5660 /* ink darkness for every channel */
5661 const double ink_darkness[] = {1.0, 0.31 / .5, 0.61 / .97, 0.08};
5662 const char* channel_order = default_channel_order;
5663
5664
5665
5666 int channel;
5667 int channel_idx;
5668
5669 if(privdata->caps->channel_order)
5670 channel_order = privdata->caps->channel_order;
5671
5672
5673 /* loop through the dither channels */
5674 for(channel_idx = 0; channel_idx < STP_NCOLORS ; channel_idx++){
5675 unsigned int i;
5676 unsigned int subchannel = 0;
5677 stp_shade_t* shades = NULL;
5678 int is_black_channel = 0;
5679 channel = channel_order[channel_idx];
5680 stp_dprintf(STP_DBG_CANON, v, "canon_setup_channels: channel %d\n", channel);
5681 if(channel == STP_ECOLOR_K && privdata->used_inks & CANON_INK_K_MASK){ /* black channel */
5682 /* find K and k inks */
5683 for(i=0;i<privdata->mode->num_inks;i++){
5684 const canon_inkset_t* ink = &privdata->mode->inks[i];
5685 if(ink->channel == primary[channel] || ink->channel == secondary[channel]) {
5686 subchannel += canon_setup_channel(v,privdata,channel,subchannel,ink,&shades);
5687 /* Gernot: add */
5688 stp_dprintf(STP_DBG_CANON, v, "canon_setup_channels: got a black channel\n");
5689 }
5690 }
5691 is_black_channel = 1;
5692 /* adding cmy channels */
5693 /*}else if(channel != STP_ECOLOR_K && privdata->used_inks & (CANON_INK_CMY_MASK | CANON_INK_cmy_MASK)){ */ /* color channels */
5694 }else if(channel != STP_ECOLOR_K && privdata->used_inks & CANON_INK_CMY_MASK){ /* color channels */
5695 for(i=0;i<privdata->mode->num_inks;i++){
5696 const canon_inkset_t* ink = &privdata->mode->inks[i];
5697 stp_dprintf(STP_DBG_CANON, v, "canon_setup_channels: loop non-K inks %d\n", i);
5698 /*if(ink->channel == primary[channel] || ((privdata->used_inks & (CANON_INK_CcMmYyKk_MASK | CANON_INK_cmy_MASK)) && (ink->channel == secondary[channel]))) {*/
5699 if(ink->channel == primary[channel] || ((privdata->used_inks & (CANON_INK_CcMmYyKk_MASK|CANON_INK_CMY_MASK)) && (ink->channel == secondary[channel]))) {
5700 /* Gernot: see if this works: use the masks that includes secondary channels */
5701 /* if(ink->channel == primary[channel] || ((privdata->used_inks & CANON_INK_CMYKk_MASK ) && (ink->channel == secondary[channel]))) {*/
5702 subchannel += canon_setup_channel(v,privdata,channel,subchannel,ink,&shades);
5703 stp_dprintf(STP_DBG_CANON, v, "canon_setup_channels: adding subchannel\n");
5704 }
5705 else {
5706 stp_dprintf(STP_DBG_CANON, v, "canon_setup_channels: not creating subchannel\n");
5707 }
5708 }
5709 }
5710
5711 /* set inks and density */
5712 if(shades){
5713 stp_dither_set_inks_full(v,channel, subchannel, shades, 1.0, ink_darkness[channel]);
5714 for(i=0;i<subchannel;i++){
5715 double density = get_double_param(v, primary_density_control[channel]) * get_double_param(v, "Density");
5716 stp_dprintf(STP_DBG_CANON, v, "canon_setup_channels: loop subchannels for shades %d\n", i);
5717 if(i > 0 && secondary_density_control[channel])
5718 density *= get_double_param(v, secondary_density_control[channel]);
5719 stp_channel_set_density_adjustment(v,channel,subchannel,density);
5720 }
5721 if (is_black_channel)
5722 stp_channel_set_black_channel(v, channel);
5723 stp_free(shades);
5724 }
5725 }
5726 }
5727
5728
5729
5730
5731
5732
5733
5734 /* FIXME move this to printercaps, and/or Esc (p command */
5735 #define CANON_CD_X 176
5736 #define CANON_CD_Y 405
5737
5738 static void setup_page(stp_vars_t* v,canon_privdata_t* privdata){
5739 const char *media_source = stp_get_string_parameter(v, "InputSlot");
5740 const char *cd_type = stp_get_string_parameter(v, "PageSize");
5741 int print_cd = (media_source && (!strcmp(media_source, "CD")));
5742 stp_dimension_t page_left,
5743 page_top,
5744 page_right,
5745 page_bottom;
5746 int hub_size = 0;
5747
5748 #if 0
5749 /* needed in workaround for Oufuku Hagaki */
5750 const stp_papersize_t *pp = stpi_get_papersize_by_size(v,
5751 stp_get_page_height(v),
5752 stp_get_page_width(v));
5753
5754 if (pp)
5755 {
5756 const char *name = pp->name;
5757 if (!strcmp(name,"w420h567")) {
5758 /* workaround for Oufuku Hagaki: wrong orientation */
5759 privdata->page_width = stp_get_width(v);
5760 privdata->page_height = stp_get_height(v);
5761 stp_set_page_width(v, privdata->page_height);
5762 stp_set_page_height(v, privdata->page_width);
5763 }
5764 }
5765 #endif
5766
5767 if (cd_type && (strcmp(cd_type, "CDCustom") == 0 ))
5768 {
5769 int outer_diameter = stp_get_dimension_parameter(v, "CDOuterDiameter");
5770 stp_set_page_width(v, outer_diameter);
5771 stp_set_page_height(v, outer_diameter);
5772 stp_set_width(v, outer_diameter);
5773 stp_set_height(v, outer_diameter);
5774 hub_size = stp_get_dimension_parameter(v, "CDInnerDiameter");
5775 }
5776 else
5777 {
5778 const char *inner_radius_name = stp_get_string_parameter(v, "CDInnerRadius");
5779 hub_size = 43 * 10 * 72 / 254; /* 43 mm standard CD hub */
5780
5781 if (inner_radius_name && strcmp(inner_radius_name, "Small") == 0)
5782 hub_size = 16 * 10 * 72 / 254; /* 15 mm prints to the hole - play it
5783 safe and print 16 mm */
5784 }
5785
5786 privdata->top = stp_get_top(v);
5787 privdata->left = stp_get_left(v);
5788 privdata->out_width = stp_get_width(v); /* check Epson: page_true_width */
5789 privdata->out_height = stp_get_height(v); /* check Epson: page_true_height */
5790
5791 stp_dprintf(STP_DBG_CANON, v,"stp_get_width: privdata->out_width is %i\n",privdata->out_width);
5792 stp_dprintf(STP_DBG_CANON, v,"stp_get_height: privdata->out_height is %i\n",privdata->out_height);
5793
5794 /* Don't use full bleed mode if the paper itself has a margin */
5795 if (privdata->left > 0 || privdata->top > 0)
5796 stp_set_boolean_parameter(v, "FullBleed", 0);
5797
5798 internal_imageable_area(v, 0, 0, &page_left, &page_right,
5799 &page_bottom, &page_top);
5800 if (print_cd) {
5801 privdata->cd_inner_radius = hub_size / 2;
5802 privdata->cd_outer_radius = stp_get_width(v) / 2;
5803 privdata->left = CANON_CD_X - privdata->cd_outer_radius + stp_get_dimension_parameter(v, "CDXAdjustment");;
5804 privdata->top = CANON_CD_Y - privdata->cd_outer_radius + stp_get_dimension_parameter(v, "CDYAdjustment");
5805 privdata->page_width = privdata->left + privdata->out_width;
5806 privdata->page_height = privdata->top + privdata->out_height;
5807 } else {
5808 privdata->left -= page_left;
5809 privdata->top -= page_top; /* checked in Epson: matches */
5810 privdata->page_width = page_right - page_left; /* checked in Epson: matches */
5811 privdata->page_height = page_bottom - page_top; /* checked in Epson: matches */
5812 }
5813
5814 stp_dprintf(STP_DBG_CANON, v, "setup_page page_top = %f\n",page_top);
5815 stp_dprintf(STP_DBG_CANON, v, "setup_page page_bottom = %f\n",page_bottom);
5816 stp_dprintf(STP_DBG_CANON, v, "setup_page page_left = %f\n",page_left);
5817 stp_dprintf(STP_DBG_CANON, v, "setup_page page_right = %f\n",page_right);
5818 stp_dprintf(STP_DBG_CANON, v, "setup_page top = %i\n",privdata->top);
5819 stp_dprintf(STP_DBG_CANON, v, "setup_page left = %i\n",privdata->left);
5820 stp_dprintf(STP_DBG_CANON, v, "setup_page out_height = %i\n",privdata->out_height);
5821 stp_dprintf(STP_DBG_CANON, v, "setup_page page_height = %i\n",privdata->page_height);
5822 stp_dprintf(STP_DBG_CANON, v, "setup_page page_width = %i\n",privdata->page_width);
5823
5824 }
5825
5826
5827 /* combine all curve parameters in s and apply them */
5828 static void canon_set_curve_parameter(stp_vars_t *v,const char* type,stp_curve_compose_t comp,const char* s1,const char* s2,const char* s3){
5829 const char * s[3];
5830 size_t count = sizeof(s) / sizeof(s[0]);
5831 stp_curve_t *ret = NULL;
5832 unsigned int curve_count = 0;
5833 unsigned int i;
5834 const size_t piecewise_point_count = 384;
5835
5836 /* ignore settings from the printercaps if the user specified his own parameters */
5837 if(stp_check_curve_parameter(v,type, STP_PARAMETER_ACTIVE))
5838 return;
5839
5840 /* init parameter list (FIXME pass array directly???)*/
5841 s[0] = s1;
5842 s[1] = s2;
5843 s[2] = s3;
5844
5845 /* skip empty curves */
5846 for(i=0;i<count;i++){
5847 if(s[i])
5848 s[curve_count++] = s[i];
5849 }
5850
5851 /* combine curves */
5852 if(curve_count){
5853 for(i=0;i<curve_count;i++){
5854 stp_curve_t* t_tmp = stp_curve_create_from_string(s[i]);
5855 if(t_tmp){
5856 if(stp_curve_is_piecewise(t_tmp)){
5857 stp_curve_resample(t_tmp, piecewise_point_count);
5858 }
5859 if(!ret){
5860 ret = t_tmp;
5861 }else{
5862 stp_curve_t* t_comp = NULL;
5863 stp_curve_compose(&t_comp, ret, t_tmp, comp, -1);
5864 if(t_comp){
5865 stp_curve_destroy(ret);
5866 ret = t_comp;
5867 }
5868 stp_curve_destroy(t_tmp);
5869 }
5870 }
5871 }
5872 }
5873
5874 /* apply result */
5875 if(ret){
5876 stp_set_curve_parameter(v, type, ret);
5877 stp_curve_destroy(ret);
5878 }
5879 }
5880
5881 /*
5882 * 'canon_print()' - Print an image to a CANON printer.
5883 */
5884 static int
5885 canon_do_print(stp_vars_t *v, stp_image_t *image)
5886 {
5887 int i;
5888 int status = 1;
5889 const char *media_source = stp_get_string_parameter(v, "InputSlot");
5890 const char *ink_type = stp_get_string_parameter(v, "InkType");
5891 const char *duplex_mode = stp_get_string_parameter(v, "Duplex");
5892 int page_number = stp_get_int_parameter(v, "PageNumber");
5893 const canon_cap_t * caps = canon_get_model_capabilities(v);
5894 const canon_modeuselist_t* mlist = caps->modeuselist;
5895 #if 0
5896 const canon_modeuse_t* muse;
5897 #endif
5898 /* int monocheck = 0;
5899 int colcheck = 0; */
5900 int x,y; /* Looping vars */
5901 canon_privdata_t privdata;
5902 int errdiv, /* Error dividend */
5903 errmod, /* Error modulus */
5904 errval, /* Current error value */
5905 errline, /* Current raster line */
5906 errlast; /* Last raster line loaded */
5907 #if 0
5908 out_channels; /* Output bytes per pixel */
5909 #endif
5910 unsigned zero_mask;
5911 int print_cd = (media_source && (!strcmp(media_source, "CD")));
5912 int image_height;
5913 #if 0
5914 int image_width;
5915 #endif
5916 double k_upper, k_lower;
5917 unsigned char *cd_mask = NULL;
5918 double outer_r_sq = 0;
5919 double inner_r_sq = 0;
5920 unsigned char* weave_cols[4] ; /* TODO clean up weaving code to be more generic */
5921
5922 stp_dprintf(STP_DBG_CANON, v, "Entering canon_do_print\n");
5923
5924 if (!stp_verify(v))
5925 {
5926 stp_eprintf(v, "Print options not verified; cannot print.\n");
5927 return 0;
5928 }
5929 /*
5930 * Setup a read-only pixel region for the entire image...
5931 */
5932
5933 stp_image_init(image);
5934
5935
5936 /* rotate even pages for DuplexNoTumble */
5937 if((page_number & 1) && duplex_mode && !strcmp(duplex_mode,"DuplexNoTumble"))
5938 image = stpi_buffer_image(image,BUFFER_FLAG_FLIP_X | BUFFER_FLAG_FLIP_Y);
5939
5940 memset(&privdata,0,sizeof(canon_privdata_t));
5941 privdata.caps = caps;
5942
5943 /* find the wanted media type */
5944 /* - media type has priority
5945 - then we select source
5946 - then inkset (cartridge selection)
5947 - then we select duplex
5948 - after that we compare if mode is compatible with media
5949 - if not, we replace it using closest quality setting
5950 - then we decide on printhead colors based on actual mode to use
5951 */
5952
5953 privdata.pt = get_media_type(caps,stp_get_string_parameter(v, "MediaType"));
5954 privdata.slot = canon_source_type(media_source,caps);
5955
5956 /* --- make adjustment to InkSet based on Media --- */
5957
5958 /* cartridge selection if any: default is Both---but should change to NULL if CANON_CAP_T is not available */
5959 /* check if InkSet chosen is possible for this Media */
5960 /* - if Black, check if modes for selected media have a black flag */
5961 /* else, set InkSet to "Both" for now */
5962
5963 /* scroll through modeuse list to find media */
5964 for(i=0;i<mlist->count;i++){
5965 if(!strcmp(privdata.pt->name,mlist->modeuses[i].name)){
5966 #if 0
5967 muse = &mlist->modeuses[i];
5968 #endif
5969 break;
5970 }
5971 }
5972
5973 if ( !strcmp(stp_get_string_parameter(v, "InkSet"),"Black")) {
5974 /* check if there is any mode for that media with K-only inktype */
5975 /* if not, change it to "Both" */
5976 /* NOTE: User cannot force monochrome printing here, since that would require changing the Color Model */
5977 if (!(mlist->modeuses[i].use_flags & INKSET_BLACK_SUPPORT)) {
5978 stp_set_string_parameter(v, "InkSet", "Both");
5979 }
5980 }
5981 /* Color-only */
5982 else if ( !strcmp(stp_get_string_parameter(v, "InkSet"),"Color") && (caps->features & CANON_CAP_T) ) {
5983 /* check if there is any mode for that media with no K in the inkset at all */
5984 /* if not, change it to "Both" */
5985 if (!(mlist->modeuses[i].use_flags & INKSET_COLOR_SUPPORT)) {
5986 stp_set_string_parameter(v, "InkSet", "Both");
5987 }
5988 }
5989 /* no restriction for "Both" (non-BJC) or "Color" (BJC) or "Photo" yet */
5990
5991 /* get InkSet after adjustment */
5992 privdata.ink_set = stp_get_string_parameter(v, "InkSet");
5993
5994 /* --- no current restrictions for Duplex setting --- */
5995
5996 /* in particular, we do not constrain duplex printing to certain media */
5997 privdata.duplex_str = duplex_mode;
5998
5999 /* --- make adjustment to InkType to comply with InkSet --- */
6000
6001 /* although InSet adjustment is pre-supposed, even if InkSet is not
6002 adjusted, the InkType adjustment will be validated against mode
6003 later */
6004 if (!strcmp(privdata.ink_set,"Black")) {
6005 if (strcmp(ink_type,"Gray")) {/* if ink_type is NOT set to Gray yet */
6006 stp_dprintf(STP_DBG_CANON, v, "canon_do_print: InkSet Black, so InkType set to Gray\n");
6007 stp_set_string_parameter(v, "InkType", "Gray");
6008 }
6009 } /* Color-only */
6010 else if ( !strcmp(privdata.ink_set,"Color") && (caps->features & CANON_CAP_T) ) {
6011 if (strcmp(ink_type,"RGB")) {/* if ink_type is NOT set to RGB (CMY) yet */
6012 stp_dprintf(STP_DBG_CANON, v, "canon_do_print: InkSet Color, so InkType changed to RGB (CMY)\n");
6013 stp_set_string_parameter(v, "InkType", "RGB");
6014 }
6015 } /* no restriction for InkSet set to "Both" or "Photo" */
6016
6017 /* --- make adjustments to mode --- */
6018
6019 /* find the wanted print mode: NULL if not yet set */
6020 stp_dprintf(STP_DBG_CANON, v, "canon_do_print: calling canon_get_current_mode\n");
6021 privdata.mode = canon_get_current_mode(v);
6022
6023 if(!privdata.mode) {
6024 privdata.mode = &caps->modelist->modes[caps->modelist->default_mode];
6025 }
6026
6027 /* then call get_current_mode again to sort out the correct matching of parameters and mode selection */
6028
6029 stp_dprintf(STP_DBG_CANON, v, "canon_do_print: calling canon_check_current_mode\n");
6030
6031 privdata.mode = canon_check_current_mode(v);
6032
6033 /* --- completed all adjustments: options should be consistent --- */
6034
6035 /* set quality */
6036 privdata.quality = privdata.mode->quality;
6037
6038
6039 /* force grayscale if image is grayscale
6040 * or single black cartridge installed
6041 */
6042 privdata.used_inks = canon_printhead_colors(v);
6043 if (privdata.used_inks == CANON_INK_K)
6044 stp_set_string_parameter(v, "PrintingMode", "BW");
6045 else
6046 stp_set_string_parameter(v, "PrintingMode", "Color");
6047
6048 setup_page(v,&privdata);
6049
6050 image_height = stp_image_height(image);
6051
6052 #if 0
6053 image_width = stp_image_width(image);
6054 #endif
6055
6056 privdata.is_first_page = (page_number == 0);
6057
6058 /*
6059 * Convert image size to printer resolution...
6060 */
6061 #if 0
6062 stp_dprintf(STP_DBG_CANON, v,"canon_do_print: unused image_width is %i pts(?)\n",image_width);
6063 #endif
6064 stp_dprintf(STP_DBG_CANON, v,"canon_do_print: privdata.out_width is %i pts\n",privdata.out_width);
6065 stp_dprintf(STP_DBG_CANON, v,"canon_do_print: privdata.out_height is %i pts\n",privdata.out_height);
6066 stp_dprintf(STP_DBG_CANON, v,"canon_do_print: privdata.left is %i pts\n",privdata.left);
6067
6068 privdata.out_width = privdata.mode->xdpi * privdata.out_width / 72;
6069 privdata.out_height = privdata.mode->ydpi * privdata.out_height / 72;
6070 privdata.left = privdata.mode->xdpi * privdata.left / 72;
6071
6072 stp_dprintf(STP_DBG_CANON, v,"canon_do_print: privdata.out_width is %i dots\n",privdata.out_width);
6073 stp_dprintf(STP_DBG_CANON, v,"canon_do_print: privdata.out_height is %i dots\n",privdata.out_height);
6074 stp_dprintf(STP_DBG_CANON, v,"canon_do_print: privdata.left is %i dots\n",privdata.left);
6075
6076 stp_dprintf(STP_DBG_CANON, v,"density is %f\n",
6077 stp_get_float_parameter(v, "Density"));
6078
6079 /*
6080 * Compute the LUT. For now, it's 8 bit, but that may eventually
6081 * sometimes change.
6082 */
6083
6084 if (!stp_check_float_parameter(v, "Density", STP_PARAMETER_DEFAULTED))
6085 {
6086 stp_set_float_parameter_active(v, "Density", STP_PARAMETER_ACTIVE);
6087 stp_set_float_parameter(v, "Density", 1.0);
6088 }
6089
6090 stp_scale_float_parameter(v, "Density", privdata.pt->base_density);
6091 stp_scale_float_parameter(v, "Density",privdata.mode->density);
6092
6093 if (stp_get_float_parameter(v, "Density") > 1.0)
6094 stp_set_float_parameter(v, "Density", 1.0);
6095
6096 if (privdata.used_inks == CANON_INK_K)
6097 stp_scale_float_parameter(v, "Gamma", 1.25);
6098 stp_scale_float_parameter( v, "Gamma", privdata.mode->gamma );
6099
6100 stp_dprintf(STP_DBG_CANON, v,"density is %f\n",
6101 stp_get_float_parameter(v, "Density"));
6102
6103 if(privdata.used_inks & CANON_INK_CMYK_MASK)
6104 stp_set_string_parameter(v, "STPIOutputType", "KCMY");
6105 else if(privdata.used_inks & CANON_INK_CMY_MASK)
6106 stp_set_string_parameter(v, "STPIOutputType", "CMY");
6107 /* Gernot: addition */
6108 /*else if(privdata.used_inks & CANON_INK_cmy_MASK)
6109 stp_set_string_parameter(v, "STPIOutputType", "cmy");*/
6110 else
6111 stp_set_string_parameter(v, "STPIOutputType", "Grayscale");
6112
6113 privdata.length = (privdata.out_width + 7) / 8;
6114
6115 stp_dprintf(STP_DBG_CANON, v,"privdata.length is %i\n",privdata.length);
6116 stp_dprintf(STP_DBG_CANON, v,"canon_do_print: privdata.num_channels is %i\n",privdata.num_channels);
6117
6118 stp_dither_init(v, image, privdata.out_width, privdata.mode->xdpi, privdata.mode->ydpi);
6119
6120
6121 stp_dprintf(STP_DBG_CANON, v,"privdata.out_width is %i (after stp_dither_init)\n",privdata.out_width);
6122 stp_dprintf(STP_DBG_CANON, v,"privdata.length is %i (after stp_dither_init)\n",privdata.length);
6123 stp_dprintf(STP_DBG_CANON, v,"canon_do_print: privdata.num_channels is %i (after stp_dither_init)\n",privdata.num_channels);
6124
6125 canon_setup_channels(v,&privdata);
6126
6127 stp_dprintf(STP_DBG_CANON, v,"privdata.out_width is %i (after canon_setup_channels)\n",privdata.out_width);
6128 stp_dprintf(STP_DBG_CANON, v,"privdata.length is %i (after canon_setup_channels)\n",privdata.length);
6129 stp_dprintf(STP_DBG_CANON, v,"canon_do_print: privdata.num_channels is %i (after canon_setup_channels)\n",privdata.num_channels);
6130
6131 stp_dprintf(STP_DBG_CANON, v,
6132 "canon: driver will use colors %s\n",privdata.channel_order);
6133
6134 /* Allocate compression buffer */
6135 if(caps->features & CANON_CAP_I)
6136 /*privdata.comp_buf = stp_zalloc(privdata.buf_length_max * 2 * caps->raster_lines_per_block * privdata.num_channels); */
6137 privdata.comp_buf = stp_zalloc(stp_compute_tiff_linewidth(v, privdata.buf_length_max * 2 * privdata.mode->raster_lines_per_block * privdata.num_channels)); /* for multiraster we need to buffer 8 lines for every color */
6138 else
6139 privdata.comp_buf = stp_zalloc(stp_compute_tiff_linewidth(v, privdata.buf_length_max * 2));
6140 /* Allocate fold buffer */
6141 privdata.fold_buf = stp_zalloc(stp_compute_tiff_linewidth(v, privdata.buf_length_max));
6142
6143
6144
6145 /*
6146 * Output the page...
6147 */
6148
6149 /* FIXME this is probably broken, kept for backward compatibility */
6150 if(privdata.num_channels > 4){
6151 k_lower = 0.4 / privdata.channels[4].props->bits + .1;
6152 }else
6153 k_lower = 0.25;
6154
6155 k_lower *= privdata.pt->k_lower_scale;
6156 k_upper = privdata.pt->k_upper;
6157
6158 if (!stp_check_float_parameter(v, "GCRLower", STP_PARAMETER_ACTIVE))
6159 stp_set_default_float_parameter(v, "GCRLower", k_lower);
6160 if (!stp_check_float_parameter(v, "GCRUpper", STP_PARAMETER_ACTIVE))
6161 stp_set_default_float_parameter(v, "GCRUpper", k_upper);
6162
6163
6164 /* init the printer */
6165 canon_init_printer(v, &privdata);
6166
6167 /* initialize weaving for S200 for resolutions > 360dpi */
6168 if (privdata.mode->flags & MODE_FLAG_WEAVE)
6169 {
6170 char weave_color_order[] = "KCMY";
6171
6172 privdata.stepper_ydpi = 720;
6173 privdata.nozzle_ydpi = 360;
6174 if (privdata.mode->xdpi == 2880)
6175 privdata.physical_xdpi = 2880;
6176 else
6177 privdata.physical_xdpi = 720;
6178
6179 stp_dprintf(STP_DBG_CANON, v,"canon: adjust leftskip: old=%d,\n", privdata.left);
6180 privdata.left = (int)( (float)privdata.left * (float)privdata.physical_xdpi / (float)privdata.mode->xdpi ); /* adjust left margin */
6181 stp_dprintf(STP_DBG_CANON, v,"canon: adjust leftskip: new=%d,\n", privdata.left);
6182
6183 privdata.ncolors = 4;
6184 privdata.head_offset = stp_zalloc(sizeof(int) * privdata.ncolors);
6185 memset(privdata.head_offset, 0, sizeof(*privdata.head_offset));
6186
6187 if ( privdata.used_inks == CANON_INK_K )
6188 privdata.nozzles = 64; /* black nozzles */
6189 else
6190 privdata.nozzles = 24; /* color nozzles */
6191 if ( privdata.used_inks == CANON_INK_K )
6192 {
6193 privdata.ncolors = 1;
6194 privdata.head_offset[0] = 0; /* K starts at 0 */
6195 privdata.head_offset[1] = 0 ;/* how far C starts after K */
6196 privdata.head_offset[2] = 0;/* how far M starts after K */
6197 privdata.head_offset[3] = 0;/* how far Y starts after K */
6198 privdata.top += 11;
6199 }
6200 else if ( privdata.used_inks == CANON_INK_CMYK )
6201 {
6202 privdata.head_offset[0] = 0; /* K starts at 0 */
6203 privdata.head_offset[1] = 144 ;/* how far C starts after K */
6204 privdata.head_offset[2] = 144 + 64;/* how far M starts after K */
6205 privdata.head_offset[3] = 144 + 64 + 64;/* how far Y starts after K */
6206 privdata.top += 5;
6207 }
6208 else /* colormode == CMY */
6209 {
6210 privdata.ncolors = 3;
6211 privdata.head_offset[0] = 0; /* K starts at 0 */
6212 privdata.head_offset[1] = 0 ;/* how far C starts after K */
6213 privdata.head_offset[2] = 64;/* how far M starts after K */
6214 privdata.head_offset[3] = 128;/* how far Y starts after K */
6215 privdata.top += 18;
6216 }
6217
6218 privdata.nozzle_separation = privdata.stepper_ydpi / privdata.nozzle_ydpi;
6219 privdata.horizontal_passes = privdata.mode->xdpi / privdata.physical_xdpi;
6220 privdata.vertical_passes = 1;
6221 privdata.vertical_oversample = privdata.mode->ydpi / privdata.stepper_ydpi;
6222 privdata.bidirectional = 1; /* 1: bidirectional; 0: unidirectional printing */
6223 privdata.direction = 1;
6224 stp_allocate_component_data(v, "Driver", NULL, NULL, &privdata);
6225 stp_dprintf(STP_DBG_CANON, v,"canon: initializing weaving: nozzles=%d, nozzle_separation=%d,\n"
6226 "horizontal_passes=%d, vertical_passes=%d,vertical_oversample=%d,\n"
6227 "ncolors=%d, out_width=%d, out_height=%d\n"
6228 "weave_top=%d, weave_page_height=%d \n"
6229 "head_offset=[%d,%d,%d,%d] \n",
6230 privdata.nozzles, privdata.nozzle_separation,
6231 privdata.horizontal_passes, privdata.vertical_passes,
6232 privdata.vertical_oversample, privdata.ncolors,
6233 privdata.out_width, privdata.out_height,
6234 privdata.top * privdata.stepper_ydpi / 72, privdata.page_height * privdata.stepper_ydpi / 72,
6235 privdata.head_offset[0],privdata.head_offset[1],
6236 privdata.head_offset[2],privdata.head_offset[3]);
6237
6238 stp_initialize_weave(v, privdata.nozzles, privdata.nozzle_separation,
6239 privdata.horizontal_passes, privdata.vertical_passes,
6240 privdata.vertical_oversample, privdata.ncolors,
6241 1,
6242 privdata.out_width, privdata.out_height,
6243 privdata.top * privdata.stepper_ydpi / 72,
6244 privdata.page_height * privdata.stepper_ydpi / 72,
6245 privdata.head_offset,
6246 STP_WEAVE_ZIGZAG,
6247 canon_flush_pass,
6248 stp_fill_uncompressed,
6249 stp_pack_uncompressed,
6250 stp_compute_tiff_linewidth);
6251 privdata.last_pass_offset = 0;
6252
6253 if (stp_get_debug_level() & STP_DBG_CANON) {
6254 for(x=0;x<4;x++){
6255 stp_dprintf(STP_DBG_CANON, v, "DEBUG print-canon weave: weave_color_order[%d]: %u\n",
6256 x, (unsigned int)weave_color_order[x]);
6257 }
6258 for(x=0;x<privdata.num_channels;x++){
6259 stp_dprintf(STP_DBG_CANON, v, "DEBUG print-canon weave: channel_order[%d]: %u\n",
6260 x, (unsigned int)privdata.channel_order[x]);
6261 }
6262 }
6263
6264 for(i=0;i<4;i++){/* need all 4 channels for weave_cols, but not for privdata.num_channels! */
6265 /* see if it helps to initialize to zero */
6266 weave_cols[i] = 0;
6267 privdata.weave_bits[i] = 0;
6268
6269 for(x=0;x<privdata.num_channels;x++){
6270 if(weave_color_order[i] == privdata.channel_order[x]){
6271 weave_cols[i] = privdata.channels[x].buf;
6272 privdata.weave_bits[i] = privdata.channels[x].props->bits;
6273 stp_dprintf(STP_DBG_CANON, v, "DEBUG print-canon weave: set weave_cols[%d] to privdata.channels[%d].buf\n",
6274 i, x);
6275 }
6276 }
6277 }
6278 }
6279
6280
6281 errdiv = image_height / privdata.out_height;
6282 errmod = image_height % privdata.out_height;
6283 errval = 0;
6284 errlast = -1;
6285 errline = 0;
6286
6287 /* set Hue, Lum and Sat Maps */
6288 canon_set_curve_parameter(v,"HueMap",STP_CURVE_COMPOSE_ADD,caps->hue_adjustment,privdata.pt->hue_adjustment,privdata.mode->hue_adjustment);
6289 canon_set_curve_parameter(v,"LumMap",STP_CURVE_COMPOSE_MULTIPLY,caps->lum_adjustment,privdata.pt->lum_adjustment,privdata.mode->lum_adjustment);
6290 canon_set_curve_parameter(v,"SatMap",STP_CURVE_COMPOSE_MULTIPLY,caps->sat_adjustment,privdata.pt->sat_adjustment,privdata.mode->sat_adjustment);
6291
6292 #if 0
6293 out_channels = stp_color_init(v, image, 65536);
6294 #endif
6295 (void) stp_color_init(v, image, 65536);
6296 stp_allocate_component_data(v, "Driver", NULL, NULL, &privdata);
6297
6298 privdata.emptylines = 0;
6299 if (print_cd) {
6300 cd_mask = stp_malloc(1 + (privdata.out_width + 7) / 8);
6301 outer_r_sq = (double)privdata.cd_outer_radius * (double)privdata.cd_outer_radius;
6302 inner_r_sq = (double)privdata.cd_inner_radius * (double)privdata.cd_inner_radius;
6303 }
6304 for (y = 0; y < privdata.out_height; y ++)
6305 {
6306 int duplicate_line = 1;
6307
6308 if (errline != errlast)
6309 {
6310 errlast = errline;
6311 duplicate_line = 0;
6312 if (stp_color_get_row(v, image, errline, &zero_mask))
6313 {
6314 status = 2;
6315 break;
6316 }
6317 }
6318 if (print_cd)
6319 {
6320 int x_center = privdata.cd_outer_radius * privdata.mode->xdpi / 72;
6321 int y_distance_from_center =
6322 privdata.cd_outer_radius - (y * 72 / privdata.mode->ydpi);
6323 if (y_distance_from_center < 0)
6324 y_distance_from_center = -y_distance_from_center;
6325 memset(cd_mask, 0, (privdata.out_width + 7) / 8);
6326 if (y_distance_from_center < privdata.cd_outer_radius)
6327 {
6328 double y_sq = (double) y_distance_from_center *
6329 (double) y_distance_from_center;
6330 int x_where = sqrt(outer_r_sq - y_sq) + .5;
6331 int scaled_x_where = x_where * privdata.mode->xdpi / 72;
6332 set_mask(cd_mask, x_center, scaled_x_where,
6333 privdata.out_width, 1, 0);
6334 if (y_distance_from_center < privdata.cd_inner_radius)
6335 {
6336 x_where = sqrt(inner_r_sq - y_sq) + .5;
6337 scaled_x_where = x_where * privdata.mode->ydpi / 72;
6338 set_mask(cd_mask, x_center, scaled_x_where,
6339 privdata.out_width, 1, 1);
6340 }
6341 }
6342 }
6343 stp_dither(v, y, duplicate_line, zero_mask, cd_mask);
6344 if ( privdata.mode->flags & MODE_FLAG_WEAVE )
6345 stp_write_weave(v, weave_cols);
6346 else if ( caps->features & CANON_CAP_I)
6347 canon_write_multiraster(v,&privdata,y);
6348 else
6349 canon_printfunc(v);
6350 errval += errmod;
6351 errline += errdiv;
6352 if (errval >= privdata.out_height)
6353 {
6354 errval -= privdata.out_height;
6355 errline ++;
6356 }
6357 }
6358
6359 if ( privdata.mode->flags & MODE_FLAG_WEAVE )
6360 {
6361 stp_flush_all(v);
6362 canon_advance_paper(v, 5);
6363 }
6364 else
6365 {
6366
6367 /*
6368 * Flush delayed buffers...
6369 */
6370
6371 if (privdata.delay_max) {
6372 stp_dprintf(STP_DBG_CANON, v,"\ncanon: flushing %d possibly delayed buffers\n",
6373 privdata.delay_max);
6374 for (y= 0; y<privdata.delay_max; y++) {
6375
6376 canon_write_line(v);
6377 for (i = 0; i < privdata.num_channels; i++)
6378 canon_advance_buffer(privdata.channels[i].buf, privdata.length,
6379 privdata.channels[i].delay);
6380 }
6381 }
6382 }
6383 stp_image_conclude(image);
6384
6385 /*
6386 * Cleanup...
6387 */
6388
6389 stp_free(privdata.fold_buf);
6390 stp_free(privdata.comp_buf);
6391
6392 if(cd_mask)
6393 stp_free(cd_mask);
6394
6395
6396 canon_deinit_printer(v, &privdata);
6397 /* canon_end_job does not get called for jobmode automatically */
6398 if(!stp_get_string_parameter(v, "JobMode") ||
6399 strcmp(stp_get_string_parameter(v, "JobMode"), "Page") == 0){
6400 canon_end_job(v,image);
6401 }
6402
6403 for(i=0;i< privdata.num_channels;i++)
6404 if(privdata.channels[i].buf)
6405 stp_free(privdata.channels[i].buf);
6406 if(privdata.channels)
6407 stp_free(privdata.channels);
6408
6409 stp_free(privdata.channel_order);
6410 if (privdata.head_offset)
6411 stp_free(privdata.head_offset);
6412
6413
6414 return status;
6415 }
6416
6417 static int
6418 canon_print(const stp_vars_t *v, stp_image_t *image)
6419 {
6420 int status;
6421 stp_vars_t *nv = stp_vars_create_copy(v);
6422 status = canon_do_print(nv, image);
6423 stp_vars_destroy(nv);
6424 return status;
6425 }
6426
6427 static const stp_printfuncs_t print_canon_printfuncs =
6428 {
6429 canon_list_parameters,
6430 canon_parameters,
6431 stp_default_media_size,
6432 canon_imageable_area,
6433 canon_maximum_imageable_area,
6434 canon_limit,
6435 canon_print,
6436 canon_describe_resolution,
6437 canon_describe_output,
6438 stp_verify_printer_params,
6439 canon_start_job,
6440 canon_end_job,
6441 NULL,
6442 stpi_standard_describe_papersize
6443 };
6444
6445 static void
6446 canon_shift_buffer(unsigned char *line,int length,int bits)
6447 {
6448 int i,j;
6449 for (j=0; j<bits; j++) {
6450 for (i=length-1; i>0; i--) {
6451 line[i]= (line[i] >> 1) | (line[i-1] << 7);
6452 }
6453 line[0] = line[0] >> 1;
6454 }
6455 }
6456
6457
6458 /* fold, apply the necessary compression, pack tiff and return the compressed length */
6459 static int canon_compress(stp_vars_t *v, canon_privdata_t *pd, unsigned char* line,int length,int offset,unsigned char* comp_buf,int bits, int ink_flags)
6460 {
6461 unsigned char
6462 *in_ptr= line,
6463 *comp_ptr, *comp_data;
6464 int offset2,bitoffset;
6465
6466 /* Don't send blank lines... */
6467
6468 if (line[0] == 0 && memcmp(line, line + 1, (length * bits) - 1) == 0)
6469 return 0;
6470
6471 /* if no modulation: 1 bit per pixel */
6472
6473 offset2 = offset / 8;
6474 bitoffset = offset % 8;
6475
6476 /* fold lsb/msb pairs if drop modulation is active */
6477
6478 if (bits==2) {
6479 int pixels_per_byte = 4;
6480 if(ink_flags & INK_FLAG_5pixel_in_1byte)
6481 pixels_per_byte = 5;
6482
6483 stp_fold(line,length,pd->fold_buf);
6484 in_ptr = pd->fold_buf;
6485 length = (length*8/4); /* 4 pixels in 8bit */
6486 /* calculate the number of compressed bytes that can be sent directly */
6487 offset2 = offset / pixels_per_byte;
6488 /* calculate the number of (uncompressed) bits that have to be added to the raster data */
6489 bitoffset = (offset % pixels_per_byte) * 2;
6490 }
6491 else if (bits==3) {
6492 stp_fold_3bit_323(line,length,pd->fold_buf);
6493 in_ptr = pd->fold_buf;
6494 length = (length*8)/3;
6495 offset2 = offset/3;
6496 #if 0
6497 switch(offset%3){
6498 case 0: offset= (offset/3)*8; break;
6499 case 1: offset= (offset/3)*8/*+3 CAREFUL! CANNOT SHIFT _AFTER_ RECODING!!*/; break;
6500 case 2: offset= (offset/3)*8/*+5 CAREFUL! CANNOT SHIFT _AFTER_ RECODING!!*/; break;
6501 }
6502 #endif
6503 bitoffset= 0;
6504 }
6505 else if (bits==4) {
6506 int pixels_per_byte = 2;
6507 if(ink_flags & INK_FLAG_3pixel5level_in_1byte)
6508 pixels_per_byte = 3;
6509 else if(ink_flags & INK_FLAG_3pixel6level_in_1byte)
6510 pixels_per_byte = 3;
6511
6512 stp_fold_4bit(line,length,pd->fold_buf);
6513 in_ptr = pd->fold_buf;
6514 length = (length*8)/2; /* 2 pixels in 8 bits */
6515 /* calculate the number of compressed bytes that can be sent directly */
6516 offset2 = offset / pixels_per_byte;
6517 /* calculate the number of (uncompressed) bits that have to be added to the raster data */
6518 bitoffset = (offset % pixels_per_byte) * 2; /* not sure what this value means */
6519 }
6520 else if (bits==8) {
6521 stp_fold_8bit(line,length,pd->fold_buf);
6522 in_ptr= pd->fold_buf;
6523 length = length*8; /* 1 pixel per 8 bits */
6524 offset2 = offset;
6525 bitoffset = 0;
6526 }
6527
6528 /* pack left border rounded to multiples of 8 dots */
6529
6530 comp_data= comp_buf;
6531
6532 while (offset2>0) {
6533 unsigned char toffset = offset2 > 127 ? 127 : offset2;
6534 comp_data[0] = 1 - toffset;
6535 comp_data[1] = 0;
6536 comp_data += 2;
6537 offset2-= toffset;
6538 }
6539 if (bitoffset) {
6540 if (bitoffset<8)
6541 {
6542 in_ptr[ length++ ] = 0;
6543 canon_shift_buffer(in_ptr,length,bitoffset);
6544 }
6545 else if (bitoffset == 8)
6546 {
6547 memmove(in_ptr + 1,in_ptr,length++);
6548 in_ptr[0] = 0;
6549 }
6550 else
6551 stp_dprintf(STP_DBG_CANON, v,"SEVERE BUG IN print-canon.c::canon_write() "
6552 "bitoffset=%d!!\n",bitoffset);
6553 }
6554
6555 if(ink_flags & INK_FLAG_5pixel_in_1byte)
6556 length = pack_pixels(in_ptr,length);
6557 else if(ink_flags & INK_FLAG_3pixel5level_in_1byte)
6558 length = pack_pixels3_5(in_ptr,length);
6559 else if(ink_flags & INK_FLAG_3pixel6level_in_1byte)
6560 length = pack_pixels3_6(in_ptr,length);
6561
6562
6563 stp_pack_tiff(v, in_ptr, length, comp_data, &comp_ptr, NULL, NULL);
6564
6565 return comp_ptr - comp_buf;
6566 }
6567
6568 /*
6569 * 'canon_write()' - Send graphics using TIFF packbits compression.
6570 */
6571
6572 static int
6573 canon_write(stp_vars_t *v, /* I - Print file or command */
6574 canon_privdata_t *pd, /* privdata */
6575 const canon_cap_t * caps, /* I - Printer model */
6576 unsigned char *line, /* I - Output bitmap data */
6577 int length, /* I - Length of bitmap data */
6578 int coloridx, /* I - Which color */
6579 int *empty, /* IO- Preceding empty lines */
6580 int width, /* I - Printed width */
6581 int offset, /* I - Offset from left side */
6582 int bits,
6583 int ink_flags)
6584 {
6585 unsigned char color;
6586 int newlength = canon_compress(v,pd,line,length,offset,pd->comp_buf,bits,ink_flags);
6587 (void)caps;
6588 (void)width;
6589
6590 if(!newlength)
6591 return 0;
6592 /* send packed empty lines if any */
6593
6594 if (*empty) {
6595 stp_zfwrite("\033\050\145\002\000", 5, 1, v);
6596 stp_put16_be(*empty, v);
6597 *empty= 0;
6598 }
6599
6600 /* Send a line of raster graphics... */
6601
6602 stp_zfwrite("\033\050\101", 3, 1, v);
6603 stp_put16_le(newlength + 1, v);
6604 color= "CMYKcmyk"[coloridx];
6605 if (!color) color= 'K';
6606 stp_putc(color,v);
6607 stp_zfwrite((const char *)pd->comp_buf, newlength, 1, v);
6608 stp_putc('\015', v);
6609 return 1;
6610 }
6611
6612
6613 static void
6614 canon_write_line(stp_vars_t *v)
6615 {
6616 canon_privdata_t *pd =
6617 (canon_privdata_t *) stp_get_component_data(v, "Driver");
6618 char write_sequence[] = "KYMCymck";
6619 static const int write_number[] = { 3, 2, 1, 0, 6, 5, 4, 7 }; /* KYMCymc */
6620 unsigned int i;
6621 int written= 0;
6622 for (i = 0; i < strlen(write_sequence) ; i++)
6623 {
6624 int x;
6625 const canon_channel_t* channel=NULL;
6626 int num = write_number[i];
6627
6628 /* TODO optimize => move reorder code to do_print */
6629 for(x=0;x < pd->num_channels; x++){
6630 if(pd->channels[x].name == write_sequence[i]){
6631 channel = &(pd->channels[x]);
6632 break;
6633 }
6634 }
6635 if(channel){
6636 written += canon_write(v, pd, pd->caps,
6637 channel->buf + channel->delay * pd->length /*buf_length[i]*/,
6638 pd->length, num,
6639 &(pd->emptylines), pd->out_width,
6640 pd->left, channel->props->bits, channel->props->flags);
6641 }
6642 }
6643 if (written)
6644 stp_zfwrite("\033\050\145\002\000\000\001", 7, 1, v);
6645 else
6646 pd->emptylines += 1;
6647 }
6648
6649
6650 /* write one multiraster block */
6651 static void canon_write_block(stp_vars_t* v,canon_privdata_t* pd,unsigned char* start, unsigned char* end)
6652 {
6653 unsigned int length = end - start;
6654 (void)pd;
6655
6656 if(!length)
6657 return;
6658 stp_zfwrite("\033(F", 3, 1, v);
6659 stp_put16_le(length, v);
6660 stp_zfwrite((const char *)start, length, 1, v);
6661 }
6662
6663
6664 static void canon_write_multiraster(stp_vars_t *v,canon_privdata_t* pd,int y){
6665 int i;
6666 /*int raster_lines_per_block = pd->caps->raster_lines_per_block;*/
6667 int raster_lines_per_block = pd->mode->raster_lines_per_block;
6668 unsigned int max_length = 2*pd->buf_length_max * raster_lines_per_block;
6669 /* a new raster block begins */
6670 if(!(y % raster_lines_per_block)){
6671 if(y != 0){
6672 /* write finished blocks */
6673 for(i=0;i<pd->num_channels;i++)
6674 canon_write_block(v,pd,pd->comp_buf + i * max_length,pd->channels[i].comp_buf_offset);
6675 }
6676 /* reset start offsets */
6677 for(i=0;i<pd->num_channels;i++)
6678 pd->channels[i].comp_buf_offset = pd->comp_buf + i * max_length;
6679 }
6680 /* compress lines and add them to the buffer */
6681 for(i=0;i<pd->num_channels;i++){
6682 pd->channels[i].comp_buf_offset += canon_compress(v,pd, pd->channels[i].buf,pd->length,pd->left,pd->channels[i].comp_buf_offset,pd->channels[i].props->bits, pd->channels[i].props->flags);
6683 *(pd->channels[i].comp_buf_offset) = 0x80; /* terminate the line */
6684 ++pd->channels[i].comp_buf_offset;
6685 }
6686 if(y == pd->out_height - 1){
6687 /* we just compressed our last line */
6688 if(pd->out_height % raster_lines_per_block){
6689 /* but our raster block is not finished yet */
6690 int missing = raster_lines_per_block - (pd->out_height % raster_lines_per_block); /* calculate missing lines */
6691 for(i=0;i<pd->num_channels;i++){
6692 /* add missing empty lines and write blocks */
6693 int x;
6694 for(x=0;x < missing ; x++){
6695 *(pd->channels[i].comp_buf_offset) = 0x80; /* terminate the line */
6696 ++pd->channels[i].comp_buf_offset;
6697 }
6698 canon_write_block(v,pd,pd->comp_buf + i * max_length,pd->channels[i].comp_buf_offset);
6699 }
6700 }
6701 }
6702 }
6703
6704
6705 static void
6706 canon_advance_paper(stp_vars_t *v, int advance)
6707 {
6708 if ( advance > 0 )
6709 {
6710 int a0, a1, a2, a3;
6711 stp_dprintf(STP_DBG_CANON, v," --advance paper %d\n", advance);
6712 a0 = advance & 0xff;
6713 a1 = (advance >> 8) & 0xff;
6714 a2 = (advance >> 16) & 0xff;
6715 a3 = (advance >> 24) & 0xff;
6716 stp_zprintf(v, "\033(e%c%c%c%c%c%c", 4, 0, a3, a2, a1, a0);
6717 }
6718 }
6719
6720 static void
6721 canon_flush_pass(stp_vars_t *v, int passno, int vertical_subpass)
6722 {
6723 stp_lineoff_t *lineoffs = stp_get_lineoffsets_by_pass(v, passno);
6724 stp_lineactive_t *lineactive = stp_get_lineactive_by_pass(v, passno);
6725 const stp_linebufs_t *bufs = stp_get_linebases_by_pass(v, passno);
6726 stp_pass_t *pass = stp_get_pass_by_pass(v, passno);
6727 stp_linecount_t *linecount = stp_get_linecount_by_pass(v, passno);
6728 canon_privdata_t *pd = (canon_privdata_t *) stp_get_component_data(v, "Driver");
6729 int papershift = (pass->logicalpassstart - pd->last_pass_offset);
6730
6731 int color, line, written = 0, linelength = 0, lines = 0;
6732 int idx[4]={3, 0, 1, 2}; /* color numbering is different between canon_write and weaving */
6733 (void)vertical_subpass;
6734
6735 stp_dprintf(STP_DBG_CANON, v,"canon_flush_pass: ----pass=%d,---- \n", passno);
6736 (pd->emptylines) = 0;
6737
6738 for ( color = 0; color < pd->ncolors; color++ ) /* find max. linecount */
6739 {
6740 if ( linecount[0].v[color] > lines )
6741 lines = linecount[0].v[color];
6742 }
6743
6744 for ( line = 0; line < lines; line++ ) /* go through each nozzle f that pass */
6745 {
6746 stp_dprintf(STP_DBG_CANON, v," --line=%d\n", line);
6747
6748 if ( written > 0 )
6749 canon_cmd(v,ESC28,0x65, 2, 0, 1); /* go to next nozzle*/
6750 /* if there was printed some data */
6751
6752 written = 0;
6753 for ( color = 0; color < pd->ncolors; color++ )
6754 {
6755 if ( line < linecount[0].v[color] ) /* try only existing lines */
6756 {
6757 if ( lineactive[0].v[color] > 0 )
6758 {
6759 linelength = lineoffs[0].v[color] / linecount[0].v[color];
6760 /* stp_dprintf(STP_DBG_CANON, v,"canon_flush_pass: linelength=%d, bufs[0].v[color]=%p,"
6761 "bufs[0].v[color]+line * linelength=%p, empty=%d \n", linelength, bufs[0].v[color],
6762 bufs[0].v[color] + line * linelength, (pd->emptylines));
6763 */
6764 if ( pass->logicalpassstart - pd->last_pass_offset > 0 )
6765 {
6766 canon_advance_paper(v, papershift);
6767 pd->last_pass_offset = pass->logicalpassstart;
6768 if (pd->bidirectional)
6769 {
6770 pd->direction = (pd->direction +1) & 1;
6771 canon_set_X72(v, pd->direction);
6772 stp_dprintf(STP_DBG_CANON, v," --set direction %d\n", pd->direction);
6773 }
6774 }
6775
6776 written += canon_write(v, pd, pd->caps,
6777 (unsigned char *)(bufs[0].v[color] + line * linelength),
6778 linelength, idx[color],
6779 &(pd->emptylines), pd->out_width,
6780 pd->left, pd->weave_bits[color],0);
6781 if (written) stp_dprintf(STP_DBG_CANON, v," --written color %d,\n", color);
6782
6783 }
6784 }
6785 }
6786
6787 if ( written == 0 ) /* count unused nozzles */
6788 (pd->emptylines) += 1;
6789 }
6790
6791 for ( color = 0; color < pd->ncolors; color++ )
6792 {
6793 lineoffs[0].v[color] = 0;
6794 linecount[0].v[color] = 0;
6795 }
6796 stp_dprintf(STP_DBG_CANON, v," --ended-- with empty=%d \n", (pd->emptylines));
6797 }
6798
6799 static stp_family_t print_canon_module_data =
6800 {
6801 &print_canon_printfuncs,
6802 NULL
6803 };
6804
6805
6806 static int
6807 print_canon_module_init(void)
6808 {
6809 return stpi_family_register(print_canon_module_data.printer_list);
6810 }
6811
6812
6813 static int
6814 print_canon_module_exit(void)
6815 {
6816 return stpi_family_unregister(print_canon_module_data.printer_list);
6817 }
6818
6819
6820 /* Module header */
6821 #define stp_module_version print_canon_LTX_stp_module_version
6822 #define stp_module_data print_canon_LTX_stp_module_data
6823
6824 stp_module_version_t stp_module_version = {0, 0};
6825
6826 stp_module_t stp_module_data =
6827 {
6828 "canon",
6829 VERSION,
6830 "Canon family driver",
6831 STP_MODULE_CLASS_FAMILY,
6832 NULL,
6833 print_canon_module_init,
6834 print_canon_module_exit,
6835 (void *) &print_canon_module_data
6836 };