~ubuntu-branches/ubuntu/quantal/gutenprint/quantal

« back to all changes in this revision

Viewing changes to src/main/print-canon.c

  • Committer: Package Import Robot
  • Author(s): Till Kamppeter
  • Date: 2012-06-19 17:12:48 UTC
  • mfrom: (1.1.15)
  • Revision ID: package-import@ubuntu.com-20120619171248-cbil10m2dqnc71rr
Tags: 5.2.8-0ubuntu1
* New upstream release
   - Added support for Canon PIXMA DS700, DS810, 50i, 80i, 450i, 455i, 470PD,
     475PD, 550i, 560i, 850i, 860i, 865R, 900PD, 950i, 960i, 990i, 6100i,
     6500i, 9100i, 9900i, i450X, i455X, i475D, i550X, i560X, i905D, i965,
     i990, i9950, iP90, iP90v, iP100, iP6320D, MP260, MX320, MX370, MX430,
     MX510, MX710, MX890, E500, E600, PIXUS iP2700, iP3100, iP4100,
     EPSON Stylus NX420, SX420, TX420
   - CD printing on many Canon printers.
   - Non-working Canon's removed.
   - More Japanese models supported.
   - Printer modes for most printer models are now determined by the
     media, based on information from the corresponding Windows
     driver. If an incompatible mode is selected by the user, a
     suitable mode is substituted, based on the other active
     parameters and quality setting. Modes are also substituted
     based on cartridge selection and duplex selection. Inktype is
     then automatically adjusted.
   - Added support for 8-bit inks to Canon backend, and modes using
     them.
   - Adjusted margins and page sizes of Canon printers.
   - Added borderless functionality to most Canon printers.
   - A problem whereby printing did not work at all on some Linux
     distributions has been fixed.
   - Printing on the Epson Stylus NX200, SX200, and SX205 is believed
     to be corrected.
* debian/patches/0002-genppd-don-t-write-color-profile-information-with-br.patch,
  debian/patches/0003-upgrade-getopt.patch,
  debian/patches/0004-no-data-dumper-needed.patch,
  debian/patches/0005-use-dnointerpolate-in-ghostscript-command-lines.patch:
  Removed, change applied upstream.
* debian/rules: Touch ppd-updater file(s) so that they have the time stamp
  of the build of this package The time stamp of the ppd-updater files tells
  CUPS' trigger script whether they come from different package versions or
  not (LP: #932882).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 * "$Id: print-canon.c,v 1.297 2011/12/23 14:03:28 rlk Exp $"
 
2
 * "$Id: print-canon.c,v 1.523 2012/05/25 17:52:30 gernot2270 Exp $"
3
3
 *
4
4
 *   Print plug-in CANON BJL driver for the GIMP.
5
5
 *
67
67
#  define MAX(a, b) ((a) > (b) ? (a) : (b))
68
68
#endif /* !MAX */
69
69
 
70
 
 
71
 
 
72
 
 
73
 
 
74
 
 
 
70
/* set this to 1 to see errors in make, set to 0 (normal) to avoid noise */
 
71
#define ERRPRINT 0
75
72
 
76
73
static int
77
74
pack_pixels(unsigned char* buf,int len)
105
102
}
106
103
 
107
104
/* model peculiarities */
108
 
#define CANON_CAP_MSB_FIRST 0x02ul    /* how to send data           */
109
 
#define CANON_CAP_a         0x04ul
110
 
#define CANON_CAP_b         0x08ul
111
 
#define CANON_CAP_q         0x10ul
112
 
#define CANON_CAP_m         0x20ul
113
 
#define CANON_CAP_d         0x40ul
114
 
#define CANON_CAP_t         0x80ul
115
 
#define CANON_CAP_c         0x100ul
116
 
#define CANON_CAP_p         0x200ul
117
 
#define CANON_CAP_l         0x400ul
118
 
#define CANON_CAP_r         0x800ul
119
 
#define CANON_CAP_g         0x1000ul
120
 
#define CANON_CAP_px        0x2000ul
121
 
#define CANON_CAP_rr        0x4000ul
122
 
#define CANON_CAP_I         0x8000ul
123
 
#define CANON_CAP_T         0x10000ul /* not sure of this yet! */
124
 
#define CANON_CAP_P         0x20000ul
125
 
#define CANON_CAP_DUPLEX    0x40000ul
126
 
#define CANON_CAP_XML       0x80000ul /* not sure of this yet */
127
 
#define CANON_CAP_CARTRIDGE 0x100000ul /* not sure of this yet */
128
 
#define CANON_CAP_M         0x200000ul /* not sure of this yet */
129
 
#define CANON_CAP_S         0x400000ul /* not sure of this yet */
 
105
#define CANON_CAP_MSB_FIRST  0x02ul    /* how to send data           */
 
106
#define CANON_CAP_a          0x04ul
 
107
#define CANON_CAP_b          0x08ul
 
108
#define CANON_CAP_q          0x10ul
 
109
#define CANON_CAP_m          0x20ul
 
110
#define CANON_CAP_d          0x40ul
 
111
#define CANON_CAP_t          0x80ul
 
112
#define CANON_CAP_c          0x100ul
 
113
#define CANON_CAP_p          0x200ul
 
114
#define CANON_CAP_l          0x400ul
 
115
#define CANON_CAP_r          0x800ul
 
116
#define CANON_CAP_g          0x1000ul
 
117
#define CANON_CAP_px         0x2000ul
 
118
#define CANON_CAP_rr         0x4000ul
 
119
#define CANON_CAP_I          0x8000ul
 
120
#define CANON_CAP_T          0x10000ul /* not sure of this yet! */
 
121
#define CANON_CAP_P          0x20000ul
 
122
#define CANON_CAP_DUPLEX     0x40000ul
 
123
#define CANON_CAP_XML        0x80000ul /* not sure of this yet */
 
124
#define CANON_CAP_CARTRIDGE  0x100000ul /* not sure of this yet */
 
125
#define CANON_CAP_M          0x200000ul /* not sure of this yet */
 
126
#define CANON_CAP_S          0x400000ul /* not sure of this yet */
 
127
#define CANON_CAP_cart       0x800000ul /* BJC printers with Color, Black, Photo options */
 
128
#define CANON_CAP_BORDERLESS 0x1000000ul /* borderless printing */
 
129
#define CANON_CAP_NOBLACK    0x2000000ul /* no Black cartridge selection */
130
130
 
131
131
#define CANON_CAP_STD0 (CANON_CAP_b|CANON_CAP_c|CANON_CAP_d|\
132
132
                        CANON_CAP_l|CANON_CAP_q|CANON_CAP_t)
137
137
#include "canon-inks.h"
138
138
#include "canon-modes.h"
139
139
#include "canon-media.h"
 
140
#include "canon-media-mode.h"
140
141
#include "canon-printers.h"
141
142
 
142
 
 
143
143
typedef struct {
144
144
    char name;
145
145
    const canon_ink_t* props;
149
149
    unsigned int delay;
150
150
} canon_channel_t;
151
151
 
152
 
 
153
 
 
154
152
typedef struct
155
153
{
156
154
  const canon_mode_t* mode; 
157
155
  const canon_slot_t* slot;
158
156
  const canon_paper_t *pt;
 
157
  /* cartridge selection for CANON_CAP_T and CANON_CAP_cart */
 
158
  const char *ink_set;
 
159
  const canon_modeuse_t* modeuse;
 
160
  /* final inks used for output, after selection process completed */
159
161
  unsigned int used_inks;
160
162
  int num_channels;
161
163
  int quality;
192
194
  double cd_outer_radius;
193
195
} canon_privdata_t;
194
196
 
 
197
const canon_modeuse_t* select_media_modes(stp_vars_t *v, const canon_paper_t* media_type,const canon_modeuselist_t* mlist);
 
198
int compare_mode_valid(stp_vars_t *v,const canon_mode_t* mode,const canon_modeuse_t* muse, const canon_modeuselist_t* mlist);
 
199
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);
 
200
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);
 
201
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);
 
202
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);
 
203
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);
 
204
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);
 
205
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);
 
206
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);
 
207
const char* find_ink_type(stp_vars_t *v,const canon_mode_t* mode,const char *printing_mode);
 
208
const canon_mode_t* canon_check_current_mode(stp_vars_t *v);
 
209
 
195
210
static void canon_write_line(stp_vars_t *v);
196
211
 
197
212
static void canon_advance_paper(stp_vars_t *, int);
254
269
    STP_PARAMETER_TYPE_STRING_LIST, STP_PARAMETER_CLASS_FEATURE,
255
270
    STP_PARAMETER_LEVEL_BASIC, 1, 1, STP_CHANNEL_NONE, 1, 0
256
271
  },
 
272
  /*
 
273
   * Don't check this parameter.  We may offer different settings for
 
274
   * different ink sets, but we need to be able to handle settings from PPD
 
275
   * files that don't have constraints set up.
 
276
   */
257
277
  {
258
278
    "InkType", N_("Ink Type"), "Color=Yes,Category=Advanced Printer Setup",
259
279
    N_("Type of ink in the printer"),
260
280
    STP_PARAMETER_TYPE_STRING_LIST, STP_PARAMETER_CLASS_FEATURE,
261
 
    STP_PARAMETER_LEVEL_BASIC, 1, 1, STP_CHANNEL_NONE, 1, 0
 
281
    STP_PARAMETER_LEVEL_BASIC, 1, 1, STP_CHANNEL_NONE, 0, 0
262
282
  },
263
283
  {
264
284
    "InkChannels", N_("Ink Channels"), "Color=Yes,Category=Advanced Printer Functionality",
266
286
    STP_PARAMETER_TYPE_INT, STP_PARAMETER_CLASS_FEATURE,
267
287
    STP_PARAMETER_LEVEL_INTERNAL, 0, 0, STP_CHANNEL_NONE, 0, 0
268
288
  },
 
289
  /*
 
290
   * Don't check this parameter.  We may offer different settings for
 
291
   * different ink sets, but we need to be able to handle settings from PPD
 
292
   * files that don't have constraints set up.
 
293
   */
269
294
  {
270
295
    "PrintingMode", N_("Printing Mode"), "Color=Yes,Category=Core Parameter",
271
296
    N_("Printing Output Mode"),
272
297
    STP_PARAMETER_TYPE_STRING_LIST, STP_PARAMETER_CLASS_CORE,
 
298
    STP_PARAMETER_LEVEL_BASIC, 1, 1, STP_CHANNEL_NONE, 0, 0
 
299
  },
 
300
  /*
 
301
   * Don't check this parameter.  We may offer different settings for
 
302
   * different ink sets, but we need to be able to handle settings from PPD
 
303
   * files that don't have constraints set up.
 
304
   */
 
305
  {
 
306
    "InkSet", N_("Ink Set"), "Color=Yes,Category=Basic Printer Setup",
 
307
    N_("Type of inkset in the printer"),
 
308
    STP_PARAMETER_TYPE_STRING_LIST, STP_PARAMETER_CLASS_FEATURE,
 
309
    STP_PARAMETER_LEVEL_BASIC, 1, 1, STP_CHANNEL_NONE, 0, 0
 
310
  },
 
311
  {
 
312
    "FullBleed", N_("Borderless"), "Color=No,Category=Basic Printer Setup",
 
313
    N_("Print without borders"),
 
314
    STP_PARAMETER_TYPE_BOOLEAN, STP_PARAMETER_CLASS_FEATURE,
273
315
    STP_PARAMETER_LEVEL_BASIC, 1, 1, STP_CHANNEL_NONE, 1, 0
274
316
  },
275
317
  {
358
400
  },
359
401
};
360
402
 
361
 
 
362
403
static const int float_parameter_count =
363
404
sizeof(float_parameters) / sizeof(const float_param_t);
364
405
 
376
417
};
377
418
#define NUM_DUPLEX (sizeof (duplex_types) / sizeof (stp_param_string_t))
378
419
 
379
 
 
380
 
 
381
420
static const canon_paper_t *
382
421
get_media_type(const canon_cap_t* caps,const char *name)
383
422
{
384
423
  int i;
385
424
  if (name && caps->paperlist)
386
 
    for (i = 0; i < caps->paperlist->count; i++)
387
 
      {
388
 
        /* translate paper_t.name */
389
 
        if (!strcmp(name, caps->paperlist->papers[i].name))
390
 
          return &(caps->paperlist->papers[i]);
391
 
      }
392
 
  return &(caps->paperlist->papers[0]);
 
425
    {
 
426
      for (i = 0; i < caps->paperlist->count; i++)
 
427
        {
 
428
          /* translate paper_t.name */
 
429
          if (!strcmp(name, caps->paperlist->papers[i].name))
 
430
            return &(caps->paperlist->papers[i]);
 
431
        }
 
432
      return &(caps->paperlist->papers[0]);
 
433
    }
 
434
  return NULL;
393
435
}
394
436
 
395
 
 
396
437
static const char* canon_families[] = {
397
438
 "", /* the old BJC printers */
398
439
 "S",
406
447
 "PIXMA MX",
407
448
 "SELPHY DS",
408
449
 "PIXMA mini",
 
450
 "PIXMA E",
409
451
};
410
452
 
411
453
/* canon model ids look like the following
421
463
  char* name;
422
464
  size_t len;
423
465
  if(family >= sizeof(canon_families) / sizeof(canon_families[0])){
424
 
    stp_erprintf("canon_get_printername: no family %i using default BJC\n", family);
 
466
    stp_eprintf(v,"canon_get_printername: no family %i using default BJC\n", family);
425
467
    family = 0;
426
468
  }
427
469
  len = strlen(canon_families[family]) + 7; /* max model nr. + terminating 0 */
428
470
  name = stp_zalloc(len);
429
471
  snprintf(name,len,"%s%u",canon_families[family],nr);
 
472
  if (ERRPRINT)
 
473
    stp_eprintf(v,"canon_get_printername: current printer name: %s\n", name);
430
474
  return name;
431
475
}
432
476
 
433
 
 
434
 
 
435
 
 
436
477
static const canon_cap_t * canon_get_model_capabilities(const stp_vars_t*v)
437
478
{
438
479
  int i;
444
485
      return &(canon_model_capabilities[i]);
445
486
    }
446
487
  }
447
 
  stp_erprintf("canon: model %s not found in capabilities list=> using default\n",name);
 
488
  stp_eprintf(v,"canon: model %s not found in capabilities list=> using default\n",name);
448
489
  stp_free(name);
449
490
  return &(canon_model_capabilities[0]);
450
491
}
462
503
    return &(caps->slotlist->slots[0]);
463
504
}
464
505
 
465
 
 
466
506
/* function returns the current set printmode (specified by resolution) */
467
507
/* if no mode is set the default mode will be returned */
468
508
static const canon_mode_t* canon_get_current_mode(const stp_vars_t *v){
473
513
    const char *resolution = stp_get_string_parameter(v, "Resolution");
474
514
    const canon_cap_t * caps = canon_get_model_capabilities(v);
475
515
    const canon_mode_t* mode = NULL;
 
516
    const char *ink_type = stp_get_string_parameter(v, "InkType");/*debug*/
 
517
    const char *ink_set = stp_get_string_parameter(v, "InkSet");/*debug*/
476
518
    int i;
477
519
 
 
520
  stp_dprintf(STP_DBG_CANON, v,"Entered canon_get_current_mode\n");
 
521
  if (ERRPRINT)
 
522
    stp_eprintf(v,"entered canon_get_current_mode\n");
 
523
 
 
524
    if (ink_set)
 
525
      stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint: InkSet value (high priority): '%s'\n",ink_set);
 
526
    else
 
527
      stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint: InkSet value is NULL\n");
 
528
      
 
529
    if (ink_type)
 
530
      stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint: InkType value (low priority): '%s'\n",ink_type);
 
531
    else
 
532
      stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint: InkType value is NULL\n");
 
533
 
478
534
    if(resolution){
479
 
        for(i=0;i<caps->modelist->count;i++){
 
535
      for(i=0;i<caps->modelist->count;i++){
480
536
            if(!strcmp(resolution,caps->modelist->modes[i].name)){
481
537
                mode = &caps->modelist->modes[i];
482
538
                break;
483
539
            }
484
540
        }
485
541
    }
486
 
 
 
542
#if 0
487
543
    if(!mode)
488
544
        mode = &caps->modelist->modes[caps->modelist->default_mode];
 
545
#endif
489
546
 
490
547
#if 0
491
548
    if(quality && strcmp(quality, "None") == 0)
508
565
    }
509
566
#endif
510
567
 
511
 
 
512
 
 
513
 
 
514
 
 
 
568
    stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint: current mode is '%s'\n",resolution);
 
569
    if (ERRPRINT)
 
570
      stp_eprintf(v,"current mode is '%s'\n",resolution);
 
571
    
515
572
    return mode;
516
573
}
517
574
 
 
575
const canon_modeuse_t* select_media_modes(stp_vars_t *v, const canon_paper_t* media_type,const canon_modeuselist_t* mlist){
 
576
  const canon_modeuse_t* muse = NULL;
 
577
  int i;
 
578
  for(i=0;i<mlist->count;i++){
 
579
    if(!strcmp(media_type->name,mlist->modeuses[i].name)){
 
580
      muse = &mlist->modeuses[i];
 
581
      stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint: mode searching: assigned media '%s'\n",mlist->name);
 
582
      if (ERRPRINT)
 
583
        stp_eprintf(v,"mode searching: assigned media '%s'\n",mlist->name);
 
584
      break;
 
585
    }
 
586
  }
 
587
  return muse;
 
588
}
 
589
 
 
590
int compare_mode_valid(stp_vars_t *v,const canon_mode_t* mode,const canon_modeuse_t* muse, const canon_modeuselist_t* mlist){
 
591
  int i=0;
 
592
  int modecheck=1;
 
593
  stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint: mode searching: assigned mode-media '%s'\n",mlist->name);
 
594
  if (ERRPRINT)
 
595
    stp_eprintf(v,"mode searching: assigned mode-media '%s'\n",mlist->name);
 
596
  while (muse->mode_name_list[i]!=NULL){
 
597
    if(!strcmp(mode->name,muse->mode_name_list[i])){
 
598
      modecheck=0;
 
599
      break;
 
600
    }
 
601
    i++;
 
602
  }
 
603
  return modecheck;
 
604
}
 
605
 
 
606
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) {
 
607
  const canon_mode_t* mode=NULL;
 
608
  int i=0;
 
609
  int j;
 
610
  int modefound=0;
 
611
 
 
612
  stp_dprintf(STP_DBG_CANON, v,"DEBUG: Entered suitable_mode_monochrome\n");
 
613
 
 
614
  while ((muse->mode_name_list[i]!=NULL) && (modefound != 1)){
 
615
    for(j=0;j<caps->modelist->count;j++){
 
616
      if(!strcmp(muse->mode_name_list[i],caps->modelist->modes[j].name)){/* find right place in canon-modes list */
 
617
        if ( (muse->use_flags & INKSET_BLACK_MODEREPL) ) { 
 
618
          /* only look at modes with MODE_FLAG_BLACK if INKSET_BLACK_MODEREPL is in force */
 
619
          if ( (caps->modelist->modes[j].quality >= quality) && (caps->modelist->modes[j].flags & MODE_FLAG_BLACK) ){ 
 
620
            /* keep setting the mode until lowest matching quality is found */
 
621
            if ( !(duplex_mode) || !(muse->use_flags & DUPLEX_SUPPORT) || !(caps->modelist->modes[j].flags & MODE_FLAG_NODUPLEX) ) {
 
622
              /* duplex check -- rare for monochrome, cannot remember any such case */
 
623
              mode = &caps->modelist->modes[j];
 
624
              modefound=1;
 
625
            }
 
626
          }
 
627
          break; /* go to next mode in muse list */
 
628
        }
 
629
        else { /* no special replacement modes for black inkset */
 
630
          if ( (caps->modelist->modes[j].quality >= quality) ){ 
 
631
            /* keep setting the mode until lowest matching quality is found */
 
632
            if ( !(duplex_mode) || !(muse->use_flags & DUPLEX_SUPPORT) || !(caps->modelist->modes[j].flags & MODE_FLAG_NODUPLEX) ) {
 
633
              /* duplex check -- rare for monochrome, cannot remember any such case */
 
634
              mode = &caps->modelist->modes[j];
 
635
              modefound=1;
 
636
            }
 
637
          }
 
638
          break; /* go to next mode in muse list */
 
639
        }
 
640
      }
 
641
    }
 
642
    i++;
 
643
  }
 
644
  return mode;
 
645
}
 
646
 
 
647
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) {
 
648
  const canon_mode_t* mode=NULL;
 
649
  /* only look at modes with MODE_FLAG_BLACK if INKSET_BLACK_MODEREPL is in force */
 
650
  int i=0;
 
651
  int modefound=0;
 
652
  int j;
 
653
 
 
654
  while ( (muse->mode_name_list[i]!=NULL)  && (modefound != 1) ) {
 
655
    /* pick first mode with MODE_FLAG_BLACK */
 
656
    for(j=0;j<caps->modelist->count;j++){
 
657
      if(!strcmp(muse->mode_name_list[i],caps->modelist->modes[j].name)){/* find right place in canon-modes list */
 
658
        /* only look at modes with MODE_FLAG_BLACK if INKSET_BLACK_MODEREPL is in force */
 
659
        if ( (caps->modelist->modes[j].flags & MODE_FLAG_BLACK) ) { 
 
660
          if ( !(duplex_mode) || !(muse->use_flags & DUPLEX_SUPPORT) || !(caps->modelist->modes[j].flags & MODE_FLAG_NODUPLEX) ) {
 
661
            /* duplex check -- rare for monochrome, cannot remember any such case */
 
662
            mode = &caps->modelist->modes[j];
 
663
            modefound=1;
 
664
          }
 
665
        }
 
666
        break; /* go to next mode in muse list */
 
667
      }
 
668
    }
 
669
    i++;
 
670
  }
 
671
  return mode;
 
672
}
 
673
 
 
674
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) {
 
675
  const canon_mode_t* mode=NULL;
 
676
  int i=0;
 
677
  int modefound=0;
 
678
  int j;
 
679
 
 
680
  while ( (muse->mode_name_list[i]!=NULL)  && (modefound != 1) ) {
 
681
    for(j=0;j<caps->modelist->count;j++){
 
682
      if(!strcmp(muse->mode_name_list[i],caps->modelist->modes[j].name)){/* find right place in canon-modes list */
 
683
        if ( !(duplex_mode) || !(muse->use_flags & DUPLEX_SUPPORT) || !(caps->modelist->modes[j].flags & MODE_FLAG_NODUPLEX) ) {
 
684
          /* duplex check -- rare for monochrome, cannot remember any such case */
 
685
          mode = &caps->modelist->modes[j];
 
686
          modefound=1;
 
687
          stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (find_first_matching_mode): picked mode without inkset limitation (%s)\n",mode->name);
 
688
        }
 
689
        break; /* go to next mode in muse list */
 
690
      }
 
691
    }
 
692
    i++;
 
693
  }
 
694
  return mode;
 
695
}
 
696
 
 
697
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) {
 
698
  const canon_mode_t* mode=NULL;
 
699
  int i=0;
 
700
  int j;
 
701
  int modefound=0;
 
702
  
 
703
  stp_dprintf(STP_DBG_CANON, v,"DEBUG: Entered suitable_mode_color\n");
 
704
 
 
705
  while ((muse->mode_name_list[i]!=NULL) && (modefound != 1)){
 
706
    for(j=0;j<caps->modelist->count;j++){
 
707
      if(!strcmp(muse->mode_name_list[i],caps->modelist->modes[j].name)){/* find right place in canon-modes list */
 
708
        if ( (muse->use_flags & INKSET_COLOR_MODEREPL) ) { 
 
709
          /* only look at modes with MODE_FLAG_COLOR if INKSET_COLOR_MODEREPL is in force */
 
710
          if ( (caps->modelist->modes[j].quality >= quality)  && (caps->modelist->modes[j].flags & MODE_FLAG_COLOR) ) { 
 
711
            /* keep setting the mode until lowest matching quality is found */
 
712
            if ( !(duplex_mode) || !(muse->use_flags & DUPLEX_SUPPORT) || !(caps->modelist->modes[j].flags & MODE_FLAG_NODUPLEX) ) {
 
713
              /* duplex check */
 
714
              mode = &caps->modelist->modes[j];
 
715
              stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (suitable_mode_color): picked mode with special replacement inkset (%s)\n",mode->name);
 
716
              modefound=1;
 
717
            }
 
718
          }
 
719
          break; /* go to next mode in muse list */
 
720
        }
 
721
        else { /* no special replacement modes for color inkset */
 
722
          if ( (caps->modelist->modes[j].quality >= quality) ){ 
 
723
            /* keep setting the mode until lowest matching quality is found */
 
724
            if ( !(duplex_mode) || !(muse->use_flags & DUPLEX_SUPPORT) || !(caps->modelist->modes[j].flags & MODE_FLAG_NODUPLEX) ) {
 
725
              /* duplex check */
 
726
              mode = &caps->modelist->modes[j];
 
727
              stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (suitable_mode_color): picked mode without any special replacement inkset (%s)\n",mode->name);
 
728
              modefound=1;
 
729
            }
 
730
          }
 
731
          break; /* go to next mode in muse list */
 
732
        }
 
733
      }
 
734
    }
 
735
    i++;
 
736
  }
 
737
  return mode;
 
738
}
 
739
 
 
740
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) {
 
741
  const canon_mode_t* mode=NULL;
 
742
  /* only look at modes with MODE_FLAG_COLOR if INKSET_COLOR_MODEREPL is in force */
 
743
  int i=0;
 
744
  int modefound=0;
 
745
  int j;
 
746
 
 
747
  while ( (muse->mode_name_list[i]!=NULL)  && (modefound != 1) ) {
 
748
    /* pick first mode with MODE_FLAG_COLOR */
 
749
    for(j=0;j<caps->modelist->count;j++){
 
750
      if(!strcmp(muse->mode_name_list[i],caps->modelist->modes[j].name)){/* find right place in canon-modes list */
 
751
        /* only look at modes with MODE_FLAG_COLOR if INKSET_COLOR_MODEREPL is in force */
 
752
        if ( (caps->modelist->modes[j].flags & MODE_FLAG_COLOR) ) { 
 
753
          if ( !(duplex_mode) || !(muse->use_flags & DUPLEX_SUPPORT) || !(caps->modelist->modes[j].flags & MODE_FLAG_NODUPLEX) ) {
 
754
            /* duplex check */
 
755
            mode = &caps->modelist->modes[j];
 
756
            stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (find_first_matching_mode_color): picked first mode with special replacement inkset (%s)\n",mode->name);
 
757
            modefound=1;
 
758
          }
 
759
        }
 
760
        break; /* go to next mode in muse list */
 
761
      }
 
762
    }
 
763
    i++;
 
764
  }
 
765
  return mode;
 
766
}
 
767
 
 
768
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) {
 
769
  const canon_mode_t* mode=NULL;
 
770
  int i=0;
 
771
  int j;
 
772
  int modefound=0;
 
773
 
 
774
  stp_dprintf(STP_DBG_CANON, v,"DEBUG: Entered suitable_mode_photo\n");
 
775
  
 
776
  while ((muse->mode_name_list[i]!=NULL) && (modefound != 1)){
 
777
    for(j=0;j<caps->modelist->count;j++){
 
778
      if(!strcmp(muse->mode_name_list[i],caps->modelist->modes[j].name)){/* find right place in canon-modes list */
 
779
        if ( (muse->use_flags & INKSET_PHOTO_MODEREPL) ) { 
 
780
          /* only look at modes with MODE_FLAG_PHOTO if INKSET_PHOTO_MODEREPL is in force */
 
781
          if ( (caps->modelist->modes[j].quality >= quality)  && (caps->modelist->modes[j].flags & MODE_FLAG_PHOTO) ) { 
 
782
            /* keep setting the mode until lowest matching quality is found */
 
783
            if ( !(duplex_mode) || !(muse->use_flags & DUPLEX_SUPPORT) || !(caps->modelist->modes[j].flags & MODE_FLAG_NODUPLEX) ) {
 
784
              /* duplex check */
 
785
              mode = &caps->modelist->modes[j];
 
786
              modefound=1;
 
787
            }
 
788
          }
 
789
          break; /* go to next mode in muse list */
 
790
        }
 
791
        else { /* if no special replacement modes for photo inkset */
 
792
          if ( (caps->modelist->modes[j].quality >= quality) ){ 
 
793
            /* keep setting the mode until lowest matching quality is found */
 
794
            if ( !(duplex_mode) || !(muse->use_flags & DUPLEX_SUPPORT) || !(caps->modelist->modes[j].flags & MODE_FLAG_NODUPLEX) ) {
 
795
              /* duplex check */
 
796
              mode = &caps->modelist->modes[j];
 
797
              modefound=1;
 
798
            }
 
799
          }
 
800
          break; /* go to next mode in muse list */
 
801
        }
 
802
      }
 
803
    }
 
804
    i++;
 
805
  }
 
806
  return mode;
 
807
}
 
