Tizen 2.1 base
[platform/upstream/hplip.git] / prnt / hpijs / apollo2xxx.cpp
1 /*****************************************************************************\
2   apollo2xxx.cpp : Implimentation for the Apollo2xxx class
3
4   Copyright (c) 2000, 2001, 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 #ifdef APDK_APOLLO2XXX
33
34 #include "header.h"
35 #include "apollo2xxx.h"
36 #include "printerproxy.h"
37
38 APDK_BEGIN_NAMESPACE
39
40 extern uint32_t ulMapDJ690_CMYK[ 9 * 9 * 9 ];
41 extern uint32_t ulMapDJ690_ClMlxx[ 9 * 9 * 9 ];
42 extern uint32_t ulMapDJ660_CCM_KCMY[ 9 * 9 * 9 ];
43 extern uint32_t ulMapDJ600_CCM_K[ 9 * 9 * 9 ];
44 extern uint32_t ulMapDJ600_CCM_CMY[ 9 * 9 * 9 ];
45
46 Apollo2xxx::Apollo2xxx(SystemServices* pSS, BOOL proto)
47     : Printer(pSS, NUM_DJ6XX_FONTS,proto)
48 {
49
50     if ((!proto) && (IOMode.bDevID))
51       {
52         constructor_error = VerifyPenInfo();
53         CERRCHECK;
54       }
55     else ePen=BOTH_PENS;    // matches default mode
56
57     CMYMap = ulMapDJ600_CCM_CMY;    // used in Mode2xxxColor
58
59     pMode[DEFAULTMODE_INDEX]        = new PrintMode(ulMapDJ660_CCM_KCMY);   // normal color kcmy
60     pMode[SPECIALMODE_INDEX]        = new Mode2xxxColor();   // normal color cmy
61     pMode[SPECIALMODE_INDEX+1]   = new Mode2xxxPhoto();   // photo
62     pMode[GRAYMODE_INDEX]           = new GrayMode2xxx();   // normal gray k
63 #ifdef APDK_EXTENDED_MEDIASIZE
64     pMode[SPECIALMODE_INDEX+2] = new Mode2xxxDraftGrayK();
65     pMode[SPECIALMODE_INDEX+3] = new Mode2xxxDraftColorKCMY();
66     pMode[SPECIALMODE_INDEX+4] = new Mode2xxxDraftColorCMY();
67     pMode[SPECIALMODE_INDEX+5] = new Mode2xxxBestGrayK();
68     ModeCount=8;
69 #else
70     ModeCount = 4;
71 #endif
72
73     DBG1("AP2xxx created\n");
74
75 }
76
77 DRIVER_ERROR Apollo2xxx::VerifyPenInfo()
78 {
79     DRIVER_ERROR err=NO_ERROR;
80
81     if(IOMode.bDevID == FALSE)
82         return err;
83
84     err = ParsePenInfo(ePen);
85     ERRCHECK;
86
87     // check for the normal case
88     if (ePen == BOTH_PENS || ePen == MDL_BOTH || ePen == COLOR_PEN || ePen == BLACK_PEN)
89         return NO_ERROR;
90
91 DBG1("Apollo2xxx::VerifyPenInfo(): ePen is not BOTH_PENS, MDL_BOTH, COLOR_PEN, or BLACK_PEN\n");
92
93     // the 2100 printers require the color pen OR the black pen to be installed, so trap
94     // on any pen type that does not include either the color pen or black pen
95     while ( (ePen != BOTH_PENS) && (ePen != MDL_BOTH) && (ePen != COLOR_PEN) && (ePen != BLACK_PEN))
96     {
97 DBG1("Apollo2xxx::VerifyPenInfo(): in while loop\n");
98
99         switch (ePen)
100         {
101             case MDL_PEN:
102                 // photopen installed, need to install color pen
103                 pSS->DisplayPrinterStatus(DISPLAY_NO_COLOR_PEN);
104                 break;
105             case NO_PEN:
106                 // neither pen installed
107             default:
108                 pSS->DisplayPrinterStatus(DISPLAY_NO_PENS);
109                 break;
110         }
111
112         if (pSS->BusyWait(500) == JOB_CANCELED)
113             return JOB_CANCELED;
114
115         err =  ParsePenInfo(ePen);
116         ERRCHECK;
117     }
118
119     pSS->DisplayPrinterStatus(DISPLAY_PRINTING);
120
121     return NO_ERROR;
122
123 }
124
125 DRIVER_ERROR Apollo2xxx::ParsePenInfo(PEN_TYPE& ePen, BOOL QueryPrinter)
126 {
127     char* str;
128     DRIVER_ERROR err = SetPenInfo(str, QueryPrinter);
129     ERRCHECK;
130
131     if (*str != '$')
132     {
133         return BAD_DEVICE_ID;
134     }
135
136     str++;    // skip $
137     // parse penID
138     PEN_TYPE temp_pen1;
139     // check pen1, assume it is black or MDL, pen2 is color
140     switch (str[0])
141     {
142         // check for MDL in case someone wedged one in there
143         case 'M': temp_pen1 = MDL_PEN; break; // (M)ulti-Dye load pen
144         case 'C': temp_pen1 = BLACK_PEN; break; // (C)andide black
145         default:  temp_pen1 = NO_PEN; break;
146     }
147
148     // now check pen2
149
150     int i = 2;
151     while(i < DevIDBuffSize && str[i]!='$') i++; // handles variable length penIDs
152
153     if (i == DevIDBuffSize)
154     {
155         return BAD_DEVICE_ID;
156     }
157
158     i++;
159
160     if(str[i]=='R') // we have the (R)obinhood color pen,
161                     // check what pen1 was
162     {
163         if (temp_pen1 == BLACK_PEN)
164                 ePen = BOTH_PENS;
165         else
166         {
167             if (temp_pen1 == MDL_PEN)
168                 ePen = MDL_BOTH;
169             else
170                 ePen = COLOR_PEN;
171         }
172     }
173     else // no color pen, just set what pen1 was
174         ePen = temp_pen1;
175
176     return NO_ERROR;
177 }
178
179
180 Mode2xxxPhoto::Mode2xxxPhoto()
181 // print mode for photo pen
182 : PrintMode(ulMapDJ690_CMYK,ulMapDJ690_ClMlxx)
183 {
184    dyeCount=6;
185    medium =  mediaSpecial;
186    theQuality = qualityNormal;
187
188    pmQuality=QUALITY_BEST;
189    pmMediaType=MEDIA_PREMIUM;
190
191
192    BaseResX = 600;
193    for (int i=0; i < 6; i++)
194         ResolutionX[i]=600;
195
196    CompatiblePens[0] = MDL_BOTH;
197
198 //   strcpy(ModeName, "Photo");
199
200 }
201
202 Mode2xxxColor::Mode2xxxColor()
203 : PrintMode(ulMapDJ600_CCM_CMY)
204 {
205    dyeCount=3;
206    CompatiblePens[0] = COLOR_PEN;   // only color pen allowed
207
208 //   strcpy(ModeName, "Color");
209 }
210
211 GrayMode2xxx::GrayMode2xxx()
212 // print mode for photo pen
213 : PrintMode( ulMapDJ600_CCM_K )
214 {
215    CompatiblePens[1] = MDL_BOTH;
216
217    pmColor=GREY_K;
218    dyeCount=1;
219
220 }
221
222 #ifdef APDK_EXTENDED_MEDIASIZE
223 Mode2xxxDraftColorKCMY::Mode2xxxDraftColorKCMY()
224 : PrintMode( ulMapDJ660_CCM_KCMY )
225 {
226     theQuality = qualityDraft;
227     Config.eHT = MATRIX;
228     pmQuality = QUALITY_DRAFT;
229 }
230
231 Mode2xxxDraftGrayK::Mode2xxxDraftGrayK()
232 : PrintMode(ulMapDJ600_CCM_K)
233 {
234    CompatiblePens[1] = MDL_BOTH;
235    pmColor=GREY_K;
236    dyeCount=1;
237    theQuality = qualityDraft;
238    pmQuality = QUALITY_DRAFT;
239 }
240
241 Mode2xxxDraftColorCMY::Mode2xxxDraftColorCMY()
242 : PrintMode( ulMapDJ600_CCM_CMY )
243 {
244     dyeCount=3;
245     CompatiblePens[0] = COLOR_PEN;   // only color pen allowed
246     theQuality = qualityDraft;
247     pmQuality = QUALITY_DRAFT;
248 }
249
250 Mode2xxxBestGrayK::Mode2xxxBestGrayK()
251 : GrayMode(ulMapDJ600_CCM_K)
252 {
253    theQuality = qualityPresentation;
254    pmQuality = QUALITY_BEST;
255    BaseResX = BaseResY = 600;
256    ResolutionX[0] = ResolutionY[0] = 600;
257 }
258 #endif // APDK_EXTENDED_MEDIASIZE
259
260 Header2xxx::Header2xxx(Printer* p,PrintContext* pc)
261     : Header(p,pc)
262 {  }
263
264
265 Header* Apollo2xxx::SelectHeader(PrintContext* pc)
266 {
267     return new Header2xxx(this,pc);
268 }
269
270 DRIVER_ERROR Header2xxx::Send()
271 {   DRIVER_ERROR err;
272
273     StartSend();
274
275     // don't disable black extraction if we are in the color pen only mode
276     // since the printer may actually have both pens so we want the printer
277     // to print the K with the K pen if it actually has one
278
279     if (thePrintMode->dyeCount != 3)
280     {
281         err = thePrinter->Send((const BYTE*)BlackExtractOff,
282                             sizeof(BlackExtractOff));
283         ERRCHECK;
284     }
285
286     err = ConfigureRasterData();
287     ERRCHECK;
288
289     if (ResolutionY[0] == 600)
290     {
291         char uom[10];
292         sprintf(uom,"%c%c%c%d%c",ESC,'&','u',thePrintMode->ResolutionY[K],'D');
293         err=thePrinter->Send((const BYTE*)uom, 7 );
294         ERRCHECK;
295     }
296
297     err=Graphics();     // start raster graphics and set compression mode
298
299 return err;
300 }
301
302 APDK_END_NAMESPACE
303
304 #endif  //APDK_APOLLO2XXX