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