808
 
 
809
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) {
 
810
  const canon_mode_t* mode=NULL;
 
811
  /* only look at modes with MODE_FLAG_PHOTO if INKSET_PHOTO_MODEREPL is in force */
 
812
  int i=0;
 
813
  int modefound=0;
 
814
  int j;
 
815
  
 
816
  while ( (muse->mode_name_list[i]!=NULL)  && (modefound != 1) ) {
 
817
    /* pick first mode with MODE_FLAG_PHOTO */
 
818
    for(j=0;j<caps->modelist->count;j++){
 
819
      if(!strcmp(muse->mode_name_list[i],caps->modelist->modes[j].name)){/* find right place in canon-modes list */
 
820
        /* only look at modes with MODE_FLAG_PHOTO if INKSET_PHOTO_MODEREPL is in force */
 
821
        if ( (caps->modelist->modes[j].flags & MODE_FLAG_PHOTO) ) { 
 
822
          if ( !(duplex_mode) || !(muse->use_flags & DUPLEX_SUPPORT) || !(caps->modelist->modes[j].flags & MODE_FLAG_NODUPLEX) ) {
 
823
            /* duplex check */
 
824
            mode = &caps->modelist->modes[j];
 
825
            modefound=1;
 
826
          }
 
827
        }
 
828
        break; /* go to next mode in muse list */
 
829
      }
 
830
    }
 
831
    i++;
 
832
  }
 
833
  return mode;
 
834
}
 
835
 
 
836
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) {
 
837
  const canon_mode_t* mode=NULL;
 
838
  int i=0;
 
839
  int j;
 
840
  int modefound=0;
 
841
 
 
842
  stp_dprintf(STP_DBG_CANON, v,"DEBUG: Entered suitable_mode_general\n");
 
843
  
 
844
  while ((muse->mode_name_list[i]!=NULL) && (modefound != 1)){
 
845
    for(j=0;j<caps->modelist->count;j++){
 
846
      if(!strcmp(muse->mode_name_list[i],caps->modelist->modes[j].name)){/* find right place in canon-modes list */
 
847
        if ( (caps->modelist->modes[j].quality >= quality) ) { 
 
848
          /* keep setting the mode until lowest matching quality is found */
 
849
          if ( !(duplex_mode) || !(muse->use_flags & DUPLEX_SUPPORT) || !(caps->modelist->modes[j].flags & MODE_FLAG_NODUPLEX) ) {
 
850
            /* duplex check */
 
851
            mode = &caps->modelist->modes[j];
 
852
            modefound=1;
 
853
          }
 
854
        }
 
855
        break; /* go to next mode in muse list */
 
856
      }
 
857
    }
 
858
    i++;
 
859
  }
 
860
  return mode;
 
861
}
 
862
 
 
863
const char* find_ink_type(stp_vars_t *v,const canon_mode_t* mode,const char *printing_mode) {
 
864
  int i,inkfound;
 
865
  const char *ink_type = stp_get_string_parameter(v, "InkType");
 
866
 
 
867
  /* if InkType does not match that of mode, change InkType to match it */
 
868
  /* choose highest color as default, as there is only one option for Black */
 
869
  /* if InkType does not match that of mode, change InkType to match it */
 
870
  /* choose highest color as default, as there is only one option for Black */
 
871
  if (printing_mode && !strcmp(printing_mode,"BW")) {
 
872
    stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (InkSet:Both): InkType changed to %u (%s)\n",CANON_INK_K, "Gray");
 
873
    stp_set_string_parameter(v, "InkType", "Gray");
 
874
    ink_type = stp_get_string_parameter(v, "InkType");
 
875
  } else {
 
876
    inkfound=0;
 
877
    stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (InkSet:Both): InkType of mode %s is currently set as %s\n",mode->name,ink_type);
 
878
    for(i=0;i<sizeof(canon_inktypes)/sizeof(canon_inktypes[0]);i++){
 
879
      if (mode->ink_types & canon_inktypes[i].ink_type) { /* a mode can have several ink_types: must compare with ink_type if set */
 
880
        if ( !(strcmp(ink_type,canon_inktypes[i].name))) {
 
881
          inkfound=1;
 
882
          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);
 
883
          stp_set_string_parameter(v, "InkType", canon_inktypes[i].name);
 
884
          ink_type = stp_get_string_parameter(v, "InkType");
 
885
          break;
 
886
        }
 
887
      }
 
888
    }
 
889
    /* if no match found choose first available inkset */
 
890
    if (inkfound==0) {
 
891
      for(i=0;i<sizeof(canon_inktypes)/sizeof(canon_inktypes[0]);i++){
 
892
        if (mode->ink_types & canon_inktypes[i].ink_type) { /* a mode can have several ink_types: must compare with ink_type if set */
 
893
          if ((!ink_type) || (strcmp(ink_type,canon_inktypes[i].name))) { /* if InkType does not match selected mode ink type*/
 
894
            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);
 
895
            stp_set_string_parameter(v, "InkType", canon_inktypes[i].name);
 
896
            ink_type = stp_get_string_parameter(v, "InkType");
 
897
            inkfound=1; /* set */
 
898
            break;
 
899
          }
 
900
        }
 
901
      }
 
902
    }
 
903
  }
 
904
  return ink_type;
 
905
}
 
906
 
 
907
/* function checks printmode (specified by resolution) */
 
908
/* and substitutes a mode if needed. NULL is returned for now */
 
909
const canon_mode_t* canon_check_current_mode(stp_vars_t *v){
 
910
#if 0
 
911
  const char* input_slot = stp_get_string_parameter(v, "InputSlot");
 
912
  const char *quality = stp_get_string_parameter(v, "Quality");
 
913
#endif
 
914
  const char *resolution = stp_get_string_parameter(v, "Resolution");
 
915
  const char *ink_set = stp_get_string_parameter(v, "InkSet");
 
916
  const char *duplex_mode = stp_get_string_parameter(v, "Duplex");
 
917
  const char *ink_type = stp_get_string_parameter(v, "InkType");
 
918
  const char *printing_mode = stp_get_string_parameter(v, "PrintingMode");
 
919
  const canon_cap_t * caps = canon_get_model_capabilities(v);
 
920
  const canon_mode_t* mode = NULL;
 
921
  const canon_modeuselist_t* mlist = caps->modeuselist;
 
922
  const canon_modeuse_t* muse = NULL;
 
923
  const canon_paper_t* media_type = get_media_type(caps,stp_get_string_parameter(v, "MediaType"));
 
924
  int i,j;
 
925
  int modecheck, quality, modefound;
 
926
#if 0
 
927
  int inkfound;
 
928
#endif
 
929
 
 
930
  stp_dprintf(STP_DBG_CANON, v,"Entered canon_check_current_mode: got PrintingMode %s\n",printing_mode);
 
931
  if (ERRPRINT)
 
932
    stp_eprintf(v,"entered canon_check_current_mode: got PrintingMode %s\n",printing_mode);
 
933
 
 
934
  /* Logic: priority of options
 
935
     1. Media --- always present for final selection.
 
936
     2. InkSet (cartridge selection) --- optional as only some printers offer this.
 
937
     3. PrintingMode --- for printers which have K-only monochrome modes can choose BW.
 
938
     4. Duplex --- for printers that have special duplex modes need to skip non-duplex modes.
 
939
     5. InkType --- suggestion only, since modes are tied to ink types in most Canon printers.
 
940
     6. Quality --- suggestion, based on initially-selected mode.
 
941
     7. Mode --- once chosen, InkType is selected based on quality, inkset, printing mode.
 
942
  */
 
943
 
 
944
  /*
 
945
    canon-mode-media:
 
946
    INKSET_BLACK_SUPPORT: media type supports black-only cartridge
 
947
    INKSET_COLOR_SUPPORT: media type supports color-only cartridge
 
948
    INKSET_BLACK_MODEREPL: media type has special modes for black-only cartridge
 
949
    INKSET_COLOR_MODEREPL: media type has special modes for black-only cartridge
 
950
    INKSET_PHOTO_SUPPORT: media type supports special photo cartridge
 
951
    DUPLEX_MODEREPL: media type has (a) special mode(s) for duplex
 
952
    canon-modes.h:
 
953
    MODE_FLAG_BLACK: mode can be used for supporting black-only cartridge
 
954
    MODE_FLAG_COLOR: mode can be used for supporting color-only cartridge
 
955
    MODE_FLAG_PHOTO: mode can be used for supporting photo cartridge
 
956
    MODE_FLAG_NOPDUPLEX: mode cannot be used for duplex, must be skipped
 
957
  */
 
958
 
 
959
  if(resolution){
 
960
    stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint:  check_current_mode --- (Initial) Resolution already known: '%s'\n",resolution);
 
961
    if (ERRPRINT)
 
962
      stp_eprintf(v,"check_current_mode --- (Initial) Resolution already known: '%s'\n",resolution);
 
963
    for(i=0;i<caps->modelist->count;i++){
 
964
      if(!strcmp(resolution,caps->modelist->modes[i].name)){
 
965
        mode = &caps->modelist->modes[i];
 
966
        break;
 
967
      }
 
968
    }
 
969
  }
 
970
  else {
 
971
    stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint:  check_current_mode --- (Initial) Resolution not yet known \n");
 
972
    if (ERRPRINT)
 
973
      stp_eprintf(v,"check_current_mode --- (Initial) Resolution not yet known \n");
 
974
  }
 
975
    
 
976
  if (ink_set)
 
977
    stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint: (Initial) InkSet value (high priority): '%s'\n",ink_set);
 
978
  else
 
979
    stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint: (Initial) InkSet value is NULL\n");
 
980
  
 
981
  if (ink_type)
 
982
    stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint: (Initial) InkType value (low priority): '%s'\n",ink_type);
 
983
  else
 
984
    stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint: (Initial) InkType value is NULL\n");
 
985
 
 
986
  /* beginning of mode replacement code */
 
987
  if (media_type && resolution && mode) {
 
988
    stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint:  check_current_mode --- Resolution, Media, Mode all known \n");
 
989
    if (ERRPRINT)
 
990
      stp_eprintf(v,"check_current_mode --- Resolution, Media, Mode all known \n");
 
991
    stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint: media type selected: '%s'\n",media_type->name);
 
992
    if (ERRPRINT)
 
993
      stp_eprintf(v,"media type selected: '%s'\n",media_type->name);
 
994
    stp_dprintf(STP_DBG_CANON, v,"DEBUG: (Inital) Gutenprint: mode initally active: '%s'\n",mode->name);
 
995
    if (ERRPRINT)
 
996
      stp_eprintf(v,"(Inital) mode initially active: '%s'\n",mode->name);
 
997
      
 
998
    /* scroll through modeuse list to find media */
 
999
    muse = select_media_modes(v,media_type,mlist);
 
1000
 
 
1001
    /* now scroll through to find if the mode is in the modeuses list */
 
1002
    modecheck=compare_mode_valid(v,mode,muse,mlist);
 
1003
 
 
1004
    stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint: modecheck value: '%i'\n",modecheck);
 
1005
    if (ERRPRINT)
 
1006
      stp_eprintf(v,"modecheck value: '%i'\n",modecheck);
 
1007
            
 
1008
    /* if we did not find a valid mode, need to replace it */
 
1009
    if (modecheck!=0) {
 
1010
 
 
1011
      stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (check_current_mode): no suitable mode exists, need to find a mode\n");
 
1012
      quality = mode->quality;
 
1013
      /* Black InkSet */
 
1014
      if (ink_set && !strcmp(ink_set,"Black"))  {
 
1015
        stp_set_string_parameter(v, "PrintingMode","BW");
 
1016
        printing_mode = stp_get_string_parameter(v, "PrintingMode");
 
1017
        if (!(mode->ink_types & CANON_INK_K)) {
 
1018
          /* need a new mode: 
 
1019
             loop through modes in muse list searching for a matching inktype, comparing quality
 
1020
          */
 
1021
          mode=suitable_mode_monochrome(v,muse,caps,quality,duplex_mode);
 
1022
          if (!mode)
 
1023
            modefound=0;
 
1024
          else
 
1025
            modefound=1;
 
1026
 
 
1027
          if (modefound == 0) { /* still did not find a mode: pick first one for that media matching the InkSet limitation */
 
1028
            if ( (muse->use_flags & INKSET_BLACK_MODEREPL) ) {  
 
1029
              mode=find_first_matching_mode_monochrome(v,muse,caps,duplex_mode);
 
1030
            }
 
1031
            else {  /* no special replacement modes for black inkset */
 
1032
              mode=find_first_matching_mode(v,muse,caps,duplex_mode);
 
1033
            }
 
1034
          }
 
1035
          if (!mode)
 
1036
            modefound=0;
 
1037
          else
 
1038
            modefound=1;
 
1039
 
 
1040
          /* set InkType for the mode found */
 
1041
          for(i=0;i<sizeof(canon_inktypes)/sizeof(canon_inktypes[0]);i++){
 
1042
            if (mode->ink_types & canon_inktypes[i].ink_type) {
 
1043
              if (strcmp(ink_type,canon_inktypes[i].name)) { /* if InkType does not match selected mode ink type*/
 
1044
                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);
 
1045
                stp_set_string_parameter(v, "InkType", canon_inktypes[i].name);
 
1046
                ink_type = stp_get_string_parameter(v, "InkType");
 
1047
                break;
 
1048
              }
 
1049
            }
 
1050
          }
 
1051
        }
 
1052
        else {
 
1053
          /* mode is fine */
 
1054
          /* matched expected K inkset, but need to check if Duplex matches, and if not, get a new mode with right inkset */
 
1055
          mode=suitable_mode_monochrome(v,muse,caps,quality,duplex_mode);
 
1056
          if (!mode)
 
1057
            modefound=0;
 
1058
          else
 
1059
            modefound=1;
 
1060
 
 
1061
          if (modefound == 0) { /* still did not find a mode: pick first one for that media matching the InkSet limitation */
 
1062
            if ( (muse->use_flags & INKSET_BLACK_MODEREPL) ) {
 
1063
            mode=find_first_matching_mode_monochrome(v,muse,caps,duplex_mode);
 
1064
            }
 
1065
            else {  /* no special replacement modes for black inkset */
 
1066
              mode=find_first_matching_mode(v,muse,caps,duplex_mode);
 
1067
            }
 
1068
          }
 
1069
 
 
1070
          ink_type=find_ink_type(v,mode,printing_mode);
 
1071
#if 0
 
1072
          /* if InkType does not match that of mode, change InkType to match it */
 
1073
          /* choose highest color as default, as there is only one option for Black */
 
1074
          /* if InkType does not match that of mode, change InkType to match it */
 
1075
          /* choose highest color as default, as there is only one option for Black */
 
1076
          if (printing_mode && !strcmp(printing_mode,"BW")) {
 
1077
            stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (InkSet:Both): InkType changed to %u (%s)\n",CANON_INK_K, "Gray");
 
1078
            stp_set_string_parameter(v, "InkType", "Gray");
 
1079
            ink_type = stp_get_string_parameter(v, "InkType");
 
1080
          } else {
 
1081
            inkfound=0;
 
1082
            stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (InkSet:Both): InkType of mode %s is currently set as %s\n",mode->name,ink_type);
 
1083
            for(i=0;i<sizeof(canon_inktypes)/sizeof(canon_inktypes[0]);i++){
 
1084
              if (mode->ink_types & canon_inktypes[i].ink_type) { /* a mode can have several ink_types: must compare with ink_type if set */
 
1085
                if ( !(strcmp(ink_type,canon_inktypes[i].name))) {
 
1086
                  inkfound=1;
 
1087
                  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);
 
1088
                  stp_set_string_parameter(v, "InkType", canon_inktypes[i].name);
 
1089
                  ink_type = stp_get_string_parameter(v, "InkType");
 
1090
                  break;
 
1091
                }
 
1092
              }
 
1093
            }
 
1094
            /* if no match found choose first available inkset */
 
1095
            if (inkfound==0) {
 
1096
              for(i=0;i<sizeof(canon_inktypes)/sizeof(canon_inktypes[0]);i++){
 
1097
                if (mode->ink_types & canon_inktypes[i].ink_type) { /* a mode can have several ink_types: must compare with ink_type if set */
 
1098
                  if ((!ink_type) || (strcmp(ink_type,canon_inktypes[i].name))) { /* if InkType does not match selected mode ink type*/
 
1099
                    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);
 
1100
                    stp_set_string_parameter(v, "InkType", canon_inktypes[i].name);
 
1101
                    ink_type = stp_get_string_parameter(v, "InkType");
 
1102
                    inkfound=1; /* set */
 
1103
                    break;
 
1104
                  }
 
1105
                }
 
1106
              }
 
1107
            }
 
1108
          }
 
1109
#endif
 
1110
          
 
1111
#if 0
 
1112
          /* set InkType for the mode found */
 
1113
          for(i=0;i<sizeof(canon_inktypes)/sizeof(canon_inktypes[0]);i++){
 
1114
            if (mode->ink_types & canon_inktypes[i].ink_type) {
 
1115
              if (strcmp(ink_type,canon_inktypes[i].name)) { /* if InkType does not match selected mode ink type*/
 
1116
                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);
 
1117
                stp_set_string_parameter(v, "InkType", canon_inktypes[i].name);
 
1118
                ink_type = stp_get_string_parameter(v, "InkType");
 
1119
                break;
 
1120
              }
 
1121
            }
 
1122
          }
 
1123
#endif
 
1124
 
 
1125
        }
 
1126
      } /* End of Black Inkset */
 
1127
      /*-------------------------------------------------------------------------------------------------*/
 
1128
      /* Color InkSet */
 
1129
      /* Added limitation: "Color" for BJC corresponds to "Both" on other types */
 
1130
      else if ( (ink_set && !strcmp(ink_set,"Color")) && (caps->features & CANON_CAP_T) ) {
 
1131
        stp_set_string_parameter(v, "PrintingMode","Color");
 
1132
        printing_mode = stp_get_string_parameter(v, "PrintingMode");
 
1133
        if (!(mode->ink_types & CANON_INK_CMY)) {
 
1134
          stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (InkSet:Color): inkset incorrect for Color cartridge---need new mode\n");
 
1135
          /* need a new mode
 
1136
             loop through modes in muse list searching for a matching inktype, comparing quality
 
1137
          */
 
1138
          mode=suitable_mode_color(v,muse,caps,quality,duplex_mode);
 
1139
          if (!mode)
 
1140
            modefound=0;
 
1141
          else
 
1142
            modefound=1;
 
1143
 
 
1144
          if (modefound == 0) { /* still did not find a mode: pick first one for that media */
 
1145
            if ( (muse->use_flags & INKSET_COLOR_MODEREPL) ) {  
 
1146
              mode=find_first_matching_mode_color(v,muse,caps,duplex_mode);
 
1147
              stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (InkSet:Color): Decided on first matching mode for color inkset (%s)\n",mode->name);
 
1148
            }
 
1149
            else {  /* no special replacement modes for color inkset */
 
1150
              mode=find_first_matching_mode(v,muse,caps,duplex_mode);
 
1151
              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);
 
1152
            }
 
1153
          }
 
1154
          if (!mode)
 
1155
            modefound=0;
 
1156
          else
 
1157
            modefound=1;
 
1158
 
 
1159
          ink_type=find_ink_type(v,mode,printing_mode);
 
1160
#if 0
 
1161
          /* if InkType does not match that of mode, change InkType to match it */
 
1162
          /* choose highest color as default, as there is only one option for Black */
 
1163
          /* if InkType does not match that of mode, change InkType to match it */
 
1164
          /* choose highest color as default, as there is only one option for Black */
 
1165
          if (printing_mode && !strcmp(printing_mode,"BW")) {
 
1166
            stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (InkSet:Both): InkType changed to %u (%s)\n",CANON_INK_K, "Gray");
 
1167
            stp_set_string_parameter(v, "InkType", "Gray");
 
1168
            ink_type = stp_get_string_parameter(v, "InkType");
 
1169
          } else {
 
1170
            inkfound=0;
 
1171
            stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (InkSet:Both): InkType of mode %s is currently set as %s\n",mode->name,ink_type);
 
1172
            for(i=0;i<sizeof(canon_inktypes)/sizeof(canon_inktypes[0]);i++){
 
1173
              if (mode->ink_types & canon_inktypes[i].ink_type) { /* a mode can have several ink_types: must compare with ink_type if set */
 
1174
                if ( !(strcmp(ink_type,canon_inktypes[i].name))) {
 
1175
                  inkfound=1;
 
1176
                  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);
 
1177
                  stp_set_string_parameter(v, "InkType", canon_inktypes[i].name);
 
1178
                  ink_type = stp_get_string_parameter(v, "InkType");
 
1179
                  break;
 
1180
                }
 
1181
              }
 
1182
            }
 
1183
            /* if no match found choose first available inkset */
 
1184
            if (inkfound==0) {
 
1185
              for(i=0;i<sizeof(canon_inktypes)/sizeof(canon_inktypes[0]);i++){
 
1186
                if (mode->ink_types & canon_inktypes[i].ink_type) { /* a mode can have several ink_types: must compare with ink_type if set */
 
1187
                  if ((!ink_type) || (strcmp(ink_type,canon_inktypes[i].name))) { /* if InkType does not match selected mode ink type*/
 
1188
                    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);
 
1189
                    stp_set_string_parameter(v, "InkType", canon_inktypes[i].name);
 
1190
                    ink_type = stp_get_string_parameter(v, "InkType");
 
1191
                    inkfound=1; /* set */
 
1192
                    break;
 
1193
                  }
 
1194
                }
 
1195
              }
 
1196
            }
 
1197
          }
 
1198
#endif    
 
1199
#if 0
 
1200
          /* set InkType for the mode found */
 
1201
          for(i=0;i<sizeof(canon_inktypes)/sizeof(canon_inktypes[0]);i++){
 
1202
            if (mode->ink_types & canon_inktypes[i].ink_type) {
 
1203
              if (strcmp(ink_type,canon_inktypes[i].name)) { /* if InkType does not match selected mode ink type*/
 
1204
                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);
 
1205
                stp_set_string_parameter(v, "InkType", canon_inktypes[i].name);
 
1206
                ink_type = stp_get_string_parameter(v, "InkType");
 
1207
                break;
 
1208
              }
 
1209
            }
 
1210
          }
 
1211
#endif
 
1212
 
 
1213
        }
 
1214
        else {
 
1215
          /* mode is fine */
 
1216
          /* matched expected RGB inkset, but need to check if Duplex matches, and if not, get a new mode with right inkset */
 
1217
          stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (InkSet:Color): inkset OK but need to check other parameters\n");
 
1218
          mode=suitable_mode_color(v,muse,caps,quality,duplex_mode);
 
1219
          if (!mode)
 
1220
            modefound=0;
 
1221
          else
 
1222
            modefound=1;
 
1223
 
 
1224
          if (modefound == 0) { /* still did not find a mode: pick first one for that media */
 
1225
            if ( (muse->use_flags & INKSET_COLOR_MODEREPL) ) {
 
1226
              mode=find_first_matching_mode_color(v,muse,caps,duplex_mode);
 
1227
              stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (InkSet:Color): Decided on first matching mode for color inkset (%s)\n",mode->name);
 
1228
            }
 
1229
            else {  /* no special replacement modes for color inkset */
 
1230
              mode=find_first_matching_mode(v,muse,caps,duplex_mode);
 
1231
              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);
 
1232
            }
 
1233
          }
 
1234
          if (!mode)
 
1235
            modefound=0;
 
1236
          else
 
1237
            modefound=1;
 
1238
 
 
1239
          ink_type=find_ink_type(v,mode,printing_mode);
 
1240
#if 0
 
1241
          /* if InkType does not match that of mode, change InkType to match it */
 
1242
          /* choose highest color as default, as there is only one option for Black */
 
1243
          /* if InkType does not match that of mode, change InkType to match it */
 
1244
          /* choose highest color as default, as there is only one option for Black */
 
1245
          if (printing_mode && !strcmp(printing_mode,"BW")) {
 
1246
            stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (InkSet:Both): InkType changed to %u (%s)\n",CANON_INK_K, "Gray");
 
1247
            stp_set_string_parameter(v, "InkType", "Gray");
 
1248
            ink_type = stp_get_string_parameter(v, "InkType");
 
1249
          } else {
 
1250
            inkfound=0;
 
1251
            stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (InkSet:Both): InkType of mode %s is currently set as %s\n",mode->name,ink_type);
 
1252
            for(i=0;i<sizeof(canon_inktypes)/sizeof(canon_inktypes[0]);i++){
 
1253
              if (mode->ink_types & canon_inktypes[i].ink_type) { /* a mode can have several ink_types: must compare with ink_type if set */
 
1254
                if ( !(strcmp(ink_type,canon_inktypes[i].name))) {
 
1255
                  inkfound=1;
 
1256
                  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);
 
1257
                  stp_set_string_parameter(v, "InkType", canon_inktypes[i].name);
 
1258
                  ink_type = stp_get_string_parameter(v, "InkType");
 
1259
                  break;
 
1260
                }
 
1261
              }
 
1262
            }
 
1263
            /* if no match found choose first available inkset */
 
1264
            if (inkfound==0) {
 
1265
              for(i=0;i<sizeof(canon_inktypes)/sizeof(canon_inktypes[0]);i++){
 
1266
                if (mode->ink_types & canon_inktypes[i].ink_type) { /* a mode can have several ink_types: must compare with ink_type if set */
 
1267
                  if ((!ink_type) || (strcmp(ink_type,canon_inktypes[i].name))) { /* if InkType does not match selected mode ink type*/
 
1268
                    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);
 
1269
                    stp_set_string_parameter(v, "InkType", canon_inktypes[i].name);
 
1270
                    ink_type = stp_get_string_parameter(v, "InkType");
 
1271
                    inkfound=1; /* set */
 
1272
                    break;
 
1273
                  }
 
1274
                }
 
1275
              }
 
1276
            }
 
1277
          }
 
1278
#endif    
 
1279
#if 0
 
1280
          /* set InkType for the mode found */
 
1281
          for(i=0;i<sizeof(canon_inktypes)/sizeof(canon_inktypes[0]);i++){
 
1282
            if (mode->ink_types & canon_inktypes[i].ink_type) {
 
1283
              if (strcmp(ink_type,canon_inktypes[i].name)) { /* if InkType does not match selected mode ink type*/
 
1284
                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);
 
1285
                stp_set_string_parameter(v, "InkType", canon_inktypes[i].name);
 
1286
                ink_type = stp_get_string_parameter(v, "InkType");
 
1287
                break;
 
1288
              }
 
1289
            }
 
1290
          }
 
1291
#endif
 
1292
 
 
1293
        }
 
1294
      }  /* end of Color InkSet */
 
1295
      /*-------------------------------------------------------------------------------------------------*/
 
1296
      /* Photo cartridge selection: only use modes that support it */
 
