1
/*****************************************************************************\
2
ljmono.cpp : Implimentation for the LJMono 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 ];
44
LJMono::LJMono (SystemServices* pSS, int numfonts, BOOL proto)
45
: Printer(pSS, numfonts, proto)
48
if ((!proto) && (IOMode.bDevID))
50
constructor_error = VerifyPenInfo ();
53
else ePen = BLACK_PEN; // matches default mode
55
pMode[GRAYMODE_INDEX] = new LJMonoDraftMode ();
56
pMode[DEFAULTMODE_INDEX] = new LJMonoNormalMode ();
57
pMode[SPECIALMODE_INDEX] = new LJMonoBestMode ();
61
m_bJobStarted = FALSE;
62
#ifdef APDK_AUTODUPLEX
63
m_bRotateBackPage = FALSE; // Lasers don't require back side image to be rotated
66
DBG1("LJMono created\n");
71
DISPLAY_STATUS eDispStatus;
72
if (IOMode.bStatus && m_bJobStarted)
74
for (int i = 0; i < 5; i++)
77
eDispStatus = ParseError (0);
78
if (eDispStatus == DISPLAY_PRINTING_COMPLETE)
80
pSS->DisplayPrinterStatus (eDispStatus);
87
LJMonoDraftMode::LJMonoDraftMode ()
88
: GrayMode(ulMapDJ600_CCM_K)
91
// By default, this is 150 dpi because LJ_BASE_RES is defined to be 300
92
// unless APDK_HIGH_RES_MODES is defined, then VIP_BASE_RES will be 600
95
ResolutionY[0] = LJ_BASE_RES;
97
BaseResY = LJ_BASE_RES;
100
theQuality = qualityDraft;
101
pmQuality = QUALITY_DRAFT;
102
#ifdef APDK_AUTODUPLEX
103
bDuplexCapable = TRUE;
107
LJMonoNormalMode::LJMonoNormalMode ()
108
: GrayMode(ulMapDJ600_CCM_K)
111
// 300 or 600 dpi depending on LJ_BASE_RES value, which in turn is affected by APDK_HIGH_RES_MODES
114
ResolutionY[0] = LJ_BASE_RES * 2;
116
BaseResY = LJ_BASE_RES * 2;
117
TextRes = LJ_BASE_RES * 2;
120
#ifdef APDK_AUTODUPLEX
121
bDuplexCapable = TRUE;
125
LJMonoBestMode::LJMonoBestMode ()
126
: GrayMode(ulMapDJ600_CCM_K)
128
ResolutionX[0] = ResolutionY[0] = 600;
129
BaseResX = BaseResY = 600;
133
pmQuality = QUALITY_BEST;
134
#ifdef APDK_AUTODUPLEX
135
bDuplexCapable = TRUE;
139
HeaderLJMono::HeaderLJMono (Printer* p,PrintContext* pc)
143
DRIVER_ERROR HeaderLJMono::Send ()
149
err = Graphics (); // start raster graphics and set compression mode
154
DRIVER_ERROR HeaderLJMono::StartSend ()
160
iRes = thePrintContext->EffectiveResolutionY ();
162
err = thePrinter->Send((const BYTE*)UEL,sizeof(UEL));
165
sprintf (res, "@PJL SET PAGEPROTECT=AUTO\015\012@PJL SET RESOLUTION=%d\015\012", iRes);
166
err = thePrinter->Send ((const BYTE *) res, strlen (res));
169
err = thePrinter->Send ((const BYTE *) "@PJL SET DENSITY=5\015\012", 20); // for lj1100, des 8/7/02
172
QUALITY_MODE eQ = QUALITY_NORMAL;
177
thePrintContext->GetPrintModeSettings (eQ, eM, eC, bD);
179
if (eQ == QUALITY_DRAFT)
181
strcpy (res, "@PJL SET RET=OFF\015\012@PJL SET ECONOMODE=ON\015\012");
182
err = thePrinter->Send ((const BYTE *) res, strlen (res));
186
if (thePrinter->IOMode.bStatus)
188
sprintf (res, "@PJL JOB NAME = \"%ld\"\015\012", (long) (thePrinter));
189
err = thePrinter->Send ((const BYTE *) res, strlen (res));
192
strcpy (res, "@PJL USTATUSOFF\015\012@PJL USTATUS DEVICE = ON\015\012@PJL USTATUS JOB = ON\015\012");
193
err = thePrinter->Send ((const BYTE *) res, strlen (res));
197
// Duplexing directive
199
strcpy (res, "@PJL SET DUPLEX=OFF\015\012");
201
#ifdef APDK_AUTODUPLEX
202
DUPLEXMODE dupmode = thePrintContext->QueryDuplexMode ();
203
if (dupmode != DUPLEXMODE_NONE)
205
strcpy (res, "@PJL SET DUPLEX=ON\015\012@PJL SET BINDING=");
206
if (dupmode == DUPLEXMODE_BOOK)
207
strcat (res, "LONGEDGE\015\012");
209
strcat (res, "SHORTEDGE\015\012");
212
err = thePrinter->Send ((const BYTE *) res, strlen (res));
215
err = thePrinter->Send ((const BYTE*) EnterLanguage, sizeof (EnterLanguage));
218
err = thePrinter->Send ((const BYTE*) "PCL\015\012", 5);
221
err = thePrinter->Send ((const BYTE*)Reset,sizeof(Reset));
224
sprintf (res, "\033&l%dH", thePrintContext->GetMediaSource());
225
err = thePrinter->Send ((const BYTE *) res, strlen (res)); // Source
228
// Media size, vertical spacing between lines and top margin
230
memcpy (res, mediasize, mscount - 1);
231
strcpy (res+mscount-1, "a8c0E");
232
err = thePrinter->Send ((const BYTE *) res, strlen (res));
235
sprintf (res, "\033*t%dR\033&u%dD", iRes, iRes);
236
err = thePrinter->Send ((const BYTE *) res, 14);
243
// Default is single sided printing
245
strcpy (res, "\033&l0S");
246
#ifdef APDK_AUTODUPLEX
247
DUPLEXMODE eDupMode = thePrintContext->QueryDuplexMode ();
248
if (eDupMode != DUPLEXMODE_NONE)
250
sprintf (res, "\033&l%dS", (eDupMode == DUPLEXMODE_BOOK) ? 1 : 2);
253
err = thePrinter->Send ((const BYTE *) res, strlen (res));
257
* Set orientation to Portrait. APDK supports printing in Portrait mode only.
258
* If users desire Landscape printing, application/gluecode will have to
259
* rearrange the rasters appropriately.
262
err = thePrinter->Send ((const BYTE *) "\033&l0O", 5);
265
sprintf (res, "\033&l%dX", thePrintContext->GetCopyCount ());
266
err = thePrinter->Send ((const BYTE *) res, strlen (res));
272
DRIVER_ERROR HeaderLJMono::Graphics ()
274
DRIVER_ERROR error = thePrinter->Send ((const BYTE*)grafStart, sizeof (grafStart) );
278
error= thePrinter->Send((const BYTE*) grafMode2, sizeof (grafMode2) );
286
DRIVER_ERROR HeaderLJMono::EndJob ()
289
DRIVER_ERROR err = NO_ERROR;
290
if (thePrinter->IOMode.bStatus)
292
sprintf (szBuff, "\033E\033%%-12345X@PJL EOJ NAME = \"%ld\"\015\012@PJL RESET\015\012",
293
(long) (thePrinter));
294
err = thePrinter->Send ((const BYTE *) szBuff, strlen (szBuff));
297
strcpy (szBuff, "\033%-12345X");
298
err = thePrinter->Send ((const BYTE *) szBuff, strlen (szBuff));
303
Header* LJMono::SelectHeader (PrintContext* pc)
305
m_bJobStarted = TRUE;
306
return new HeaderLJMono (this,pc);
309
DRIVER_ERROR LJMono::VerifyPenInfo()
312
DRIVER_ERROR err = NO_ERROR;
314
if(IOMode.bDevID == FALSE)
323
DRIVER_ERROR LJMono::ParsePenInfo(PEN_TYPE& ePen, BOOL QueryPrinter)
331
Compressor* LJMono::CreateCompressor (unsigned int RasterSize)
333
return new Mode2 (pSS,RasterSize);
336
DISPLAY_STATUS LJMono::ParseError (BYTE status_reg)
338
DBG1("LJMono: parsing error info\n");
340
DRIVER_ERROR err = NO_ERROR;
341
BYTE szReadBuff[256];
342
DWORD iReadCount = 256;
343
DISPLAY_STATUS eStatus = (DISPLAY_STATUS) status_reg;
350
memset (szReadBuff, 0, 256);
351
err = pSS->FromDevice (szReadBuff, &iReadCount);
352
if (err == NO_ERROR && iReadCount == 0)
355
if (strstr ((char *) szReadBuff, "JOB"))
357
if (!(tmpStr = strstr ((char *) szReadBuff, "NAME")))
358
return DISPLAY_PRINTING;
360
while (*tmpStr < '0' || *tmpStr > '9')
362
sscanf (tmpStr, "%d", &iErrorCode);
363
if (iErrorCode != (long) (this))
364
return DISPLAY_PRINTING;
367
if (strstr ((char *) szReadBuff, "END"))
369
return DISPLAY_PRINTING_COMPLETE;
373
if (strstr ((char *) szReadBuff, "CANCEL"))
374
return DISPLAY_PRINTING_CANCELED;
376
if (!(tmpStr = strstr ((char *) szReadBuff, "CODE")))
380
while (*tmpStr < '0' || *tmpStr > '9')
382
sscanf (tmpStr, "%d", &iErrorCode);
384
if (iErrorCode < 32000)
385
return DISPLAY_PRINTING;
387
if (iErrorCode == 40010 || iErrorCode == 40020)
388
return DISPLAY_NO_PENS; // Actually, out of toner
390
if (iErrorCode == 40021)
391
return DISPLAY_TOP_COVER_OPEN;
393
if ((iErrorCode / 100) == 419)
394
return DISPLAY_OUT_OF_PAPER;
396
if ((iErrorCode / 1000) == 42 || iErrorCode == 40022)
398
DBG1("Paper Jammed\n");
399
return DISPLAY_PAPER_JAMMED;
402
if (iErrorCode > 40049 && iErrorCode < 41000)
405
return DISPLAY_ERROR_TRAP;
408
if (iErrorCode == 40079)
409
return DISPLAY_OFFLINE;
411
return DISPLAY_ERROR_TRAP;
416
#endif // defined APDK_LJMono