Tizen 2.1 base
[platform/upstream/hplip.git] / prnt / hpijs / djgenericvip.cpp
1 /*****************************************************************************\
2   djgenericvip.cpp : Implimentation for the generic VIP class
3
4   Copyright (c) 2001-2006, Hewlett-Packard Co.
5   All rights reserved.
6
7   Redistribution and use in source and binary forms, with or without
8   modification, are permitted provided that the following conditions
9   are met:
10   1. Redistributions of source code must retain the above copyright
11      notice, this list of conditions and the following disclaimer.
12   2. Redistributions in binary form must reproduce the above copyright
13      notice, this list of conditions and the following disclaimer in the
14      documentation and/or other materials provided with the distribution.
15   3. Neither the name of Hewlett-Packard nor the names of its
16      contributors may be used to endorse or promote products derived
17      from this software without specific prior written permission.
18
19   THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
20   WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21   MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN
22   NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
24   TO, PATENT INFRINGEMENT; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
25   OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26   ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 \*****************************************************************************/
30
31
32 #if defined(APDK_DJGENERICVIP) && defined (APDK_DJ9xxVIP)
33
34 #include "header.h"
35 #include "dj9xxvip.h"
36 #include "djgenericvip.h"
37 #include "printerproxy.h"
38
39 APDK_BEGIN_NAMESPACE
40
41 extern uint32_t ulMapDJ600_CCM_K[ 9 * 9 * 9 ];
42
43 /*
44  *  All VIP printers that are released after the APDK release.
45  *  This subclass is mainly there to allow any combination of
46  *  installed pens.
47  */
48
49 DJGenericVIP::DJGenericVIP (SystemServices* pSS, BOOL proto)
50     : DJ9xxVIP (pSS, proto)
51 {
52
53     if (!proto && IOMode.bDevID)
54     {
55         bCheckForCancelButton = TRUE;
56         constructor_error = VerifyPenInfo ();
57         if (constructor_error != NO_ERROR)
58         {
59             constructor_error = NO_ERROR;
60             ePen = BOTH_PENS;
61         }
62     }
63     else
64         ePen = BOTH_PENS;
65
66 /*
67  *  For this printer class, allow any print mode to be compatible with
68  *  any installed pen set. Printer is expected to do the right thing.
69  *  Also, language has to be PCL3GUI because some printers may not work
70  *  properly in plain PCL3 mode. ex. PhotoSmart 1xx family. This means
71  *  no device text support.
72  */
73
74     pMode[ModeCount++] = new VIPFastDraftMode ();        // Fast Draft
75     pMode[ModeCount++] = new VIPGrayFastDraftMode ();    // Grayscale Fast Draft
76     pMode[ModeCount++] = new VIPAutoPQMode ();           // Printer selects PrintMode
77     pMode[ModeCount++] = new VIPFastPhotoMode ();        // Fast Photo
78     pMode[ModeCount++] = new VIPCDDVDMode ();            // CD/DVD PrintMode
79 \r
80 #ifdef APDK_EXTENDED_MEDIASIZE\r
81     pMode[ModeCount++] = new VIPBrochureNormalMode ();   // Normal, Brochure media\r
82     pMode[ModeCount++] = new VIPPremiumNormalMode ();    // Normal, Premium paper\r
83     pMode[ModeCount++] = new VIPPlainBestMode ();        // Best, Plain media\r
84     pMode[ModeCount++] = new VIPBrochureBestMode ();     // Best, Brochure media\r
85     pMode[ModeCount++] = new VIPPremiumBestMode ();      // Best, Premium media     \r
86 #endif\r
87
88     for (int i = 0; i < (int) ModeCount; i++)
89     {
90         pMode[i]->bFontCapable = FALSE;
91         for (int j = BLACK_PEN; j < MAX_COMPATIBLE_PENS; j++)
92         {
93             pMode[i]->CompatiblePens[j] = (PEN_TYPE) j;
94         }
95     }
96 #ifdef APDK_EXTENDED_MEDIASIZE
97 /*
98  *  Set quality to marvellous for high res (1200 dpi) mode.
99  *  This mode was not available in the older printers, which only supported the
100  *  media_high_res paper type, but used qualityPresentation for 1200 dpi mode.
101  */
102     pMode[4]->theQuality = qualityMarvellous;
103 #endif
104 }
105
106 VIPFastDraftMode::VIPFastDraftMode () : PrintMode (NULL)
107 {
108     bFontCapable = FALSE;
109 #ifdef APDK_AUTODUPLEX
110     bDuplexCapable = TRUE;
111 #endif
112 #if defined(APDK_VIP_COLORFILTERING)
113     Config.bErnie = TRUE;
114 #endif
115
116    Config.bColorImage = FALSE;
117
118     medium = mediaPlain;
119     theQuality = qualityFastDraft;
120     pmQuality = QUALITY_FASTDRAFT;
121     pmMediaType   = MEDIA_PLAIN;
122 } // VIPFastDraftMode
123
124 VIPGrayFastDraftMode::VIPGrayFastDraftMode () : GrayMode (ulMapDJ600_CCM_K)
125 {
126     bFontCapable = FALSE;
127
128 #if defined(APDK_VIP_COLORFILTERING)
129     Config.bErnie = TRUE;
130 #endif
131
132     Config.bColorImage = FALSE;
133
134 #ifdef APDK_AUTODUPLEX
135     bDuplexCapable = TRUE;
136 #endif
137
138     dyeCount    = 1;
139     medium      = mediaPlain;
140     theQuality  = qualityFastDraft;
141     pmQuality   = QUALITY_FASTDRAFT;
142     pmMediaType = MEDIA_PLAIN;
143     pmColor     = GREY_K;
144 }
145
146 VIPFastPhotoMode::VIPFastPhotoMode () : PrintMode (NULL)
147 {
148     bFontCapable = FALSE;
149 #if defined(APDK_VIP_COLORFILTERING)
150     Config.bErnie = FALSE;
151 #endif
152     medium = mediaHighresPhoto;
153     theQuality = qualityFastDraft;
154     pmQuality = QUALITY_FASTDRAFT;
155     pmMediaType = MEDIA_PHOTO;
156 } // VIPFastPhotoMode
157
158 VIPAutoPQMode::VIPAutoPQMode () : PrintMode (NULL)
159 {
160     BaseResX =
161     BaseResY = 600;
162     ResolutionX[0] = 600;
163     ResolutionY[0] = 600;
164     bFontCapable = FALSE;
165 #ifdef APDK_AUTODUPLEX
166     bDuplexCapable = FALSE;
167 #endif
168 #if defined(APDK_VIP_COLORFILTERING)
169     Config.bErnie = TRUE;
170 #endif
171
172     Config.bColorImage = FALSE;
173
174     medium     = mediaAuto;
175     theQuality = qualityAuto;
176     pmQuality  = QUALITY_AUTO;
177 } // VIPAutoPQMode
178
179 VIPCDDVDMode::VIPCDDVDMode () : PrintMode (NULL)
180 {
181     BaseResX =
182     BaseResY = 600;
183     ResolutionX[0] = 600;
184     ResolutionY[0] = 600;
185     bFontCapable = FALSE;
186 #ifdef APDK_AUTODUPLEX
187     bDuplexCapable = FALSE;
188 #endif
189 #if defined(APDK_VIP_COLORFILTERING)
190     Config.bErnie = TRUE;
191 #endif
192
193     Config.bColorImage = FALSE;
194
195     medium      = mediaCDDVD;
196     theQuality  = qualityPresentation;
197     pmQuality   = QUALITY_BEST;
198     pmMediaType = MEDIA_CDDVD;
199 }
200 \r
201 VIPBrochureNormalMode::VIPBrochureNormalMode () : PrintMode (NULL)\r
202 {\r
203     BaseResX =\r
204     BaseResY = 600;\r
205     ResolutionX[0] = 600;\r
206     ResolutionY[0] = 600;\r
207     bFontCapable = FALSE;\r
208 #ifdef APDK_AUTODUPLEX\r
209     bDuplexCapable = TRUE;\r
210 #endif\r
211 #if defined(APDK_VIP_COLORFILTERING)\r
212     Config.bErnie = TRUE;\r
213 #endif\r
214 \r
215     Config.bColorImage = FALSE;\r
216 \r
217     medium      = mediaBrochure;\r
218     theQuality  = qualityNormal;\r
219     pmQuality   = QUALITY_NORMAL;\r
220     pmMediaType = MEDIA_BROCHURE;\r
221 } // Added by Lizzie\r
222 \r
223 VIPPremiumNormalMode::VIPPremiumNormalMode () : PrintMode (NULL)\r
224 {\r
225     BaseResX =\r
226     BaseResY = 600;\r
227     ResolutionX[0] = 600;\r
228     ResolutionY[0] = 600;\r
229     bFontCapable = FALSE;\r
230 #ifdef APDK_AUTODUPLEX\r
231     bDuplexCapable = TRUE;\r
232 #endif\r
233 #if defined(APDK_VIP_COLORFILTERING)\r
234     Config.bErnie = TRUE;\r
235 #endif\r
236 \r
237     Config.bColorImage = FALSE;\r
238 \r
239     medium      = mediaSpecial;\r
240     theQuality  = qualityNormal;\r
241     pmQuality   = QUALITY_NORMAL;\r
242     pmMediaType = MEDIA_PREMIUM;\r
243 } // Added by Lizzie\r
244 \r
245 VIPPlainBestMode::VIPPlainBestMode () : PrintMode (NULL)\r
246 {\r
247     BaseResX =\r
248     BaseResY = 600;\r
249     ResolutionX[0] = 600;\r
250     ResolutionY[0] = 600;\r
251     bFontCapable = FALSE;\r
252 #ifdef APDK_AUTODUPLEX\r
253     bDuplexCapable = TRUE;\r
254 #endif\r
255 #if defined(APDK_VIP_COLORFILTERING)\r
256     Config.bErnie = TRUE;\r
257 #endif\r
258 \r
259     Config.bColorImage = FALSE;\r
260 \r
261     medium      = mediaPlain;\r
262     theQuality  = qualityPresentation;\r
263     pmQuality   = QUALITY_BEST;\r
264     pmMediaType = MEDIA_PLAIN;\r
265 \r
266 } // Added by Lizzie\r
267 \r
268 VIPBrochureBestMode::VIPBrochureBestMode () : PrintMode (NULL)\r
269 {\r
270     BaseResX =\r
271     BaseResY = 600;\r
272     ResolutionX[0] = 600;\r
273     ResolutionY[0] = 600;\r
274     bFontCapable = FALSE;\r
275 #ifdef APDK_AUTODUPLEX\r
276     bDuplexCapable = TRUE;\r
277 #endif\r
278 #if defined(APDK_VIP_COLORFILTERING)\r
279     Config.bErnie = TRUE;\r
280 #endif\r
281 \r
282     Config.bColorImage = FALSE;\r
283 \r
284     medium      = mediaBrochure;\r
285     theQuality  = qualityPresentation;\r
286     pmQuality   = QUALITY_BEST;\r
287     pmMediaType = MEDIA_BROCHURE;\r
288 } // Added by Lizzie\r
289 \r
290 VIPPremiumBestMode::VIPPremiumBestMode () : PrintMode (NULL)\r
291 {\r
292     BaseResX =\r
293     BaseResY = 600;\r
294     ResolutionX[0] = 600;\r
295     ResolutionY[0] = 600;\r
296     bFontCapable = FALSE;\r
297 #ifdef APDK_AUTODUPLEX\r
298     bDuplexCapable = TRUE;\r
299 #endif\r
300 #if defined(APDK_VIP_COLORFILTERING)\r
301     Config.bErnie = TRUE;\r
302 #endif\r
303 \r
304     Config.bColorImage = FALSE;\r
305 \r
306     medium      = mediaSpecial;\r
307     theQuality  = qualityPresentation;\r
308     pmQuality   = QUALITY_BEST;\r
309     pmMediaType = MEDIA_PREMIUM;\r
310 } // Added by Lizzie\r
311
312 BOOL DJGenericVIP::UseGUIMode (PrintMode* pPrintMode)
313 {
314     return TRUE;
315 }
316
317 /*
318  *  We don't really know beforehand the largest papersize the attached printer
319  *  can support. The first reserved nibble after the VIP flag nibble contains
320  *  this information. Only firmware version 4 or greater support this feature.
321  */
322
323 PAPER_SIZE DJGenericVIP::MandatoryPaperSize ()
324 {
325     BYTE    sDevIdStr[DevIDBuffSize];
326     char    *pStr;
327
328 /*
329  *  Try to get the DevID. Advance the pointer to the beginning of the status field.
330  *  Currently, only 3 lower bits are used for reporting paper size. Meaning of these
331  *  bit-values is as follows:
332  *      000 - Allow any size
333  *      001 - A6
334  *      010 - Letter
335  *      011 - B4
336  *      100 - 13 X 19 size
337  */
338
339     if ((pSS->GetDeviceID (sDevIdStr, DevIDBuffSize, FALSE)) == NO_ERROR)
340     {
341         if ((pStr = strstr ((char *) sDevIdStr, ";S:")) && (pSS->GetVIPVersion ()) >= 3)
342         {
343 #ifdef APDK_EXTENDED_MEDIASIZE
344                         PAPER_SIZE  PaperSizes[8] = {UNSUPPORTED_SIZE, A6, LETTER, B4, SUPERB_SIZE, UNSUPPORTED_SIZE, UNSUPPORTED_SIZE, UNSUPPORTED_SIZE};
345 #else
346             PAPER_SIZE  PaperSizes[8] = {UNSUPPORTED_SIZE, A6, LETTER, B4, UNSUPPORTED_SIZE, UNSUPPORTED_SIZE, UNSUPPORTED_SIZE, UNSUPPORTED_SIZE};
347 #endif
348                         char  byte12 = pStr[17];
349                         short value = (byte12 >= '0' && byte12 <= '9') ? byte12 - '0' : 
350                                           ((byte12 >= 'A' && byte12 <= 'F') ? byte12 - 'A' + 10 :
351                                           ((byte12 >= 'a' && byte12 <= 'f') ? byte12 - 'a' + 10 : -1));
352                         return (value == -1) ? UNSUPPORTED_SIZE : PaperSizes[(value & 0x07)];
353                 }
354     }
355     return UNSUPPORTED_SIZE;
356 } //MandantoryPaperSize
357
358
359 /*
360 * byte 13 - indicates full bleed (to every edge of paper) is supported if 
361 * the modifier bit in the lowest position is "set".  
362 *
363
364 * 0000b or 0h = Unimplemented, or not specified.
365 * 0001b or 1h = Full bleed (4 edge) printing supported on photo quality papers; this field is a modifier upon the bits in byte 12. That is, if this bit is set, it implies that the "max print width supported" values and smaller widths, ALL support full bleed, 4 edge, printing on photo quality paper.
366 * 0010b or 2h = Full bleed (4 edge) printing supported on non-photo papers (e.g. plain, bond, etc.); this field is a modifier upon the bits in byte 12. If this bit is set, it implies that the "max print width supported" values and smaller widths, all support full bleed, 4 edge, printing on non-photo paper.
367 * nn00b  = The "nn" bits are reserved for future definitions
368 */
369
370 BOOL DJGenericVIP::FullBleedCapable (PAPER_SIZE ps, FullbleedType  *fbType, float *xOverSpray, float *yOverSpray,
371                                      float *fLeftOverSpray, float *fTopOverSpray)
372 {
373     BYTE    sDevIdStr[DevIDBuffSize];
374     char    *pStr;
375     sDevIdStr[0] = 0;
376 \r
377         // if overspray is passed down and set\r
378         if (this->m_iTopOverspray && this->m_iLeftOverspray && this->m_iRightOverspray && this->m_iBottomOverspray)\r
379     {\r
380 \r
381 /*\r
382  *      This check is needed because of method override. \r
383  *      Another caller would not pass down this parameter, \r
384  *      and this is default to NULL\r
385  */\r
386                 if (fTopOverSpray) \r
387                         *fTopOverSpray = (float) this->m_iTopOverspray / (float) 1000.0;\r
388                 if (fLeftOverSpray)\r
389                         *fLeftOverSpray = (float) this->m_iLeftOverspray / (float) 1000.0;\r
390                 \r
391                 *xOverSpray = (float) (this->m_iLeftOverspray + this->m_iRightOverspray) / (float) 1000.0;\r
392                 *yOverSpray = (float) (this->m_iTopOverspray + this->m_iBottomOverspray) / (float) 1000.0;\r
393 \r
394                 *fbType = fullbleed4EdgeAllMedia;\r
395 \r
396                 return TRUE;\r
397         }\r
398
399     if ((pSS->GetDeviceID (sDevIdStr, DevIDBuffSize, FALSE)) == NO_ERROR)
400     {
401         if ((pStr = strstr ((char *) sDevIdStr, ";S:")) && (pSS->GetVIPVersion ()) >= 3)
402         {
403                         char  byte13 = pStr[18];
404                         short value = (byte13 >= '0' && byte13 <= '9') ? byte13 - '0' : 
405                                           ((byte13 >= 'A' && byte13 <= 'F') ? byte13 - 'A' + 10 :
406                                           ((byte13 >= 'a' && byte13 <= 'f') ? byte13 - 'a' + 10 : -1));
407                         switch (ps)
408                         {
409                                 case PHOTO_SIZE:
410                                 case A6:
411                                 case CARD_4x6:
412                                 case OUFUKU:
413                                 case HAGAKI:
414                                 case A6_WITH_TEAR_OFF_TAB:\r
415                                 case CUSTOM_SIZE:\r
416                                 {
417                                         *xOverSpray = (float) 0.12;
418                                         *yOverSpray = (float) 0.06;
419
420                                         if (fLeftOverSpray)
421                                                 *fLeftOverSpray = (float) 0.05;
422                                         if (fTopOverSpray)
423                                                 *fTopOverSpray  = (float) 0.03;
424
425                                         if (ps == PHOTO_SIZE || ps == A6_WITH_TEAR_OFF_TAB)
426                                                 *fbType = fullbleed4EdgeAllMedia;
427                                         else if ((value != -1) && ((value & 0x03) == 0x03))
428                                                 *fbType = fullbleed4EdgeAllMedia;
429                                         else if ((value != -1) && ((value & 0x01) == 0x01))
430                                                 *fbType = fullbleed4EdgePhotoMedia;
431                                         else if ((value != -1) && ((value & 0x02) == 0x02))
432                                                 *fbType = fullbleed4EdgeNonPhotoMedia;
433                                         else
434                                                 *fbType = fullbleed3EdgeAllMedia;
435
436                                         return TRUE;
437                                 }
438                                 default:
439                                         break;
440                         }
441
442                         if ((value != -1) && (value & 0x03))
443                         {
444                                 *xOverSpray = (float) 0.216;
445                                 *yOverSpray = (float) 0.149;
446                                 if (fLeftOverSpray)
447                                         *fLeftOverSpray = (float) 0.098;
448                                 if (fTopOverSpray)
449                                         *fTopOverSpray  = (float) 0.051;
450
451                                 if ((value & 0x03) == 0x03)
452                                         *fbType = fullbleed4EdgeAllMedia;
453                                 else if ((value & 0x01) == 0x01)
454                                         *fbType = fullbleed4EdgePhotoMedia;
455                                 else if ((value & 0x02) == 0x02)
456                                         *fbType = fullbleed4EdgeNonPhotoMedia;
457
458                                 return TRUE; 
459
460                         }
461                         else
462                         {
463                                 *xOverSpray = (float) 0;
464                                 *yOverSpray = (float) 0;
465                                 if (fLeftOverSpray)
466                                         *fLeftOverSpray = (float) 0;
467                                 if (fTopOverSpray)
468                                         *fTopOverSpray  = (float) 0;
469                                 *fbType = fullbleedNotSupported;
470                                 return FALSE;
471                         }
472         }
473     }
474
475         switch (ps)
476         {
477                 case PHOTO_SIZE:
478                 case A6:
479                 case CARD_4x6:
480                 case OUFUKU:
481                 case HAGAKI:
482                 case A6_WITH_TEAR_OFF_TAB:\r
483                 case LETTER:\r
484                 case A4:\r
485                 case CUSTOM_SIZE:\r
486                 {
487                         *xOverSpray = (float) 0.12;
488                         *yOverSpray = (float) 0.06;
489
490                         if (fLeftOverSpray)
491                                 *fLeftOverSpray = (float) 0.05;
492                         if (fTopOverSpray)
493                                 *fTopOverSpray  = (float) 0.03;
494
495                         if (ps == PHOTO_SIZE || ps == A6_WITH_TEAR_OFF_TAB)
496                                 *fbType = fullbleed4EdgeAllMedia;\r
497                         else if (ps==LETTER||ps==A4||ps==CUSTOM_SIZE)\r
498                         {\r
499                                 *fbType = fullbleed4EdgeAllMedia;                                                               \r
500                                 *xOverSpray = (float) 0.1;\r
501                                 *yOverSpray = (float) 0.1;\r
502                                 if (fLeftOverSpray)\r
503                                         *fLeftOverSpray = (float) 0.05;\r
504                                 if (fTopOverSpray)\r
505                                         *fTopOverSpray  = (float) 0.05;\r
506                         }\r
507                         else
508                                 *fbType = fullbleed3EdgeAllMedia;
509
510                         return TRUE;
511                 }
512                 default:
513                         break;
514         }
515
516     *xOverSpray = (float) 0;
517     *yOverSpray = (float) 0;
518     if (fLeftOverSpray)
519         *fLeftOverSpray = (float) 0;
520     if (fTopOverSpray)
521         *fTopOverSpray  = (float) 0;
522         *fbType = fullbleedNotSupported;
523     return FALSE;
524 }
525
526 BOOL DJGenericVIP::GetMargins (PAPER_SIZE ps, float *fMargins)
527 {
528     float           xo, yo, xl, yt;
529     FullbleedType   fbType = fullbleedNotSupported;
530
531     if (ps == CDDVD_120 || ps == CDDVD_80)
532     {
533         fMargins[0] = (float) 0.06;
534         fMargins[1] = (float) 0.06;
535         fMargins[2] = (float) 0.06;
536         fMargins[3] = (float) 0.06;
537         return TRUE;
538     }
539
540     fMargins[0] = (float) 0.125;
541     fMargins[1] = (float) 0.125;
542     fMargins[2] = (float) 0.125;
543     fMargins[3] = (float) 0.5;
544     if ((FullBleedCapable (ps, &fbType, &xo, &yo, &xl, &yt)) &&
545         (fbType == fullbleed4EdgeAllMedia ||
546          fbType == fullbleed4EdgePhotoMedia ||
547          fbType == fullbleed4EdgeNonPhotoMedia))
548     {
549         fMargins[3] = (float) 0.125;
550     }
551
552     if (ps == SUPERB_SIZE)
553     {
554         fMargins[0] = (float) 0.125;
555         fMargins[1] = (float) 0.5;
556         fMargins[2] = (float) 0.125;
557         fMargins[3] = (float) 0.75;
558     }
559
560     return TRUE;
561 }
562
563
564 PHOTOTRAY_STATE DJGenericVIP::PhotoTrayEngaged (BOOL bQueryPrinter)
565 {
566     return UNKNOWN;
567 }
568
569 //! Returns TRUE if a hagaki feed is present in printer.
570 BOOL DJGenericVIP::HagakiFeedPresent(BOOL bQueryPrinter) 
571 {
572     DRIVER_ERROR err;
573     char* pStr;
574
575     BYTE bDevIDBuff[DevIDBuffSize];
576
577     if (!IOMode.bDevID)
578     {
579         bQueryPrinter = FALSE;
580     }
581
582     err = pSS->GetDeviceID(bDevIDBuff, DevIDBuffSize, bQueryPrinter);
583     if (err!=NO_ERROR)
584     {
585         return 0;
586     }
587
588     if ( (pStr=(char *)strstr((const char*)bDevIDBuff+2,";S:")) == NULL )
589     {
590         return 0;
591     }
592
593     // skip over ";S:<version=2bytes><topcover><inklid><duplexer>"
594     pStr += 8;
595     BYTE b = *pStr;
596     return ((b & 4) == 4);
597 }
598
599 #ifdef APDK_AUTODUPLEX
600 //!Returns TRUE if duplexer and hagaki feed (combined) unit is present in printer.
601 BOOL DJGenericVIP::HagakiFeedDuplexerPresent(BOOL bQueryPrinter)
602 {
603     DRIVER_ERROR err;
604     char* pStr;
605
606     BYTE bDevIDBuff[DevIDBuffSize];
607
608     if (!IOMode.bDevID)
609     {
610         bQueryPrinter = FALSE;
611     }
612
613     err = pSS->GetDeviceID (bDevIDBuff, DevIDBuffSize, bQueryPrinter);
614     if (err!=NO_ERROR)
615     {
616         return 0;
617     }
618
619     if ( (pStr=(char *)strstr((const char*)bDevIDBuff+2,";S:")) == NULL )
620     {
621         return 0;
622     }
623
624     // skip over ";S:<version=2bytes><topcover><inklid>"
625     pStr += 6;
626     BYTE b = *pStr;
627     return ((b & 4) == 4);
628 }
629 #endif
630
631
632 DRIVER_ERROR DJGenericVIP::VerifyPenInfo ()
633 {
634
635     DRIVER_ERROR err = NO_ERROR;
636
637     if (IOMode.bDevID == FALSE)
638         return err;
639
640     ePen = NO_PEN;
641
642     err = ParsePenInfo (ePen);
643
644     if(err == UNSUPPORTED_PEN) // probably Power Off - pens couldn't be read
645     {
646
647         // have to delay or the POWER ON will be ignored
648         if (pSS->BusyWait ((DWORD) 2000) == JOB_CANCELED)
649         {
650             return JOB_CANCELED;
651         }
652
653         DWORD length = sizeof (DJ895_Power_On);
654         err = pSS->ToDevice (DJ895_Power_On, &length);
655         ERRCHECK;
656
657         err = pSS->FlushIO ();
658         ERRCHECK;
659
660         // give the printer some time to power up
661         if (pSS->BusyWait ((DWORD) 2500) == JOB_CANCELED)
662         {
663             return JOB_CANCELED;
664         }
665
666         err = ParsePenInfo (ePen);
667     }
668
669     ERRCHECK;
670
671 /*
672  *  If one or more pens are not installed, check the device id for ReserveMode
673  *  capability for this printer. This info in in the flags nibble
674  *  ;S:<XX><toplid><supplylic><duplexer><phototray><in-1><in-2><banner><flags>
675  *  flags : x1xx - reserve mode supported, x0xx - not supported
676  */
677
678     BYTE    sDevIdStr[DevIDBuffSize];
679     char    *pStr;
680     BOOL    bNeedAllPens = FALSE;
681
682     if (iNumMissingPens > 0 && ((pSS->GetDeviceID (sDevIdStr, DevIDBuffSize, FALSE)) == NO_ERROR))
683     {
684         if ((pStr = strstr ((char *) sDevIdStr, ";S:")))
685         {
686                         char  byte7 = pStr[12];
687                         short value = (byte7 >= '0' && byte7 <= '9') ? byte7 - '0' : 
688                       ((byte7 >= 'A' && byte7 <= 'F') ? byte7 - 'A' + 10 :
689                       ((byte7 >= 'a' && byte7 <= 'f') ? byte7 - 'a' + 10 : 0));
690                         bNeedAllPens = !(value & 0x04);
691         }
692     }
693
694     while (ePen == NO_PEN || (bNeedAllPens && iNumMissingPens > 0))
695     {
696         if (ePen == NO_PEN || iNumMissingPens > 0)
697         {
698             pSS->DisplayPrinterStatus (DISPLAY_NO_PENS);
699
700             if (pSS->BusyWait (500) == JOB_CANCELED)
701             {
702                 return JOB_CANCELED;
703             }
704         }
705         err =  ParsePenInfo (ePen);
706         ERRCHECK;
707     }
708
709     pSS->DisplayPrinterStatus(DISPLAY_PRINTING);
710
711     return NO_ERROR;
712 } //ParasePenInfo
713
714 void DJGenericVIP::AdjustModeSettings (BOOL bDoFullBleed, MEDIATYPE ReqMedia,
715                                        MediaType *medium, Quality *quality)
716 {
717
718 /*
719  *  Malibu platform printers have a defect that prevents these printers from
720  *  performing full-bleed and media detect functions correctly. Check for this
721  *  case, i.e., full-bleed and media detect flags and explicitly set the
722  *  media type and quality as requested by the application.
723  */
724
725     if (bDoFullBleed && *medium == mediaAuto)
726     {
727
728         if (ReqMedia == MEDIA_PHOTO)
729         {
730             *medium  = mediaGlossy;
731             *quality = qualityPresentation;
732
733         }
734         else
735         {
736             *medium  = mediaPlain;
737             *quality = qualityNormal;
738
739         }
740
741     }
742     // Added by Lizzie - plain and premium will default to Auto when PQ is not fast draft\r
743     // so fix the media type here\r
744     if( ReqMedia == MEDIA_PLAIN)\r
745         *medium = mediaPlain;\r
746 \r
747     if( ReqMedia == MEDIA_PREMIUM)\r
748         *medium = mediaSpecial;\r
749 \r
750     if( ReqMedia == MEDIA_BROCHURE)\r
751         *medium = mediaBrochure;\r
752
753 } // AdjustModeSettings
754
755 #ifdef APDK_LINUX
756 DRIVER_ERROR DJGenericVIP::SendSpeedMechCmd (BOOL bLastPage)
757 {
758     DRIVER_ERROR    err = NO_ERROR;
759     BYTE            szStr[16];
760     if (m_iNumPages > 1)
761     {
762         memcpy (szStr, "\x1B*o5W\x0D\x02\x00\x00\x00", 10);
763                 szStr[7] = (BYTE) ((m_iNumPages & 0x00FF0000) >> 16);
764                 szStr[8] = (BYTE) ((m_iNumPages & 0x0000FF00) >> 8);
765                 szStr[9] = (BYTE) (m_iNumPages & 0x000000FF);
766         err = Send ((const BYTE *) szStr, 10);
767         if (bLastPage)
768         {
769             err = Send ((const BYTE *) "\x1B*o5W\x0D\x05\x00\x00\x01", 10);
770         }
771         else
772         {
773             err = Send ((const BYTE *) "\x1B*o5W\x0D\x05\x00\x00\x00", 10);
774         }
775     }
776         return err;
777 }
778 #endif // APDK_LINUX
779
780 Header *DJGenericVIP::SelectHeader (PrintContext *pc)
781 {
782     return new HeaderDJGenericVIP (this, pc);
783 }
784
785 HeaderDJGenericVIP::HeaderDJGenericVIP (Printer *p, PrintContext *pc) : HeaderDJ990 (p, pc)
786 {
787     m_uiCAPy = 0;
788 }
789
790 DRIVER_ERROR HeaderDJGenericVIP::SendCAPy (unsigned int iAbsY)
791 {
792     char    str[16];
793     DRIVER_ERROR err = NO_ERROR;
794     if (m_uiCAPy == 0)
795     {
796         sprintf (str, "\x1B*p%dY", iAbsY);
797         err = thePrinter->Send ((const BYTE *) str, strlen (str));
798         m_uiCAPy = iAbsY;
799     }
800     return err;
801 }
802
803 DRIVER_ERROR HeaderDJGenericVIP::FormFeed ()
804 {
805     BYTE FF = 12;
806     m_uiCAPy = 0;
807     return thePrinter->Send ((const BYTE *) &FF, 1);
808 }
809
810 APDK_END_NAMESPACE
811
812
813 #endif // defined(APDK_DJGENERICVIP) && defined (APDK_DJ9xxVIP)