1297
      else if (ink_set && !strcmp(ink_set,"Photo")) {
 
1298
        /* Photo cartridge printing does not seem to have any monochrome option */
 
1299
        stp_set_string_parameter(v, "PrintingMode","Color");
 
1300
        printing_mode = stp_get_string_parameter(v, "PrintingMode");
 
1301
        /* need to match photo cartridge mode flag */
 
1302
        if (!(mode->flags & MODE_FLAG_PHOTO)) {
 
1303
          /* need a new mode
 
1304
             loop through modes in muse list searching for a matching inkset, comparing quality
 
1305
          */
 
1306
          mode=suitable_mode_photo(v,muse,caps,quality,duplex_mode);
 
1307
          if (!mode)
 
1308
            modefound=0;
 
1309
          else
 
1310
            modefound=1;
 
1311
 
 
1312
          if (modefound == 0) { /* still did not find a mode: pick first one for that media */
 
1313
            if ( (muse->use_flags & INKSET_PHOTO_MODEREPL) ) {
 
1314
              mode=find_first_matching_mode_photo(v,muse,caps,duplex_mode);
 
1315
            }
 
1316
            else {  /* no special replacement modes for photo inkset */
 
1317
              mode=find_first_matching_mode(v,muse,caps,duplex_mode);
 
1318
            }
 
1319
          }
 
1320
          if (!mode)
 
1321
            modefound=0;
 
1322
          else
 
1323
            modefound=1;
 
1324
 
 
1325
          ink_type=find_ink_type(v,mode,printing_mode);
 
1326
#if 0
 
1327
          /* if InkType does not match that of mode, change InkType to match it */
 
1328
          /* choose highest color as default, as there is only one option for Black */
 
1329
          /* if InkType does not match that of mode, change InkType to match it */
 
1330
          /* choose highest color as default, as there is only one option for Black */
 
1331
          if (printing_mode && !strcmp(printing_mode,"BW")) {
 
1332
            stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (InkSet:Both): InkType changed to %u (%s)\n",CANON_INK_K, "Gray");
 
1333
            stp_set_string_parameter(v, "InkType", "Gray");
 
1334
            ink_type = stp_get_string_parameter(v, "InkType");
 
1335
          } else {
 
1336
            inkfound=0;
 
1337
            stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (InkSet:Both): InkType of mode %s is currently set as %s\n",mode->name,ink_type);
 
1338
            for(i=0;i<sizeof(canon_inktypes)/sizeof(canon_inktypes[0]);i++){
 
1339
              if (mode->ink_types & canon_inktypes[i].ink_type) { /* a mode can have several ink_types: must compare with ink_type if set */
 
1340
                if ( !(strcmp(ink_type,canon_inktypes[i].name))) {
 
1341
                  inkfound=1;
 
1342
                  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);
 
1343
                  stp_set_string_parameter(v, "InkType", canon_inktypes[i].name);
 
1344
                  ink_type = stp_get_string_parameter(v, "InkType");
 
1345
                  break;
 
1346
                }
 
1347
              }
 
1348
            }
 
1349
            /* if no match found choose first available inkset */
 
1350
            if (inkfound==0) {
 
1351
              for(i=0;i<sizeof(canon_inktypes)/sizeof(canon_inktypes[0]);i++){
 
1352
                if (mode->ink_types & canon_inktypes[i].ink_type) { /* a mode can have several ink_types: must compare with ink_type if set */
 
1353
                  if ((!ink_type) || (strcmp(ink_type,canon_inktypes[i].name))) { /* if InkType does not match selected mode ink type*/
 
1354
                    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);
 
1355
                    stp_set_string_parameter(v, "InkType", canon_inktypes[i].name);
 
1356
                    ink_type = stp_get_string_parameter(v, "InkType");
 
1357
                    inkfound=1; /* set */
 
1358
                    break;
 
1359
                  }
 
1360
                }
 
1361
              }
 
1362
            }
 
1363
          }
 
1364
#endif
 
1365
#if 0
 
1366
          /* set InkType for the mode found */
 
1367
          for(i=0;i<sizeof(canon_inktypes)/sizeof(canon_inktypes[0]);i++){
 
1368
            if (mode->ink_types & canon_inktypes[i].ink_type) {
 
1369
              if (strcmp(ink_type,canon_inktypes[i].name)) { /* if InkType does not match selected mode ink type*/
 
1370
                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);
 
1371
                stp_set_string_parameter(v, "InkType", canon_inktypes[i].name);
 
1372
                ink_type = stp_get_string_parameter(v, "InkType");
 
1373
                break;
 
1374
              }
 
1375
            }
 
1376
          }
 
1377
#endif
 
1378
 
 
1379
        }
 
1380
        else {
 
1381
          /* mode is fine */
 
1382
          /* matched expected inkset, but need to check if Duplex matches, and if not, get a new mode with right inkset */
 
1383
          mode=suitable_mode_photo(v,muse,caps,quality,duplex_mode);
 
1384
          if (!mode)
 
1385
            modefound=0;
 
1386
          else
 
1387
            modefound=1;
 
1388
 
 
1389
          if (modefound == 0) { /* still did not find a mode: pick first one for that media */
 
1390
            if ( (muse->use_flags & INKSET_PHOTO_MODEREPL) ) {
 
1391
              mode=find_first_matching_mode_photo(v,muse,caps,duplex_mode);
 
1392
            }
 
1393
            else {  /* no special replacement modes for photo inkset */
 
1394
              mode=find_first_matching_mode(v,muse,caps,duplex_mode);
 
1395
            }
 
1396
          }
 
1397
          if (!mode)
 
1398
            modefound=0;
 
1399
          else
 
1400
            modefound=1;
 
1401
 
 
1402
          ink_type=find_ink_type(v,mode,printing_mode);
 
1403
#if 0
 
1404
          /* if InkType does not match that of mode, change InkType to match it */
 
1405
          /* choose highest color as default, as there is only one option for Black */
 
1406
          /* if InkType does not match that of mode, change InkType to match it */
 
1407
          /* choose highest color as default, as there is only one option for Black */
 
1408
          if (printing_mode && !strcmp(printing_mode,"BW")) {
 
1409
            stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (InkSet:Both): InkType changed to %u (%s)\n",CANON_INK_K, "Gray");
 
1410
            stp_set_string_parameter(v, "InkType", "Gray");
 
1411
            ink_type = stp_get_string_parameter(v, "InkType");
 
1412
          } else {
 
1413
            inkfound=0;
 
1414
            stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (InkSet:Both): InkType of mode %s is currently set as %s\n",mode->name,ink_type);
 
1415
            for(i=0;i<sizeof(canon_inktypes)/sizeof(canon_inktypes[0]);i++){
 
1416
              if (mode->ink_types & canon_inktypes[i].ink_type) { /* a mode can have several ink_types: must compare with ink_type if set */
 
1417
                if ( !(strcmp(ink_type,canon_inktypes[i].name))) {
 
1418
                  inkfound=1;
 
1419
                  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);
 
1420
                  stp_set_string_parameter(v, "InkType", canon_inktypes[i].name);
 
1421
                  ink_type = stp_get_string_parameter(v, "InkType");
 
1422
                  break;
 
1423
                }
 
1424
              }
 
1425
            }
 
1426
            /* if no match found choose first available inkset */
 
1427
            if (inkfound==0) {
 
1428
              for(i=0;i<sizeof(canon_inktypes)/sizeof(canon_inktypes[0]);i++){
 
1429
                if (mode->ink_types & canon_inktypes[i].ink_type) { /* a mode can have several ink_types: must compare with ink_type if set */
 
1430
                  if ((!ink_type) || (strcmp(ink_type,canon_inktypes[i].name))) { /* if InkType does not match selected mode ink type*/
 
1431
                    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);
 
1432
                    stp_set_string_parameter(v, "InkType", canon_inktypes[i].name);
 
1433
                    ink_type = stp_get_string_parameter(v, "InkType");
 
1434
                    inkfound=1; /* set */
 
1435
                    break;
 
1436
                  }
 
1437
                }
 
1438
              }
 
1439
            }
 
1440
          }
 
1441
#endif    
 
1442
#if 0
 
1443
          /* set InkType for the mode found */
 
1444
          for(i=0;i<sizeof(canon_inktypes)/sizeof(canon_inktypes[0]);i++){
 
1445
            if (mode->ink_types & canon_inktypes[i].ink_type) {
 
1446
              if (strcmp(ink_type,canon_inktypes[i].name)) { /* if InkType does not match selected mode ink type*/
 
1447
                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);
 
1448
                stp_set_string_parameter(v, "InkType", canon_inktypes[i].name);
 
1449
                ink_type = stp_get_string_parameter(v, "InkType");
 
1450
                break;
 
1451
              }
 
1452
            }
 
1453
          }
 
1454
 
 
1455
#endif
 
1456
 
 
1457
        } 
 
1458
      } /* end of Photo Inkset  */
 
1459
      /*-------------------------------------------------------------------------------------------------*/
 
1460
      /* no restrictions for InkSet "Both" (non-BJC) or "Color" (BJC) or if no InkSet set yet --- do not worry about InkSet at all */
 
1461
      else {
 
1462
        if (printing_mode && !strcmp(printing_mode,"Color")) {
 
1463
          stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (InkSet:Both) PrintingMode Color\n");
 
1464
          /* 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 */
 
1465
          /*if ( (duplex_mode) || (mode->flags & MODE_FLAG_NODUPLEX) ) {*/
 
1466
          i=0;
 
1467
          quality = mode->quality;
 
1468
          modefound=0;
 
1469
          while ( (muse->mode_name_list[i]!=NULL)  && (modefound != 1) ) {
 
1470
            for(j=0;j<caps->modelist->count;j++){
 
1471
              if(!strcmp(muse->mode_name_list[i],caps->modelist->modes[j].name)){/* find right place in canon-modes list */
 
1472
                if ( (caps->modelist->modes[j].quality >= quality) ) {
 
1473
                  if ( !(duplex_mode) || !(muse->use_flags & DUPLEX_SUPPORT) || !(caps->modelist->modes[j].flags & MODE_FLAG_NODUPLEX) ) {
 
1474
                    /* duplex check */
 
1475
                    if (caps->modelist->modes[j].ink_types > CANON_INK_K) {
 
1476
                      mode = &caps->modelist->modes[j];
 
1477
                      modefound=1;
 
1478
                    }
 
1479
                  }
 
1480
                }
 
1481
                break; /* go to next mode in muse list */
 
1482
              }
 
1483
            }
 
1484
            i++;
 
1485
          }
 
1486
          /*}*/
 
1487
        }
 
1488
        else if (printing_mode && !strcmp(printing_mode,"BW")) {
 
1489
          stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (InkSet:Both) PrintingMode BW\n");
 
1490
          /* need to find K-only inksets: they must exist since we declared the printer to have this capability! */
 
1491
          /*if ( (duplex_mode) || (mode->flags & MODE_FLAG_NODUPLEX) ) {*/
 
1492
          i=0;
 
1493
          quality = mode->quality;
 
1494
          modefound=0;
 
1495
          while ( (muse->mode_name_list[i]!=NULL)  && (modefound != 1) ) {
 
1496
            for(j=0;j<caps->modelist->count;j++){
 
1497
              if(!strcmp(muse->mode_name_list[i],caps->modelist->modes[j].name)){/* find right place in canon-modes list */
 
1498
                if ( (caps->modelist->modes[j].quality >= quality) ) {
 
1499
                  if ( !(duplex_mode) || !(muse->use_flags & DUPLEX_SUPPORT) || !(caps->modelist->modes[j].flags & MODE_FLAG_NODUPLEX) ) {
 
1500
                    /* duplex check */
 
1501
                    if (caps->modelist->modes[j].ink_types & CANON_INK_K) { /* AND means support for CANON_IN_K is included */
 
1502
                      mode = &caps->modelist->modes[j];
 
1503
                      modefound=1;
 
1504
                    }
 
1505
                  }
 
1506
                }
 
1507
                break; /* go to next mode in muse list */
 
1508
              }
 
1509
            }
 
1510
            i++;
 
1511
          }
 
1512
          /*}*/
 
1513
        }
 
1514
        else { /* no restriction from PrintingMode if not set yet */
 
1515
          stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (InkSet:Both) PrintingMode not set yet\n");
 
1516
          /* if mode is not a matching duplex mode, need to find a new one */
 
1517
          /*if ( (duplex_mode) || (mode->flags & MODE_FLAG_NODUPLEX) ) {*/
 
1518
          i=0;
 
1519
          quality = mode->quality;
 
1520
          modefound=0;
 
1521
          while ( (muse->mode_name_list[i]!=NULL)  && (modefound != 1) ) {
 
1522
            for(j=0;j<caps->modelist->count;j++){
 
1523
              if(!strcmp(muse->mode_name_list[i],caps->modelist->modes[j].name)){/* find right place in canon-modes list */
 
1524
                if ( (caps->modelist->modes[j].quality >= quality) ) {
 
1525
                  if ( !(duplex_mode) || !(muse->use_flags & DUPLEX_SUPPORT) || !(caps->modelist->modes[j].flags & MODE_FLAG_NODUPLEX) ) {
 
1526
                    /* duplex check */
 
1527
                    mode = &caps->modelist->modes[j];
 
1528
                    modefound=1;
 
1529
                  }
 
1530
                }
 
1531
                break; /* go to next mode in muse list */
 
1532
              }
 
1533
            }
 
1534
            i++;
 
1535
          }
 
1536
          /*}*/
 
1537
        }
 
1538
        /* if no mode was found yet, repeat with no restrictions --- since some media may not allow PrintingMode to be what was selected */
 
1539
        /*if ( (duplex_mode) || (mode->flags & MODE_FLAG_NODUPLEX) ) {*/
 
1540
        if (modefound==0) {
 
1541
          i=0;
 
1542
          quality = mode->quality;
 
1543
          while ( (muse->mode_name_list[i]!=NULL)  && (modefound != 1) ) {
 
1544
            for(j=0;j<caps->modelist->count;j++){
 
1545
              if(!strcmp(muse->mode_name_list[i],caps->modelist->modes[j].name)){/* find right place in canon-modes list */
 
1546
                if ( (caps->modelist->modes[j].quality >= quality) ) {
 
1547
                  if ( !(duplex_mode) || !(muse->use_flags & DUPLEX_SUPPORT) || !(caps->modelist->modes[j].flags & MODE_FLAG_NODUPLEX) ) {
 
1548
                    /* duplex check */
 
1549
                    mode = &caps->modelist->modes[j];
 
1550
                    modefound=1;
 
1551
                    /* set PrintingMode to whatever the mode is capable of */
 
1552
                    if (caps->modelist->modes[j].ink_types > CANON_INK_K) {
 
1553
                      stp_set_string_parameter(v,"PrintingMode","Color");
 
1554
                      printing_mode = stp_get_string_parameter(v, "PrintingMode");
 
1555
                      stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (InkSet:Both) PrintingMode set to Color\n");
 
1556
                    } else {
 
1557
                      stp_set_string_parameter(v,"PrintingMode","BW");
 
1558
                      printing_mode = stp_get_string_parameter(v, "PrintingMode");
 
1559
                      stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (InkSet:Both) PrintingMode set to BW\n");
 
1560
                    }
 
1561
                  }
 
1562
                }
 
1563
                break; /* go to next mode in muse list */
 
1564
              }
 
1565
            }
 
1566
            i++;
 
1567
          }
 
1568
        }
 
1569
 
 
1570
        ink_type=find_ink_type(v,mode,printing_mode);
 
1571
#if 0
 
1572
        /* if InkType does not match that of mode, change InkType to match it */
 
1573
        /* choose highest color as default, as there is only one option for Black */
 
1574
        /* if InkType does not match that of mode, change InkType to match it */
 
1575
        /* choose highest color as default, as there is only one option for Black */
 
1576
        if (printing_mode && !strcmp(printing_mode,"BW")) {
 
1577
          stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (InkSet:Both): InkType changed to %u (%s)\n",CANON_INK_K, "Gray");
 
1578
          stp_set_string_parameter(v, "InkType", "Gray");
 
1579
          ink_type = stp_get_string_parameter(v, "InkType");
 
1580
        } else {
 
1581
          inkfound=0;
 
1582
          stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (InkSet:Both): InkType of mode %s is currently set as %s\n",mode->name,ink_type);
 
1583
          for(i=0;i<sizeof(canon_inktypes)/sizeof(canon_inktypes[0]);i++){
 
1584
            if (mode->ink_types & canon_inktypes[i].ink_type) { /* a mode can have several ink_types: must compare with ink_type if set */
 
1585
              if ( !(strcmp(ink_type,canon_inktypes[i].name))) {
 
1586
                inkfound=1;
 
1587
                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);
 
1588
                stp_set_string_parameter(v, "InkType", canon_inktypes[i].name);
 
1589
                ink_type = stp_get_string_parameter(v, "InkType");
 
1590
                break;
 
1591
              }
 
1592
            }
 
1593
          }
 
1594
          /* if no match found choose first available inkset */
 
1595
          if (inkfound==0) {
 
1596
            for(i=0;i<sizeof(canon_inktypes)/sizeof(canon_inktypes[0]);i++){
 
1597
              if (mode->ink_types & canon_inktypes[i].ink_type) { /* a mode can have several ink_types: must compare with ink_type if set */
 
1598
                if ((!ink_type) || (strcmp(ink_type,canon_inktypes[i].name))) { /* if InkType does not match selected mode ink type*/
 
1599
                  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);
 
1600
                  stp_set_string_parameter(v, "InkType", canon_inktypes[i].name);
 
1601
                  ink_type = stp_get_string_parameter(v, "InkType");
 
1602
                  inkfound=1; /* set */
 
1603
                  break;
 
1604
                }
 
1605
              }
 
1606
            }
 
1607
          }
 
1608
        }
 
1609
#endif
 
1610
 
 
1611
        /* end of cartridge option block */
 
1612
        
 
1613
        stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint: mode searching: replaced mode with: '%s'\n",mode->name);
 
1614
        if (ERRPRINT)
 
1615
          stp_eprintf(v,"mode searching: replaced mode with: '%s'\n",mode->name);
 
1616
        
 
1617
#if 0
 
1618
        /* set InkType for the mode decided upon */
 
1619
        for(i=0;i<sizeof(canon_inktypes)/sizeof(canon_inktypes[0]);i++){
 
1620
          if (mode->ink_types & canon_inktypes[i].ink_type) {
 
1621
            if (strcmp(ink_type,canon_inktypes[i].name)) {
 
1622
              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);
 
1623
              stp_set_string_parameter(v, "InkType", canon_inktypes[i].name);
 
1624
              ink_type = stp_get_string_parameter(v, "InkType");
 
1625
              break;
 
1626
            }
 
1627
          }
 
1628
        }
 
1629
#endif
 
1630
        
 
1631
      }
 
1632
    }/* added one here */
 
1633
    else { /* we did find the mode in the list for media, so it should take precedence over other settings, as it is more specific. */
 
1634
 
 
1635
      stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (check_current_mode):  mode exists, need to check for consistency (%s)\n",mode->name);
 
1636
      quality = mode->quality;
 
1637
      /* Black InkSet */
 
1638
      if (ink_set && !strcmp(ink_set,"Black")) {
 
1639
        stp_set_string_parameter(v, "PrintingMode","BW");
 
1640
        printing_mode = stp_get_string_parameter(v, "PrintingMode");
 
1641
        if (!(mode->ink_types & CANON_INK_K)) {
 
1642
          /* need a new mode: 
 
1643
             loop through modes in muse list searching for a matching inktype, comparing quality
 
1644
          */
 
1645
          mode=suitable_mode_monochrome(v,muse,caps,quality,duplex_mode);
 
1646
          if (!mode)
 
1647
            modefound=0;
 
1648
          else
 
1649
            modefound=1;
 
1650
 
 
1651
          if (modefound == 0) { /* still did not find a mode: pick first one for that media */
 
1652
            if ( (muse->use_flags & INKSET_BLACK_MODEREPL) ) {  
 
1653
              mode=find_first_matching_mode_monochrome(v,muse,caps,duplex_mode);
 
1654
            }
 
1655
            else {  /* no special replacement modes for black inkset */
 
1656
              mode=find_first_matching_mode(v,muse,caps,duplex_mode);
 
1657
            }
 
1658
          }
 
1659
          if (!mode)
 
1660
            modefound=0;
 
1661
          else
 
1662
            modefound=1;
 
1663
 
 
1664
          ink_type=find_ink_type(v,mode,printing_mode);
 
1665
#if 0     
 
1666
          /* if InkType does not match that of mode, change InkType to match it */
 
1667
          /* choose highest color as default, as there is only one option for Black */
 
1668
          /* if InkType does not match that of mode, change InkType to match it */
 
1669
          /* choose highest color as default, as there is only one option for Black */
 
1670
          if (printing_mode && !strcmp(printing_mode,"BW")) {
 
1671
            stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (InkSet:Both): InkType changed to %u (%s)\n",CANON_INK_K, "Gray");
 
1672
            stp_set_string_parameter(v, "InkType", "Gray");
 
1673
            ink_type = stp_get_string_parameter(v, "InkType");
 
1674
          } else {
 
1675
            inkfound=0;
 
1676
            stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (InkSet:Both): InkType of mode %s is currently set as %s\n",mode->name,ink_type);
 
1677
            for(i=0;i<sizeof(canon_inktypes)/sizeof(canon_inktypes[0]);i++){
 
1678
              if (mode->ink_types & canon_inktypes[i].ink_type) { /* a mode can have several ink_types: must compare with ink_type if set */
 
1679
                if ( !(strcmp(ink_type,canon_inktypes[i].name))) {
 
1680
                  inkfound=1;
 
1681
                  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);
 
1682
                  stp_set_string_parameter(v, "InkType", canon_inktypes[i].name);
 
1683
                  ink_type = stp_get_string_parameter(v, "InkType");
 
1684
                  break;
 
1685
                }
 
1686
              }
 
1687
            }
 
1688
            /* if no match found choose first available inkset */
 
1689
            if (inkfound==0) {
 
1690
              for(i=0;i<sizeof(canon_inktypes)/sizeof(canon_inktypes[0]);i++){
 
1691
                if (mode->ink_types & canon_inktypes[i].ink_type) { /* a mode can have several ink_types: must compare with ink_type if set */
 
1692
                  if ((!ink_type) || (strcmp(ink_type,canon_inktypes[i].name))) { /* if InkType does not match selected mode ink type*/
 
1693
                    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);
 
1694
                    stp_set_string_parameter(v, "InkType", canon_inktypes[i].name);
 
1695
                    ink_type = stp_get_string_parameter(v, "InkType");
 
1696
                    inkfound=1; /* set */
 
1697
                    break;
 
1698
                  }
 
1699
                }
 
1700
              }
 
1701
            }
 
1702
          }
 
1703
#endif    
 
1704
#if 0
 
1705
          /* set InkType for the mode found */
 
1706
          for(i=0;i<sizeof(canon_inktypes)/sizeof(canon_inktypes[0]);i++){
 
1707
            if (mode->ink_types & canon_inktypes[i].ink_type) {
 
1708
              if (strcmp(ink_type,canon_inktypes[i].name)) { /* if InkType does not match selected mode ink type*/
 
1709
                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);
 
1710
                stp_set_string_parameter(v, "InkType", canon_inktypes[i].name);
 
1711
                ink_type = stp_get_string_parameter(v, "InkType");
 
1712
                break;
 
1713
              }
 
1714
            }
 
1715
          }
 
1716
#endif
 
1717
 
 
1718
        }
 
1719
        else {
 
1720
          /* mode is fine */
 
1721
          /* matched expected K inkset, but need to check if Duplex matches, and if not, get a new mode with right inkset */
 
1722
          mode=suitable_mode_monochrome(v,muse,caps,quality,duplex_mode);
 
1723
          if (!mode)
 
1724
            modefound=0;
 
1725
          else
 
1726
            modefound=1;
 
1727
 
 
1728
          if (modefound == 0) { /* still did not find a mode: pick first one for that media */
 
1729
            if ( (muse->use_flags & INKSET_BLACK_MODEREPL) ) {  
 
1730
              mode=find_first_matching_mode_monochrome(v,muse,caps,duplex_mode);
 
1731
            }
 
1732
            else {  /* no special replacement modes for black inkset */
 
1733
              mode=find_first_matching_mode(v,muse,caps,duplex_mode);
 
1734
            }
 
1735
          }
 
1736
          if (!mode)
 
1737
            modefound=0;
 
1738
          else
 
1739
            modefound=1;
 
1740
 
 
1741
          ink_type=find_ink_type(v,mode,printing_mode);
 
1742
#if 0
 
1743
          /* if InkType does not match that of mode, change InkType to match it */
 
1744
          /* choose highest color as default, as there is only one option for Black */
 
1745
          /* if InkType does not match that of mode, change InkType to match it */
 
1746
          /* choose highest color as default, as there is only one option for Black */
 
1747
          if (printing_mode && !strcmp(printing_mode,"BW")) {
 
1748
            stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (InkSet:Both): InkType changed to %u (%s)\n",CANON_INK_K, "Gray");
 
1749
            stp_set_string_parameter(v, "InkType", "Gray");
 
1750
            ink_type = stp_get_string_parameter(v, "InkType");
 
1751
          } else {
 
1752
            inkfound=0;
 
1753
            stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (InkSet:Both): InkType of mode %s is currently set as %s\n",mode->name,ink_type);
 
1754
            for(i=0;i<sizeof(canon_inktypes)/sizeof(canon_inktypes[0]);i++){
 
1755
              if (mode->ink_types & canon_inktypes[i].ink_type) { /* a mode can have several ink_types: must compare with ink_type if set */
 
1756
                if ( !(strcmp(ink_type,canon_inktypes[i].name))) {
 
1757
                  inkfound=1;
 
1758
                  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);
 
1759
                  stp_set_string_parameter(v, "InkType", canon_inktypes[i].name);
 
1760
                  ink_type = stp_get_string_parameter(v, "InkType");
 
1761
                  break;
 
1762
                }
 
1763
              }
 
1764
            }
 
1765
            /* if no match found choose first available inkset */
 
1766
            if (inkfound==0) {
 
1767
              for(i=0;i<sizeof(canon_inktypes)/sizeof(canon_inktypes[0]);i++){
 
1768
                if (mode->ink_types & canon_inktypes[i].ink_type) { /* a mode can have several ink_types: must compare with ink_type if set */
 
1769
                  if ((!ink_type) || (strcmp(ink_type,canon_inktypes[i].name))) { /* if InkType does not match selected mode ink type*/
 
1770
                    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);
 
1771
                    stp_set_string_parameter(v, "InkType", canon_inktypes[i].name);
 
1772
                    ink_type = stp_get_string_parameter(v, "InkType");
 
1773
                    inkfound=1; /* set */
 
1774
                    break;
 
1775
                  }
 
1776
                }
 
1777
              }
 
1778
            }
 
1779
          }
 
1780
#endif    
 
1781
#if 0
 
1782
          /* set InkType for the mode found */
 
1783
          for(i=0;i<sizeof(canon_inktypes)/sizeof(canon_inktypes[0]);i++){
 
1784
            if (mode->ink_types & canon_inktypes[i].ink_type) {
 
1785
              if (strcmp(ink_type,canon_inktypes[i].name)) { /* if InkType does not match selected mode ink type*/
 
1786
                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);
 
1787
                stp_set_string_parameter(v, "InkType", canon_inktypes[i].name);
 
1788
                ink_type = stp_get_string_parameter(v, "InkType");
 
1789
                break;
 
1790
              }
 
1791
            }
 
1792
          }
 
1793
#endif
 
1794
 
 
1795
        }
 
1796
      } /* End of Black Inkset */
 
1797
      /*-------------------------------------------------------------------------------------------------*/
 
1798
      /* InkSet Color */
 
