1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445
|
/*****************************************************************************\
header.cpp : Implimentation for the Header class
Copyright (c) 1996 - 2008, HP Co.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. Neither the name of HP nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
TO, PATENT INFRINGEMENT; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
\*****************************************************************************/
#include "header.h"
APDK_BEGIN_NAMESPACE
extern BYTE EscCopy(BYTE *dest,const char *s,int num, char end);
extern BYTE EscAmplCopy(BYTE *dest, int num, char end);
extern PAPER_SIZE MediaSizeToPaper(MediaSize msize);
extern MediaSize PaperToMediaSize(PAPER_SIZE psize);
float frac(float f)
// Returns fractional part of float
{ int g=(int)f;
float fp= f - (float)g;
return fp;
}
//////////////////////////////////////////////////////////////////////////////////////
// Header constructor
// Each printer model has a routine SelectHeader to call the constructor as needed.
// The various PCL options we support are collected and initialized here.
//
Header::Header(Printer* p,PrintContext* pc)
: CAPy(0), thePrinter(p), thePrintContext(pc)
{
thePrintMode = thePrintContext->CurrentMode;
dyeCount = thePrintMode->dyeCount;
DBG1("In Header constructor\n");
for (int i=0; i<MAXCOLORPLANES; i++)
{
ResolutionX[i] = thePrintMode->ResolutionX[i];
ResolutionY[i] = thePrintMode->ResolutionY[i];
}
// Set up internal data members with proper escape sequence data, for easy output later.
// Get values from PrintContext
/*
* Malibu platform printers have a defect that prevents these printers from
* performing full-bleed and media detect functions correctly. Check for this
* case, i.e., full-bleed and media detect flags and explicitly set the
* media type and quality as requested by the application.
*/
thePrinter->AdjustModeSettings (thePrintContext->bDoFullBleed,
thePrintContext->m_mtReqMediaType,
&thePrintContext->CurrentMode->medium,
&thePrintContext->CurrentMode->theQuality);
SetMediaType(thePrintContext->CurrentMode->medium);
SetQuality(thePrintContext->CurrentMode->theQuality);
SetMediaSize( thePrintContext->thePaperSize );
SetMediaSource (thePrintContext->GetMediaSource ());
SetSimpleColor();
} //Header
Header::~Header ()
{
}
//////////////////////////////////////////////////////////////////////////
// routines to set internal data members
void Header::SetMediaType(MediaType mtype)
// Sets value of mediatype and associated counter mtcount
{
mtcount=EscAmplCopy((BYTE*)mediatype,mtype,'M');
}
void Header::SetMediaSize(PAPER_SIZE psize)
// Sets value of PCL::mediasize and associated counter mscount
{
int msizeCode;
if ((msizeCode = thePrintContext->GetJobAttributes(MEDIASIZE_PCL)) < 0)
{
msizeCode = PaperToMediaSize(psize);
}
mscount=EscAmplCopy((BYTE*)mediasize,msizeCode,'A');
}
void Header::SetMediaSource(MediaSource msource)
// Sets value of PCL::mediasource and associated counter msrccount
{
#if defined(DEBUG) && (DBG_MASK & DBG_LVL1)
DBG1("Setting MediaSource to ");
switch(msource)
{
case sourceTray1: DBG1("Tray1\n"); break;
case sourceTray2: DBG1("Tray2\n"); break;
case sourceManual: DBG1("Manual\n"); break;
case sourceManualEnv: DBG1("ManualEnv\n"); break;
case sourceTrayAuto: DBG1("AutoTray\n"); break;
case sourceDuplexerNHagakiFeed: DBG1("HagakiTray\n"); break;
case sourceBanner: DBG1("Bannerpaper\n"); break;
case sourceTrayCDDVD: DBG1("CD/DVD Tray\n"); break;
default: DBG1("<out of range, using> Tray1\n"); break;
}
#endif
ASSERT( (msource==sourceTray1) || (msource==sourceManual) ||
(msource==sourceTray2) || (msource==sourceDuplexerNHagakiFeed) ||
(msource==sourceManualEnv) || (msource==sourceTrayAuto) ||
(msource == sourceOptionalEnv) || (msource == sourceBanner) ||
(msource == sourceTrayCDDVD));
if( (msource!=sourceTray1) && (msource!=sourceManual) &&
(msource!=sourceTray2) && (msource!=sourceDuplexerNHagakiFeed) &&
(msource!=sourceManualEnv) && (msource!=sourceTrayAuto) &&
(msource != sourceOptionalEnv) && (msource != sourceBanner) &&
(msource != sourceTrayCDDVD))
msource=sourceTray1;
if (thePrinter != NULL)
{
if (msource==sourceDuplexerNHagakiFeed && !thePrinter->HagakiFeedPresent(TRUE))
{
msource=sourceTray1;
}
}
msrccount=EscAmplCopy((BYTE*)mediasource,msource,'H');
}
void Header::SetQuality(Quality qual)
// Sets value of PCL::quality and associated counter qualcount
{
#if defined(DEBUG) && (DBG_MASK & DBG_LVL1)
DBG1("Setting Quality to ");
switch(qual)
{
case qualityPresentation: DBG1("Presentation\n"); break;
case qualityNormal: DBG1("Normal\n"); break;
case qualityDraft: DBG1("Draft\n"); break;
case qualityFastDraft: DBG1 ("FastDraft\n"); break;
default: DBG1("<out of range, using> Normal\n"); break;
}
#endif
ASSERT (qual >= qualityAuto && qual <= qualityFastNormal);
if (qual < qualityAuto || qual > qualityFastNormal)
qual = qualityNormal;
qualcount = EscCopy ((BYTE *) quality,"*o",qual,'M');
}
BYTE Header::QualityCode()
{ return quality[3]; }
void Header::SetSimpleColor()
// Sets value of SimpleColor and associated counter sccount
// Only applicable to one-pen products.
// SimpleColor command tells printer how many color planes; alternative to
// configure raster data in 6xx.
{
DBG1("Setting SimpleColor mode\n");
int planes= 0 - dyeCount;
sccount=EscCopy((BYTE*)SimpleColor,"*r",planes,'U');
}
DRIVER_ERROR Header::StartSend()
// common items gathered for code savings
{
DRIVER_ERROR err;
/*
* OfficeJet 600 series printers do not like Reset ahead of UEL.
err = thePrinter->Send((const BYTE*)Reset,sizeof(Reset));
ERRCHECK;
*/
err = thePrinter->Send((const BYTE*)UEL,sizeof(UEL));
ERRCHECK;
err = thePrinter->Send((const BYTE*)EnterLanguage,sizeof(EnterLanguage));
ERRCHECK;
err = thePrinter->Send((const BYTE*)PCL3,sizeof(PCL3));
ERRCHECK;
err = thePrinter->Send((const BYTE*)Reset,sizeof(Reset));
ERRCHECK;
err = thePrinter->Send((const BYTE*)&LF,1);
ERRCHECK;
err=Modes(); // Set media source, type, size and quality modes.
ERRCHECK;
err=Margins(); // set margins
return err;
}
///////////////////////////////////////////////////////////////////////////
DRIVER_ERROR Header::ConfigureRasterData()
// This is the more sophisticated way of setting color and resolution info.
//
// NOTE: Will need to be overridden for DJ5xx.
{
#define CRDSIZE 41 // 5 + 6 (max#dyes) * 6
char buff[CRDSIZE];
char *out=buff;
// begin the CRD command
memcpy(out,crdStart,sizeof(crdStart) );
out += sizeof(crdStart);
// now set up the "#W" part, where #= number of data bytes in the command
// #= 6 per color (2 each for horiz. res., vert. res., and color levels)
// + 2 for format and dye count
char sBuffer[3];
int num = dyeCount * MAXCOLORPLANES + 2;
sprintf( sBuffer, "%d", num );
*out++ = sBuffer[0];
if (num > 9)
*out++ = sBuffer[1];
*out++ = 'W';
*out++ = crdFormat;
*out++ = (BYTE)dyeCount;
int start=K; // most common case
if (dyeCount==3) // CMY pen
start=C;
for (unsigned int color = start; color < (start + dyeCount); color++)
{
*out++ = ResolutionX[color]/256;
*out++ = ResolutionX[color]%256;
*out++ = ResolutionY[color]/256;
*out++ = ResolutionY[color]%256;
int depth=ColorLevels(color);
*out++ = depth/256;
*out++ = depth%256;
}
DRIVER_ERROR error= thePrinter->Send((const BYTE*) buff, out-buff);
return error;
}
#define unprintable (float).04
#define granularity 48
DRIVER_ERROR Header::Margins()
// Some code shared between different header flavors.
{
#define MARGINSIZE (5 * 6) // each item can be 6
BYTE buff[MARGINSIZE];
BYTE *out=buff;
// Calculate top margin.
// This is given in terms of text line spacing, the smallest available
// granularity of which is 48.
// There also seems to be a starting unprintable distance, which is
// .04 for printers checked so far. (Empirical check; 600 manual says zero.)
// So our formula is: marginvalue = granularity * (startY/verticalres - unprintable)
float tmInches = thePrintContext->PrintableStartY();
float AdjustedStartY = tmInches - unprintable;
float fTopMargin = (float)granularity * AdjustedStartY;
// now round result up or down
int iTopMargin = (int) fTopMargin;
if (frac(fTopMargin) > (float).5)
iTopMargin++;
out += EscAmplCopy(out,0, 'L'); // turn perforation-skip OFF
out += EscAmplCopy(out,granularity,'D'); // set line spacing (for top margin)
out += EscAmplCopy(out,iTopMargin,'E'); // set top margin
out += EscAmplCopy(out,6,'D'); // reset to default in case of
// simple text mode
// set CAPx -- this must be done prior to grafStart (start of raster graphics)
// to fix the graphics margin
out += EscCopy(out,"*p", 0, 'X');
DRIVER_ERROR error= thePrinter->Send((const BYTE*) buff,(out-buff) );
return error;
}
DRIVER_ERROR Header::Graphics()
{
DRIVER_ERROR error= thePrinter->Send((const BYTE*)grafStart, sizeof(grafStart) );
if (error!=NO_ERROR)
return error;
if (thePrintMode->Config.bCompress)
{
error= thePrinter->Send((const BYTE*)grafMode9, sizeof(grafMode9) );
if (error!=NO_ERROR)
return error;
error= thePrinter->Send((const BYTE*)SeedSame, sizeof(SeedSame) );
}
else
error= thePrinter->Send((const BYTE*)grafMode0, sizeof(grafMode0) );
return error;
#define GRAPHICSIZE (sizeof(grafStart)+sizeof(grafMode9)+sizeof(SeedSame))
}
DRIVER_ERROR Header::Simple()
// Items pertaining to "simple color" mode, including resolution and width.
// (This is an alternative method to the CRD command.)
// This sequence is used when in text-only mode, so reference no graphics data.
{
#define SIMPLESIZE 21 // max 7 for each of 3
BYTE buff[SIMPLESIZE];
BYTE *out = buff;
int resolution = thePrintContext->CurrentMode->BaseResX;
int gwidth = thePrintContext->PageWidth;
memcpy(out, SimpleColor, sccount);
out += sccount;
// set resolution
out += EscCopy(out,"*t", resolution, 'R');
// set graphics width
out += EscCopy(out,"*r", gwidth, 'S');
DRIVER_ERROR error= thePrinter->Send((const BYTE*) buff,(out-buff) );
return error;
}
DRIVER_ERROR Header::Modes()
// Set media source, type, size and quality modes.
{
#define MODESIZE 6*4
BYTE buff[MODESIZE];
BYTE *out = buff;
memcpy(out,mediasource, msrccount );
out += msrccount;
memcpy(out,mediatype, mtcount );
out += mtcount;
/*
* Don't know why we don't want to send papersize command for PHOTO_SIZE
* AtomAnt needs the papersize set, else it will not print from the top edge
* when fullbleed printing is requested
* Perhaps, there was a valid reason with 9xx with photo-tray, so we need to
* fully test that we did not break anything else.
* Raghu - 12/21/01
*/
// if (thePrintContext->thePaperSize != PHOTO_SIZE)
{
memcpy(out,mediasize,mscount );
out += mscount;
}
memcpy(out,quality, qualcount );
out += qualcount;
DRIVER_ERROR error= thePrinter->Send((const BYTE*) buff,(out-buff) );
// Now send media pre-load command
// error = thePrinter->Send ((const BYTE *) "\033&l-2H", 6); // moved pre-load to dj9xxvip, dj8xx, dj850, des 2/4/03
return error;
}
////////////////////////////////////////////////////////////////////
DRIVER_ERROR Header::EndJob()
{
DRIVER_ERROR err = thePrinter->Send((const BYTE*)Reset,sizeof(Reset));
ERRCHECK;
return thePrinter->Send((const BYTE*)UEL,sizeof(UEL));
}
DRIVER_ERROR Header::SendCAPy(unsigned int iAbsY)
{ int len; BYTE temp[10];
len = EscCopy (temp,"*p",iAbsY,'Y');
return thePrinter->Send( temp, len);
}
unsigned int Header::ColorLevels(unsigned int ColorPlane)
{
// convert from number of bits to levels
int bits=thePrintContext->CurrentMode->ColorDepth[ColorPlane];
int res=1;
for (int i=0; i<bits; i++)
res=res*2;
return res;
}
DRIVER_ERROR Header::FormFeed()
{
BYTE FF=12;
return thePrinter->Send((const BYTE*)&FF,1);
}
APDK_END_NAMESPACE
|