1 /*****************************************************************************\
2 ljcolor.cpp : Implimentation for the LJColor class
4 Copyright (c) 1996 - 2001, Hewlett-Packard Co.
7 Redistribution and use in source and binary forms, with or without
8 modification, are permitted provided that the following conditions
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.
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 \*****************************************************************************/
37 #include "printerproxy.h"
38 #include "resources.h"
42 extern uint32_t ulMapDJ600_CCM_K[ 9 * 9 * 9 ];
43 extern uint32_t ulMapGRAY_K_6x6x1[9 * 9 * 9];
45 LJColor::LJColor (SystemServices* pSS, int numfonts, BOOL proto)
46 : Printer(pSS, numfonts, proto)
49 if ((!proto) && (IOMode.bDevID))
51 constructor_error = VerifyPenInfo();
54 else ePen = BOTH_PENS; // matches default mode
56 pMode[GRAYMODE_INDEX] = new LJColorGrayMode ();
57 pMode[DEFAULTMODE_INDEX] = new LJColor300DPIMode ();
58 pMode[SPECIALMODE_INDEX] = new LJColor600DPIMode ();
59 pMode[SPECIALMODE_INDEX+1] = new LJColor150DPIMode ();
60 pMode[SPECIALMODE_INDEX+2] = new LJColorKDraftMode ();
65 m_bJobStarted = FALSE;
66 #ifdef APDK_AUTODUPLEX
67 m_bRotateBackPage = FALSE; // Lasers don't require back side image to be rotated
69 #ifdef APDK_EXTENDED_MEDIASIZE
70 pMode[SPECIALMODE_INDEX+3] = new LJColorPlainBestMode ();
76 DBG1("LJColor created\n");
81 DISPLAY_STATUS eDispStatus;
82 if (IOMode.bStatus && m_bJobStarted)
84 for (int i = 0; i < 5; i++)
87 eDispStatus = ParseError (0);
88 if (eDispStatus == DISPLAY_PRINTING_COMPLETE)
90 pSS->DisplayPrinterStatus (eDispStatus);
97 LJColorKDraftMode::LJColorKDraftMode ()
98 : GrayMode (ulMapDJ600_CCM_K)
100 theQuality = qualityDraft;
101 pmQuality = QUALITY_DRAFT;
103 #ifdef APDK_AUTODUPLEX
104 bDuplexCapable = TRUE;
108 LJColorGrayMode::LJColorGrayMode () : GrayMode (ulMapGRAY_K_6x6x1)
115 #ifdef APDK_AUTODUPLEX
116 bDuplexCapable = TRUE;
120 LJColor150DPIMode::LJColor150DPIMode ()
123 ResolutionX[0] = ResolutionY[0] = 150;
124 BaseResX = BaseResY = 150;
126 Config.bColorImage = FALSE;
127 theQuality = qualityDraft;
128 pmQuality = QUALITY_DRAFT;
129 #ifdef APDK_AUTODUPLEX
130 bDuplexCapable = TRUE;
134 LJColor300DPIMode::LJColor300DPIMode ()
137 ResolutionX[0] = 300;
138 ResolutionY[0] = 300;
139 BaseResX = BaseResY = 300;
141 Config.bColorImage = FALSE;
142 theQuality = qualityNormal;
145 pmQuality = QUALITY_NORMAL;
146 Config.bColorImage = FALSE;
147 #ifdef APDK_AUTODUPLEX
148 bDuplexCapable = TRUE;
152 LJColor600DPIMode::LJColor600DPIMode ()
155 ResolutionX[0] = 600;
156 ResolutionY[0] = 600;
157 BaseResX = BaseResY = 600;
158 Config.bColorImage = FALSE;
159 theQuality = qualityPresentation;
161 pmQuality = QUALITY_BEST;
162 pmMediaType = MEDIA_PHOTO;
163 #ifdef APDK_AUTODUPLEX
164 bDuplexCapable = TRUE;
168 #ifdef APDK_EXTENDED_MEDIASIZE
169 LJColorPlainBestMode::LJColorPlainBestMode ()
172 ResolutionX[0] = 600;
173 ResolutionY[0] = 600;
174 BaseResX = BaseResY = 600;
176 Config.bColorImage = FALSE;
177 theQuality = qualityPresentation;
179 pmQuality = QUALITY_BEST;
180 #ifdef APDK_AUTODUPLEX
181 bDuplexCapable = TRUE;
186 HeaderLJColor::HeaderLJColor (Printer* p, PrintContext* pc)
190 DRIVER_ERROR HeaderLJColor::Send ()
195 COLORMODE eC = COLOR;
200 ((LJColor *)thePrinter)->bGrey_K = FALSE;
201 if ((thePrintContext->GetPrintModeSettings (eQ, eM, eC, bD)) == NO_ERROR &&
204 ((LJColor *)thePrinter)->bGrey_K = TRUE;
213 * Configure image data - ESC*v#W - # = 6 bytes
214 * 02 - RGB colorspace (00 - Device RGB)
216 * 08 - bits per index - ignored for direct pixel
217 * 08, 08, 08 - bits per primary each
220 err = thePrinter->Send ((const BYTE *) "\033*v6W\00\03\010\010\010\010", 11);
223 // Continues tone dither
224 // Logical operation - 0
226 // err = thePrinter->Send ((const BYTE *) "\033*t18J\033*l204O", 13);
227 err = thePrinter->Send ((const BYTE *) "\033*t18J", 6);
232 * Driver Configuration Command - ESC*#W - # = 3 bytes
233 * device id - 6 = color HP LaserJet Printer
234 * func index - 4 = Select Colormap
235 * argument - 2 = Vivid Graphics
238 err = thePrinter->Send ((const BYTE *) "\033*o3W\06\04\06", 8);
242 * Program color palette entries
244 err = thePrinter->Send ((const BYTE *) "\033*v255A\033*v255B\033*v255C\033*v0I", 26);
247 err = thePrinter->Send ((const BYTE *) "\033*v255A\033*v0B\033*v0C\033*v6I", 22);
249 err = thePrinter->Send ((const BYTE *) "\033*v0A\033*v255B\033*v0C\033*v5I", 22);
251 err = thePrinter->Send ((const BYTE *) "\033*v0A\033*v0B\033*v255C\033*v3I", 22);
253 err = thePrinter->Send ((const BYTE *) "\033*v255A\033*v255B\033*v0C\033*v4I", 24);
255 err = thePrinter->Send ((const BYTE *) "\033*v255A\033*v0B\033*v255C\033*v2I", 24);
257 err = thePrinter->Send ((const BYTE *) "\033*v0A\033*v255B\033*v255C\033*v1I", 24);
259 err = thePrinter->Send ((const BYTE *) "\033*v0A\033*v0B\033*v0C\033*v7I", 20);
263 sprintf (uom, "\033*r%dS", thePrintContext->OutputPixelsPerRow ());
264 err = thePrinter->Send ((const BYTE*)uom, strlen (uom));
267 err = Graphics (); // start raster graphics and set compression mode
272 DRIVER_ERROR HeaderLJColor::StartSend ()
278 iRes = thePrintContext->EffectiveResolutionY ();
280 err = thePrinter->Send ((const BYTE*)UEL,sizeof(UEL));
283 sprintf (res, "@PJL SET PAGEPROTECT=AUTO@PJL SET RESOLUTION=%d\015\012", iRes);
284 err = thePrinter->Send ((const BYTE *) res, strlen (res));
287 if (thePrinter->IOMode.bStatus)
289 sprintf (res, "@PJL JOB NAME = \"%ld\"\015\012", (long) (thePrinter));
290 err = thePrinter->Send ((const BYTE *) res, strlen (res));
294 QUALITY_MODE eQ = QUALITY_NORMAL;
299 thePrintContext->GetPrintModeSettings (eQ, eM, eC, bD);
301 if (eQ == QUALITY_DRAFT)
303 strcpy (res, "@PJL SET RET=OFF\015\012@PJL SET ECONOMODE=ON\015\012");
304 err = thePrinter->Send ((const BYTE *) res, strlen (res));
308 if (thePrinter->IOMode.bStatus)
310 strcpy (res, "@PJL USTATUSOFF\015\012@PJL USTATUS DEVICE = ON\015\012@PJL USTATUS JOB = ON\015\012");
311 err = thePrinter->Send ((const BYTE *) res, strlen (res));
315 // Duplexing directive
317 strcpy (res, "@PJL SET DUPLEX=OFF\015\012");
319 #ifdef APDK_AUTODUPLEX
320 DUPLEXMODE dupmode = thePrintContext->QueryDuplexMode ();
\r
321 if (dupmode != DUPLEXMODE_NONE)
\r
323 strcpy (res, "@PJL SET DUPLEX=ON\015\012@PJL SET BINDING=");
\r
324 if (dupmode == DUPLEXMODE_BOOK)
\r
325 strcat (res, "LONGEDGE\015\012");
\r
327 strcat (res, "SHORTEDGE\015\012");
\r
331 err = thePrinter->Send ((const BYTE *) res, strlen (res));
334 err = thePrinter->Send ((const BYTE*) EnterLanguage, sizeof (EnterLanguage));
337 err = thePrinter->Send ((const BYTE*) "PCL\015\012", 5);
340 err = thePrinter->Send ((const BYTE*) Reset,sizeof (Reset));
343 sprintf (res, "\033&l%dH", thePrintContext->GetMediaSource ());
344 err = thePrinter->Send ((const BYTE *) res, strlen (res)); // Source
347 // Media size, vertical spacing between lines and top margin
349 memcpy (res, mediasize, mscount - 1);
350 strcpy (res+mscount-1, "a8c0E");
351 err = thePrinter->Send ((const BYTE *) res, strlen (res));
354 sprintf (res, "\033*t%dR\033&u%dD", iRes, iRes);
355 err=thePrinter->Send ((const BYTE*) res, strlen (res));
362 // Default is single sided printing
364 strcpy (res, "\033&l0S");
366 #ifdef APDK_AUTODUPLEX
367 DUPLEXMODE eDupMode = thePrintContext->QueryDuplexMode ();
368 if (eDupMode != DUPLEXMODE_NONE)
370 sprintf (res, "\033&l%dS", (eDupMode == DUPLEXMODE_BOOK) ? 1 : 2);
373 err = thePrinter->Send ((const BYTE *) res, strlen (res));
377 * Set orientation to Portrait. APDK supports printing in Portrait mode only.
378 * If users desire Landscape printing, application/gluecode will have to
379 * rearrange the rasters appropriately.
382 err = thePrinter->Send ((const BYTE *) "\033&l0O", 5);
385 sprintf (res, "\033&l%dX", thePrintContext->GetCopyCount ());
386 err = thePrinter->Send ((const BYTE *) res, strlen (res));
392 DRIVER_ERROR HeaderLJColor::Graphics ()
396 err = thePrinter->Send ((const BYTE*) grafStart, sizeof (grafStart));
399 if (((LJColor *) thePrinter)->bGrey_K)
401 err = thePrinter->Send ((const BYTE*) "\033*b2M", 5);
406 err = thePrinter->Send ((const BYTE*) "\033*b3M", 5);
412 DRIVER_ERROR HeaderLJColor::EndJob ()
415 DRIVER_ERROR err = NO_ERROR;
416 if (thePrinter->IOMode.bStatus)
418 sprintf (szBuff, "\033E\033%%-12345X@PJL EOJ NAME = \"%ld\"\015\012@PJL RESET\015\012",
419 (long) (thePrinter));
420 err = thePrinter->Send ((const BYTE *) szBuff, strlen (szBuff));
423 strcpy (szBuff, "\033%-12345X");
424 err = thePrinter->Send ((const BYTE *) szBuff, strlen (szBuff));
429 DRIVER_ERROR HeaderLJColor::FormFeed ()
431 ((LJColor *)thePrinter)->bFGColorSet = FALSE;
432 ((LJColor *)thePrinter)->m_iYPos = 0;
434 return (thePrinter->Send ((const BYTE *) "\014", 1));
437 DRIVER_ERROR HeaderLJColor::SendCAPy (unsigned int iAbsY)
441 return thePrinter->Send ((const BYTE *) "\033*p0Y", 5);
446 DRIVER_ERROR LJColor::Encapsulate (const RASTERDATA* InputRaster, BOOL bLastPlane)
448 char szScratchStr[16];
451 if (bFGColorSet == FALSE)
453 Send ((const BYTE *) "\033*v7S", 5);
456 sprintf (szScratchStr, "\033*b%uW", InputRaster->rastersize[COLORTYPE_COLOR]);
457 err = Send ((const BYTE *) szScratchStr, strlen (szScratchStr));
460 err = Send (InputRaster->rasterdata[COLORTYPE_COLOR], InputRaster->rastersize[COLORTYPE_COLOR]);
464 * Printers with low memory (64 MB or less) can run out of memory during decompressing
465 * the image data and will abort the job. To prevent this, restart raster command.
470 m_iYResolution == 600 &&
474 err = Send ((const BYTE *) "\033*rC\033*r1A\033*b3M", 14);
480 DRIVER_ERROR LJColor::SkipRasters (int nBlankRasters)
482 char szScratchStr[16];
483 DRIVER_ERROR err = NO_ERROR;
486 m_pCompressor->Flush ();
488 if (nBlankRasters > 0)
490 m_iYPos += nBlankRasters;
491 sprintf (szScratchStr, "\033*p%dY", m_iYPos);
492 err = Send ((const BYTE *) szScratchStr, strlen (szScratchStr));
498 Header* LJColor::SelectHeader (PrintContext *pc)
500 m_iYResolution = pc->EffectiveResolutionY ();
501 return new HeaderLJColor (this, pc);
504 DRIVER_ERROR LJColor::VerifyPenInfo()
507 DRIVER_ERROR err = NO_ERROR;
509 if(IOMode.bDevID == FALSE)
518 DRIVER_ERROR LJColor::ParsePenInfo(PEN_TYPE& ePen, BOOL QueryPrinter)
521 // DRIVER_ERROR err = SetPenInfo(str, QueryPrinter);
529 Compressor* LJColor::CreateCompressor (unsigned int RasterSize)
533 return new Mode2 (pSS, RasterSize);
535 m_pCompressor = new Mode3 (pSS, this, RasterSize);
536 return m_pCompressor;
540 * Function name: ParseError
542 * Owner: Darrell Walker
544 * Purpose: To determine what error state the printer is in.
548 * Parameters on entry: status_reg is the contents of the centronics
549 * status register (at the time the error was
552 * Parameters on exit: unchanged
554 * Return Values: The proper DISPLAY_STATUS to reflect the printer
559 /* We have to override the base class's (Printer) ParseError function due
560 to the fact that the 8XX series returns a status byte of F8 when it's out of
561 paper. Unfortunately, the 600 series returns F8 when they're turned off.
562 The way things are structured in Printer::ParseError, we used to check only
563 for DEVICE_IS_OOP. This would return true even if we were connected to a
564 600 series printer that was turned off, causing the Out of paper status
565 message to be displayed. This change also reflects a corresponding change
566 in IO_defs.h, where I split DEVICE_IS_OOP into DEVICE_IS_OOP, DJ400_IS_OOP, and
567 DJ8XX_IS_OOP and we now check for DJ8XX_IS_OOP in the DJ8xx class's
568 ParseError function below. 05/11/99 DGC.
571 DISPLAY_STATUS LJColor::ParseError(BYTE status_reg)
573 DBG1("LJColor: parsing error info\n");
575 DRIVER_ERROR err = NO_ERROR;
576 BYTE szReadBuff[256];
577 DWORD iReadCount = 256;
578 DISPLAY_STATUS eStatus = (DISPLAY_STATUS) status_reg;
585 memset (szReadBuff, 0, 256);
586 err = pSS->FromDevice (szReadBuff, &iReadCount);
587 if (err == NO_ERROR && iReadCount == 0)
590 if (strstr ((char *) szReadBuff, "JOB"))
592 if (!(tmpStr = strstr ((char *) szReadBuff, "NAME")))
593 return DISPLAY_PRINTING;
595 while (*tmpStr < '0' || *tmpStr > '9')
597 sscanf (tmpStr, "%d", &iErrorCode);
598 if (iErrorCode != (long) (this))
599 return DISPLAY_PRINTING;
602 if (strstr ((char *) szReadBuff, "END"))
604 return DISPLAY_PRINTING_COMPLETE;
608 if (strstr ((char *) szReadBuff, "CANCEL"))
609 return DISPLAY_PRINTING_CANCELED;
611 if (!(tmpStr = strstr ((char *) szReadBuff, "CODE")))
615 while (*tmpStr < '0' || *tmpStr > '9')
617 sscanf (tmpStr, "%d", &iErrorCode);
619 if (iErrorCode < 32000)
620 return DISPLAY_PRINTING;
622 if (iErrorCode == 40010 || iErrorCode == 40020)
623 return DISPLAY_NO_PENS; // Actually, out of toner
625 if (iErrorCode == 40021)
626 return DISPLAY_TOP_COVER_OPEN;
628 if ((iErrorCode / 100) == 419)
629 return DISPLAY_OUT_OF_PAPER;
631 if ((iErrorCode / 1000) == 42 || iErrorCode == 40022)
633 DBG1("Paper Jammed\n");
634 return DISPLAY_PAPER_JAMMED;
637 if (iErrorCode > 40049 && iErrorCode < 41000)
640 return DISPLAY_ERROR_TRAP;
643 if (iErrorCode == 40079)
644 return DISPLAY_OFFLINE;
646 return DISPLAY_ERROR_TRAP;
651 #endif // defined APDK_LJCOLOR