1799
      else if ( (ink_set && !strcmp(ink_set,"Color")) && (caps->features & CANON_CAP_T) ) {
 
1800
        stp_set_string_parameter(v, "PrintingMode","Color");
 
1801
        printing_mode = stp_get_string_parameter(v, "PrintingMode");
 
1802
        if (!(mode->ink_types & CANON_INK_CMY)) { /* Color InkSet */
 
1803
          stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (InkSet:Color): inkset incorrect for Color cartridge---need new mode\n");
 
1804
          /* need a new mode
 
1805
             loop through modes in muse list searching for a matching inktype, comparing quality
 
1806
          */
 
1807
          mode=suitable_mode_color(v,muse,caps,quality,duplex_mode);
 
1808
 
 
1809
          if (!mode)
 
1810
            modefound=0;
 
1811
          else
 
1812
            modefound=1;
 
1813
 
 
1814
          if (modefound == 0) { /* still did not find a mode: pick first one for that media */
 
1815
            if ( (muse->use_flags & INKSET_COLOR_MODEREPL) ) {  
 
1816
              mode=find_first_matching_mode_monochrome(v,muse,caps,duplex_mode);
 
1817
              stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (InkSet:Color): Decided on first matching mode for color inkset (%s)\n",mode->name);
 
1818
            }
 
1819
            else {  /* no special replacement modes for color inkset */
 
1820
              mode=find_first_matching_mode(v,muse,caps,duplex_mode);
 
1821
              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);
 
1822
            }
 
1823
          }
 
1824
          if (!mode)
 
1825
            modefound=0;
 
1826
          else
 
1827
            modefound=1;
 
1828
 
 
1829
          ink_type=find_ink_type(v,mode,printing_mode);
 
1830
#if 0
 
1831
          /* if InkType does not match that of mode, change InkType to match it */
 
1832
          /* choose highest color as default, as there is only one option for Black */
 
1833
          /* if InkType does not match that of mode, change InkType to match it */
 
1834
          /* choose highest color as default, as there is only one option for Black */
 
1835
          if (printing_mode && !strcmp(printing_mode,"BW")) {
 
1836
            stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (InkSet:Both): InkType changed to %u (%s)\n",CANON_INK_K, "Gray");
 
1837
            stp_set_string_parameter(v, "InkType", "Gray");
 
1838
            ink_type = stp_get_string_parameter(v, "InkType");
 
1839
          } else {
 
1840
            inkfound=0;
 
1841
            stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (InkSet:Both): InkType of mode %s is currently set as %s\n",mode->name,ink_type);
 
1842
            for(i=0;i<sizeof(canon_inktypes)/sizeof(canon_inktypes[0]);i++){
 
1843
              if (mode->ink_types & canon_inktypes[i].ink_type) { /* a mode can have several ink_types: must compare with ink_type if set */
 
1844
                if ( !(strcmp(ink_type,canon_inktypes[i].name))) {
 
1845
                  inkfound=1;
 
1846
                  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);
 
1847
                  stp_set_string_parameter(v, "InkType", canon_inktypes[i].name);
 
1848
                  ink_type = stp_get_string_parameter(v, "InkType");
 
1849
                  break;
 
1850
                }
 
1851
              }
 
1852
            }
 
1853
            /* if no match found choose first available inkset */
 
1854
            if (inkfound==0) {
 
1855
              for(i=0;i<sizeof(canon_inktypes)/sizeof(canon_inktypes[0]);i++){
 
1856
                if (mode->ink_types & canon_inktypes[i].ink_type) { /* a mode can have several ink_types: must compare with ink_type if set */
 
1857
                  if ((!ink_type) || (strcmp(ink_type,canon_inktypes[i].name))) { /* if InkType does not match selected mode ink type*/
 
1858
                    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);
 
1859
                    stp_set_string_parameter(v, "InkType", canon_inktypes[i].name);
 
1860
                    ink_type = stp_get_string_parameter(v, "InkType");
 
1861
                    inkfound=1; /* set */
 
1862
                    break;
 
1863
                  }
 
1864
                }
 
1865
              }
 
1866
            }
 
1867
          }
 
1868
#endif
 
1869
#if 0
 
1870
          /* set InkType for the mode found */
 
1871
          for(i=0;i<sizeof(canon_inktypes)/sizeof(canon_inktypes[0]);i++){
 
1872
            if (mode->ink_types & canon_inktypes[i].ink_type) {
 
1873
              if (strcmp(ink_type,canon_inktypes[i].name)) { /* if InkType does not match selected mode ink type*/
 
1874
                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);
 
1875
                stp_set_string_parameter(v, "InkType", canon_inktypes[i].name);
 
1876
                ink_type = stp_get_string_parameter(v, "InkType");
 
1877
                break;
 
1878
              }
 
1879
            }
 
1880
          }
 
1881
#endif
 
1882
 
 
1883
        }
 
1884
        else {
 
1885
          /* mode is fine */
 
1886
          /* matched expected RGB inkset, but need to check if Duplex matches, and if not, get a new mode with right inkset */
 
1887
          stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (InkSet:Color): inkset OK but need to check other parameters\n");
 
1888
          mode=suitable_mode_color(v,muse,caps,quality,duplex_mode); /* something wrong here!!! */
 
1889
          stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (InkSet:Color): returned mode for color inkset: %s\n",mode->name);
 
1890
          if (!mode)
 
1891
            modefound=0;
 
1892
          else
 
1893
            modefound=1;
 
1894
 
 
1895
          if (modefound == 0) { /* still did not find a mode: pick first one for that media */
 
1896
            if ( (muse->use_flags & INKSET_COLOR_MODEREPL) ) {
 
1897
              mode=find_first_matching_mode_monochrome(v,muse,caps,duplex_mode);
 
1898
              stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (InkSet:Color): Decided on first matching mode for color inkset (%s)\n",mode->name);
 
1899
            }
 
1900
            else {  /* no special replacement modes for color inkset */
 
1901
              mode=find_first_matching_mode(v,muse,caps,duplex_mode);
 
1902
              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);
 
1903
            }
 
1904
          }
 
1905
          if (!mode)
 
1906
            modefound=0;
 
1907
          else
 
1908
            modefound=1;
 
1909
 
 
1910
          ink_type=find_ink_type(v,mode,printing_mode);
 
1911
#if 0
 
1912
          /* if InkType does not match that of mode, change InkType to match it */
 
1913
          /* choose highest color as default, as there is only one option for Black */
 
1914
          /* if InkType does not match that of mode, change InkType to match it */
 
1915
          /* choose highest color as default, as there is only one option for Black */
 
1916
          if (printing_mode && !strcmp(printing_mode,"BW")) {
 
1917
            stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (InkSet:Both): InkType changed to %u (%s)\n",CANON_INK_K, "Gray");
 
1918
            stp_set_string_parameter(v, "InkType", "Gray");
 
1919
            ink_type = stp_get_string_parameter(v, "InkType");
 
1920
          } else {
 
1921
            inkfound=0;
 
1922
            stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (InkSet:Both): InkType of mode %s is currently set as %s\n",mode->name,ink_type);
 
1923
            for(i=0;i<sizeof(canon_inktypes)/sizeof(canon_inktypes[0]);i++){
 
1924
              if (mode->ink_types & canon_inktypes[i].ink_type) { /* a mode can have several ink_types: must compare with ink_type if set */
 
1925
                if ( !(strcmp(ink_type,canon_inktypes[i].name))) {
 
1926
                  inkfound=1;
 
1927
                  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);
 
1928
                  stp_set_string_parameter(v, "InkType", canon_inktypes[i].name);
 
1929
                  ink_type = stp_get_string_parameter(v, "InkType");
 
1930
                  break;
 
1931
                }
 
1932
              }
 
1933
            }
 
1934
            /* if no match found choose first available inkset */
 
1935
            if (inkfound==0) {
 
1936
              for(i=0;i<sizeof(canon_inktypes)/sizeof(canon_inktypes[0]);i++){
 
1937
                if (mode->ink_types & canon_inktypes[i].ink_type) { /* a mode can have several ink_types: must compare with ink_type if set */
 
1938
                  if ((!ink_type) || (strcmp(ink_type,canon_inktypes[i].name))) { /* if InkType does not match selected mode ink type*/
 
1939
                    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);
 
1940
                    stp_set_string_parameter(v, "InkType", canon_inktypes[i].name);
 
1941
                    ink_type = stp_get_string_parameter(v, "InkType");
 
1942
                    inkfound=1; /* set */
 
1943
                    break;
 
1944
                  }
 
1945
                }
 
1946
              }
 
1947
            }
 
1948
          }
 
1949
#endif
 
1950
#if 0
 
1951
          /* set InkType for the mode found */
 
1952
          for(i=0;i<sizeof(canon_inktypes)/sizeof(canon_inktypes[0]);i++){
 
1953
            if (mode->ink_types & canon_inktypes[i].ink_type) {
 
1954
              if (strcmp(ink_type,canon_inktypes[i].name)) { /* if InkType does not match selected mode ink type*/
 
1955
                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);
 
1956
                stp_set_string_parameter(v, "InkType", canon_inktypes[i].name);
 
1957
                ink_type = stp_get_string_parameter(v, "InkType");
 
1958
                break;
 
1959
              }
 
1960
            }
 
1961
          }
 
1962
#endif
 
1963
 
 
1964
        }
 
1965
      } /* End of Color Inkset */
 
1966
      /*-------------------------------------------------------------------------------------------------*/
 
1967
      /* Photo cartridge selection: only use modes that support it */
 
1968
      else if (ink_set && !strcmp(ink_set,"Photo")) {
 
1969
        /* Photo cartridge printing does not seem to have any monochrome option */
 
1970
        stp_set_string_parameter(v, "PrintingMode","Color");
 
1971
        printing_mode = stp_get_string_parameter(v, "PrintingMode");
 
1972
        /* need to match photo cartridge mode flag */
 
1973
        if (!(mode->flags & MODE_FLAG_PHOTO)) {
 
1974
          /* need a new mode
 
1975
             loop through modes in muse list searching for a matching inkset, comparing quality
 
1976
          */
 
1977
          mode=suitable_mode_photo(v,muse,caps,quality,duplex_mode);
 
1978
          if (!mode)
 
1979
            modefound=0;
 
1980
          else
 
1981
            modefound=1;
 
1982
 
 
1983
          if (modefound == 0) { /* still did not find a mode: pick first one for that media */
 
1984
            if ( (muse->use_flags & INKSET_PHOTO_MODEREPL) ) {  
 
1985
              mode=find_first_matching_mode_photo(v,muse,caps,duplex_mode);
 
1986
            }
 
1987
            else {  /* no special replacement modes for photo inkset */
 
1988
              mode=find_first_matching_mode(v,muse,caps,duplex_mode);
 
1989
            }
 
1990
          }
 
1991
          if (!mode)
 
1992
            modefound=0;
 
1993
          else
 
1994
            modefound=1;
 
1995
 
 
1996
          ink_type=find_ink_type(v,mode,printing_mode);
 
1997
#if 0
 
1998
          /* if InkType does not match that of mode, change InkType to match it */
 
1999
          /* choose highest color as default, as there is only one option for Black */
 
2000
          /* if InkType does not match that of mode, change InkType to match it */
 
2001
          /* choose highest color as default, as there is only one option for Black */
 
2002
          if (printing_mode && !strcmp(printing_mode,"BW")) {
 
2003
            stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (InkSet:Both): InkType changed to %u (%s)\n",CANON_INK_K, "Gray");
 
2004
            stp_set_string_parameter(v, "InkType", "Gray");
 
2005
            ink_type = stp_get_string_parameter(v, "InkType");
 
2006
          } else {
 
2007
            inkfound=0;
 
2008
            stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (InkSet:Both): InkType of mode %s is currently set as %s\n",mode->name,ink_type);
 
2009
            for(i=0;i<sizeof(canon_inktypes)/sizeof(canon_inktypes[0]);i++){
 
2010
              if (mode->ink_types & canon_inktypes[i].ink_type) { /* a mode can have several ink_types: must compare with ink_type if set */
 
2011
                if ( !(strcmp(ink_type,canon_inktypes[i].name))) {
 
2012
                  inkfound=1;
 
2013
                  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);
 
2014
                  stp_set_string_parameter(v, "InkType", canon_inktypes[i].name);
 
2015
                  ink_type = stp_get_string_parameter(v, "InkType");
 
2016
                  break;
 
2017
                }
 
2018
              }
 
2019
            }
 
2020
            /* if no match found choose first available inkset */
 
2021
            if (inkfound==0) {
 
2022
              for(i=0;i<sizeof(canon_inktypes)/sizeof(canon_inktypes[0]);i++){
 
2023
                if (mode->ink_types & canon_inktypes[i].ink_type) { /* a mode can have several ink_types: must compare with ink_type if set */
 
2024
                  if ((!ink_type) || (strcmp(ink_type,canon_inktypes[i].name))) { /* if InkType does not match selected mode ink type*/
 
2025
                    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);
 
2026
                    stp_set_string_parameter(v, "InkType", canon_inktypes[i].name);
 
2027
                    ink_type = stp_get_string_parameter(v, "InkType");
 
2028
                    inkfound=1; /* set */
 
2029
                    break;
 
2030
                  }
 
2031
                }
 
2032
              }
 
2033
            }
 
2034
          }
 
2035
#endif    
 
2036
#if 0
 
2037
          /* set InkType for the mode found */
 
2038
          for(i=0;i<sizeof(canon_inktypes)/sizeof(canon_inktypes[0]);i++){
 
2039
            if (mode->ink_types & canon_inktypes[i].ink_type) {
 
2040
              if (strcmp(ink_type,canon_inktypes[i].name)) { /* if InkType does not match selected mode ink type*/
 
2041
                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);
 
2042
                stp_set_string_parameter(v, "InkType", canon_inktypes[i].name);
 
2043
                ink_type = stp_get_string_parameter(v, "InkType");
 
2044
                break;
 
2045
              }
 
2046
            }
 
2047
          }
 
2048
#endif
 
2049
 
 
2050
        }
 
2051
        else {
 
2052
          /* mode is fine */
 
2053
          /* matched expected inkset, but need to check if Duplex matches, and if not, get a new mode with right inkset */
 
2054
          mode=suitable_mode_photo(v,muse,caps,quality,duplex_mode);
 
2055
          if (!mode)
 
2056
            modefound=0;
 
2057
          else
 
2058
            modefound=1;
 
2059
 
 
2060
          if (modefound == 0) { /* still did not find a mode: pick first one for that media */
 
2061
            if ( (muse->use_flags & INKSET_PHOTO_MODEREPL) ) {
 
2062
              mode=find_first_matching_mode_photo(v,muse,caps,duplex_mode);
 
2063
            }
 
2064
            else {  /* no special replacement modes for photo inkset */
 
2065
              mode=find_first_matching_mode(v,muse,caps,duplex_mode);
 
2066
            }
 
2067
          }
 
2068
          if (!mode)
 
2069
            modefound=0;
 
2070
          else
 
2071
            modefound=1;
 
2072
 
 
2073
          ink_type=find_ink_type(v,mode,printing_mode);
 
2074
#if 0
 
2075
          /* if InkType does not match that of mode, change InkType to match it */
 
2076
          /* choose highest color as default, as there is only one option for Black */
 
2077
          /* if InkType does not match that of mode, change InkType to match it */
 
2078
          /* choose highest color as default, as there is only one option for Black */
 
2079
          if (printing_mode && !strcmp(printing_mode,"BW")) {
 
2080
            stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (InkSet:Both): InkType changed to %u (%s)\n",CANON_INK_K, "Gray");
 
2081
            stp_set_string_parameter(v, "InkType", "Gray");
 
2082
            ink_type = stp_get_string_parameter(v, "InkType");
 
2083
          } else {
 
2084
            inkfound=0;
 
2085
            stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (InkSet:Both): InkType of mode %s is currently set as %s\n",mode->name,ink_type);
 
2086
            for(i=0;i<sizeof(canon_inktypes)/sizeof(canon_inktypes[0]);i++){
 
2087
              if (mode->ink_types & canon_inktypes[i].ink_type) { /* a mode can have several ink_types: must compare with ink_type if set */
 
2088
                if ( !(strcmp(ink_type,canon_inktypes[i].name))) {
 
2089
                  inkfound=1;
 
2090
                  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);
 
2091
                  stp_set_string_parameter(v, "InkType", canon_inktypes[i].name);
 
2092
                  ink_type = stp_get_string_parameter(v, "InkType");
 
2093
                  break;
 
2094
                }
 
2095
              }
 
2096
            }
 
2097
            /* if no match found choose first available inkset */
 
2098
            if (inkfound==0) {
 
2099
              for(i=0;i<sizeof(canon_inktypes)/sizeof(canon_inktypes[0]);i++){
 
2100
                if (mode->ink_types & canon_inktypes[i].ink_type) { /* a mode can have several ink_types: must compare with ink_type if set */
 
2101
                  if ((!ink_type) || (strcmp(ink_type,canon_inktypes[i].name))) { /* if InkType does not match selected mode ink type*/
 
2102
                    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);
 
2103
                    stp_set_string_parameter(v, "InkType", canon_inktypes[i].name);
 
2104
                    ink_type = stp_get_string_parameter(v, "InkType");
 
2105
                    inkfound=1; /* set */
 
2106
                    break;
 
2107
                  }
 
2108
                }
 
2109
              }
 
2110
            }
 
2111
          }
 
2112
#endif    
 
2113
#if 0
 
2114
          /* set InkType for the mode found */
 
2115
          for(i=0;i<sizeof(canon_inktypes)/sizeof(canon_inktypes[0]);i++){
 
2116
            if (mode->ink_types & canon_inktypes[i].ink_type) {
 
2117
              if (strcmp(ink_type,canon_inktypes[i].name)) { /* if InkType does not match selected mode ink type*/
 
2118
                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);
 
2119
                stp_set_string_parameter(v, "InkType", canon_inktypes[i].name);
 
2120
                ink_type = stp_get_string_parameter(v, "InkType");
 
2121
                break;
 
2122
              }
 
2123
            }
 
2124
          }
 
2125
#endif
 
2126
 
 
2127
        } 
 
2128
      } /* end of Photo Inkset  */
 
2129
      /*-------------------------------------------------------------------------------------------------*/
 
2130
      /* no restrictions for InkSet "Both" (non-BJC) or "Color" (BJC) or if no InkSet set yet */
 
2131
      else {
 
2132
        if (printing_mode && !strcmp(printing_mode,"Color")) {
 
2133
          stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (InkSet:Both) PrintingMode Color\n");
 
2134
          /* 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 */
 
2135
          /*if ( (duplex_mode) || (mode->flags & MODE_FLAG_NODUPLEX) ) {*/
 
2136
            i=0;
 
2137
            quality = mode->quality;
 
2138
            modefound=0;
 
2139
            while ( (muse->mode_name_list[i]!=NULL)  && (modefound != 1) ) {
 
2140
              for(j=0;j<caps->modelist->count;j++){
 
2141
                if(!strcmp(muse->mode_name_list[i],caps->modelist->modes[j].name)){/* find right place in canon-modes list */
 
2142
                  if ( (caps->modelist->modes[j].quality >= quality) ) {
 
2143
                    if ( !(duplex_mode) || !(muse->use_flags & DUPLEX_SUPPORT) || !(caps->modelist->modes[j].flags & MODE_FLAG_NODUPLEX) ) {
 
2144
                      /* duplex check */
 
2145
                      if (caps->modelist->modes[j].ink_types > CANON_INK_K) {
 
2146
                        if (!strcmp(mode->name,caps->modelist->modes[j].name)) {
 
2147
                          mode = &caps->modelist->modes[j];
 
2148
                          stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (InkSet:Both) Color: Decided on mode (%s)\n",mode->name);
 
2149
                          modefound=1;
 
2150
                        }
 
2151
                      }
 
2152
                    }
 
2153
                  }
 
2154
                  break; /* go to next mode in muse list */
 
2155
                }
 
2156
              }
 
2157
              i++;
 
2158
            }
 
2159
            /*}*/
 
2160
        }
 
2161
        else if (printing_mode && !strcmp(printing_mode,"BW")) {
 
2162
          stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (InkSet:Both) PrintingMode BW\n");
 
2163
          /* need to find K-only inksets: they must exist since we declared the printer to have this capability! */
 
2164
          /*if ( (duplex_mode) || (mode->flags & MODE_FLAG_NODUPLEX) ) {*/
 
2165
            i=0;
 
2166
            quality = mode->quality;
 
2167
            modefound=0;
 
2168
            while ( (muse->mode_name_list[i]!=NULL)  && (modefound != 1) ) {
 
2169
              for(j=0;j<caps->modelist->count;j++){
 
2170
                if(!strcmp(muse->mode_name_list[i],caps->modelist->modes[j].name)){/* find right place in canon-modes list */
 
2171
                  if ( (caps->modelist->modes[j].quality >= quality) ) {
 
2172
                    if ( !(duplex_mode) || !(muse->use_flags & DUPLEX_SUPPORT) || !(caps->modelist->modes[j].flags & MODE_FLAG_NODUPLEX) ) {
 
2173
                      /* duplex check */
 
2174
                      if (caps->modelist->modes[j].ink_types & CANON_INK_K) { /* AND means CANON_INK_K is included in the support */
 
2175
                        if (!strcmp(mode->name,caps->modelist->modes[j].name)) {
 
2176
                          mode = &caps->modelist->modes[j];
 
2177
                          stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (InkSet:Both) BW: Decided on mode (%s)\n",mode->name);
 
2178
                          modefound=1;
 
2179
                        }
 
2180
                      }
 
2181
                    }
 
2182
                  }
 
2183
                  break; /* go to next mode in muse list */
 
2184
                }
 
2185
              }
 
2186
              i++;
 
2187
            }
 
2188
            /*}*/
 
2189
        }
 
2190
        else { /* no restriction from PrintingMode if not set yet */
 
2191
          stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (InkSet:Both) PrintingMode not set yet\n");
 
2192
          /* if mode is not a matching duplex mode, need to find a new one */
 
2193
          /*if ( (duplex_mode) || (mode->flags & MODE_FLAG_NODUPLEX) ) {*/
 
2194
            i=0;
 
2195
            quality = mode->quality;
 
2196
            modefound=0;
 
2197
            while ( (muse->mode_name_list[i]!=NULL)  && (modefound != 1) ) {
 
2198
              for(j=0;j<caps->modelist->count;j++){
 
2199
                if(!strcmp(muse->mode_name_list[i],caps->modelist->modes[j].name)){/* find right place in canon-modes list */
 
2200
                  if ( (caps->modelist->modes[j].quality >= quality) ) {
 
2201
                    if ( !(duplex_mode) || !(muse->use_flags & DUPLEX_SUPPORT) || !(caps->modelist->modes[j].flags & MODE_FLAG_NODUPLEX) ) {
 
2202
                      /* duplex check */
 
2203
                      if (!strcmp(mode->name,caps->modelist->modes[j].name)) {
 
2204
                        mode = &caps->modelist->modes[j];
 
2205
                        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);
 
2206
                        modefound=1;
 
2207
                      }
 
2208
                    }
 
2209
                  }
 
2210
                  break; /* go to next mode in muse list */
 
2211
                }
 
2212
              }
 
2213
              i++;
 
2214
            }
 
2215
            /*}*/
 
2216
        }
 
2217
        /* if no mode was found yet, repeat with no restrictions --- since some media may not allow PrintingMode to be what was selected */
 
2218
        /*if ( (duplex_mode) || (mode->flags & MODE_FLAG_NODUPLEX) ) {*/
 
2219
        if (modefound==0) {
 
2220
          i=0;
 
2221
          quality = mode->quality;
 
2222
          while ( (muse->mode_name_list[i]!=NULL)  && (modefound != 1) ) {
 
2223
            for(j=0;j<caps->modelist->count;j++){
 
2224
              if(!strcmp(muse->mode_name_list[i],caps->modelist->modes[j].name)){/* find right place in canon-modes list */
 
2225
                if ( (caps->modelist->modes[j].quality >= quality) ) {
 
2226
                  if ( !(duplex_mode) || !(muse->use_flags & DUPLEX_SUPPORT) || !(caps->modelist->modes[j].flags & MODE_FLAG_NODUPLEX) ) {
 
2227
                    /* duplex check */
 
2228
                    mode = &caps->modelist->modes[j];
 
2229
                    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);
 
2230
                    modefound=1;
 
2231
                    /* set PrintingMode to whatever the mode is capable of */
 
2232
                    if (caps->modelist->modes[j].ink_types > CANON_INK_K){
 
2233
                      stp_set_string_parameter(v,"PrintingMode","Color");
 
2234
                      printing_mode = stp_get_string_parameter(v, "PrintingMode");
 
2235
                      stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (InkSet:Both) PrintingMode set to Color\n");
 
2236
                    } else {
 
2237
                      stp_set_string_parameter(v,"PrintingMode","BW");
 
2238
                      printing_mode = stp_get_string_parameter(v, "PrintingMode");
 
2239
                      stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (InkSet:Both) PrintingMode set to BW\n");
 
2240
                    }
 
2241
                  }
 
2242
                }
 
2243
                break; /* go to next mode in muse list */
 
2244
              }
 
2245
            }
 
2246
            i++;
 
2247
          }
 
2248
        }
 
2249
 
 
2250
        ink_type=find_ink_type(v,mode,printing_mode);
 
2251
#if 0
 
2252
        /* if InkType does not match that of mode, change InkType to match it */
 
2253
        /* choose highest color as default, as there is only one option for Black */
 
2254
        /* if InkType does not match that of mode, change InkType to match it */
 
2255
        /* choose highest color as default, as there is only one option for Black */
 
2256
        if (printing_mode && !strcmp(printing_mode,"BW")) {
 
2257
          stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (InkSet:Both): InkType changed to %u (%s)\n",CANON_INK_K, "Gray");
 
2258
          stp_set_string_parameter(v, "InkType", "Gray");
 
2259
          ink_type = stp_get_string_parameter(v, "InkType");
 
2260
        } else {
 
2261
          inkfound=0;
 
2262
          stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint (InkSet:Both): InkType of mode %s is currently set as %s\n",mode->name,ink_type);
 
2263
          for(i=0;i<sizeof(canon_inktypes)/sizeof(canon_inktypes[0]);i++){
 
2264
            if (mode->ink_types & canon_inktypes[i].ink_type) { /* a mode can have several ink_types: must compare with ink_type if set */
 
2265
              if ( !(strcmp(ink_type,canon_inktypes[i].name))) {
 
2266
                inkfound=1;
 
2267
                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);
 
2268
                stp_set_string_parameter(v, "InkType", canon_inktypes[i].name);
 
2269
                ink_type = stp_get_string_parameter(v, "InkType");
 
2270
                break;
 
2271
              }
 
2272
            }
 
2273
          }
 
2274
          /* if no match found choose first available inkset */
 
2275
          if (inkfound==0) {
 
2276
            for(i=0;i<sizeof(canon_inktypes)/sizeof(canon_inktypes[0]);i++){
 
2277
              if (mode->ink_types & canon_inktypes[i].ink_type) { /* a mode can have several ink_types: must compare with ink_type if set */
 
2278
                if ((!ink_type) || (strcmp(ink_type,canon_inktypes[i].name))) { /* if InkType does not match selected mode ink type*/
 
2279
                  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);
 
2280
                  stp_set_string_parameter(v, "InkType", canon_inktypes[i].name);
 
2281
                  ink_type = stp_get_string_parameter(v, "InkType");
 
2282
                  inkfound=1; /* set */
 
2283
                  break;
 
2284
                }
 
2285
              }
 
2286
            }
 
2287
          }
 
2288
        }
 
2289
#endif
 
2290
      }
 
2291
    }
 
2292
  }
 
2293
  /* end of mode replacement code */
 
2294
 
 
2295
 
 
2296
#if 0
 
2297
  if(quality && strcmp(quality, "None") == 0)
 
2298
    quality = "Standard";
 
2299
 
 
2300
  if(quality && !strcmp(quality,"Standard")){
 
2301
    return &caps->modelist->modes[caps->modelist->default_mode];
 
2302
  }
 
2303
#endif
 
2304
 
 
2305
#if 0
 
2306
  /* only some modes can print to cd */
 
2307
  if(input_slot && !strcmp(input_slot,"CD") && !(mode->flags & MODE_FLAG_CD)){
 
2308
    for(i=0;i<caps->modelist->count;i++){
 
2309
      if(caps->modelist->modes[i].flags & MODE_FLAG_CD){
 
2310
        mode = &caps->modelist->modes[i];
 
2311
        break;
 
2312
      }
 
2313
    }
 
2314
  }
 
2315
#endif
 
2316
 
 
2317
 
 
2318
  if (mode) {
 
2319
    stp_set_string_parameter(v, "Resolution",mode->text);  /* check_current_mode checks resolution! */
 
2320
    stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint:  check_current_mode --- updated Resolution: '%s'\n",mode->name);
 
2321
  }
 
2322
 
 
2323
  if (mode) {
 
2324
    stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint:  check_current_mode --- Final returned mode: '%s'\n",mode->name);
 
2325
    if (ERRPRINT)
 
2326
      stp_eprintf(v,"check_current_mode --- Final returned mode: '%s'\n",mode->name);
 
2327
  }
 
2328
  else {
 
2329
    stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint:  check_current_mode --- Final returned mode is NULL \n");
 
2330
    if (ERRPRINT)
 
2331
      stp_eprintf(v,"check_current_mode --- Final returned mode is NULL \n");
 
2332
  }
 
2333
 
 
2334
  /* set PrintingMode in case of Inkset precedence */
 
2335
  if (mode) { /* final mode takes precedence */
 
2336
    if (mode->ink_types == CANON_INK_K)
 
2337
      stp_set_string_parameter(v, "PrintingMode", "BW");
 
2338
    else
 
2339
      stp_set_string_parameter(v, "PrintingMode", "Color");
 
2340
  }
 
2341
  else if (ink_type) { /* mode not yet known, but InkType known. InkSet should have been handled together with InkType above */
 
2342
    if (!strcmp(ink_type,"Gray"))
 
2343
      stp_set_string_parameter(v, "PrintingMode", "BW");
 
2344
    else
 
2345
      stp_set_string_parameter(v, "PrintingMode", "Color");
 
2346
  }
 
