diff options
Diffstat (limited to 'src/main/print-canon.c')
-rw-r--r-- | src/main/print-canon.c | 399 |
1 files changed, 304 insertions, 95 deletions
diff --git a/src/main/print-canon.c b/src/main/print-canon.c index 89c7fff..f8d4613 100644 --- a/src/main/print-canon.c +++ b/src/main/print-canon.c @@ -190,6 +190,8 @@ pack_pixels3_6(unsigned char* buf,int len) #define CANON_CAP_NOBLACK 0x2000000ul /* no Black cartridge selection */ #define CANON_CAP_v 0x4000000ul /* not sure of this yet */ #define CANON_CAP_w 0x8000000ul /* related to media type selection */ +#define CANON_CAP_s 0x10000000ul /* not sure of this yet: duplex-related? */ +#define CANON_CAP_u 0x20000000ul /* not sure of this yet: duplex-related? */ #define CANON_CAP_STD0 (CANON_CAP_b|CANON_CAP_c|CANON_CAP_d|\ CANON_CAP_l|CANON_CAP_q|CANON_CAP_t) @@ -276,6 +278,8 @@ static void canon_advance_paper(stp_vars_t *, int); static void canon_flush_pass(stp_vars_t *, int, int); static void canon_write_multiraster(stp_vars_t *v,canon_privdata_t* pd,int y); +static void fix_papersize(unsigned char arg_ESCP_1, int *paper_width, int *paper_length); + static const stp_parameter_t the_parameters[] = { { @@ -395,6 +399,12 @@ static const stp_parameter_t the_parameters[] = STP_PARAMETER_TYPE_STRING_LIST, STP_PARAMETER_CLASS_FEATURE, STP_PARAMETER_LEVEL_BASIC, 1, 1, STP_CHANNEL_NONE, 0, 0 }, + { + "Orientation", N_("Orientation"), "Color=No,Category=Basic Printer Setup", + N_("Orientation, Portrait, Landscape, Upside Down, Seascape"), + STP_PARAMETER_TYPE_STRING_LIST, STP_PARAMETER_CLASS_FEATURE, + STP_PARAMETER_LEVEL_BASIC, 1, 1, STP_CHANNEL_NONE, 1, 0, + }, }; static const int the_parameter_count = @@ -486,6 +496,20 @@ static const stp_param_string_t duplex_types[] = }; #define NUM_DUPLEX (sizeof (duplex_types) / sizeof (stp_param_string_t)) +/* + * Orientation support - modes available + * Note that the internal names MUST match those in cups/genppd.c else the + * PPD files will not be generated correctly + */ + +static const stp_param_string_t orientation_types[] = { + {"Portrait", N_("Portrait")}, + {"Landscape", N_("Landscape")}, + {"UpsideDown", N_("Reverse Portrait")}, + {"Seascape", N_("Reverse Landscape")}, +}; +#define NUM_ORIENTATION (sizeof (orientation_types) / sizeof (stp_param_string_t)) + static const canon_paper_t * get_media_type(const canon_cap_t* caps,const char *name) { @@ -1061,7 +1085,7 @@ const canon_mode_t* canon_check_current_mode(stp_vars_t *v){ if (media_type && resolution && mode) { stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint: check_current_mode --- Resolution, Media, Mode all known \n"); stp_dprintf(STP_DBG_CANON, v,"DEBUG: Gutenprint: media type selected: '%s'\n",media_type->name); - stp_dprintf(STP_DBG_CANON, v,"DEBUG: (Inital) Gutenprint: mode initally active: '%s'\n",mode->name); + stp_dprintf(STP_DBG_CANON, v,"DEBUG: (Initial) Gutenprint: mode initially active: '%s'\n",mode->name); /* scroll through modeuse list to find media */ muse = select_media_modes(v,media_type,mlist); @@ -2447,13 +2471,13 @@ canon_printhead_colors(const stp_vars_t*v) stp_dprintf(STP_DBG_CANON, v,"(canon_printhead_colors[BW]) NOBLACK? %lu\n",(caps->features & CANON_CAP_NOBLACK)); return CANON_INK_K; } - /* alternatively, if the cartridge selection is in force, and black cartride is selected, accept it */ + /* alternatively, if the cartridge selection is in force, and black cartridge is selected, accept it */ if(ink_set && !strcmp(ink_set, "Black")){ stp_dprintf(STP_DBG_CANON, v,"(canon_printhead_colors[BW]) Found InkSet black selection\n"); return CANON_INK_K; } - /* originaly finds selected InkType of form: CANON_INK_<inks> */ + /* originally finds selected InkType of form: CANON_INK_<inks> */ /* but this is incorrect, since it does not check media or mode */ /* change: deal with mode set and mode not set cases */ @@ -2531,9 +2555,13 @@ canon_size_type(const stp_vars_t *v, const canon_cap_t * caps) { const stp_papersize_t *pp = stp_get_papersize_by_size(stp_get_page_height(v), stp_get_page_width(v)); + + stp_deprintf(STP_DBG_CANON,"canon: entered canon_size_type\n"); + if (pp) { const char *name = pp->name; + stp_deprintf(STP_DBG_CANON,"canon: in canon_size_type is pp->name: '%s'\n",name); /* used internally: do not translate */ /* built ins: Japanese driver notation */ if (!strcmp(name,"A5")) return 0x01; @@ -2543,25 +2571,25 @@ canon_size_type(const stp_vars_t *v, const canon_cap_t * caps) if (!strcmp(name,"B4")) return 0x0a; if (!strcmp(name,"Letter")) return 0x0d; if (!strcmp(name,"Legal")) return 0x0f; - if (!strcmp(name,"Tabloid")) return 0x11; /* 11x17 */ + if (!strcmp(name,"Tabloid")) return 0x11; /* 11x17 inch */ if (!strcmp(name,"w283h420")) return 0x14; /* Hagaki */ /* if (!strcmp(name,"COM10")) return 0x16;*/ /* if (!strcmp(name,"DL")) return 0x17;*/ if (!strcmp(name,"LetterExtra")) return 0x2a; /* Letter navi --- Letter+ */ if (!strcmp(name,"A4Extra")) return 0x2b; /* A4navi --- A4+ */ - if (!strcmp(name,"A3plus")) return 0x2c; /* A3navi --- A3+ */ - if (!strcmp(name,"w288h144")) return 0x2d; /* ??? */ + if (!strcmp(name,"A3plus")) return 0x2c; /* A3navi --- A3+ (13x19 inch) */ + if (!strcmp(name,"w288h144")) return 0x2d; /* 4x2 inch labels */ if (!strcmp(name,"COM10")) return 0x2e; /* US Comm #10 Env */ if (!strcmp(name,"DL")) return 0x2f; /* Euro DL Env */ if (!strcmp(name,"w297h666")) return 0x30; /* Western Env #4 (you4) */ if (!strcmp(name,"w277h538")) return 0x31; /* Western Env #6 (you6) */ - if (!strcmp(name,"w252h360J")) return 0x32; /* L --- similar to US 3.5x5 size */ - if (!strcmp(name,"w360h504J")) return 0x33; /* 2L --- similar to US5x7 */ - if (!strcmp(name,"w288h432J")) return 0x34; /* KG --- same size as US 4x6 */ + if (!strcmp(name,"w252h360J")) return 0x32; /* L --- similar to US 3.5x5 inch size */ + if (!strcmp(name,"w360h504J")) return 0x33; /* 2L --- similar to US5x7 inch */ + if (!strcmp(name,"w288h432J")) return 0x34; /* KG --- same size as US 4x6 inch */ /* if (!strcmp(name,"CD5Inch")) return 0x35; */ /* CD Custom Tray */ if (!strcmp(name,"w155h257")) return 0x36; /* Japanese Business Card 55mm x 91mm */ - if (!strcmp(name,"w360h504")) return 0x37; /* US5x7 */ - if (!strcmp(name,"w420h567")) return 0x39; /* Ofuku Hagaki */ + if (!strcmp(name,"w360h504")) return 0x37; /* US5x7 inch */ + if (!strcmp(name,"w420h567")) return 0x39; /* Oufuku Hagaki --- but should be w567h420 */ if (!strcmp(name,"w340h666")) return 0x3a; /* Japanese Long Env #3 (chou3) */ if (!strcmp(name,"w255h581")) return 0x3b; /* Japanese Long Env #4 (chou4) */ /* if (!strcmp(name,"CD5Inch")) return 0x3f; */ /* CD Tray A */ @@ -2580,9 +2608,9 @@ canon_size_type(const stp_vars_t *v, const canon_cap_t * caps) /* if (!strcmp(name,"Letter")) return 0x45; */ /* FineArt Letter 35mm border */ if (!strcmp(name,"w288h576")) return 0x46; /* US4x8 */ - if (!strcmp(name,"w1008h1224J")) return 0x47; /* HanKire --- 14in x 17in */ - if (!strcmp(name,"720h864J")) return 0x48; /* YonKire --- 10in x 12 in*/ - if (!strcmp(name,"c8x10J")) return 0x49; /* RokuKire --- same size as 8x10 */ + if (!strcmp(name,"w1008h1224J")) return 0x47; /* HanKire --- 14in x 17 inch */ + if (!strcmp(name,"720h864J")) return 0x48; /* YonKire --- 10in x 12 inch */ + if (!strcmp(name,"c8x10J")) return 0x49; /* RokuKire --- same size as 8x10 inch */ /* if (!strcmp(name,"CD5Inch")) return 0x4a; */ /* CD Tray C */ /* if (!strcmp(name,"CD5Inch")) return 0x4b; */ /* CD Tray D */ @@ -2596,8 +2624,8 @@ canon_size_type(const stp_vars_t *v, const canon_cap_t * caps) /* if (!strcmp(name,"A3plus")) return 0x50; */ /* FineArt A3plus 35mm border */ /* if (!strcmp(name,"CD5Inch")) return 0x51; */ /* CD Tray F */ - if (!strcmp(name,"w288h512")) return 0x52; /* Wide101.6x180.6 */ - /* w283h566 Wide postcard 148mm x 200mm */ + if (!strcmp(name,"w288h512")) return 0x52; /* Wide 101.6x180.6mm */ + /* w283h566 Wide postcard 100mm x 200mm */ /* media size codes for CD (and other media depending on printer model */ @@ -2626,6 +2654,84 @@ canon_size_type(const stp_vars_t *v, const canon_cap_t * caps) return 0; } +/* fix paper_width and paper_length for known papersizes in ESC (p command */ +static void fix_papersize(unsigned char arg_ESCP_1, int *paper_width, int *paper_length){ + + switch(arg_ESCP_1) + { + case 0x01: *paper_width = 3497; *paper_length = 4961; break;; /* A5 */ + case 0x03: *paper_width = 4961; *paper_length = 7016; break;; /* A4 */ + case 0x05: *paper_width = 7016; *paper_length = 9922; break;; /* A3 */ + case 0x08: *paper_width = 4300; *paper_length = 6071; break;; /* B5 */ + case 0x0a: *paper_width = 6071; *paper_length = 8599; break;; /* B4 */ + case 0x0d: *paper_width = 5100; *paper_length = 6600; break;; /* Letter */ + case 0x0f: *paper_width = 5100; *paper_length = 8400; break;; /* Legal */ + case 0x11: *paper_width = 6600; *paper_length = 10200; break;; /* Tabloid : 11x17" */ + /* Letter+, A4+ only seem to be available in shirink-to-fit */ + /* case 0x2a: paper_width = ( init->page_width + border_left + border_right ) * unit / 72; break;; */ /* LetterExtra : Letter navi, Letter+ */ + /* case 0x2b: paper_width = ( init->page_width + border_left + border_right ) * unit / 72; break;; */ /* A4Extra : A4navi, A4+ */ + case 0x2c: *paper_width = 7772; *paper_length = 11410; break;; /* A3Extra : A3navi, A3+ (13x19") */ + /* case 0x2d: paper_width = ( init->page_width + border_left + border_right ) * unit / 72; break;; */ /* w288h144 : 4x2" labels */ + /* Hagaki media */ + case 0x14: *paper_width = 2363; *paper_length = 3497; break;; /* w283h420 : Hagaki */ + /* Oufuku Hagaki should be swapped: w567h420, same height as Hagaki */ + /* case 0x39: paper_width = 4725; l: 3497 */ + /* w420h567 : Oufuku Hagaki */ + /* case 0x39: paper_width=(init->page_width + border_left + border_right) * unit / 72; break;;*/ /* leave untouched since orientation wrong */ + case 0x52: *paper_width = 2400; *paper_length = 4267; break;; /* w288h512 : Wide101.6x180.6mm */ + /* Envelope media */ + case 0x16: *paper_width = 2475; *paper_length = 5700; break;; /* COM10 : US Commercial #10 */ + case 0x17: *paper_width = 2599; *paper_length = 5197; break;; /* DL : Euro DL */ + case 0x2e: *paper_width = 2475; *paper_length = 5700; break;; /* COM10 : US Commercial #10 */ + case 0x2f: *paper_width = 2599; *paper_length = 5197; break;; /* DL : Euro DL */ + case 0x30: *paper_width = 2481; *paper_length = 5552; break;; /* w297xh666 : Western Env #4 (you4) */ + case 0x31: *paper_width = 2155; *paper_length = 4489; break;; /* w277xh538 : Western Env #6 (you6) */ + case 0x3a: *paper_width = 2835; *paper_length = 5552; break;; /* w340xh666 : Japanese Long Env #3 (chou3) */ + case 0x3b: *paper_width = 2126; *paper_length = 4843; break;; /* w255xh581 : Japanese Long Env #4 (chou4) */ + /* Photo media */ + case 0x32: *paper_width = 2103; *paper_length = 3000; break;; /* w252h360 : L --- similar to US 3.5x5" */ + case 0x33: *paper_width = 3000; *paper_length = 4205; break;; /* w360h504 : 2L --- similar to US 5x7" */ + case 0x37: *paper_width = 3000; *paper_length = 4200; break;; /* w360h504 : US 5x7" */ + case 0x34: *paper_width = 2400; *paper_length = 3600; break;; /* w288h432J : KG --- same as US 4x6" */ + case 0x46: *paper_width = 2400; *paper_length = 4800; break;; /* w288h576 : US 4x8" */ + /* CD media */ + case 0x35: *paper_width = 3207; *paper_length = 6041; break;; /* CD5Inch : CD Custom Tray */ + case 0x3f: *paper_width = 3378; *paper_length = 6206; break;; /* CD5Inch : CD Tray A */ + case 0x40: *paper_width = 3095; *paper_length = 5640; break;; /* CD5Inch : CD Tray B */ + case 0x4a: *paper_width = 3095; *paper_length = 5640; break;; /* CD5Inch : CD Tray C */ + case 0x4b: *paper_width = 3095; *paper_length = 5640; break;; /* CD5Inch : CD Tray D */ + case 0x4c: *paper_width = 4063; *paper_length = 6497; break;; /* CD5Inch : CD Tray E */ + case 0x51: *paper_width = 3095; *paper_length = 5730; break;; /* CD5Inch : CD Tray F */ + case 0x53: *paper_width = 3095; *paper_length = 6008; break;; /* CD5Inch : CD Tray G */ + case 0x56: *paper_width = 3095; *paper_length = 6008; break;; /* CD5Inch : CD Tray G late version */ + case 0x57: *paper_width = 3572; *paper_length = 8953; break;; /* CD5Inch : CD Tray H */ + case 0x5b: *paper_width = 3071; *paper_length = 5311; break;; /* CD5Inch : CD Tray J */ + /* case 0x62: paper_width = ( init->page_width + border_left + border_right ) * unit / 72; break;; */ /* CD5Inch : CD Tray L */ + /* Business/Credit Card media */ + case 0x36: *paper_width = 1300; *paper_length = 2150; break;; /* w155h257 : Japanese Business Card 55x91mm */ + case 0x41: *paper_width = 1276; *paper_length = 2032; break;; /* w155h244 : Business/Credit Card 54x86mm */ + /* Fine Art media */ + case 0x42: *paper_width = 4961; *paper_length = 7016; break;; /* FineArt A4 35mm border */ + case 0x43: *paper_width = 7016; *paper_length = 9922; break;; /* FineArt A3 35mm border */ + case 0x44: *paper_width = 7772; *paper_length = 11410; break;; /* FineArt A3+ 35mm border */ + case 0x45: *paper_width = 5100; *paper_length = 6600; break;; /* FineArt Letter 35mm border */ + case 0x4d: *paper_width = 4961; *paper_length = 7016; break;; /* FineArt A4 35mm border */ + case 0x4e: *paper_width = 7016; *paper_length = 9922; break;; /* FineArt A3 35mm border */ + case 0x4f: *paper_width = 5100; *paper_length = 6600; break;; /* FineArt Letter 35mm border */ + case 0x50: *paper_width = 7772; *paper_length = 11410; break;; /* FineArt A3+ 35mm border */ + case 0x58: *paper_width = 4961; *paper_length = 7016; break;; /* FineArt A4 35mm border */ + case 0x59: *paper_width = 7016; *paper_length = 9922; break;; /* FineArt A3 35mm border */ + case 0x5a: *paper_width = 5100; *paper_length = 6600; break;; /* FineArt Letter 35mm border */ + case 0x5d: *paper_width = 7772; *paper_length = 11410; break;; /* FineArt A3+ 35mm border */ + /* Other media */ + case 0x47: *paper_width = 8400; *paper_length = 10200; break;; /* w1008h1224J : HanKire --- 14x17" */ + case 0x48: *paper_width = 6000; *paper_length = 7200; break;; /* 720h864J : YonKire --- 10x12" */ + case 0x49: *paper_width = 4800; *paper_length = 6000; break;; /* c8x10J : RokuKire --- same as 8x10" */ + /* default */ + /* default: paper_width=(init->page_width + border_left + border_right) * unit / 72; break;; */ /* custom */ + } +} + static void canon_describe_resolution(const stp_vars_t *v, int *x, int *y) { @@ -3097,6 +3203,16 @@ canon_parameters(const stp_vars_t *v, const char *name, else description->is_active = 0; } + else if (strcmp(name, "Orientation") == 0) + { + description->bounds.str = stp_string_list_create(); + description->deflt.str = orientation_types[0].name; + for (i=0; i < NUM_ORIENTATION; i++) + { + stp_string_list_add_string(description->bounds.str, + orientation_types[i].name,gettext(orientation_types[i].text)); + } + } else if (strcmp(name, "Quality") == 0) { #if 0 @@ -3165,11 +3281,12 @@ internal_imageable_area(const stp_vars_t *v, /* I */ if (media_size) pt = stp_get_papersize_by_name(media_size); - + if(input_slot && !strcmp(input_slot,"CD")) cd = 1; stp_default_media_size(v, &width, &length); + if (cd) { /* ignore printer margins for the cd print, margins get adjusted in do_print for now */ if (pt) { @@ -3576,7 +3693,8 @@ canon_init_setPrintMode(const stp_vars_t *v, const canon_privdata_t *init) if (!arg_6d_a) arg_6d_b= 1; - arg_6d_1= 0x04; + arg_6d_1= 0x04; + if ((!strcmp(init->caps->name,"7000")) && (init->used_inks == CANON_INK_K || init->used_inks == CANON_INK_CcMmYK || init->used_inks == CANON_INK_CcMmYyK)) arg_6d_1= 0x03; @@ -3614,7 +3732,7 @@ static void canon_init_setPageMargins2(const stp_vars_t *v, canon_privdata_t *init) { unsigned char arg_70_1,arg_70_2,arg_70_3,arg_70_4; - + int border_left,border_right,border_top,border_bottom; int border_left2,border_top2; int border_right2; @@ -3641,7 +3759,16 @@ canon_init_setPageMargins2(const stp_vars_t *v, canon_privdata_t *init) int adjust_tray_H_left, adjust_tray_H_right, adjust_tray_H_top, adjust_tray_H_bottom; int adjust_tray_J_left, adjust_tray_J_right, adjust_tray_J_top, adjust_tray_J_bottom; int adjust_tray_L_left, adjust_tray_L_right, adjust_tray_L_top, adjust_tray_L_bottom; + int paper_width, paper_length; + /* Canon printer firmware requires paper_width (and paper_length?) + to be exact matches in units of 1/600 inch. + To this end, papersize code is used to find the papersize for the + printjob, and paper_width and paper_length set to exact values, + rather than calculated. + */ + unsigned char arg_ESCP_1 = (init->pt) ? canon_size_type(v,init->caps) : 0x03; /* default size A4 */ + stp_dprintf(STP_DBG_CANON, v,"setPageMargins2: arg_ESCP_1 = '%x'\n",arg_ESCP_1); /* TOFIX: what exactly is to be sent? * Is it the printable length or the bottom border? @@ -3649,12 +3776,12 @@ canon_init_setPageMargins2(const stp_vars_t *v, canon_privdata_t *init) */ int unit = 600; - int printable_width= (init->page_width + 1)*5/6; - int printable_length= (init->page_height + 1)*5/6; + int printable_width = (init->page_width + 1)*5/6; + int printable_length = (init->page_height + 1)*5/6; const char* input_slot = stp_get_string_parameter(v, "InputSlot"); - int print_cd= (input_slot && (!strcmp(input_slot, "CD"))); - + int print_cd = (input_slot && (!strcmp(input_slot, "CD"))); + stp_dprintf(STP_DBG_CANON, v,"setPageMargins2: print_cd = %d\n",print_cd); test_cd = 1; @@ -4175,16 +4302,16 @@ canon_init_setPageMargins2(const stp_vars_t *v, canon_privdata_t *init) /* calculated depending on borderless or not: uses modified borders */ if ( (init->caps->features & CANON_CAP_BORDERLESS) && !(print_cd) && stp_get_boolean_parameter(v, "FullBleed") ) { + /* borderless */ stp_put32_be((init->page_width - border_left2 - border_right2 ) * unit / 72,v); /* area_width */ stp_put32_be((init->page_height - border_top2 - border_bottom2 ) * unit / 72,v); /* area_length */ } else { - /* for CD */ - if ( (print_cd) && (test_cd==1) ) { + if ( (print_cd) && (test_cd==1) ) { /* bordered for CD */ stp_put32_be(init->page_width * unit / 72,v); /* area_width */ stp_put32_be(init->page_height * unit / 72,v); /* area_length */ } - else { /* no CD */ + else { /* bordered non CD media */ stp_put32_be((init->page_width) * unit / 72,v); /* area_width */ stp_put32_be((init->page_height) * unit / 72,v); /* area_length */ } @@ -4194,21 +4321,35 @@ canon_init_setPageMargins2(const stp_vars_t *v, canon_privdata_t *init) stp_put32_be(0,v); /* paper_right : Windows also 0 here for all Trays */ stp_put32_be(0,v); /* paper_top : Windows also 0 here for all Trays */ - /* standard paper sizes, unchanged for borderless so use original borders */ + /* standard paper sizes, unchanged for borderless so use + original borders */ + + /* discovered that paper_width needs to be same as Windows + dimensions for Canon printer firmware to automatically + determine which tray to pull paper from automatically. + */ + if ( (init->caps->features & CANON_CAP_BORDERLESS) && !(print_cd) && stp_get_boolean_parameter(v, "FullBleed") ) { + /* borderless */ stp_put32_be((init->page_width) * unit / 72,v); /* paper_width */ stp_put32_be((init->page_height) * unit / 72,v); /* paper_length */ } else { - /* for CD */ - if ( (print_cd) && (test_cd==1) ) { - stp_put32_be((init->page_width + border_left2 + border_right2) * unit / 72,v); /* paper_width */ - stp_put32_be((init->page_height + border_top2 + border_bottom2) * unit / 72,v); /* paper_length */ + if ( (print_cd) && (test_cd==1) ) { /* bordered for CD */ + paper_width = (init->page_width + border_left2 + border_right2) * unit / 72; /* paper_width */ + paper_length = (init->page_height + border_top2 + border_bottom2) * unit / 72; /* paper_length */ + fix_papersize(arg_ESCP_1, &paper_width, &paper_length); + stp_put32_be(paper_width,v); /* paper_width */ + stp_put32_be(paper_length,v); /* paper_length */ } - else { /* not CD */ - stp_put32_be((init->page_width + border_left + border_right) * unit / 72,v); /* paper_width */ - stp_put32_be((init->page_height + border_top + border_bottom) * unit / 72,v); /* paper_length */ + else { /* bordered non CD media */ + /* set by calculation first, then correct if necessary */ + paper_width = (init->page_width + border_left + border_right) * unit / 72; /* paper_width */ + paper_length = (init->page_height + border_top + border_bottom) * unit / 72; /* paper_length */ + fix_papersize(arg_ESCP_1, &paper_width, &paper_length); + stp_put32_be(paper_width,v); /* paper_width */ + stp_put32_be(paper_length,v); /* paper_length */ } } @@ -4221,16 +4362,24 @@ canon_init_setPageMargins2(const stp_vars_t *v, canon_privdata_t *init) } /* ESC (P -- 0x50 -- unknown -- : - pt = stp_get_papersize_by_name(media_size); - seems to set media and page information. Different byte lengths depending on printer model. */ + Seems to set media and page information. Different byte lengths + depending on printer model. + Page rotation option in driver [ESC (v] influences ESC (P command + parameters 5 and 6: + none: 1 0 + 90 deg: 2 0 + 180 deg: 1 1 + 270 deg: 2 1 +*/ static void canon_init_setESC_P(const stp_vars_t *v, const canon_privdata_t *init) { - unsigned char arg_ESCP_1, arg_ESCP_2, arg_ESCP_9; + unsigned char arg_ESCP_1, arg_ESCP_2, arg_ESCP_5, arg_ESCP_6, arg_ESCP_9; int width, length; /* const char *media_size = stp_get_string_parameter(v, "PageSize"); const stp_papersize_t *pt = NULL; */ + const char* orientation_type = stp_get_string_parameter(v, "Orientation"); const char* input_slot = stp_get_string_parameter(v, "InputSlot"); const char* input_tray = stp_get_string_parameter(v, "CassetteTray"); /* const canon_cap_t * caps= canon_get_model_capabilities(v); */ @@ -4257,9 +4406,30 @@ canon_init_setESC_P(const stp_vars_t *v, const canon_privdata_t *init) else user_ESCP_9=0x00; /* fall-through setting, but this value is not used */ - arg_ESCP_1 = (init->pt) ? canon_size_type(v,init->caps): 0x03; + arg_ESCP_1 = (init->pt) ? canon_size_type(v,init->caps): 0x03; /* set to A4 size as default */ + stp_deprintf(STP_DBG_CANON,"canon: ESCP (P code read paper size, resulting arg_ESCP_1: '%x'\n",arg_ESCP_1); arg_ESCP_2 = (init->pt) ? init->pt->media_code_P: 0x00; + arg_ESCP_5 = 0x01; /* default for portrait orientation */ + arg_ESCP_6 = 0x00; /* default for portrait orientation */ + + if( orientation_type && !strcmp(orientation_type,"Portrait")) { /* none */ + arg_ESCP_5 = 0x01; + arg_ESCP_6 = 0x00; + } + else if( orientation_type && !strcmp(orientation_type,"Landscape")) { /* 90 deg */ + arg_ESCP_5 = 0x02; + arg_ESCP_6 = 0x00; + } + else if( orientation_type && !strcmp(orientation_type,"UpsideDown")) { /* 180 deg */ + arg_ESCP_5 = 0x01; + arg_ESCP_6 = 0x01; + } + else if( orientation_type && !strcmp(orientation_type,"Seascape")) { /* 270 deg */ + arg_ESCP_5 = 0x02; + arg_ESCP_6 = 0x01; + } + /* Code for last argument in 9-byte ESC (P printers with and upper and lower tray included in the cassette input source The intention appears to be to allow printing of photos and non-photo paper without needing to change trays. Note, envelopes are printed from the lower tray. @@ -4611,14 +4781,14 @@ canon_init_setESC_P(const stp_vars_t *v, const canon_privdata_t *init) if ( !(strcmp(init->caps->name,"PIXMA MG7700")) ) { /* output with 3 extra 0s at the end */ - canon_cmd( v,ESC28,0x50,12,0x00,arg_ESCP_1,0x00,arg_ESCP_2,0x01,0x00,0x01,0x00,arg_ESCP_9,0x00,0x00,0x00); + canon_cmd( v,ESC28,0x50,12,0x00,arg_ESCP_1,0x00,arg_ESCP_2,arg_ESCP_5,arg_ESCP_6,0x01,0x00,arg_ESCP_9,0x00,0x00,0x00 ); } else { /* arg_ESCP_1 = 0x03; */ /* A4 size */ /* arg_ESCP_2 = 0x00; */ /* plain media */ - /* size media tray */ - canon_cmd( v,ESC28,0x50,9,0x00,arg_ESCP_1,0x00,arg_ESCP_2,0x01,0x00,0x01,0x00,arg_ESCP_9); + /* size media tray */ + canon_cmd( v,ESC28,0x50,9,0x00,arg_ESCP_1,0x00,arg_ESCP_2,arg_ESCP_5,arg_ESCP_6,0x01,0x00,arg_ESCP_9 ); } } @@ -4628,7 +4798,7 @@ canon_init_setESC_P(const stp_vars_t *v, const canon_privdata_t *init) /* arg_ESCP_1 = 0x03; */ /* A4 size */ /* arg_ESCP_2 = 0x00; */ /* plain media */ /* size media */ - canon_cmd( v,ESC28,0x50,8,0x00,arg_ESCP_1,0x00,arg_ESCP_2,0x01,0x00,0x01,0x00); + canon_cmd( v,ESC28,0x50,8,0x00,arg_ESCP_1,0x00,arg_ESCP_2,arg_ESCP_5,arg_ESCP_6,0x01,0x00 ); } else if ( init->caps->ESC_P_len == 6 ) /* first devices with XML header and ender */ {/* the 4th of the 6 bytes is the media type. 2nd byte is media size. Both read from canon-media array. */ @@ -4636,7 +4806,7 @@ canon_init_setESC_P(const stp_vars_t *v, const canon_privdata_t *init) /* arg_ESCP_1 = 0x03; */ /* A4 size */ /* arg_ESCP_2 = 0x00; */ /* plain media */ /* size media */ - canon_cmd( v,ESC28,0x50,6,0x00,arg_ESCP_1,0x00,arg_ESCP_2,0x01,0x00); + canon_cmd( v,ESC28,0x50,6,0x00,arg_ESCP_1,0x00,arg_ESCP_2,arg_ESCP_5,arg_ESCP_6 ); } else if ( init->caps->ESC_P_len == 4 ) {/* 4 bytes */ /* size media */ @@ -4651,9 +4821,10 @@ canon_init_setESC_P(const stp_vars_t *v, const canon_privdata_t *init) "ESC_P_len=%d!!\n",init->caps->ESC_P_len); } -#if 0 -/* ESC (s -- 0x73 -- used in some newer printers for duplex pages except last one -- */ -/* When capability available, used for non-tumble and tumble (unlike Esc (u which is non-tumble only) */ +/* ESC (s -- 0x73 -- : + used in some newer printers for duplex pages except last one. + When capability available, used for non-tumble and tumble (unlike Esc (u which is non-tumble only) + Limitation: outputs on every page */ static void canon_init_setESC_s(const stp_vars_t *v, const canon_privdata_t *init) { @@ -4664,7 +4835,6 @@ canon_init_setESC_s(const stp_vars_t *v, const canon_privdata_t *init) canon_cmd(v,ESC28,0x73, 1, 0x00); } -#endif /* ESC (S -- 0x53 -- unknown -- : Required by iP90/iP90v and iP100 printers. @@ -5082,32 +5252,54 @@ canon_init_setESC_u(const stp_vars_t *v, const canon_privdata_t *init) if (!(init->caps->features & CANON_CAP_DUPLEX)) return; - canon_cmd(v,ESC28,0x75, 1, 0x01); + canon_cmd( v,ESC28,0x75, 1, 0x01 ); } /* ESC (v -- 0x76 -- */ +/* page rotation in Windows driver settings: */ +/* none: 0x0 */ +/* 90 deg: 0x1 */ +/* 180 deg: 0x2 */ +/* 270 deg: 0x3 */ +/* also influences ESC (P command parameters 5 and 6 */ +/* none: 1 0 */ +/* 90 deg: 2 0 */ +/* 180 deg: 1 1 */ +/* 270 deg: 2 1 */ static void canon_init_setESC_v(const stp_vars_t *v, const canon_privdata_t *init) { + const char *orientation_type =stp_get_string_parameter(v, "Orientation"); + unsigned char arg_ESCv_1 = 0x00; + if (!(init->caps->features & CANON_CAP_v)) return; - - canon_cmd(v,ESC28,0x76, 1, 0x00); + + if( orientation_type && !strcmp(orientation_type,"Portrait")) /* none */ + arg_ESCv_1 = 0x00; + else if( orientation_type && !strcmp(orientation_type,"Landscape")) /* 90 deg */ + arg_ESCv_1 = 0x01; + else if( orientation_type && !strcmp(orientation_type,"UpsideDown")) /* 180 deg */ + arg_ESCv_1 = 0x02; + else if( orientation_type && !strcmp(orientation_type,"Seascape")) /* 270 deg */ + arg_ESCv_1 = 0x03; + + canon_cmd( v,ESC28,0x76, 1, arg_ESCv_1 ); } -/* ESC (w -- 0x77 -- */ +/* ESC (w -- 0x77 -- : + Unknown. + new September 2015, currently only 1 byte. +*/ static void canon_init_setESC_w(const stp_vars_t *v, const canon_privdata_t *init) { unsigned char arg_ESCw_1; - - /* new September 2015, currently only 1 byte */ if (!(init->caps->features & CANON_CAP_w)) return; arg_ESCw_1 = (init->pt) ? init->pt->media_code_w: 0x00; - - canon_cmd(v,ESC28,0x77, 1, arg_ESCw_1); + canon_cmd( v,ESC28,0x77, 1, arg_ESCw_1 ); } static void @@ -5115,12 +5307,12 @@ canon_init_printer(const stp_vars_t *v, canon_privdata_t *init) { unsigned int mytop; int page_number = stp_get_int_parameter(v, "PageNumber"); - const char *duplex_mode =stp_get_string_parameter(v, "Duplex"); + const char *duplex_mode = stp_get_string_parameter(v, "Duplex"); /* init printer */ if (init->is_first_page) { - canon_init_resetPrinter(v,init); /* ESC [K */ - canon_init_setESC_M(v,init); /* ESC (M */ - canon_init_setDuplex(v,init); /* ESC ($ */ + canon_init_resetPrinter(v,init); /* ESC [K */ + canon_init_setESC_M(v,init); /* ESC (M */ + canon_init_setDuplex(v,init); /* ESC ($ */ } canon_init_setPageMode(v,init); /* ESC (a */ canon_init_setDataCompression(v,init); /* ESC (b */ @@ -5137,9 +5329,12 @@ canon_init_printer(const stp_vars_t *v, canon_privdata_t *init) canon_init_setTray(v,init); /* ESC (l */ canon_init_setX72(v,init); /* ESC (r */ canon_init_setESC_v(v,init); /* ESC (v */ - canon_init_setESC_w(v,init); /* ESC (w */ + if (init->is_first_page) + canon_init_setESC_w(v,init); /* ESC (w */ if((page_number & 1) && duplex_mode && !strcmp(duplex_mode,"DuplexNoTumble")) - canon_init_setESC_u(v,init); /* ESC (u 0x1 */ + canon_init_setESC_u(v,init); /* ESC (u 0x1 */ + if(duplex_mode) + canon_init_setESC_s(v,init); /* ESC (s 0x0 */ canon_init_setMultiRaster(v,init); /* ESC (I (J (L */ /* some linefeeds */ @@ -5439,47 +5634,61 @@ static void canon_setup_channels(stp_vars_t *v,canon_privdata_t* privdata){ #define CANON_CD_Y 405 static void setup_page(stp_vars_t* v,canon_privdata_t* privdata){ - const char *media_source = stp_get_string_parameter(v, "InputSlot"); + const char *media_source = stp_get_string_parameter(v, "InputSlot"); const char *cd_type = stp_get_string_parameter(v, "PageSize"); - int print_cd= (media_source && (!strcmp(media_source, "CD"))); - int page_left, - page_top, - page_right, - page_bottom; + int print_cd = (media_source && (!strcmp(media_source, "CD"))); + int page_left, page_top, page_right, page_bottom; int hub_size = 0; - +#if 0 + /* needed in workaround for Oufuku Hagaki */ + const stp_papersize_t *pp = stp_get_papersize_by_size(stp_get_page_height(v), + stp_get_page_width(v)); + + if (pp) + { + const char *name = pp->name; + if (!strcmp(name,"w420h567")) { + /* workaround for Oufuku Hagaki: wrong orientation */ + privdata->page_width = stp_get_width(v); + privdata->page_height = stp_get_height(v); + stp_set_page_width(v, privdata->page_height); + stp_set_page_height(v, privdata->page_width); + } + } +#endif + if (cd_type && (strcmp(cd_type, "CDCustom") == 0 )) - { - int outer_diameter = stp_get_dimension_parameter(v, "CDOuterDiameter"); - stp_set_page_width(v, outer_diameter); - stp_set_page_height(v, outer_diameter); - stp_set_width(v, outer_diameter); - stp_set_height(v, outer_diameter); - hub_size = stp_get_dimension_parameter(v, "CDInnerDiameter"); - } - else { - const char *inner_radius_name = stp_get_string_parameter(v, "CDInnerRadius"); - hub_size = 43 * 10 * 72 / 254; /* 43 mm standard CD hub */ - - if (inner_radius_name && strcmp(inner_radius_name, "Small") == 0) - hub_size = 16 * 10 * 72 / 254; /* 15 mm prints to the hole - play it - safe and print 16 mm */ + int outer_diameter = stp_get_dimension_parameter(v, "CDOuterDiameter"); + stp_set_page_width(v, outer_diameter); + stp_set_page_height(v, outer_diameter); + stp_set_width(v, outer_diameter); + stp_set_height(v, outer_diameter); + hub_size = stp_get_dimension_parameter(v, "CDInnerDiameter"); } - + else + { + const char *inner_radius_name = stp_get_string_parameter(v, "CDInnerRadius"); + hub_size = 43 * 10 * 72 / 254; /* 43 mm standard CD hub */ + + if (inner_radius_name && strcmp(inner_radius_name, "Small") == 0) + hub_size = 16 * 10 * 72 / 254; /* 15 mm prints to the hole - play it + safe and print 16 mm */ + } + privdata->top = stp_get_top(v); privdata->left = stp_get_left(v); privdata->out_width = stp_get_width(v); /* check Epson: page_true_width */ privdata->out_height = stp_get_height(v); /* check Epson: page_true_height */ - + stp_deprintf(STP_DBG_CANON,"stp_get_width: privdata->out_width is %i\n",privdata->out_width); - stp_deprintf(STP_DBG_CANON,"stp_get_height: privdata->out_height is %i\n",privdata->out_height); - + stp_deprintf(STP_DBG_CANON,"stp_get_height: privdata->out_height is %i\n",privdata->out_height); + /* Don't use full bleed mode if the paper itself has a margin */ if (privdata->left > 0 || privdata->top > 0) stp_set_boolean_parameter(v, "FullBleed", 0); - + internal_imageable_area(v, 0, 0, &page_left, &page_right, &page_bottom, &page_top); if (print_cd) { @@ -5574,9 +5783,9 @@ canon_do_print(stp_vars_t *v, stp_image_t *image) int status = 1; const char *media_source = stp_get_string_parameter(v, "InputSlot"); const char *ink_type = stp_get_string_parameter(v, "InkType"); - const char *duplex_mode =stp_get_string_parameter(v, "Duplex"); + const char *duplex_mode = stp_get_string_parameter(v, "Duplex"); int page_number = stp_get_int_parameter(v, "PageNumber"); - const canon_cap_t * caps= canon_get_model_capabilities(v); + const canon_cap_t * caps = canon_get_model_capabilities(v); const canon_modeuselist_t* mlist = caps->modeuselist; #if 0 const canon_modeuse_t* muse; @@ -5594,7 +5803,7 @@ canon_do_print(stp_vars_t *v, stp_image_t *image) out_channels; /* Output bytes per pixel */ #endif unsigned zero_mask; - int print_cd= (media_source && (!strcmp(media_source, "CD"))); + int print_cd = (media_source && (!strcmp(media_source, "CD"))); int image_height; #if 0 int image_width; @@ -5820,11 +6029,11 @@ canon_do_print(stp_vars_t *v, stp_image_t *image) /* Allocate compression buffer */ if(caps->features & CANON_CAP_I) /*privdata.comp_buf = stp_zalloc(privdata.buf_length_max * 2 * caps->raster_lines_per_block * privdata.num_channels); */ - privdata.comp_buf = stp_zalloc(privdata.buf_length_max * 2 * privdata.mode->raster_lines_per_block * privdata.num_channels); /* for multiraster we need to buffer 8 lines for every color */ + privdata.comp_buf = stp_zalloc(stp_compute_tiff_linewidth(v, privdata.buf_length_max * 2 * privdata.mode->raster_lines_per_block * privdata.num_channels)); /* for multiraster we need to buffer 8 lines for every color */ else - privdata.comp_buf = stp_zalloc(privdata.buf_length_max * 2); + privdata.comp_buf = stp_zalloc(stp_compute_tiff_linewidth(v, privdata.buf_length_max * 2)); /* Allocate fold buffer */ - privdata.fold_buf = stp_zalloc(privdata.buf_length_max); + privdata.fold_buf = stp_zalloc(stp_compute_tiff_linewidth(v, privdata.buf_length_max)); @@ -6262,7 +6471,7 @@ canon_write(stp_vars_t *v, /* I - Print file or command */ unsigned char *line, /* I - Output bitmap data */ int length, /* I - Length of bitmap data */ int coloridx, /* I - Which color */ - int *empty, /* IO- Preceeding empty lines */ + int *empty, /* IO- Preceding empty lines */ int width, /* I - Printed width */ int offset, /* I - Offset from left side */ int bits, |