2347
 
 
2348
  if (printing_mode)
 
2349
    stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint: Final PrintingMode %s\n",printing_mode);
 
2350
  else /* should not happen */
 
2351
    stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint: Final PrintingMode is NULL\n");
 
2352
 
 
2353
  if (ink_set)
 
2354
    stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint: Final InkSet value (high priority): '%s'\n",ink_set);
 
2355
  else
 
2356
    stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint: Final InkSet value is NULL\n");
 
2357
  
 
2358
  if (ink_type)
 
2359
    stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint: Final InkType value (low priority): '%s'\n",ink_type);
 
2360
  else
 
2361
    stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint: Final InkType value is NULL\n");
 
2362
 
 
2363
  return mode;
 
2364
}
 
2365
 
518
2366
/* function returns the best ink_type for the current mode */
519
2367
static unsigned int
520
2368
canon_printhead_colors(const stp_vars_t*v)
521
2369
{
522
 
  int i;
 
2370
  int i,j;
523
2371
  const canon_mode_t* mode;
 
2372
  const canon_cap_t * caps = canon_get_model_capabilities(v);
524
2373
  const char *print_mode = stp_get_string_parameter(v, "PrintingMode");
525
2374
  const char *ink_type = stp_get_string_parameter(v, "InkType");
526
 
  if(print_mode && strcmp(print_mode, "BW") == 0)
527
 
    return CANON_INK_K;
528
 
 
529
 
  if(ink_type){
530
 
      for(i=0;i<sizeof(canon_inktypes)/sizeof(canon_inktypes[0]);i++){
531
 
          if(ink_type && !strcmp(canon_inktypes[i].name,ink_type))
532
 
              return canon_inktypes[i].ink_type;
533
 
     }
534
 
  }
 
2375
  const char *ink_set = stp_get_string_parameter(v, "InkSet");
 
2376
 
 
2377
  stp_dprintf(STP_DBG_CANON, v,"Entered canon_printhead_colors: got PrintingMode %s\n",print_mode);
 
2378
  if (ERRPRINT)
 
2379
    stp_eprintf(v,"entered canon_printhead_colors: got PrintingMode %s\n",print_mode);
 
2380
 
 
2381
  /* if a mode is available, use it. Else mode is NULL */
 
2382
  if (ERRPRINT)
 
2383
    stp_eprintf(v,"Calling get_current_parameter from canon_printhead_colors");
535
2384
  mode = canon_get_current_mode(v);
536
 
  for(i=0;i<sizeof(canon_inktypes)/sizeof(canon_inktypes[0]);i++){
537
 
    if(mode->ink_types & canon_inktypes[i].ink_type)
538
 
        return canon_inktypes[i].ink_type;
539
 
  }
540
 
  return CANON_INK_K;
 
2385
  
 
2386
  /* get the printing mode again */
 
2387
  print_mode = stp_get_string_parameter(v, "PrintingMode");
 
2388
 
 
2389
  /* if the printing mode was already selected as BW, accept it */
 
2390
  if(print_mode && !strcmp(print_mode, "BW") && !(caps->features & CANON_CAP_NOBLACK) ){ /* workaround in case BW is a default */
 
2391
    stp_dprintf(STP_DBG_CANON, v,"(canon_printhead_colors[BW]) Found InkType %u (CANON_INK_K)\n",CANON_INK_K);
 
2392
    stp_dprintf(STP_DBG_CANON, v,"(canon_printhead_colors[BW]) NOBLACK? %lu\n",(caps->features & CANON_CAP_NOBLACK));
 
2393
    if (ERRPRINT) {
 
2394
      stp_eprintf(v,"(canon_printhead_colors[BW]) Found InkType %u (CANON_INK_K)\n",CANON_INK_K);
 
2395
      stp_eprintf(v,"(canon_printhead_colors[BW]) NOBLACK? %lu\n",(caps->features & CANON_CAP_NOBLACK));
 
2396
    }
 
2397
    return CANON_INK_K;
 
2398
  }
 
2399
  /* alternatively, if the cartridge selection is in force, and black cartride is selected, accept it */
 
2400
  if(ink_set && !strcmp(ink_set, "Black")){
 
2401
    stp_dprintf(STP_DBG_CANON, v,"(canon_printhead_colors[BW]) Found InkSet black selection\n");
 
2402
    if (ERRPRINT)
 
2403
      stp_eprintf(v,"(canon_printhead_colors[BW]) Found InkSet black selection\n");
 
2404
    return CANON_INK_K;
 
2405
  }
 
2406
  
 
2407
  /* originaly finds selected InkType of form: CANON_INK_<inks> */
 
2408
  /* but this is incorrect, since it does not check media or mode */
 
2409
  /* change: deal with mode set and mode not set cases */
 
2410
 
 
2411
  /* if mode was already set, then return the ink types for only that mode */
 
2412
 
 
2413
  if (mode) {
 
2414
    /* if an inktype selected check what it is */
 
2415
    if(ink_type){
 
2416
      for(i=0;i<sizeof(canon_inktypes)/sizeof(canon_inktypes[0]);i++){
 
2417
        if (mode->ink_types & canon_inktypes[i].ink_type) {
 
2418
          stp_dprintf(STP_DBG_CANON, v,"(canon_printhead_colors[inktype]) Found InkType %i(%s)\n",canon_inktypes[i].ink_type,canon_inktypes[i].name);
 
2419
          if (ERRPRINT)
 
2420
            stp_eprintf(v,"(canon_printhead_colors[inktype]) Found InkType %i(%s)\n",canon_inktypes[i].ink_type,canon_inktypes[i].name);
 
2421
          return canon_inktypes[i].ink_type;
 
2422
        }
 
2423
      }
 
2424
    }
 
2425
    else {
 
2426
      /* find the matching inks for the mode: chooses the first one found for a mode! */
 
2427
      /* ink types are arranged in decreasing order so those with more meta inks are discovered first */
 
2428
      for(i=0;i<sizeof(canon_inktypes)/sizeof(canon_inktypes[0]);i++){
 
2429
        if(mode->ink_types & canon_inktypes[i].ink_type) {
 
2430
          stp_dprintf(STP_DBG_CANON, v,"(canon_printhead_colors[mode]) Found InkType %i(%s)\n",canon_inktypes[i].ink_type,canon_inktypes[i].name);
 
2431
          if (ERRPRINT)
 
2432
            stp_eprintf(v,"(canon_printhead_colors[mode]) Found InkType %i(%s)\n",canon_inktypes[i].ink_type,canon_inktypes[i].name);
 
2433
          return canon_inktypes[i].ink_type;
 
2434
        }
 
2435
      }
 
2436
    }
 
2437
  }
 
2438
  else { /* mode not yet set */
 
2439
    /* if an inktype selected check what it is */
 
2440
    if(ink_type){
 
2441
      for(i=0;i<sizeof(canon_inktypes)/sizeof(canon_inktypes[0]);i++){
 
2442
        if(ink_type && !strcmp(canon_inktypes[i].name,ink_type)) {
 
2443
          stp_dprintf(STP_DBG_CANON, v,"(canon_printhead_colors[inktype]) Found InkType %i(%s)\n",canon_inktypes[i].ink_type,canon_inktypes[i].name);
 
2444
          if (ERRPRINT)
 
2445
            stp_eprintf(v,"(canon_printhead_colors[inktype]) Found InkType %i(%s)\n",canon_inktypes[i].ink_type,canon_inktypes[i].name);
 
2446
          return canon_inktypes[i].ink_type;
 
2447
        }
 
2448
      }
 
2449
    }
 
2450
    else { /* no ink type selected yet */
 
2451
      if (ERRPRINT)
 
2452
        stp_eprintf(v,"canon_printhead_colors: no mode and no inktype: we have to choose the highest one to return\n");
 
2453
      /* loop through all modes, and return the highest inktype found */
 
2454
      for(i=0;i<sizeof(canon_inktypes)/sizeof(canon_inktypes[0]);i++){
 
2455
        for(j=0;j<caps->modelist->count;j++){
 
2456
          if(caps->modelist->modes[j].ink_types & canon_inktypes[i].ink_type){
 
2457
            stp_dprintf(STP_DBG_CANON, v," highest inktype found ---  %s(%s)\n",canon_inktypes[i].name,canon_inktypes[i].text);
 
2458
            if (ERRPRINT)
 
2459
              stp_eprintf(v,"highest inktype found --- %s(%s)\n",canon_inktypes[i].name,canon_inktypes[i].text);
 
2460
            return canon_inktypes[i].ink_type;
 
2461
          }
 
2462
        }
 
2463
      }
 
2464
    }
 
2465
    
 
2466
  }
 
2467
 
 
2468
  /* originally as fallback choose CANON_INK_K */
 
2469
  /* However, some Canon printers do not have monochrome mode at all, only color meta ink modes, like iP6000 series */
 
2470
#if 0
 
2471
  stp_dprintf(STP_DBG_CANON, v,"(canon_printhead_colors[fall-through]) Returning InkType %i(CANON_INK_K)\n",CANON_INK_K);
 
2472
  if (ERRPRINT)
 
2473
    stp_eprintf(v,"(canon_printhead_colors[fall-through]) Found InkType %i(CANON_INK_K)\n",CANON_INK_K);
 
2474
  return CANON_INK_K;
 
2475
#endif
 
2476
  /* 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 */
 
2477
  for(i=((sizeof(canon_inktypes)/sizeof(canon_inktypes[0]))-1);i>=0;i--){
 
2478
    for(j=0;j<caps->modelist->count;j++){
 
2479
      if(caps->modelist->modes[j].ink_types & canon_inktypes[i].ink_type){
 
2480
        stp_dprintf(STP_DBG_CANON, v," lowest inktype found ---  %s(%s)\n",canon_inktypes[i].name,canon_inktypes[i].text);
 
2481
        if (ERRPRINT)
 
2482
          stp_eprintf(v,"lowest inktype found --- %s(%s)\n",canon_inktypes[i].name,canon_inktypes[i].text);
 
2483
        return canon_inktypes[i].ink_type;
 
2484
      }
 
2485
    }
 
2486
  }
 
2487
 
 
2488
  /* if fails until here, return something reasonable in most situations */
 
2489
  return CANON_INK_K;
 
2490
  
541
2491
}
542
2492
 
543
2493
static unsigned char
591
2541
      if (!strcmp(name,"w288h512"))    return 0x52; /* Wide101.6x180.6 */
592
2542
      /* w283h566 Wide postcard 148mm x 200mm */
593
2543
 
 
2544
      /* media size codes for CD (and other media depending on printer model */
 
2545
      if (!strcmp(name,"CD5Inch"))    return 0x53; /* CD --- arbitrary choice here, modify in ESC (P command */
 
2546
      /* similar needed for FineArt media which have common sizes but different codes */
 
2547
 
594
2548
      /* custom */
595
2549
 
596
 
      /* media size codes for CD (and other media depending on printer model */
597
 
      /*  850i:  CD Tray custom: none --- no ESC (P */
598
 
      /*  865i:  CD Tray custom: 0x35               */
599
 
      /* MP500:  CD Tray D     : 0x4b               */
600
 
      /* MP530:  CD Tray D     : 0x4b               */
601
 
      /* MP600:  CD Tray F     : 0x51               */
602
 
      /* MP610:  CD Tray F     : 0x51               */
603
 
      /* MP630:  CD Tray G     : 0x53               */
604
 
      /* MP640:  CD Tray G     : 0x53               */
605
 
      /* MP700:  CD tray custom: none --- no ESC (P */
606
 
      /* MP710:  CD tray custom: 0x35               */
607
 
      /* MP730:  CD tray custom: none --- no ESC (P */
608
 
      /* MP740:  CD tray custom: 0x35               */
609
 
      /* MP750:  CD Tray B     : 0x40               */
610
 
      /* MP760:  CD Tray B     : 0x40               */
611
 
      /* MP770:  CD Tray B     : 0x40               */
612
 
      /* MP780:  CD Tray B     : 0x40               */
613
 
      /* MP790:  CD Tray B     : 0x40               */
614
 
      /* MP800:  CD Tray D     : 0x4b               */
615
 
      /* MP810:  CD Tray F     : 0x51               */
616
 
      /* MP830:  CD Tray D     : 0x4b               */
617
 
      /* MP900:  CD Tray custom: 0x35               */
618
 
      /* MP950:  CD Tray C     : 0x4a               */
619
 
      /* MP960:  CD Tray F     : 0x51               */
620
 
      /* MP970:  CD Tray F     : 0x51               */
621
 
      /* MP980:  CD Tray G     : 0x53               */
622
 
      /* MP990:  CD Tray G     : 0x53               */
623
 
      /* MX850:  CD Tray F     : 0x51               */
624
 
      /* iP3000: CD Tray B     : 0x40               */
625
 
      /* iP3100: CD Tray B     : 0x40               */
626
 
      /* iP4000: CD Tray B     : 0x40               */
627
 
      /* iP4100: CD Tray B     : 0x40               */
628
 
      /* iP4200: CD Tray C     : 0x4a               */
629
 
      /* iP4300: CD Tray F     : 0x51               */
630
 
      /* iP4500: CD Tray F     : 0x51               */
631
 
      /* iP4600: CD Tray G     : 0x53               */
632
 
      /* iP4700: CD Tray G     : 0x53               */
633
 
      /* iP4800: CD Tray G     : 0x56               */
634
 
      /* iP4900: CD Tray G     : 0x56               */
635
 
      /* iP5000: CD Tray B     : 0x40               */
636
 
      /* iP5200: CD Tray C     : 0x4a               */
637
 
      /* iP5300: CD Tray F     : 0x51               */
638
 
      /* iP6000D:CD Tray B     : 0x40               */
639
 
      /* iP6100D:CD Tray B     : 0x40               */
640
 
      /* iP6700D:CD Tray C     : 0x4a               */
641
 
      /* iP7100: CD Tray B     : 0x40               */
642
 
      /* iP7500: CD Tray C     : 0x4a               */
643
 
      /* iP8100: CD Tray B     : 0x40               */
644
 
      /* iP8500 :CD Tray B     : 0x40               */
645
 
      /* iP8600: CD Tray B     : 0x40               */
646
 
      /* iP9910: CD Tray A     : 0x3f               */
647
 
      /* MG5200: CD Tray G     : 0x56               */
648
 
      /* MG5300: CD Tray G     : 0x56               */
649
 
      /* MG6100: CD Tray G     : 0x56               */
650
 
      /* MG6200: CD Tray G     : 0x56               */
651
 
      /* MG8100: CD Tray G     : 0x56               */
652
 
      /* MG8200: CD Tray G     : 0x56               */
653
 
      /* pro9000:CD Tray E     : 0x4c               */
654
 
      /* pro9000mk2:CD Tray E  : 0x4c               */
655
 
      /* pro9500:CD Tray E     : 0x4c               */
656
 
      /* pro9500mk2:CD Tray E  : 0x4c               */
657
 
      /* PRO-1:  CD Tray H     : 0x57               */
658
 
 
659
 
      /* MP950:  FineArtA4     : 0x42               */
660
 
      /* MP960:  FineArtA4     : 0x42               */
661
 
      /* MP970:  FineArtA4     : 0x42               */
662
 
      /* MP980:  FineArtA4     : 0x42               */
663
 
      /* MP990:  FineArtA4     : 0x42               */
664
 
      /* MX7600: FineArtA4     : 0x42               */
665
 
      /* iP6700D:FineArtA4     : 0x42               */
666
 
      /* iP7100: FineArtA4     : 0x42               */
667
 
      /* iP7500: FineArtA4     : 0x42               */
668
 
      /* iP8100: FineArtA4     : 0x42               */
669
 
      /* iP8600: FineArtA4     : 0x42               */
670
 
      /* iP9910: FineArtA4     : 0x42               */
671
 
      /* iX7000: FineArtA4     : 0x42               */
672
 
      /* MG6100: FineArtA4     : 0x42               */
673
 
      /* MG6200: FineArtA4     : 0x42               */
674
 
      /* MG8100: FineArtA4     : 0x42               */
675
 
      /* MG8200: FineArtA4     : 0x42               */
676
 
      /* pro9000:FineArtA4     : 0x4d               */
677
 
      /* pro9000mk2:FineArtA4  : 0x4d               */
678
 
      /* pro9500:FineArtA4     : 0x4d               */
679
 
      /* pro9500mk2:FineArtA4  : 0x4d               */
680
 
      /* PRO-1:  FineArtA4     : 0x4d               */
681
 
 
682
 
 
683
2550
      stp_deprintf(STP_DBG_CANON,"canon: Unknown paper size '%s' - using custom\n",name);
684
2551
    } else {
685
2552
      stp_deprintf(STP_DBG_CANON,"canon: Couldn't look up paper size %dx%d - "
691
2558
static void
692
2559
canon_describe_resolution(const stp_vars_t *v, int *x, int *y)
693
2560
{
694
 
    const canon_mode_t* mode = canon_get_current_mode(v);
 
2561
  const canon_mode_t* mode = NULL;
 
2562
  const canon_cap_t * caps = canon_get_model_capabilities(v);
 
2563
 
 
2564
  /* if mode is not yet set, it remains NULL */
 
2565
  if (ERRPRINT)
 
2566
    stp_eprintf(v,"Calling get_current_parameter from canon_describe_resolution");
 
2567
  mode = canon_get_current_mode(v);
 
2568
 
 
2569
  if(!mode)
 
2570
    mode = &caps->modelist->modes[caps->modelist->default_mode];
 
2571
 
 
2572
  if (mode) {
695
2573
    *x = mode->xdpi;
696
2574
    *y = mode->ydpi;
 
2575
  }
697
2576
}
698
2577
 
699
2578
static const char *
705
2584
    return "CMYK";
706
2585
  if(ink_type & CANON_INK_CMY_MASK)
707
2586
    return "CMY";
 
2587
  /* Gernot added */
 
2588
  /*if(ink_type & CANON_INK_cmy_MASK)
 
2589
    return "cmy";*/
708
2590
  return "Grayscale";
709
2591
}
710
2592
 
728
2610
canon_parameters(const stp_vars_t *v, const char *name,
729
2611
                 stp_parameter_t *description)
730
2612
{
731
 
  int           i;
 
2613
  int           i,j;
732
2614
 
733
2615
  const canon_cap_t * caps=
734
2616
    canon_get_model_capabilities(v);
740
2622
  for (i = 0; i < float_parameter_count; i++)
741
2623
    if (strcmp(name, float_parameters[i].param.name) == 0)
742
2624
      {
 
2625
        /* presumably need to return the maximum number of inks the printer can handle */
743
2626
        unsigned int ink_type = canon_printhead_colors(v);
744
2627
 
745
2628
        stp_fill_parameter_settings(description,
858
2741
        if(!(input_slot && !strcmp(input_slot,"CD") && !(caps->modelist->modes[i].flags & MODE_FLAG_CD)))
859
2742
#endif
860
2743
          stp_string_list_add_string(description->bounds.str,
861
 
                                        caps->modelist->modes[i].name, gettext(caps->modelist->modes[i].text));
 
2744
                                     caps->modelist->modes[i].name, gettext(caps->modelist->modes[i].text));
862
2745
        stp_deprintf(STP_DBG_CANON,"supports mode '%s'\n",
863
 
                      caps->modelist->modes[i].name);
 
2746
                     caps->modelist->modes[i].name);
864
2747
        if(i == caps->modelist->default_mode)
865
 
            description->deflt.str=caps->modelist->modes[i].name;
866
 
 
867
 
 
 
2748
          description->deflt.str=caps->modelist->modes[i].name;
868
2749
    }
869
2750
  }
870
2751
  else if (strcmp(name, "InkType") == 0)
871
2752
  {
872
 
    const canon_mode_t* mode = canon_get_current_mode(v);
 
2753
    const canon_mode_t* mode = NULL;
 
2754
 
 
2755
    if (ERRPRINT)
 
2756
      stp_eprintf(v,"Calling get_current_parameter from InkType block in canon_parameters");
 
2757
    mode=canon_get_current_mode(v);
 
2758
 
873
2759
    description->bounds.str= stp_string_list_create();
874
 
    for(i=0;i<sizeof(canon_inktypes)/sizeof(canon_inktypes[0]);i++){
875
 
      if(mode->ink_types & canon_inktypes[i].ink_type){
 
2760
    if (mode) {
 
2761
      for(i=0;i<sizeof(canon_inktypes)/sizeof(canon_inktypes[0]);i++){
 
2762
        if(mode->ink_types & canon_inktypes[i].ink_type){
876
2763
          stp_string_list_add_string(description->bounds.str,canon_inktypes[i].name,_(canon_inktypes[i].text));
877
 
      }
878
 
    }
879
 
    description->deflt.str = stp_string_list_param(description->bounds.str, 0)->name;
 
2764
          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);
 
2765
          if (ERRPRINT)
 
2766
            stp_eprintf(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);
 
2767
        }
 
2768
      }
 
2769
      description->deflt.str = stp_string_list_param(description->bounds.str, 0)->name;
 
2770
    }
 
2771
    /* mode not defined yet --- needed for PPD generation */
 
2772
    else {
 
2773
      for(i=0;i<sizeof(canon_inktypes)/sizeof(canon_inktypes[0]);i++){
 
2774
        for(j=0;j<caps->modelist->count;j++){
 
2775
          if(caps->modelist->modes[j].ink_types & canon_inktypes[i].ink_type){
 
2776
            stp_string_list_add_string(description->bounds.str,canon_inktypes[i].name,_(canon_inktypes[i].text));
 
2777
            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);
 
2778
            if (ERRPRINT)
 
2779
              stp_eprintf(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);
 
2780
            break;
 
2781
          }      
 
2782
        }
 
2783
      }
 
2784
      /* default type must be deduced from the default mode */
 
2785
      /* use color if available, so break after first (color) is found, since inkt types ordered with gray last */
 
2786
      for(i=0;i<sizeof(canon_inktypes)/sizeof(canon_inktypes[0]);i++){
 
2787
        if(caps->modelist->modes[caps->modelist->default_mode].ink_types & canon_inktypes[i].ink_type){
 
2788
          description->deflt.str = canon_inktypes[i].name;
 
2789
          break;
 
2790
        }      
 
2791
      }
 
2792
    }
 
2793
    /* default type must be deduced from the default mode */
 
2794
    /*description->deflt.str = stp_string_list_param(description->bounds.str, 0)->name;*/
880
2795
  }
881
2796
  else if (strcmp(name, "InkChannels") == 0)
882
2797
    {
883
2798
      unsigned int ink_type = canon_printhead_colors(v);
884
2799
      for(i=0;i<sizeof(canon_inktypes)/sizeof(canon_inktypes[0]);i++){
885
 
          if(ink_type == canon_inktypes[i].ink_type)
 
2800
        if(ink_type == canon_inktypes[i].ink_type){
886
2801
              description->deflt.integer = canon_inktypes[i].num_channels;
 
2802
              stp_dprintf(STP_DBG_CANON, v,"Added %d InkChannels\n",canon_inktypes[i].num_channels);
 
2803
              if (ERRPRINT)
 
2804
                stp_eprintf(v,"Added %d InkChannels\n",canon_inktypes[i].num_channels);
 
2805
        }
887
2806
      }
888
2807
      description->bounds.integer.lower = -1;
889
2808
      description->bounds.integer.upper = -1;
895
2814
    description->bounds.str= stp_string_list_create();
896
2815
    description->deflt.str= canon_paper_list[0].name;
897
2816
 
898
 
    for (i = 0; i < count; i ++)
 
2817
    for (i = 0; i < count; i ++) {
899
2818
      stp_string_list_add_string(description->bounds.str,
900
2819
                                canon_paper_list[i].name,
901
2820
                                gettext(canon_paper_list[i].text));
 
2821
 
 
2822
      stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint:  Added Media Type: '%s'\n",canon_paper_list[i].name);
 
2823
    }
902
2824
  }
903
2825
  else if (strcmp(name, "InputSlot") == 0)
904
2826
  {
914
2836
  }
915
2837
  else if (strcmp(name, "PrintingMode") == 0)
916
2838
  {
917
 
    const canon_mode_t* mode = canon_get_current_mode(v);
 
2839
    int found_color, found_mono;
 
2840
    const canon_mode_t* mode = NULL;
 
2841
    /* mode remains NULL if not yet set */
 
2842
    
 
2843
    if (ERRPRINT)
 
2844
      stp_eprintf(v,"Calling get_current_mode from PrintingMode block in canon_parameter");
 
2845
    mode = canon_get_current_mode(v);
 
2846
    
 
2847
    /* If mode is not set need to search ink types for all modes and
 
2848
       see whether we have any color there
 
2849
     */
 
2850
 
 
2851
    if (ERRPRINT)
 
2852
      stp_eprintf(v,"PrintingMode---entered enumeration block in canon_printers\n");
 
2853
 
918
2854
    description->bounds.str = stp_string_list_create();
919
 
    if (mode->ink_types != CANON_INK_K)
 
2855
 
 
2856
    if (ERRPRINT)
 
2857
      stp_eprintf(v,"PrintingMode---created list\n");
 
2858
 
 
2859
    if (mode) {
 
2860
      if (ERRPRINT)
 
2861
        stp_eprintf(v,"PrintingMode: (mode known) what is the current mode inktype value: %i\n",mode->ink_types);
 
2862
      /* e.g., ink_types is 21 = 16 + 4 + 1 */
 
2863
      if (mode->ink_types > 1) {
 
2864
        stp_string_list_add_string
 
2865
          (description->bounds.str, "Color", _("Color"));
 
2866
        if (ERRPRINT)
 
2867
          stp_eprintf(v,"PrintingMode: (mode known) added Color\n");
 
2868
      }
 
2869
      if (mode->ink_types & CANON_INK_K) {
 
2870
        stp_string_list_add_string
 
2871
          (description->bounds.str, "BW", _("Black and White"));
 
2872
        if (ERRPRINT)
 
2873
          stp_eprintf(v,"PrintingMode: (mode known) added BW\n");
 
2874
      }
 
2875
    }
 
2876
#if 0
 
2877
      /* original code */
 
2878
      if (mode)
 
2879
        if (mode->ink_types != CANON_INK_K) {
 
2880
          stp_string_list_add_string
 
2881
            (description->bounds.str, "Color", _("Color"));
 
2882
          if (ERRPRINT)
 
2883
            stp_eprintf(v,"PrintingMode: (mode known) added Color\n");
 
2884
        }
 
2885
#endif
 
2886
 
 
2887
    else { /* mode not known yet --- needed for PPD generation */
 
2888
      if (ERRPRINT)
 
2889
        stp_eprintf(v,"PrintingMode: entered mode not known conditional block\n");
 
2890
      /* add code to find color inks */
 
2891
      /* default type must be deduced from the default mode */
 
2892
      /* use color if available, so break after first (color) is found, since ink types ordered with gray last */
 
2893
      found_color=0;
 
2894
      for(i=0;i<sizeof(canon_inktypes)/sizeof(canon_inktypes[0]);i++){
 
2895
        for(j=0;j<caps->modelist->count;j++){
 
2896
          if(caps->modelist->modes[j].ink_types > 1){
 
2897
            stp_string_list_add_string
 
2898
              (description->bounds.str, "Color", _("Color"));
 
2899
            found_color=1;
 
2900
            if (ERRPRINT)
 
2901
              stp_eprintf(v,"PrintingMode: (mode not known) added Color\n");
 
2902
            break;
 
2903
          }
 
2904
        }
 
2905
        if (found_color==1)
 
2906
          break;
 
2907
      }
 
2908
      found_mono=0;
 
2909
      for(i=0;i<sizeof(canon_inktypes)/sizeof(canon_inktypes[0]);i++){
 
2910
        for(j=0;j<caps->modelist->count;j++){
 
2911
          if(caps->modelist->modes[j].ink_types & CANON_INK_K){
 
2912
            stp_string_list_add_string
 
2913
              (description->bounds.str, "BW", _("Black and White"));
 
2914
            found_mono=1;
 
2915
            if (ERRPRINT)
 
2916
              stp_eprintf(v,"PrintingMode: (mode not known) added BW\n");
 
2917
            break;
 
2918
          }
 
2919
        }
 
2920
        if (found_mono==1)
 
2921
          break;
 
2922
      }
 
2923
 
 
2924
#if 0
 
2925
      /* ink types for default mode*/
 
2926
      if(caps->modelist->modes[caps->modelist->default_mode].ink_types > 1){
 
2927
        stp_string_list_add_string
 
2928
          (description->bounds.str, "Color", _("Color"));
 
2929
        if (ERRPRINT)
 
2930
          stp_eprintf(v,"PrintingMode: (mode not known) added Color\n");
 
2931
      }
 
2932
      if(caps->modelist->modes[caps->modelist->default_mode].ink_types & CANON_INK_K){
 
2933
        stp_string_list_add_string
 
2934
        (description->bounds.str, "BW", _("Black and White"));
 
2935
        if (ERRPRINT)
 
2936
          stp_eprintf(v,"PrintingMode: (mode not known) added BW\n");   
 
2937
      }
 
2938
#endif
 
2939
#if 0
 
2940
      /* original code */
920
2941
      stp_string_list_add_string
921
 
        (description->bounds.str, "Color", _("Color"));
922
 
    stp_string_list_add_string
923
 
      (description->bounds.str, "BW", _("Black and White"));
 
2942
        (description->bounds.str, "BW", _("Black and White"));
 
2943
      if (ERRPRINT)
 
2944
        stp_eprintf(v,"PrintingMode: added BW\n");
 
2945
#endif
 
2946
    }
 
2947
    
 
2948
    /* original code --- fine as is */
924
2949
    description->deflt.str =
925
2950
      stp_string_list_param(description->bounds.str, 0)->name;
926
2951
  } 
 
2952
  else if (strcmp(name, "InkSet") == 0)
 
2953
    {
 
2954
      description->bounds.str= stp_string_list_create();
 
2955
      if (caps->features & CANON_CAP_T) {
 
2956
        stp_string_list_add_string
 
2957
          (description->bounds.str, "Both", _("Both"));
 
2958
        if (!(caps->features & CANON_CAP_NOBLACK)) {
 
2959
            stp_string_list_add_string
 
2960
              (description->bounds.str, "Black", _("Black"));
 
2961
        }
 
2962
        stp_string_list_add_string
 
2963
          (description->bounds.str, "Color", _("Color"));
 
2964
      } /* mutually exclusive */
 
2965
      else if (caps->features & CANON_CAP_cart) {
 
2966
        stp_string_list_add_string
 
2967
          (description->bounds.str, "Color", _("Color"));
 
2968
        stp_string_list_add_string
 
2969
          (description->bounds.str, "Black", _("Black"));
 
2970
        stp_string_list_add_string
 
2971
          (description->bounds.str, "Photo", _("Photo"));
 
2972
      } else {
 
2973
        /* make sure to have at least a default value: no choice */
 
2974
        stp_string_list_add_string
 
2975
          (description->bounds.str, "None", _("None"));
 
2976
      }
 
2977
      description->deflt.str =
 
2978
        stp_string_list_param(description->bounds.str, 0)->name;
 
2979
    }
 
2980
  /* Test implementation of borderless printing */
 
2981
  else if (strcmp(name, "FullBleed") == 0)
 
2982
    {
 
2983
      const char* input_slot = stp_get_string_parameter(v, "InputSlot");
 
2984
      if (input_slot && !strcmp(input_slot,"CD"))
 
2985
        description->is_active = 0;
 
2986
      else if (caps->features & CANON_CAP_BORDERLESS)
 
2987
        description->deflt.boolean = 0;
 
2988
      else
 
2989
        description->is_active = 0;
 
2990
    }
927
2991
  else if (strcmp(name, "Duplex") == 0)
928
2992
  {
929
2993
    int offer_duplex=0;
1002
3066
static void
1003
3067
internal_imageable_area(const stp_vars_t *v,   /* I */
1004
3068
                        int  use_paper_margins,
 
3069
                        int use_maximum_area,
1005
3070
                        int  *left,     /* O - Left position in points */
1006
3071
                        int  *right,    /* O - Right position in points */
1007
3072
                        int  *bottom,   /* O - Bottom position in points */
1008
3073
                        int  *top)      /* O - Top position in points */
1009
3074
{
1010
 
  int   width, length;                  /* Size of page */
 
3075
  int width, length;                    /* Size of page */
 
3076
  int cd = 0;                           /* CD selected */
 
3077
  const char *media_size = stp_get_string_parameter(v, "PageSize");
1011
3078
  int left_margin = 0;
1012
3079
  int right_margin = 0;
1013
3080
  int bottom_margin = 0;
1014
3081
  int top_margin = 0;
1015
 
  int cd = 0;
1016
 
 
1017
 
  const canon_cap_t * caps= canon_get_model_capabilities(v);
1018
 
  const char *media_size = stp_get_string_parameter(v, "PageSize");
1019
3082
  const stp_papersize_t *pt = NULL;
1020
3083
  const char* input_slot = stp_get_string_parameter(v, "InputSlot");
1021
3084
 
 
3085
  const canon_cap_t * caps= canon_get_model_capabilities(v);
 
3086
 
 
3087
  if (media_size)
 
3088
    pt = stp_get_papersize_by_name(media_size);
 
3089
 
1022
3090
  if(input_slot && !strcmp(input_slot,"CD"))
1023
3091
    cd = 1;
1024
3092
 
1025
 
  if (media_size && use_paper_margins)
1026
 
    pt = stp_get_papersize_by_name(media_size);
1027
 
 
1028
3093
  stp_default_media_size(v, &width, &length);
1029
 
  if (pt)
1030
 
    {
 
3094
  if (cd) {
 
3095
    /* ignore printer margins for the cd print, margins get adjusted in do_print for now */
 
3096
    if (pt) {
 
3097
      /* move code from do_print here */
 
3098
    }
 
3099
    else {
 
3100
      /* move code from do_print here */
 
3101
    }
 
3102
  }
 
3103
  /* non-CD media */
 
3104
  else {
 
3105
    if (pt && use_paper_margins) {
1031
3106
      left_margin = pt->left;
1032
3107
      right_margin = pt->right;
1033
3108
      bottom_margin = pt->bottom;
1034
3109
      top_margin = pt->top;
1035
3110
    }
1036
 
  /* ignore printer margins for the cd print, margins get adjusted in do_print */
1037
 
  if(!cd){
 
3111
    /* limit to printer capabilities---without fullbleed */
1038
3112
    left_margin = MAX(left_margin, caps->border_left);
1039
3113
    right_margin = MAX(right_margin, caps->border_right);
1040
3114
    top_margin = MAX(top_margin, caps->border_top);
1041
3115
    bottom_margin = MAX(bottom_margin, caps->border_bottom);
1042
3116
  }
1043
3117
 
 
3118
  /* temporarily limit to non-CD media until page size code moved here from do_print */
 
3119
  /* Note: written beloe code to handle CD case as well */
 
3120
  if(!cd){
 
3121
    if (ERRPRINT) {
 
3122
      stp_eprintf(v,"internal_imageable_area: about to enter the borderless condition block\n");
 
3123
      stp_eprintf(v,"internal_imageable_area: is borderless available? %016lx\n",caps->features & CANON_CAP_BORDERLESS);
 
3124
      stp_eprintf(v,"internal_imageable_area: is borderless selected? %d\n",stp_get_boolean_parameter(v, "FullBleed"));
 
3125
    }
 
3126
    
 
3127
    if ( (caps->features & CANON_CAP_BORDERLESS) &&
 
3128
         (use_maximum_area || (!cd && stp_get_boolean_parameter(v, "FullBleed")))) {
 
3129
      
 
3130
      if (ERRPRINT)
 
3131
        stp_eprintf(v,"internal_imageable_area: entered borderless condition\n");
 
3132
      
 
3133
      if (pt) {
 
3134
        
 
3135
        if (ERRPRINT)
 
3136
          stp_eprintf(v,"internal_imageable_area: entered pt condition\n");
 
3137
        
 
3138
        if (pt->left <= 0 && pt->right <= 0 && pt->top <= 0 && pt->bottom <= 0) {
 
3139
          
 
3140
          if (ERRPRINT)
 
3141
            stp_eprintf(v,"internal_imageable_area: enetered margin<=0 condition\n");
 
3142
          
 
3143
          if (use_paper_margins) {
 
3144
            unsigned width_limit = caps->max_width;
 
3145
            left_margin = -8;
 
3146
            right_margin = -8;
 
3147
            if (width - right_margin - 3 > width_limit)
 
3148
              right_margin = width - width_limit - 3;
 
3149
            top_margin = -6;
 
3150
            bottom_margin = -15;
 
3151
            
 
3152
            if (ERRPRINT)
 
3153
              stp_eprintf(v,"internal_imageable_area: use_paper_margins so set margins all to -7\n");
 
3154
 
 
3155
          }
 
3156
          else {
 
3157
            left_margin = 0;
 
3158
            right_margin = 0;
 
3159
            top_margin = 0;
 
3160
            bottom_margin = 0;
 
3161
            
 
3162
            if (ERRPRINT)
 
3163
              stp_eprintf(v,"internal_imageable_area: does not use paper margins so set margins all to 0\n");
 
3164
 
 
3165
          }
 
3166
        }
 
3167
      }
 
3168
    }
 
3169
  }
 
3170
 
 
3171
  if (ERRPRINT) 
 
3172
    {
 
3173
      stp_eprintf(v,"internal_imageable_area: left_margin %d\n",left_margin);
 
3174
      stp_eprintf(v,"internal_imageable_area: right_margin %d\n",right_margin);
 
3175
      stp_eprintf(v,"internal_imageable_area: top_margin %d\n",top_margin);
 
3176
      stp_eprintf(v,"internal_imageable_area: bottom_margin %d\n",bottom_margin);
 
3177
    }
 
3178
 
1044
3179
  *left =       left_margin;
1045
3180
  *right =      width - right_margin;
1046
3181
  *top =        top_margin;
1047
3182
  *bottom =     length - bottom_margin;
 
3183
 
 
3184
  if (ERRPRINT) 
 
3185
    {
 
3186
      stp_eprintf(v,"internal_imageable_area: page_left %d\n",*left);
 
3187
      stp_eprintf(v,"internal_imageable_area: page_right %d\n",*right);
 
3188
      stp_eprintf(v,"internal_imageable_area: page_top %d\n",*top);
 
3189
      stp_eprintf(v,"internal_imageable_area: page_bottom %d\n",*bottom);
 
3190
    }
 
3191
 
1048
3192
}
1049
3193
 
1050
3194
static void
1054
3198
                     int  *bottom,      /* O - Bottom position in points */
1055
3199
                     int  *top)         /* O - Top position in points */
1056
3200
{
1057
 
  internal_imageable_area(v, 1, left, right, bottom, top);
 
3201
  internal_imageable_area(v, 1, 0, left, right, bottom, top);
 
3202
}
 
3203
 
 
3204
static void
 
3205
canon_maximum_imageable_area(const stp_vars_t *v,   /* I */
 
3206
                     int  *left,        /* O - Left position in points */
 
3207
                     int  *right,       /* O - Right position in points */
 
3208
                     int  *bottom,      /* O - Bottom position in points */
 
3209
                     int  *top)         /* O - Top position in points */
 
3210
{
 
3211
  internal_imageable_area(v, 1, 1, left, right, bottom, top);
1058
3212
}
1059
3213
 
1060
3214
static void
1147
3301
  if (!(init->caps->features & CANON_CAP_DUPLEX))
1148
3302
    return;
1149
3303
  if (strncmp(init->duplex_str, "Duplex", 6)) {
1150
 
    if ( !(strcmp(init->caps->name,"i860")) || !(strcmp(init->caps->name,"i865")) || !(strcmp(init->caps->name,"i950")) ) {
1151
 
      /* i860, i865, i950 use ESC ($ command even for simplex mode */
 
3304
    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")) ) {
 
3305
      /* i860, i865, i950, i960, i990 use ESC ($ command even for simplex mode */
1152
3306
      canon_cmd(v,ESC28,0x24,9,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00);
1153
3307
      return;
1154
3308
    }
1327
3481
    if ( (!strcmp(init->caps->name,"PIXMA MP710")) || (!strcmp(init->caps->name,"PIXMA MP740")) ) 
1328
3482
      arg_6c_3 = 0x10;
1329
3483
 
1330
 
  if (init->pt) arg_6c_2= init->pt->media_code_l;
1331
 
  if(init->caps->model_id >= 3)
 
3484
  if (init->pt) arg_6c_2 = init->pt->media_code_l;
 
3485
  /* select between length 2 and 3 byte variations of command */
 
3486
  /*if(init->caps->model_id >= 3)*/
 
3487
  if(init->caps->ESC_l_len == 3)
1332
3488
    canon_cmd(v,ESC28,0x6c, 3, arg_6c_1, arg_6c_2, arg_6c_3); /* 3rd arg is "gap" */
1333
 
  else
 
3489
  else /* else 2 bytes---no other option for now */
1334
3490
    canon_cmd(v,ESC28,0x6c, 2, arg_6c_1, arg_6c_2);
1335
3491
}
1336
3492
 
1391
3547
static void
1392
3548
canon_init_setPageMargins2(const stp_vars_t *v, const canon_privdata_t *init)
1393
3549
{
 
3550
  unsigned char arg_70_1,arg_70_2,arg_70_3,arg_70_4;
 
3551
 
 
3552
  int border_left,border_right,border_top,border_bottom;
 
3553
  int border_left2,border_top2;
 
3554
  int border_right2;
 
3555
  int border_bottom2;
 
3556
  int area_right,area_top;
 
3557
 
1394
3558
  /* TOFIX: what exactly is to be sent?
1395
3559
   * Is it the printable length or the bottom border?
1396
3560
   * Is is the printable width or the right border?
1397
3561
   */
 
3562
 
 
3563
  int unit = 600;
1398
3564
  int printable_width=  (init->page_width + 1)*5/6;
1399
3565
  int printable_length= (init->page_height + 1)*5/6;
1400
3566
 
1401
 
  unsigned char arg_70_1= (printable_length >> 8) & 0xff;
1402
 
  unsigned char arg_70_2= (printable_length) & 0xff;
1403
 
  unsigned char arg_70_3= (printable_width >> 8) & 0xff;
1404
 
  unsigned char arg_70_4= (printable_width) & 0xff;
1405
 
  const char* input_slot = stp_get_string_parameter(v, "InputSlot");
 
3567
  const char* input_slot = stp_get_string_parameter(v, "InputSlot");  
 
3568
  int print_cd= (input_slot && (!strcmp(input_slot, "CD")));
 
3569
 
 
3570
  if (ERRPRINT) {
 
3571
    stp_eprintf(v,"canon_init_setPageMargins2: borderless capability? %016lx\n", init->caps->features & CANON_CAP_BORDERLESS);
 
3572
    stp_eprintf(v,"canon_init_setPageMargins2: borderless active? %d\n", stp_get_boolean_parameter(v, "FullBleed"));
 
3573
  }
 
3574
 
 
3575
  if ( (init->caps->features & CANON_CAP_BORDERLESS) && 
 
3576
       !(print_cd) && stp_get_boolean_parameter(v, "FullBleed") ) 
 
3577
    {
 
3578
      if (ERRPRINT)
 
3579
        stp_eprintf(v,"canon_init_setPageMargins2: for borderless set printable length and width to 0\n");
 
3580
      /* set to 0 for borderless */
 
3581
      printable_width = 0;
 
3582
      printable_length = 0;
 
3583
    }
 
3584
 
 
3585
  arg_70_1= (printable_length >> 8) & 0xff;
 
3586
  arg_70_2= (printable_length) & 0xff;
 
3587
  arg_70_3= (printable_width >> 8) & 0xff;
 
3588
  arg_70_4= (printable_width) & 0xff;
1406
3589
 
1407
3590
  if (!(init->caps->features & CANON_CAP_px) && !(init->caps->features & CANON_CAP_p))
1408
3591
        return;
1409
3592
 
1410
 
  if ((init->caps->features & CANON_CAP_px) && !(input_slot && !strcmp(input_slot,"CD")))
1411
 
  {
1412
 
    unsigned int unit = 600;
1413
 
    stp_zfwrite(ESC28,2,1,v); /* ESC( */
1414
 
    stp_putc(0x70,v);         /* p    */
1415
 
    stp_put16_le(46, v);      /* len  */
1416
 
    stp_put16_be(printable_length,v);
1417
 
    stp_put16_be(0,v);
1418
 
    stp_put16_be(printable_width,v);
1419
 
    stp_put16_be(0,v);
1420
 
    stp_put32_be(0,v);
1421
 
    stp_put16_be(unit,v);
1422
 
    
1423
 
    stp_put32_be(init->caps->border_left * unit / 72,v); /* area_right */
1424
 
    stp_put32_be(init->caps->border_top * unit / 72,v);  /* area_top */
1425
 
    stp_put32_be(init->page_width  * unit / 72,v); /* area_width */
1426
 
    stp_put32_be(init->page_height * unit / 72,v); /* area_length */
1427
 
    stp_put32_be(0,v); /* paper_right */
1428
 
    stp_put32_be(0,v); /* paper_top */
1429
 
    stp_put32_be((init->page_width + init->caps->border_left + init->caps->border_right) * unit / 72,v); /* paper_width */
1430
 
    stp_put32_be((init->page_height + init->caps->border_top + init->caps->border_bottom) * unit / 72,v); /* paper_height */
1431
 
    return;
 
3593
  if ((init->caps->features & CANON_CAP_px) ) {
 
3594
    /* workaround for CD writing that uses CANON_CAP_px --- fix with capabilities */
 
3595
    if ( !(input_slot && !strcmp(input_slot,"CD")) || !(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 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 MG8100")) || !(strcmp(init->caps->name,"PIXMA MG8200")) )
 
3596
      {
 
3597
 
 
3598
        /* original borders */
 
3599
        border_left=init->caps->border_left;
 
3600
        border_right=init->caps->border_right;
 
3601
        border_top=init->caps->border_top;
 
3602
        border_bottom=init->caps->border_bottom;
 
3603
 
 
3604
        if (print_cd) {
 
3605
          border_top=9;
 
3606
          border_bottom=9;
 
3607
        }
 
3608
 
 
3609
        /* modified borders */
 
3610
        border_left2=border_left;
 
3611
        border_top2=border_top;
 
3612
        border_right2=border_right;
 
3613
        border_bottom2=border_bottom;
 
3614
 
 
3615
        area_right = border_left2 * unit / 72;
 
3616
        area_top = border_top2 * unit / 72;
 
3617
 
 
3618
        if ( (init->caps->features & CANON_CAP_BORDERLESS) && 
 
3619
             !(print_cd) && stp_get_boolean_parameter(v, "FullBleed") ) {
 
3620
          border_left2=-8; /* -8 mini series -6 */
 
3621
          border_right2=-8; /* -8 */
 
3622
          border_top2=-6; /* -6 standard */
 
3623
          border_bottom2=-15; /* -15 standard */
 
3624
          area_right = border_left2 * unit / 72;
 
3625
          area_top = border_top2 * unit / 72;
 
3626
        }
 
3627
 
 
3628
        if (ERRPRINT) {
 
3629
          stp_eprintf(v,"setPageMargins2: init->page_height = %d\n",init->page_height);
 
3630
          stp_eprintf(v,"setPageMargins2: printable_length = %d\n",printable_length);
 
3631
          stp_eprintf(v,"setPageMargins2: paper_height = %d\n",(init->page_height + border_top + border_bottom) * unit / 72);
 
3632
        }
 
3633
 
 
3634
 
 
3635
        stp_zfwrite(ESC28,2,1,v); /* ESC( */
 
3636
        stp_putc(0x70,v);         /* p    */
 
3637
        stp_put16_le(46, v);      /* len  */
 
3638
        /* 0 for borderless, calculated otherwise */
 
3639
        stp_put16_be(printable_length,v); /* Windows 698, gutenprint 570 */
 
3640
        stp_put16_be(0,v);
 
3641
        /* 0 for borderless, calculated otherwise */
 
3642
        stp_put16_be(printable_width,v); /* Windows 352, gutenprint 342 */
 
3643
        stp_put16_be(0,v);
 
3644
        stp_put32_be(0,v);
 
3645
        stp_put16_be(unit,v);
 
3646
        
 
3647
        /* depends on borderless or not: uses modified borders */
 
3648
        stp_put32_be(area_right,v); /* area_right : Windows seems to use 9.6, gutenprint uses 10 */
 
3649
        stp_put32_be(area_top,v);  /* area_top : Windows seems to use 8.4, gutenprint uses 15 */
 
3650
        /* calculated depending on borderless or not: uses modified borders */
 
3651
        stp_put32_be((init->page_width + (border_left - border_left2) + (border_right - border_right2) ) * unit / 72,v); /* area_width : Windows seems to use 352 for Tray G, gutenprint uses 340.92 */
 
3652
        stp_put32_be((init->page_height + (border_top - border_top2) + (border_bottom - border_bottom2) ) * unit / 72,v); /* area_length : Windows seems to use 698.28 for Tray G, gutenprint uses 570 */
 
3653
        /* 0 under all currently known circumstances */
 
3654
        stp_put32_be(0,v); /* paper_right : Windows also 0 here for all Trays */
 
3655
        stp_put32_be(0,v); /* paper_top : Windows also 0 here for all Trays */
 
3656
        /* standard paper sizes, unchanged for borderless so use original borders */
 
3657
        stp_put32_be((init->page_width + border_left + border_right) * unit / 72,v); /* paper_width : Windows 371.4, gutenprint 360.96 */
 
3658
        stp_put32_be((init->page_height + border_top + border_bottom) * unit / 72,v); /* paper_height : Windows 720.96, gutenprint 600 */
 
3659
        return;
 
3660
      }
1432
3661
  }
1433
 
 
1434
3662
  canon_cmd(v,ESC28,0x70, 8,
1435
3663
              arg_70_1, arg_70_2, 0x00, 0x00,
1436
3664
              arg_70_3, arg_70_4, 0x00, 0x00);
1449
3677
  arg_ESCP_1 = (init->pt) ? canon_size_type(v,init->caps): 0x03;
1450
3678
  arg_ESCP_2 = (init->pt) ? init->pt->media_code_P: 0x00;
1451
3679
 
 
3680
  /* workaround for CD media */
 
3681
 
 
3682
  if ( (arg_ESCP_2 == 0x1f) || ( arg_ESCP_2 == 0x20) ) {
 
3683
    if ( arg_ESCP_1 == 0x53 ) {
 
3684
      /* Tray G as default */
 
3685
      arg_ESCP_1 = 0x53;
 
3686
      /* Custom CD tray */
 
3687
      if ( !(strcmp(init->caps->name,"i865")) || !(strcmp(init->caps->name,"PIXMA MP710")) || !(strcmp(init->caps->name,"PIXMA MP740")) || !(strcmp(init->caps->name,"PIXMA MP900")) ) {
 
3688
        arg_ESCP_1 = 0x35;
 
3689
      }
 
3690
      /* Tray A */
 
3691
      if ( !(strcmp(init->caps->name,"PIXMA iP9910")) ) {
 
3692
        arg_ESCP_1 = 0x3f;
 
3693
      }
 
3694
      /* Tray B */
 
3695
      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")) ) {
 
3696
        arg_ESCP_1 = 0x40;
 
3697
      }
 
3698
      /* Tray C */
 
3699
      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")) ) {
 
3700
        arg_ESCP_1 = 0x4a;
 
3701
      }
 
3702
      /* Tray D */
 
3703
      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")) ) {
 
3704
        arg_ESCP_1 = 0x4b;
 
3705
      }
 
3706
      /* Tray E */
 
3707
      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")) ) {
 
3708
        arg_ESCP_1 = 0x4c;
 
3709
      }
 
3710
      /* Tray F */
 
3711
      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")) ) {
 
3712
        arg_ESCP_1 = 0x51;
 
3713
      }
 
3714
      /* Tray G from iP4800 onwards */
 
3715
      if ( !(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")) ) {
 
3716
        arg_ESCP_1 = 0x56;
 
3717
      }
 
3718
    }
 
3719
  }
 
3720
      /*  850i:  CD Tray custom: none --- no ESC (P */
 
3721
      /*  865i:  CD Tray custom: 0x35               */
 
3722
      /* MP500:  CD Tray D     : 0x4b               */
 
3723
      /* MP530:  CD Tray D     : 0x4b               */
 
3724
      /* MP600:  CD Tray F     : 0x51               */
 
3725
      /* MP610:  CD Tray F     : 0x51               */
 
3726
      /* MP630:  CD Tray G     : 0x53               */
 
3727
      /* MP640:  CD Tray G     : 0x53               */
 
3728
      /* MP700:  CD tray custom: none --- no ESC (P */
 
3729
      /* MP710:  CD tray custom: 0x35               */
 
3730
      /* MP730:  CD tray custom: none --- no ESC (P */
 
3731
      /* MP740:  CD tray custom: 0x35               */
 
3732
      /* MP750:  CD Tray B     : 0x40               */
 
3733
      /* MP760:  CD Tray B     : 0x40               */
 
3734
      /* MP770:  CD Tray B     : 0x40               */
 
3735
      /* MP780:  CD Tray B     : 0x40               */
 
3736
      /* MP790:  CD Tray B     : 0x40               */
 
3737
      /* MP800:  CD Tray D     : 0x4b               */
 
3738
      /* MP810:  CD Tray F     : 0x51               */
 
3739
      /* MP830:  CD Tray D     : 0x4b               */
 
3740
      /* MP900:  CD Tray custom: 0x35               */
 
3741
      /* MP950:  CD Tray C     : 0x4a               */
 
3742
      /* MP960:  CD Tray F     : 0x51               */
 
3743
      /* MP970:  CD Tray F     : 0x51               */
 
3744
      /* MP980:  CD Tray G     : 0x53               */
 
3745
      /* MP990:  CD Tray G     : 0x53               */
 
3746
      /* MX850:  CD Tray F     : 0x51               */
 
3747
      /* iP3000: CD Tray B     : 0x40               */
 
3748
      /* iP3100: CD Tray B     : 0x40               */
 
3749
      /* iP4000: CD Tray B     : 0x40               */
 
3750
      /* iP4100: CD Tray B     : 0x40               */
 
3751
      /* iP4200: CD Tray C     : 0x4a               */
 
3752
      /* iP4300: CD Tray F     : 0x51               */
 
3753
      /* iP4500: CD Tray F     : 0x51               */
 
3754
      /* iP4600: CD Tray G     : 0x53               */
 
3755
      /* iP4700: CD Tray G     : 0x53               */
 
3756
      /* iP4800: CD Tray G     : 0x56               */
 
3757
      /* iP4900: CD Tray G     : 0x56               */
 
3758
      /* iP5000: CD Tray B     : 0x40               */
 
3759
      /* iP5200: CD Tray C     : 0x4a               */
 
3760
      /* iP5300: CD Tray F     : 0x51               */
 
3761
      /* iP6000D:CD Tray B     : 0x40               */
 
3762
      /* iP6100D:CD Tray B     : 0x40               */
 
3763
      /* iP6700D:CD Tray C     : 0x4a               */
 
3764
      /* iP7100: CD Tray B     : 0x40               */
 
3765
      /* iP7500: CD Tray C     : 0x4a               */
 
3766
      /* iP8100: CD Tray B     : 0x40               */
 
3767
      /* iP8500 :CD Tray B     : 0x40               */
 
3768
      /* iP8600: CD Tray B     : 0x40               */
 
3769
      /* iP9910: CD Tray A     : 0x3f               */
 
3770
      /* MG5200: CD Tray G     : 0x56               */
 
3771
      /* MG5300: CD Tray G     : 0x56               */
 
3772
      /* MG6100: CD Tray G     : 0x56               */
 
3773
      /* MG6200: CD Tray G     : 0x56               */
 
3774
      /* MG8100: CD Tray G     : 0x56               */
 
3775
      /* MG8200: CD Tray G     : 0x56               */
 
3776
      /* pro9000:CD Tray E     : 0x4c               */
 
3777
      /* pro9000mk2:CD Tray E  : 0x4c               */
 
3778
      /* pro9500:CD Tray E     : 0x4c               */
 
3779
      /* pro9500mk2:CD Tray E  : 0x4c               */
 
3780
      /* PRO-1:  CD Tray H     : 0x57               */
 
3781
 
 
3782
 
 
3783
 
1452
3784
  /* workaround for FineArt media having same size as non-FineArt media */
 
3785
 
 
3786
      /* MP950:  FineArtA4     : 0x42               */
 
3787
      /* MP960:  FineArtA4     : 0x42               */
 
3788
      /* MP970:  FineArtA4     : 0x42               */
 
3789
      /* MP980:  FineArtA4     : 0x42               */
 
3790
      /* MP990:  FineArtA4     : 0x42               */
 
3791
      /* MX7600: FineArtA4     : 0x42               */
 
3792
      /* iP6700D:FineArtA4     : 0x42               */
 
3793
      /* iP7100: FineArtA4     : 0x42               */
 
3794
      /* iP7500: FineArtA4     : 0x42               */
 
3795
      /* iP8100: FineArtA4     : 0x42               */
 
3796
      /* iP8600: FineArtA4     : 0x42               */
 
3797
      /* iP9910: FineArtA4     : 0x42               */
 
3798
      /* iX7000: FineArtA4     : 0x42               */
 
3799
      /* MG6100: FineArtA4     : 0x42               */
 
3800
      /* MG6200: FineArtA4     : 0x42               */
 
3801
      /* MG8100: FineArtA4     : 0x42               */
 
3802
      /* MG8200: FineArtA4     : 0x42               */
 
3803
      /* pro9000:FineArtA4     : 0x4d               */
 
3804
      /* pro9000mk2:FineArtA4  : 0x4d               */
 
3805
      /* pro9500:FineArtA4     : 0x4d               */
 
3806
      /* pro9500mk2:FineArtA4  : 0x4d               */
 
3807
      /* PRO-1:  FineArtA4     : 0x4d               */
 
3808
 
1453
3809
  /* iP7100 is an exception needing yet another papersize code */
1454
3810
  if ( (arg_ESCP_2 == 0x28) || ( arg_ESCP_2 == 0x29) || (arg_ESCP_2 ==  0x2c) || (arg_ESCP_2 == 0x31) ) {
1455
3811
    /* A4 */
1456
3812
    if ( arg_ESCP_1 == 0x03 ) {
 
3813
      /* default */
1457
3814
      arg_ESCP_1 = 0x4d;
1458
 
      if ( !(strcmp(init->caps->name,"PIXMA iP7100")) ) {
 
3815
      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 MG8200")) || !(strcmp(init->caps->name,"PIXMA MG8100")) || !(strcmp(init->caps->name,"PIXMA MG8200")) ) {
1459
3816
        arg_ESCP_1 = 0x42;
1460
3817
      }
1461
3818
    }
1462
3819
    /* A3 */
1463
3820
    if ( arg_ESCP_1 == 0x05 ) {
1464
3821
      arg_ESCP_1 = 0x4e;
1465
 
      if ( !(strcmp(init->caps->name,"PIXMA iP7100")) ) {
 
3822
      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 MG8200")) || !(strcmp(init->caps->name,"PIXMA MG8100")) || !(strcmp(init->caps->name,"PIXMA MG8200")) ) {
1466
3823
        arg_ESCP_1 = 0x43;
1467
3824
      }
1468
3825
    }
1469
3826
    /* Letter */
1470
3827
    if ( arg_ESCP_1 == 0x0d ) {
1471
3828
      arg_ESCP_1 = 0x4f;
1472
 
      if ( !(strcmp(init->caps->name,"PIXMA iP7100")) ) {
 
3829
      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 MG8200")) || !(strcmp(init->caps->name,"PIXMA MG8100")) || !(strcmp(init->caps->name,"PIXMA MG8200")) ) {
1473
3830
        arg_ESCP_1 = 0x44;
1474
3831
      }
1475
3832
    }
1476
3833
  }
1477
3834
 
1478
 
  /* models that add two more bytes "1 0" to the end of the usual 4-byte sequence: */
1479
 
  /* TODO: the code for 6-byte sequences can be replaced by a simple test of XML-capability */
1480
 
  /* MX340 */
1481
 
  /* MX350 --- same driver as MX340 */
1482
 
  /* MX360 */
1483
 
  /* MX410 --- same driver as MX360 */
1484
 
  /* MX420 */
1485
 
  /* MX870 */
1486
 
  /* MX880 */
1487
 
  /* MP250 */
1488
 
  /* MP270 */
1489
 
  /* MP280 */
1490
 
  /* MP490 */
1491
 
  /* MP493 */
1492
 
  /* MP495 */
1493
 
  /* MP550 */
1494
 
  /* MP560 */
1495
 
  /* MP640 */
1496
 
  /* MP990 */
1497
 
  /* iX6500 */
1498
 
  /* iX7000 */
1499
 
  /* iP2700 */
1500
 
  /* iP4700 */
1501
 
  /* iP4800 */
1502
 
  /* iP4900 */
1503
 
  /* iP9910 */
1504
 
  /* MG2100 */
1505
 
  /* MG3100 */
1506
 
  /* MG4100 */
1507
 
  /* MG5100 */
1508
 
  /* MG5200 */
1509
 
  /* MG5300 */
1510
 
  /* MG6100 */
1511
 
  /* MG6200 */
1512
 
  /* MG8100 */
1513
 
  /* MG8200 */
1514
 
  if ( !(strcmp(init->caps->name,"PIXMA MX340")) || !(strcmp(init->caps->name,"PIXMA MX350")) || !(strcmp(init->caps->name,"PIXMA MX360")) || !(strcmp(init->caps->name,"PIXMA MX410")) || !(strcmp(init->caps->name,"PIXMA MX420")) || !(strcmp(init->caps->name,"PIXMA MX870")) || !(strcmp(init->caps->name,"PIXMA MX880")) || !(strcmp(init->caps->name,"PIXMA MP250")) || !(strcmp(init->caps->name,"PIXMA MP270")) || !(strcmp(init->caps->name,"PIXMA MP280")) || !(strcmp(init->caps->name,"PIXMA MP490")) || !(strcmp(init->caps->name,"PIXMA MP493")) || !(strcmp(init->caps->name,"PIXMA MP495")) || !(strcmp(init->caps->name,"PIXMA MP550")) || !(strcmp(init->caps->name,"PIXMA MP560")) || !(strcmp(init->caps->name,"PIXMA MP640")) ||  !(strcmp(init->caps->name,"PIXMA MP990")) || !(strcmp(init->caps->name,"PIXMA iX6500")) || !(strcmp(init->caps->name,"PIXMA iX7000")) || !(strcmp(init->caps->name,"PIXMA iP2700")) || !(strcmp(init->caps->name,"PIXMA iP4700")) || !(strcmp(init->caps->name,"PIXMA iP4800")) || !(strcmp(init->caps->name,"PIXMA iP4900")) || !(strcmp(init->caps->name,"PIXMA iP9910")) || !(strcmp(init->caps->name,"PIXMA MG2100")) || !(strcmp(init->caps->name,"PIXMA MG3100")) || !(strcmp(init->caps->name,"PIXMA MG4100")) || !(strcmp(init->caps->name,"PIXMA MG5100")) || !(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")) )
1515
 
 /* add a lot more here: try if(init->caps->model_id >= 3) how to guess for 4 bytes or more */
 
3835
  if ( init->caps->ESC_P_len == 8 ) /* support for new devices from 2012. TODO: check if XML contents are identical to 6-byte devices */
 
3836
    {/* the 4th of the 6 bytes is the media type. 2nd byte is media size. Both read from canon-media array. */
 
3837
 
 
3838
      /* arg_ESCP_1 = 0x03; */ /* A4 size */
 
3839
      /* arg_ESCP_2 = 0x00; */ /* plain media */
 
3840
      /*                             size                media             */
 
3841
      canon_cmd( v,ESC28,0x50,8,0x00,arg_ESCP_1,0x00,arg_ESCP_2,0x01,0x00,0x01,0x00);
 
3842
    }
 
3843
  else if ( init->caps->ESC_P_len == 6 ) /* first devices with XML header and ender */
1516
3844
    {/* the 4th of the 6 bytes is the media type. 2nd byte is media size. Both read from canon-media array. */
1517
3845
 
1518
3846
      /* arg_ESCP_1 = 0x03; */ /* A4 size */
1520
3848
      /*                             size                media             */
1521
3849
      canon_cmd( v,ESC28,0x50,6,0x00,arg_ESCP_1,0x00,arg_ESCP_2,0x01,0x00);
1522
3850
    }
1523
 
  else if ( !(strcmp(init->caps->name,"i80")) || !(strcmp(init->caps->name,"i560")) || !(strcmp(init->caps->name,"i860")) || !(strcmp(init->caps->name,"i865")) || !(strcmp(init->caps->name,"i900")) || !(strcmp(init->caps->name,"i950")) || !(strcmp(init->caps->name,"i960")) || !(strcmp(init->caps->name,"i9900")) || !(strcmp(init->caps->name,"SELPHY DS700")) || !(strcmp(init->caps->name,"PIXMA MP130")) || !(strcmp(init->caps->name,"PIXMA MP360")) || !(strcmp(init->caps->name,"PIXMA MP370")) || !(strcmp(init->caps->name,"PIXMA MP375R")) || !(strcmp(init->caps->name,"PIXMA MP390")) || !(strcmp(init->caps->name,"PIXMA MP710")) || !(strcmp(init->caps->name,"PIXMA MP740")) || !(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 MP900"))  || !(strcmp(init->caps->name,"PIXMA iP1000"))  || !(strcmp(init->caps->name,"PIXMA iP1500"))  || !(strcmp(init->caps->name,"PIXMA iP2000"))  || !(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 iP6000D")) || !(strcmp(init->caps->name,"PIXMA iP6100D")) || !(strcmp(init->caps->name,"PIXMA iP8500"))  )  {
 
3851
  else if ( init->caps->ESC_P_len == 4 )  {/* 4 bytes */
 
3852
    /*                             size            media       */
 
3853
    canon_cmd( v,ESC28,0x50,4,0x00,arg_ESCP_1,0x00,arg_ESCP_2 );
 
3854
  }
 
3855
  else if ( init->caps->ESC_P_len == 2 )  {
1524
3856
    /* 2 bytes only */
1525
3857
      canon_cmd( v,ESC28,0x50,2,0x00,arg_ESCP_1 );
1526
3858
    }   
1527
 
  else /* 4 bytes */
1528
 
    /*                             size            media       */
1529
 
    canon_cmd( v,ESC28,0x50,4,0x00,arg_ESCP_1,0x00,arg_ESCP_2 );
1530
 
}
 
3859
  else /* error in definition */
 
3860
    stp_deprintf(STP_DBG_CANON,"SEVERE BUG IN print-canon.c::canon_init_setESC_P() "
 
3861
                 "ESC_P_len=%d!!\n",init->caps->ESC_P_len);
 
3862
}
 
3863
 
 
3864
/* ESC (S -- 0x53 -- unknown -- :
 
3865
   Required by iP90/iP90v and iP100 printers.
 
3866
 */
 
3867
static void
 
3868
canon_init_setESC_S(const stp_vars_t *v, const canon_privdata_t *init)
 
3869
{
 
3870
  unsigned char arg_ESCS_01,arg_ESCS_04,arg_ESCS_09,arg_ESCS_11;
 
3871
 
 
3872
  if (!(init->caps->features & CANON_CAP_S))
 
3873
    return;
 
3874
 
 
3875
  if (!(init->mode->flags & MODE_FLAG_S))
 
3876
    return;
 
3877
 
 
3878
  /* iP90 defaults: based on non-photo media */
 
3879
  arg_ESCS_01 = 0x01;
 
3880
  arg_ESCS_04 = 0xff;
 
3881
  arg_ESCS_09 = 0x1a;
 
3882
  arg_ESCS_11 = 0x68;
 
3883
  
 
3884
  /* hard-coded for different media, color and  quality settings */
 
3885
  /* iP90 bytes 1,4,9 and 11 vary */
 
3886
  if ( !(strcmp(init->caps->name,"PIXMA iP90")) ) {
 
3887
    if ( !strcmp(init->mode->name,"600x600dpi_high2") || !strcmp(init->mode->name,"600x600dpi_high4") ) {
 
3888
      /* if inkset is color then set special bytes, else leave default.
 
3889
         Note: in this case the mode only has CMYK, mono is a different mode.
 
3890
      */
 
3891
      if (init->used_inks == CANON_INK_CMYK) {
 
3892
        arg_ESCS_01 = 0xc1;
 
3893
        arg_ESCS_04 = 0xf1;
 
3894
        arg_ESCS_09 = 0x50;
 
3895
        arg_ESCS_11 = 0x28;
 
3896
      }
 
3897
    } else if ( !strcmp(init->mode->name,"300x300dpi_draft") ) {
 
3898
      /* set regardless of inkset */
 
3899
      arg_ESCS_09 = 0x02;
 
3900
      arg_ESCS_11 = 0x08;
 
3901
    } else if ( !strcmp(init->mode->name,"600x600dpi_draft2") ) {
 
3902
      /* if inkset is color then set special bytes, else leave default */
 
3903
      if (init->used_inks == CANON_INK_CMYK) {
 
3904
        arg_ESCS_09 = 0x0a;
 
3905
        arg_ESCS_11 = 0x28;
 
3906
      }
 
3907
    } else if ( !strcmp(init->mode->name,"600x600dpi_photohigh") || !strcmp(init->mode->name,"600x600dpi_photo") || !strcmp(init->mode->name,"600x600dpi_photodraft") ) {
 
3908
      /* almost all photo media need (same) changes from defaults */
 
3909
      /* exception: "600x600dpi_photohigh2" no ESC (S command */
 
3910
      /* exception: "600x600dpi_tshirt" no ESC (S command */
 
3911
      arg_ESCS_01 = 0xc1;
 
3912
      arg_ESCS_04 = 0xf0;
 
3913
      arg_ESCS_09 = 0x50;
 
3914
      arg_ESCS_11 = 0x28;
 
3915
    }
 
3916
  }
 
3917
  else if ( !(strcmp(init->caps->name,"PIXMA iP100")) ) {
 
3918
    /* iP100 bytes 9 and 11 vary */       
 
3919
    if ( !strcmp(init->mode->name,"300x300dpi_draft") ) {
 
3920
      /* set regardless of inkset */
 
3921
      arg_ESCS_09 = 0x02;
 
3922
      arg_ESCS_11 = 0x08;
 
3923
    } 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") ) {
 
3924
      /* all photo media need (same) changes from defaults */
 
3925
      arg_ESCS_09 = 0x0a;
 
3926
      arg_ESCS_11 = 0x28;
 
3927
    }
 
3928
  }
 
3929
 
 
3930
      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);
 
3931
 
 
3932
}
 
3933
 
1531
3934
 
1532
3935
/* ESC (T -- 0x54 -- setCartridge -- :
1533
3936
 */
1534
3937
static void
1535
3938
canon_init_setCartridge(const stp_vars_t *v, const canon_privdata_t *init)
1536
3939
{
 
3940
  const char *ink_set;
 
3941
 
1537
3942
  if (!(init->caps->features & CANON_CAP_T))
1538
3943
    return;
1539
3944
 
1540
 
  if ( !(strcmp(init->caps->name,"PIXMA iP90")) || !(strcmp(init->caps->name,"PIXMA iP90v")) ) {
1541
 
    canon_cmd(v,ESC28,0x54,3,0x02,0x00,0x00); /* default for iP90, iP100 */
1542
 
    /* black save     : 2 1 0 for selected modes, rest 2 0 0 */
1543
 
    /* composite black: 2 0 1 for selected modes, rest 2 0 0 */
1544
 
    /* both blacks    : 2 1 1 for selected modes, some 2 0 1, rest 2 0 0  */
1545
 
  }
1546
 
  else if ( !(strcmp(init->caps->name,"PIXMA iP6210")) || !(strcmp(init->caps->name,"PIXMA iP6220")) || !(strcmp(init->caps->name,"PIXMA iP6310")) ) {
1547
 
    canon_cmd(v,ESC28,0x54,3,0x03,0x06,0x06); /* default for iP6210D, iP6220D, iP6310D */
1548
 
    /* both:  0x3 0x6 0x6 */
1549
 
    /* color: 0x3 0x1 0x1 */
 
3945
  ink_set = stp_get_string_parameter(v, "InkSet");
 
3946
 
 
3947
  if (ink_set && !(strcmp(ink_set,"Both"))) {
 
3948
    if ( !(strcmp(init->caps->name,"PIXMA iP90")) || !(strcmp(init->caps->name,"PIXMA iP100")) ) {
 
3949
      canon_cmd(v,ESC28,0x54,3,0x02,0x00,0x00); /* default for iP90, iP100 */
 
3950
    } 
 
3951
    else if ( !(strcmp(init->caps->name,"PIXMA iP6210")) ) {
 
3952
      canon_cmd(v,ESC28,0x54,3,0x03,0x06,0x06); /* default for iP6210D, iP6220D, iP6310D */
 
3953
      /* both:  0x3 0x6 0x6 */
 
3954
      /* color: 0x3 0x1 0x1 */
 
3955
    }
 
3956
    else {
 
3957
      canon_cmd(v,ESC28,0x54,3,0x03,0x04,0x04); /* default: both cartridges */
 
3958
    }
 
3959
  }
 
3960
  else if (ink_set && !(strcmp(ink_set,"Black"))) {
 
3961
    if ( !(strcmp(init->caps->name,"PIXMA iP90")) || !(strcmp(init->caps->name,"PIXMA iP100")) ) {
 
3962
      canon_cmd(v,ESC28,0x54,3,0x02,0x00,0x00); /* default for iP90, iP100 */
 
3963
    } 
 
3964
    else if ( !(strcmp(init->caps->name,"PIXMA iP6210")) ) {
 
3965
        canon_cmd(v,ESC28,0x54,3,0x03,0x06,0x06); /* default for iP6210D, iP6220D, iP6310D */
 
3966
        /* both:  0x3 0x6 0x6 */
 
3967
        /* color: 0x3 0x1 0x1 */
 
3968
        /* workaround since does not have black option */
 
3969
    }
 
3970
    else {
 
3971
      canon_cmd(v,ESC28,0x54,3,0x03,0x02,0x02); /* default: black cartridge */
 
3972
    }
 
3973
  }
 
3974
  else if (ink_set && !(strcmp(ink_set,"Color"))) {
 
3975
    if ( !(strcmp(init->caps->name,"PIXMA iP90")) || !(strcmp(init->caps->name,"PIXMA iP100")) ) {
 
3976
      canon_cmd(v,ESC28,0x54,3,0x02,0x00,0x01); /* composite for iP90, iP100 */
 
3977
      /* black save     : 2 1 0 for selected plain (600dpi std) modes, rest remain 2 0 0 */
 
3978
      /* composite black: 2 0 1 for selected plain (600dpi std & draft) modes, rest remain 2 0 0 */
 
3979
      /* both above set : AND of bytes above */
 
3980
    } 
 
3981
    else if ( !(strcmp(init->caps->name,"PIXMA iP6210")) ) {
 
3982
      canon_cmd(v,ESC28,0x54,3,0x03,0x01,0x01); /* default for iP6210D, iP6220D, iP6310D */
 
3983
      /* both:  0x3 0x6 0x6 */
 
3984
      /* color: 0x3 0x1 0x1 */
 
3985
    }
 
3986
    else {
 
3987
      canon_cmd(v,ESC28,0x54,3,0x03,0x01,0x01); /* default: color cartridges */
 
3988
    }
1550
3989
  }
1551
3990
  else {
1552
3991
    canon_cmd(v,ESC28,0x54,3,0x03,0x04,0x04); /* default: both cartridges */
1575
4014
 
1576
4015
  if ( (init->caps->features & CANON_CAP_r)
1577
4016
       || (init->caps->features & CANON_CAP_rr) )
1578
 
    canon_cmd(v,ESC28,0x72, 1, init->caps->ESC_r_arg); /* whatever for - 8200/S200 need it */
 
4017
    if  (init->caps->ESC_r_arg != 0) /* only output arg if non-zero */
 
4018
      canon_cmd(v,ESC28,0x72, 1, init->caps->ESC_r_arg); /* whatever for - 8200/S200 need it */
1579
4019
  if (init->caps->features & CANON_CAP_rr) {
1580
4020
    if ( !(strcmp(init->caps->name,"S200")) ) {
1581
4021
      canon_cmd(v,ESC28,0x72, 3, 0x63, 1, 0); /* whatever for - S200 needs it */
1584
4024
    else if ( !(strcmp(init->caps->name,"S820")) || !(strcmp(init->caps->name,"S900")) || !(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")) ) {
1585
4025
      canon_cmd(v,ESC28,0x72, 2, 0x62, 0); /* 2 bytes */
1586
4026
    }
1587
 
    /* no other cases yet */
 
4027
    /* CD mode only */
 
4028
    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")) ) ) {
 
4029
      canon_cmd(v,ESC28,0x72, 1, 0x65);
 
4030
    }
 
4031
    /* CD mode only */
 
4032
    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")) ) ) {
 
4033
      canon_cmd(v,ESC28,0x72, 1, 0x68);
 
4034
    }
 
4035
    /* CD mode only -- no ESC (r at all otherwise */
 
4036
    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")) ) ) {
 
4037
      canon_cmd(v,ESC28,0x72, 1, 0x68);
 
4038
    }
 
4039
    /* other cases here */
1588
4040
  }
1589
4041
}
1590
4042
 
1632
4084
        buf[2]=0x01;
1633
4085
    }
1634
4086
    for(i=0;i<init->mode->num_inks;i++){
1635
 
        if(init->mode->inks[i].ink){
 
4087
        if(init->mode->inks[i].channel != 0){ /* 0 means ink is used in gutenprint for sub-channel setup but not intended for printer */
1636
4088
          if(init->mode->inks[i].ink->flags & INK_FLAG_5pixel_in_1byte)
1637
4089
            buf[3+i*3+0]=(1<<5)|init->mode->inks[i].ink->bits; /*info*/
1638
4090
           /*else if(init->mode->inks[i].ink->flags & INK_FLAG_lowresmode)
1650
4102
            buf[3+i*3+2] = 0x04;*/
1651
4103
          /*else if (init->mode->inks[i].ink->bits == 1)
1652
4104
            buf[3+i*3+2] = 0x02;*/
1653
 
          buf[3+i*3+2]= init->mode->inks[i].ink->numsizes+1;/*level*/
 
4105
          /*else*/ /* normal operation */
 
4106
            buf[3+i*3+2]= init->mode->inks[i].ink->numsizes+1;/*level*/
1654
4107
          /*else
1655
4108
            buf[3+i*3+2] = 0x00;*/
1656
4109
          /* this should show that there is an error */
1689
4142
       generic condition based on CANON_INK_CMY */
1690
4143
    if (init->used_inks == CANON_INK_CMY) arg_74_3= 0x02; /* for BC-06 cartridge!!! */
1691
4144
    /* example of better way: for BJC-3000 series */
1692
 
    if  (!strcmp(init->caps->name,"3000")) {
 
4145
    if  (!strcmp(init->caps->name,"3000") || !strcmp(init->caps->name,"4300")) {
1693
4146
      /* but if photo cartridge selection, set differently again */
1694
4147
      if (init->mode->flags & MODE_FLAG_PHOTO)
1695
4148
        arg_74_3= 0x0a;
1740
4193
  stp_put16_le(init->num_channels, v);
1741
4194
  /* add an exception here to add 0x60 of cmy channels for those printers/modes that require it */
1742
4195
  raster_channel_order=init->channel_order;
1743
 
  /*  if (!strcmp(init->caps->name,"MP450"))*/
 
4196
  if ( !(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 iP2700")) || !(strcmp(init->caps->name,"PIXMA MG2100")) )
1744
4197
    {
1745
 
      /* if cmy there, add 0x60 to each --- this is not yet correct, some modes do not require it! */
1746
 
      /*      if (init->num_channels==7) {*/
1747
 
        for(i=0;i<init->num_channels;i++){
1748
 
          switch(init->channel_order[i]){
1749
 
            /* case 'c':raster_channel_order[i]+=0x60; break;;*/
1750
 
            /* case 'm':raster_channel_order[i]+=0x60; break;;*/
1751
 
            /* case 'y':raster_channel_order[i]+=0x60; break;;*/
1752
 
          }
1753
 
        }
1754
 
        /*}*/
 
4198
      /* if cmy there, add 0x60 to each --- all modes using cmy require it */
 
4199
      for(i=0;i<init->num_channels;i++){
 
4200
        switch(init->channel_order[i]){
 
4201
        case 'c':raster_channel_order[i]+=0x60; break;;
 
4202
        case 'm':raster_channel_order[i]+=0x60; break;;
 
4203
        case 'y':raster_channel_order[i]+=0x60; break;;
 
4204
        }
 
4205
      }
 
4206
      /* Gernot: debug */
 
4207
      /* if CMY there, add 0x80 to each to change to cmy+0x60 */
 
4208
      /*     for(i=0;i<init->num_channels;i++){
 
4209
        switch(init->channel_order[i]){
 
4210
        case 'C':raster_channel_order[i]+=0x80; break;;
 
4211
        case 'M':raster_channel_order[i]+=0x80; break;;
 
4212
        case 'Y':raster_channel_order[i]+=0x80; break;;
 
4213
        }
 
4214
        }*/
1755
4215
      stp_zfwrite((const char *)raster_channel_order,init->num_channels, 1, v);
1756
4216
    }
1757
 
    /*  else
 
4217
  /* note these names are from canon-printers.h, only separate driver strings are required */
 
4218
  else if ( !(strcmp(init->caps->name,"PIXMA iP6210")) ) {
 
4219
    /* if cmy there, add 0x60 to each --- only some modes using cmy require it */
 
4220
    /* case one: all modes with only cmy */
 
4221
    if (init->num_channels==3) {
 
4222
      for(i=0;i<init->num_channels;i++){
 
4223
        switch(init->channel_order[i]){
 
4224
        case 'c':raster_channel_order[i]+=0x60; break;;
 
4225
        case 'm':raster_channel_order[i]+=0x60; break;;
 
4226
        case 'y':raster_channel_order[i]+=0x60; break;;
 
4227
        }
 
4228
      }
 
4229
    }
 
4230
    /* case two: CMYcmy modes, but not CMYkcm modes */
 
4231
    else if ( (init->num_channels==6) && (init->used_inks==CANON_INK_CMY) ) {
 
4232
      for(i=0;i<init->num_channels;i++){
 
4233
        switch(init->channel_order[i]){
 
4234
        case 'c':raster_channel_order[i]+=0x60; break;;
 
4235
        case 'm':raster_channel_order[i]+=0x60; break;;
 
4236
        case 'y':raster_channel_order[i]+=0x60; break;;
 
4237
        }
 
4238
      }
 
4239
    }
 
4240
    /* case three: CMYkm modes with 0x80 to subtract from all inks with 2 or 8 bits */
 
4241
    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)) ) {
 
4242
      for(i=0;i<init->num_channels;i++){
 
4243
        switch(init->channel_order[i]){
 
4244
        case 'C':raster_channel_order[i]+=0x80; break;;
 
4245
        case 'M':raster_channel_order[i]+=0x80; break;;
 
4246
        case 'Y':raster_channel_order[i]+=0x80; break;;
 
4247
        case 'c':raster_channel_order[i]+=0x80; break;;
 
4248
        case 'm':raster_channel_order[i]+=0x80; break;;
 
4249
        case 'k':raster_channel_order[i]+=0x80; break;;
 
4250
        }
 
4251
      }
 
4252
    }
 
4253
    stp_zfwrite((const char *)raster_channel_order,init->num_channels, 1, v);
 
4254
  }
 
4255
  else
1758
4256
    {
1759
4257
      stp_zfwrite((const char *)init->channel_order,init->num_channels, 1, v);
1760
 
      }*/
 
4258
    }
1761
4259
}
1762
4260
 
1763
4261
 
1784
4282
  canon_init_setPageMargins2(v,init);    /* ESC (p */
1785
4283
  canon_init_setESC_P(v,init);           /* ESC (P */
1786
4284
  canon_init_setCartridge(v,init);       /* ESC (T */
 
4285
  canon_init_setESC_S(v,init);           /* ESC (S */
1787
4286
  canon_init_setTray(v,init);            /* ESC (l */
1788
4287
  canon_init_setX72(v,init);             /* ESC (r */
1789
4288
  canon_init_setMultiRaster(v,init);     /* ESC (I (J (L */
1945
4444
    if(ink->channel && ink->density > 0.0){
1946
4445
        int delay = canon_get_delay(privdata,ink->channel);
1947
4446
        canon_channel_t* current;
1948
 
        stp_dprintf(STP_DBG_CANON, v, "canon_setup_channel: privdata->num_channels %d\n", privdata->num_channels);
 
4447
        stp_dprintf(STP_DBG_CANON, v, "canon_setup_channel: (start) privdata->num_channels %d\n", privdata->num_channels);
 
4448
        stp_dprintf(STP_DBG_CANON, v, "canon_setup_channel: (start) privdata->channel_order %s\n", privdata->channel_order);
1949
4449
        /* create a new channel */
1950
4450
        privdata->channels = stp_realloc(privdata->channels,sizeof(canon_channel_t) * (privdata->num_channels + 1));
1951
4451
        privdata->channel_order = stp_realloc(privdata->channel_order,privdata->num_channels + 2);
1953
4453
        privdata->channel_order[privdata->num_channels]=ink->channel;
1954
4454
        stp_dprintf(STP_DBG_CANON, v, "canon_setup_channel: ink->channel %c\n", ink->channel);
1955
4455
        privdata->channel_order[privdata->num_channels+1]='\0';
 
4456
        stp_dprintf(STP_DBG_CANON, v, "canon_setup_channel: (terminated)privdata->channel_order %s\n", privdata->channel_order);
1956
4457
        current = &(privdata->channels[privdata->num_channels]);
1957
4458
        ++privdata->num_channels;
1958
4459
        /* fill ink properties */
1978
4479
        (*shades)[0].value = ink->density;
1979
4480
        stp_dprintf(STP_DBG_CANON, v, "canon_setup_channel: ink->density %.3f\n", ink->density);
1980
4481
        (*shades)[0].numsizes = ink->ink->numsizes;
 
4482
        /* test for 4-4 inket with 8 levels spaced every 2nd */
 
4483
        /*if (ink->ink->bits == 4)
 
4484
          (*shades)[0].numsizes = 8;*/
 
4485
 
1981
4486
        (*shades)[0].dot_sizes = ink->ink->dot_sizes;
1982
4487
        return 1;
1983
4488
    } 
2024
4529
            /* find K and k inks */
2025
4530
            for(i=0;i<privdata->mode->num_inks;i++){
2026
4531
                const canon_inkset_t* ink = &privdata->mode->inks[i];
2027
 
                if(ink->channel == primary[channel] || ink->channel == secondary[channel])
 
4532
                if(ink->channel == primary[channel] || ink->channel == secondary[channel]) {
2028
4533
                    subchannel += canon_setup_channel(v,privdata,channel,subchannel,ink,&shades);
 
4534
                    /* Gernot: add */
 
4535
                    stp_dprintf(STP_DBG_CANON, v, "canon_setup_channels: got a black channel\n");
 
4536
                }
2029
4537
            }
2030
4538
            is_black_channel = 1;
 
4539
            /* adding cmy channels */
 
4540
            /*}else if(channel != STP_ECOLOR_K && privdata->used_inks & (CANON_INK_CMY_MASK | CANON_INK_cmy_MASK)){ */ /* color channels */
2031
4541
        }else if(channel != STP_ECOLOR_K && privdata->used_inks & CANON_INK_CMY_MASK){  /* color channels */
2032
4542
            for(i=0;i<privdata->mode->num_inks;i++){
2033
4543
                const canon_inkset_t* ink = &privdata->mode->inks[i];
2034
4544
                stp_dprintf(STP_DBG_CANON, v, "canon_setup_channels: loop non-K inks %d\n", i);
2035
 
                /* if(ink->channel == primary[channel] || ((privdata->used_inks & CANON_INK_CcMmYyKk_MASK) && (ink->channel == secondary[channel]))) */
 
4545
                /*if(ink->channel == primary[channel] || ((privdata->used_inks & (CANON_INK_CcMmYyKk_MASK | CANON_INK_cmy_MASK)) && (ink->channel == secondary[channel]))) {*/
 
4546
                if(ink->channel == primary[channel] || ((privdata->used_inks & (CANON_INK_CcMmYyKk_MASK|CANON_INK_CMY_MASK)) && (ink->channel == secondary[channel]))) {
2036
4547
                /* Gernot: see if this works: use the masks that includes secondary channels */
2037
 
                if(ink->channel == primary[channel] || ((privdata->used_inks & CANON_INK_CMYKk_MASK ) && (ink->channel == secondary[channel])))
2038
 
                    subchannel += canon_setup_channel(v,privdata,channel,subchannel,ink,&shades);
 
4548
                /* if(ink->channel == primary[channel] || ((privdata->used_inks & CANON_INK_CMYKk_MASK ) && (ink->channel == secondary[channel]))) {*/
 
4549
                  subchannel += canon_setup_channel(v,privdata,channel,subchannel,ink,&shades);
 
4550
                  stp_dprintf(STP_DBG_CANON, v, "canon_setup_channels: adding subchannel\n");
 
4551
                }
 
4552
                else {
 
4553
                  stp_dprintf(STP_DBG_CANON, v, "canon_setup_channels: not creating subchannel\n"); 
 
4554
                }
2039
4555
            } 
2040
4556
        }
2041
4557
 
2098
4614
 
2099
4615
  privdata->top = stp_get_top(v);
2100
4616
  privdata->left = stp_get_left(v);
2101
 
  privdata->out_width = stp_get_width(v);
2102
 
  privdata->out_height = stp_get_height(v);
2103
 
 
2104
 
  internal_imageable_area(v, 0, &page_left, &page_right,
 
4617
  privdata->out_width = stp_get_width(v); /* check Epson: page_true_width */
 
4618
  privdata->out_height = stp_get_height(v); /* check Epson: page_true_height */
 
4619
 
 
4620
  stp_deprintf(STP_DBG_CANON,"stp_get_width: privdata->out_width is %i\n",privdata->out_width);
 
4621
  stp_deprintf(STP_DBG_CANON,"stp_get_height: privdata->out_height is %i\n",privdata->out_height);
 
4622
 
 
4623
  /* Don't use full bleed mode if the paper itself has a margin */
 
4624
  if (privdata->left > 0 || privdata->top > 0)
 
4625
    stp_set_boolean_parameter(v, "FullBleed", 0);
 
4626
 
 
4627
  internal_imageable_area(v, 0, 0, &page_left, &page_right,
2105
4628
                          &page_bottom, &page_top);
2106
4629
  if (print_cd) {
2107
4630
    privdata->cd_inner_radius = hub_size / 2;
2112
4635
    privdata->page_height = privdata->top + privdata->out_height;
2113
4636
  } else {
2114
4637
    privdata->left -= page_left;
2115
 
    privdata->top -= page_top;
2116
 
    privdata->page_width = page_right - page_left;
2117
 
    privdata->page_height = page_bottom - page_top;
 
4638
    privdata->top -= page_top; /* checked in Epson: matches */
 
4639
    privdata->page_width = page_right - page_left; /* checked in Epson: matches */
 
4640
    privdata->page_height = page_bottom - page_top; /* checked in Epson: matches */
 
4641
 
 
4642
    if (ERRPRINT) {
 
4643
      stp_eprintf(v,"============================set_imageable_area========================\n");
 
4644
      stp_eprintf(v,"setup_page page_top = %i\n",page_top);
 
4645
      stp_eprintf(v,"setup_page page_bottom = %i\n",page_bottom);
 
4646
      stp_eprintf(v,"setup_page page_left = %i\n",page_left);
 
4647
      stp_eprintf(v,"setup_page page_right = %i\n",page_right);
 
4648
      stp_eprintf(v,"setup_page top = %i\n",privdata->top);
 
4649
      stp_eprintf(v,"setup_page left = %i\n",privdata->left);
 
4650
      stp_eprintf(v,"setup_page out_height = %i\n",privdata->out_height);
 
4651
      stp_eprintf(v,"setup_page page_height = %i\n",privdata->page_height);
 
4652
      stp_eprintf(v,"setup_page page_width = %i\n",privdata->page_width);
 
4653
    }
 
4654
 
 
4655
    stp_dprintf(STP_DBG_CANON, v, "setup_page page_top = %i\n",page_top);
 
4656
    stp_dprintf(STP_DBG_CANON, v, "setup_page page_bottom = %i\n",page_bottom);
 
4657
    stp_dprintf(STP_DBG_CANON, v, "setup_page page_left = %i\n",page_left);
 
4658
    stp_dprintf(STP_DBG_CANON, v, "setup_page page_right = %i\n",page_right);
 
4659
    stp_dprintf(STP_DBG_CANON, v, "setup_page top = %i\n",privdata->top);
 
4660
    stp_dprintf(STP_DBG_CANON, v, "setup_page left = %i\n",privdata->left);
 
4661
    stp_dprintf(STP_DBG_CANON, v, "setup_page out_height = %i\n",privdata->out_height);
 
4662
    stp_dprintf(STP_DBG_CANON, v, "setup_page page_height = %i\n",privdata->page_height);
 
4663
    stp_dprintf(STP_DBG_CANON, v, "setup_page page_width = %i\n",privdata->page_width);
 
4664
 
2118
4665
  }
2119
 
 
2120
4666
}
2121
4667
 
2122
4668
 
2184
4730
  int i;
2185
4731
  int           status = 1;
2186
4732
  const char    *media_source = stp_get_string_parameter(v, "InputSlot");
 
4733
  const char    *ink_type = stp_get_string_parameter(v, "InkType");
2187
4734
  const char    *duplex_mode =stp_get_string_parameter(v, "Duplex");
2188
4735
  int           page_number = stp_get_int_parameter(v, "PageNumber");
2189
4736
  const canon_cap_t * caps= canon_get_model_capabilities(v);
2190
 
  int           y;              /* Looping vars */
 
4737
  const canon_modeuselist_t* mlist = caps->modeuselist;
 
4738
#if 0
 
4739
  const canon_modeuse_t* muse;
 
4740
#endif
 
4741
  /*  int monocheck = 0;
 
4742
      int colcheck = 0; */
 
4743
  int           x,y;            /* Looping vars */
2191
4744
  canon_privdata_t privdata;
2192
4745
  int           errdiv,         /* Error dividend */
2193
4746
                errmod,         /* Error modulus */
2201
4754
  int           print_cd= (media_source && (!strcmp(media_source, "CD")));
2202
4755
  int           image_height;
2203
4756
#if 0
2204
 
                image_width;
 
4757
  int           image_width;
2205
4758
#endif
2206
4759
  double        k_upper, k_lower;
2207
4760
  unsigned char *cd_mask = NULL;
2209
4762
  double inner_r_sq = 0;
2210
4763
  unsigned char* weave_cols[4] ; /* TODO clean up weaving code to be more generic */
2211
4764
 
 
4765
  stp_dprintf(STP_DBG_CANON, v, "Entering canon_do_print\n");
 
4766
 
2212
4767
  if (!stp_verify(v))
2213
4768
    {
2214
4769
      stp_eprintf(v, "Print options not verified; cannot print.\n");
2228
4783
  memset(&privdata,0,sizeof(canon_privdata_t));
2229
4784
  privdata.caps = caps;
2230
4785
 
2231
 
  /* find the wanted print mode */
 
4786
  /* find the wanted media type */
 
4787
  /* - media type has priority
 
4788
     - then we select source
 
4789
     - then inkset (cartridge selection)
 
4790
     - then we select duplex
 
4791
     - after that we compare if mode is compatible with media
 
4792
     - if not, we replace it using closest quality setting
 
4793
     - then we decide on printhead colors based on actual mode to use
 
4794
   */
 
4795
 
 
4796
  privdata.pt = get_media_type(caps,stp_get_string_parameter(v, "MediaType"));
 
4797
  privdata.slot = canon_source_type(media_source,caps);
 
4798
 
 
4799
  /* ---  make adjustment to InkSet based on Media --- */
 
4800
 
 
4801
  /* cartridge selection if any: default is Both---but should change to NULL if CANON_CAP_T is not available */
 
4802
  /* check if InkSet chosen is possible for this Media */
 
4803
  /* - if Black, check if modes for selected media have a black flag */
 
4804
  /*   else, set InkSet to "Both" for now */
 
4805
 
 
4806
  /* scroll through modeuse list to find media */
 
4807
  for(i=0;i<mlist->count;i++){
 
4808
    if(!strcmp(privdata.pt->name,mlist->modeuses[i].name)){
 
4809
#if 0
 
4810
      muse = &mlist->modeuses[i];
 
4811
#endif
 
4812
      break;
 
4813
    }
 
4814
  }
 
4815
 
 
4816
  if ( !strcmp(stp_get_string_parameter(v, "InkSet"),"Black")) {
 
4817
    /* check if there is any mode for that media with K-only inktype */
 
4818
    /* if not, change it to "Both" */
 
4819
    /* NOTE: User cannot force monochrome printing here, since that would require changing the Color Model */
 
4820
    if (!(mlist->modeuses[i].use_flags & INKSET_BLACK_SUPPORT)) {
 
4821
      stp_set_string_parameter(v, "InkSet", "Both");    
 
4822
    }
 
4823
  }
 
4824
  /* Color-only */
 
4825
  else if ( !strcmp(stp_get_string_parameter(v, "InkSet"),"Color") && (caps->features & CANON_CAP_T) ) {
 
4826
    /* check if there is any mode for that media with no K in the inkset at all */
 
4827
    /* if not, change it to "Both" */
 
4828
    if (!(mlist->modeuses[i].use_flags & INKSET_COLOR_SUPPORT)) {
 
4829
      stp_set_string_parameter(v, "InkSet", "Both");    
 
4830
    }
 
4831
  }
 
4832
  /* no restriction for "Both" (non-BJC) or "Color" (BJC) or "Photo" yet */
 
4833
 
 
4834
  /* get InkSet after adjustment */
 
4835
  privdata.ink_set = stp_get_string_parameter(v, "InkSet");
 
4836
 
 
4837
  /* --- no current restrictions for Duplex setting --- */
 
4838
 
 
4839
  /* in particular, we do not constraint duplex printing to certain media */
 
4840
  privdata.duplex_str = duplex_mode;
 
4841
 
 
4842
  /* ---  make adjustment to InkType to comply with InkSet --- */
 
4843
 
 
4844
  /*  although InSet adjustment is pre-supposed, even if InkSet is not
 
4845
      adjusted, the InkType adjustment will be validated against mode
 
4846
      later */
 
4847
  if (!strcmp(privdata.ink_set,"Black")) {
 
4848
    if (strcmp(ink_type,"Gray")) {/* if ink_type is NOT set to Gray yet */
 
4849
      stp_dprintf(STP_DBG_CANON, v, "canon_do_print: InkSet Black, so InkType set to Gray\n");
 
4850
      stp_set_string_parameter(v, "InkType", "Gray");
 
4851
    }
 
4852
  } /* Color-only */
 
4853
  else if ( !strcmp(privdata.ink_set,"Color") && (caps->features & CANON_CAP_T) ) {
 
4854
    if (strcmp(ink_type,"RGB")) {/* if ink_type is NOT set to RGB (CMY) yet */
 
4855
      stp_dprintf(STP_DBG_CANON, v, "canon_do_print: InkSet Color, so InkType changed to RGB (CMY)\n");
 
4856
      stp_set_string_parameter(v, "InkType", "RGB");
 
4857
    }
 
4858
  } /* no restriction for InkSet set to "Both" or "Photo" */
 
4859
 
 
4860
  /* --- make adjustments to mode --- */
 
4861
 
 
4862
  /* find the wanted print mode: NULL if not yet set */
 
4863
  if (ERRPRINT)
 
4864
    stp_eprintf(v,"Calling get_current_parameter from canon_do_print routine (before default set)");
 
4865
  stp_dprintf(STP_DBG_CANON, v, "canon_do_print: calling canon_get_current_mode\n");
2232
4866
  privdata.mode = canon_get_current_mode(v);
2233
4867
 
 
4868
  if(!privdata.mode) {
 
4869
    privdata.mode = &caps->modelist->modes[caps->modelist->default_mode];
 
4870
  }
 
4871
  
 
4872
  /* then call get_current_mode again to sort out the correct matching of parameters and mode selection */
 
4873
  if (ERRPRINT)
 
4874
    stp_eprintf(v,"Calling cannon_check_current_parameter from canon_do_print routine (after default set)");
 
4875
  
 
4876
  stp_dprintf(STP_DBG_CANON, v, "canon_do_print: calling canon_check_current_mode\n");
 
4877
 
 
4878
  privdata.mode = canon_check_current_mode(v);
 
4879
 
 
4880
  /* --- completed all adjustments: options should be consistent --- */
 
4881
 
2234
4882
  /* set quality */
2235
4883
  privdata.quality = privdata.mode->quality;
2236
4884
 
 
4885
 
2237
4886
  /* force grayscale if image is grayscale
2238
4887
   *                 or single black cartridge installed
2239
4888
   */
2240
4889
  privdata.used_inks = canon_printhead_colors(v);
2241
4890
  if (privdata.used_inks == CANON_INK_K)
2242
4891
      stp_set_string_parameter(v, "PrintingMode", "BW");
 
4892
  else
 
4893
    stp_set_string_parameter(v, "PrintingMode", "Color");
2243
4894
 
2244
4895
  setup_page(v,&privdata);
2245
4896
 
2246
4897
  image_height = stp_image_height(image);
 
4898
 
2247
4899
#if 0
2248
4900
  image_width = stp_image_width(image);
2249
4901
#endif
2250
4902
 
2251
 
  privdata.pt = get_media_type(caps,stp_get_string_parameter(v, "MediaType"));
2252
 
  privdata.slot = canon_source_type(media_source,caps);
2253
 
  privdata.duplex_str = duplex_mode;
2254
4903
  privdata.is_first_page = (page_number == 0);
2255
4904
 
2256
4905
 /*
2257
4906
  * Convert image size to printer resolution...
2258
4907
  */
 
4908
#if 0
 
4909
  stp_deprintf(STP_DBG_CANON,"canon_do_print: unused image_width is %i pts(?)\n",image_width);
 
4910
#endif
 
4911
  stp_deprintf(STP_DBG_CANON,"canon_do_print: privdata.out_width is %i pts\n",privdata.out_width);
 
4912
  stp_deprintf(STP_DBG_CANON,"canon_do_print: privdata.out_height is %i pts\n",privdata.out_height);
 
4913
  stp_deprintf(STP_DBG_CANON,"canon_do_print: privdata.left is %i pts\n",privdata.left);
2259
4914
 
2260
4915
  privdata.out_width  = privdata.mode->xdpi * privdata.out_width / 72;
2261
4916
  privdata.out_height = privdata.mode->ydpi * privdata.out_height / 72;
 
4917
  privdata.left       = privdata.mode->xdpi * privdata.left / 72;
2262
4918
 
2263
 
  privdata.left = privdata.mode->xdpi * privdata.left / 72;
 
4919
  stp_deprintf(STP_DBG_CANON,"canon_do_print: privdata.out_width is %i dots\n",privdata.out_width);
 
4920
  stp_deprintf(STP_DBG_CANON,"canon_do_print: privdata.out_height is %i dots\n",privdata.out_height);
 
4921
  stp_deprintf(STP_DBG_CANON,"canon_do_print: privdata.left is %i dots\n",privdata.left);
2264
4922
 
2265
4923
  stp_deprintf(STP_DBG_CANON,"density is %f\n",
2266
4924
               stp_get_float_parameter(v, "Density"));
2293
4951
    stp_set_string_parameter(v, "STPIOutputType", "KCMY");
2294
4952
  else if(privdata.used_inks & CANON_INK_CMY_MASK)
2295
4953
    stp_set_string_parameter(v, "STPIOutputType", "CMY");
 
4954
  /* Gernot: addition */
 
4955
  /*else if(privdata.used_inks & CANON_INK_cmy_MASK)
 
4956
    stp_set_string_parameter(v, "STPIOutputType", "cmy");*/
2296
4957
  else
2297
4958
    stp_set_string_parameter(v, "STPIOutputType", "Grayscale");
2298
4959
 
2299
4960
  privdata.length = (privdata.out_width + 7) / 8;
2300
4961
 
 
4962
  stp_deprintf(STP_DBG_CANON,"privdata.length is %i\n",privdata.length);
 
4963
  stp_deprintf(STP_DBG_CANON,"canon_do_print: privdata.num_channels is %i\n",privdata.num_channels);
 
4964
 
2301
4965
  stp_dither_init(v, image, privdata.out_width, privdata.mode->xdpi, privdata.mode->ydpi);
2302
4966
 
 
4967
 
 
4968
  stp_deprintf(STP_DBG_CANON,"privdata.out_width is %i (after stp_dither_init)\n",privdata.out_width);
 
4969
  stp_deprintf(STP_DBG_CANON,"privdata.length is %i (after stp_dither_init)\n",privdata.length);
 
4970
  stp_deprintf(STP_DBG_CANON,"canon_do_print: privdata.num_channels is %i (after stp_dither_init)\n",privdata.num_channels);
 
4971
 
2303
4972
  canon_setup_channels(v,&privdata);
2304
4973
 
 
4974
  stp_deprintf(STP_DBG_CANON,"privdata.out_width is %i (after canon_setup_channels)\n",privdata.out_width);
 
4975
  stp_deprintf(STP_DBG_CANON,"privdata.length is %i (after canon_setup_channels)\n",privdata.length);
 
4976
  stp_deprintf(STP_DBG_CANON,"canon_do_print: privdata.num_channels is %i (after canon_setup_channels)\n",privdata.num_channels);
2305
4977
 
2306
4978
  stp_deprintf(STP_DBG_CANON,
2307
4979
               "canon: driver will use colors %s\n",privdata.channel_order);
2357
5029
 
2358
5030
       privdata.ncolors = 4;
2359
5031
       privdata.head_offset = stp_zalloc(sizeof(int) * privdata.ncolors);
2360
 
       memset(privdata.head_offset, 0, sizeof(privdata.head_offset));
 
5032
       memset(privdata.head_offset, 0, sizeof(*privdata.head_offset));
2361
5033
 
2362
5034
       if ( privdata.used_inks == CANON_INK_K )
2363
5035
           privdata.nozzles = 64; /* black nozzles */
2382
5054
         }
2383
5055
       else  /* colormode == CMY */
2384
5056
         {
 
5057
           privdata.ncolors = 3;
2385
5058
           privdata.head_offset[0] = 0; /* K starts at 0 */
2386
5059
           privdata.head_offset[1] = 0 ;/* how far C starts after K */
2387
5060
           privdata.head_offset[2] = 64;/* how far M starts after K */
2424
5097
                                stp_compute_uncompressed_linewidth);
2425
5098
       privdata.last_pass_offset = 0;
2426
5099
 
2427
 
 
2428
 
       for(i=0;i<4;i++){
2429
 
           int x;
 
5100
       if (ERRPRINT) {
 
5101
         for(x=0;x<4;x++){
 
5102
           stp_eprintf(v, "DEBUG print-canon weave: weave_color_order[%d]: %u\n",
 
5103
                       x, (unsigned int)weave_color_order[x]);
 
5104
         }
 
5105
         for(x=0;x<privdata.num_channels;x++){
 
5106
           stp_eprintf(v, "DEBUG print-canon weave: channel_order[%d]: %u\n",
 
5107
                       x, (unsigned int)privdata.channel_order[x]);
 
5108
         }
 
5109
       }
 
5110
 
 
5111
       for(i=0;i<4;i++){/* need all 4 channels for weave_cols, but not for privdata.num_channels! */
 
5112
           /* see if it helps to initialize to zero */
 
5113
           weave_cols[i] = 0;
 
5114
           privdata.weave_bits[i] = 0;
 
5115
 
2430
5116
           for(x=0;x<privdata.num_channels;x++){
2431
 
               if(weave_color_order[i] == privdata.channel_order[x])
2432
 
                   weave_cols[i] = privdata.channels[x].buf;
2433
 
                   privdata.weave_bits[i] = privdata.channels[x].props->bits;
 
5117
             if(weave_color_order[i] == privdata.channel_order[x]){
 
5118
               weave_cols[i] = privdata.channels[x].buf;
 
5119
               privdata.weave_bits[i] = privdata.channels[x].props->bits;
 
5120
               if (ERRPRINT)
 
5121
                 stp_eprintf(v, "DEBUG print-canon weave: set weave_cols[%d] to privdata.channels[%d].buf\n",
 
5122
                             i, x);
 
5123
             }
2434
5124
           }
2435
5125
       }
2436
5126
  }
2589
5279
  canon_parameters,
2590
5280
  stp_default_media_size,
2591
5281
  canon_imageable_area,
2592
 
  canon_imageable_area,
 
5282
  canon_maximum_imageable_area,
2593
5283
  canon_limit,
2594
5284
  canon_print,
2595
5285
  canon_describe_resolution,
2622
5312
  int offset2,bitoffset;
2623
5313
 
2624
5314
  /* Don't send blank lines... */
2625
 
 
 
5315
  
2626
5316
  if (line[0] == 0 && memcmp(line, line + 1, (length * bits)  - 1) == 0)
2627
5317
    return 0;
2628
 
 
 
5318
  
 
5319
  /* if no modulation: 1 bit per pixel */
 
5320
  
2629
5321
  offset2 = offset / 8;
2630
5322
  bitoffset = offset % 8;
2631
 
 
 
5323
  
2632
5324
  /* fold lsb/msb pairs if drop modulation is active */
2633
 
 
2634
 
 
 
5325
  
2635
5326
  if (bits==2) {
2636
5327
    int pixels_per_byte = 4;
2637
5328
    if(ink_flags & INK_FLAG_5pixel_in_1byte)
2638
5329
      pixels_per_byte = 5;
2639
 
 
 
5330
    
2640
5331
    stp_fold(line,length,pd->fold_buf);
2641
5332
    in_ptr= pd->fold_buf;
2642
5333
    length= (length*8/4); /* 4 pixels in 8bit */
2666
5357
    offset2 = offset / 2; 
2667
5358
    bitoffset= offset % 2;
2668
5359
  }
 
5360
  else if (bits==8) {
 
5361
    stp_fold_8bit(line,length,pd->fold_buf);
 
5362
    in_ptr= pd->fold_buf;
 
5363
    length    = length*8; /* 1 pixel per 8 bits */
 
5364
    offset2   = offset;
 
5365
    bitoffset = 0;
 
5366
  }
2669
5367
    
2670
5368
  /* pack left border rounded to multiples of 8 dots */
2671
5369
 
2672
5370
  comp_data= comp_buf;
 
5371
 
2673
5372
  while (offset2>0) {
2674
5373
    unsigned char toffset = offset2 > 127 ? 127 : offset2;
2675
5374
    comp_data[0] = 1 - toffset;
2679
5378
  }
2680
5379
  if (bitoffset) {
2681
5380
    if (bitoffset<8)
2682
 
    {
2683
 
       in_ptr[ length++ ] = 0;
2684
 
       canon_shift_buffer(in_ptr,length,bitoffset);
2685
 
    }
 
5381
      {
 
5382
        in_ptr[ length++ ] = 0;
 
5383
        canon_shift_buffer(in_ptr,length,bitoffset);
 
5384
      }
2686
5385
    else if (bitoffset == 8)
2687
 
    {
2688
 
      memmove(in_ptr + 1,in_ptr,length++);
2689
 
      in_ptr[0] = 0;
2690
 
    }
 
5386
      {
 
5387
        memmove(in_ptr + 1,in_ptr,length++);
 
5388
        in_ptr[0] = 0;
 
5389
      }
2691
5390
    else
2692
5391
      stp_deprintf(STP_DBG_CANON,"SEVERE BUG IN print-canon.c::canon_write() "
2693
 
              "bitoffset=%d!!\n",bitoffset);
 
5392
                   "bitoffset=%d!!\n",bitoffset);
2694
5393
  }
2695
 
 
2696
 
    if(ink_flags & INK_FLAG_5pixel_in_1byte)
2697
 
       length = pack_pixels(in_ptr,length);
2698
 
 
 
5394
  
 
5395
  if(ink_flags & INK_FLAG_5pixel_in_1byte)
 
5396
    length = pack_pixels(in_ptr,length);
 
5397
  
2699
5398
  stp_pack_tiff(v, in_ptr, length, comp_data, &comp_ptr, NULL, NULL);
2700
 
 
 
5399
  
2701
5400
  return comp_ptr - comp_buf;
2702
5401
}
2703
5402
 
2761
5460
 
2762
5461
      /* TODO optimize => move reorder code to do_print */
2763
5462
      for(x=0;x < pd->num_channels; x++){
2764
 
          if(pd->channels[x].name == write_sequence[i]){
 
5463
        if(pd->channels[x].name == write_sequence[i]){
2765
5464
              channel = &(pd->channels[x]);
2766
5465
              break;
2767
5466
          }