⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 printer.cpp

📁 HP喷墨打印机驱动代码 HP内部资料! 珍贵 珍贵 珍贵
💻 CPP
📖 第 1 页 / 共 3 页
字号:
/*****************************************************************************\  printer.cpp : Implimentation for the Printer class  Copyright (c) 1996 - 2001, Hewlett-Packard 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 Hewlett-Packard 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"#include "io_defs.h"#include "resources.h"//// ** Printer CLASS **APDK_BEGIN_NAMESPACEextern BYTE* GetHTBinary();APDK_END_NAMESPACEAPDK_BEGIN_NAMESPACEPrinter::Printer(    SystemServices* pSys,    int numfonts,    BOOL proto) :    constructor_error(NO_ERROR),    IOMode(pSys->IOMode),#if defined(APDK_FONTS_NEEDED)    iNumFonts(numfonts),#else    iNumFonts(0),#endif    bCheckForCancelButton(FALSE),    ulBytesSentSinceCancelCheck(0),    ePen(NO_PEN),    CMYMap(NULL),    pSS(pSys),    InSlowPollMode(0),    iTotal_SLOW_POLL_Count(0),    iMax_SLOW_POLL_Count(DEFAULT_SLOW_POLL_COUNT),    ErrorTerminationState(FALSE),    iBuffSize(pSys->GetSendBufferSize()),    iCurrBuffSize(0),    EndJob(FALSE),    ModeCount(2),    m_bVIPPrinter(FALSE){    int i = 0; // counter    for (i = 0; i < MAX_PRINTMODES; i++)    {        pMode[i]=NULL;    }    //CompatiblePens[0] = BOTH_PENS;    //for (i = 1; i < MAX_COMPATIBLE_PENS; i++)    //{    //    CompatiblePens[i] = DUMMY_PEN;    //}    if (IOMode.bDevID)    {       iMax_SLOW_POLL_Count = DEFAULT_SLOW_POLL_BIDI;    }    // Allocate memory for my send buffer    pSendBuffer = NULL;#ifdef APDK_BUFFER_SEND    pSendBuffer = pSS->AllocMem(iBuffSize);    CNEWCHECK(pSendBuffer);#endif#ifdef APDK_AUTODUPLEX    bDuplexCapable = FALSE;    m_bRotateBackPage = TRUE;#endif/* *  LaserJet printers do not send status via device id string. PJL is used to *  get status. *  REVISIT:    Do the same for Business Inkjets as well. */    m_bStatusByPJL = FALSE;    char    *tmpStr;    if ((strstr ((char *) pSS->strDevID, "LaserJet")) &&        (tmpStr = strstr ((char *) pSS->strDevID, "CMD:")) &&        (tmpStr = strstr (tmpStr+4, "PJL")))    {        m_bStatusByPJL = TRUE;    }#if defined(APDK_FONTS_NEEDED)    // create dummy font objects to be queried via EnumFont    // these fonts used by all except DJ400    for (i = 0; i<=MAX_PRINTER_FONTS; i++)        fontarray[i] = NULL;#ifdef APDK_COURIER    fontarray[COURIER_INDEX] = new Courier();    CNEWCHECK(fontarray[COURIER_INDEX]);#endif#ifdef APDK_CGTIMES    fontarray[CGTIMES_INDEX] = new CGTimes();    CNEWCHECK(fontarray[CGTIMES_INDEX]);#endif#ifdef APDK_LTRGOTHIC    fontarray[LETTERGOTHIC_INDEX] = new LetterGothic();    CNEWCHECK(fontarray[LETTERGOTHIC_INDEX]);#endif#ifdef APDK_UNIVERS    fontarray[UNIVERS_INDEX] = new Univers();    CNEWCHECK(fontarray[UNIVERS_INDEX]);#endif#endif  //} //PrinterPrinter::~Printer(){    if (pMode[GRAYMODE_INDEX])    {        if (pMode[GRAYMODE_INDEX]->dyeCount==3) // only happens when compgray map used        {            pSS->FreeMem((BYTE*) pMode[GRAYMODE_INDEX]->cmap.ulMap1 );        }    }    for (int i = 0; i < MAX_PRINTMODES; i++)    {        if (pMode[i])        {            delete pMode[i];        }    }#ifdef APDK_BUFFER_SEND    if (pSendBuffer != NULL)    {        pSS->FreeMem(pSendBuffer);    }#endif#ifdef APDK_COURIER    delete fontarray[COURIER_INDEX];#endif#ifdef APDK_CGTIMES    delete fontarray[CGTIMES_INDEX];#endif#ifdef APDK_LTRGOTHIC    delete fontarray[LETTERGOTHIC_INDEX];#endif#ifdef APDK_UNIVERS    delete fontarray[UNIVERS_INDEX];#endif} //~Printer////////////////////////////////////////////////////////////////////////////Compressor* Printer::CreateCompressor(    unsigned int RasterSize){    return new Mode9(pSS,RasterSize);   // most printers use mode 9}////////////////////////////////////////////////////////////////////////////Compressor* Printer::CreateBlackPlaneCompressor(    unsigned int RasterSize){    return new Mode9(pSS,RasterSize);   // most printers use mode 9}////////////////////////////////////////////////////////////////////////////// ** API functions//DRIVER_ERROR Printer::Flush(    int FlushSize       // = MAX_RASTERSIZE)// flush possible leftover garbage --// default call will send one (maximal) raster's worth of zeroes{    ASSERT(FlushSize > 0);    ASSERT(FlushSize <= MAX_RASTERSIZE);    DRIVER_ERROR err = NO_ERROR;    int iChunkSize = 1000;    BYTE *zero = NULL;    // Try to allocate iChunkSize bytes of memory.  If we fail then cut size    // in half and try again.  If we can't allocate even 10 bytes then bail    // with a memory allocation error.  Flush is called at the beginning of    // the print job - if there is no memory allocate now then we won't be    // printing in any case.    while (iChunkSize > 10 && zero == NULL)    {        zero = pSS->AllocMem(iChunkSize);        if (zero == NULL)        {            iChunkSize /= 2;        }    }    if (zero == NULL)    {        return ALLOCMEM_ERROR;    }    memset(zero, 0, iChunkSize);    int iChunks = (FlushSize / iChunkSize) + 1;    for (int i = 0; i < iChunks; i++)    {        if ((err = Send( zero, iChunkSize)) != NO_ERROR)        {            break;              // there was an error        }    }    pSS->FreeMem(zero);         //break to here    return err;} //Flush/* *  Function name: ParseError * *  Owner: Darrell Walker * *  Purpose:  To determine what error state the printer is in. * *  Called by: Send() * *  Parameters on entry: status_reg is the contents of the centronics *                      status register (at the time the error was *                      detected) * *  Parameters on exit: unchanged * *  Return Values: The proper DISPLAY_STATUS to reflect the printer *              error state. * */DISPLAY_STATUS Printer::ParseError(    BYTE status_reg){    DBG1("Printer: parsing error info\n");    DRIVER_ERROR err = NO_ERROR;    BYTE DevIDBuffer[DevIDBuffSize];    if(IOMode.bDevID)    {        // If a bi-di cable was plugged in and everything was OK, let's see if it's still        // plugged in and everything is OK        err = pSS->GetDeviceID(DevIDBuffer, DevIDBuffSize, TRUE);        if(err != NO_ERROR)        {            // job was bi-di but now something's messed up, probably cable unplugged            // or printer turned off during print job            return DISPLAY_COMM_PROBLEM;        }    }    // check for errors we can detect from the status reg    if (IOMode.bStatus)    {        if ( DEVICE_IS_OOP(status_reg) )        {            DBG1("Out Of Paper\n");            return DISPLAY_OUT_OF_PAPER;        }		if (DEVICE_PAPER_JAMMED(status_reg))		{			DBG1("Paper Jammed\n");			return DISPLAY_PAPER_JAMMED;		}		if (DEVICE_IO_TRAP(status_reg))        {            DBG1("IO Trap\n");            return DISPLAY_ERROR_TRAP;        }    }    if (IOMode.bDevID)    {        if ( TopCoverOpen(status_reg) )        {            DBG1("Top Cover Open\n");            return DISPLAY_TOP_COVER_OPEN;        }        // VerifyPenInfo will handle prompting the user        //  if this is a problem        VerifyPenInfo();    }    // don't know what the problem is-    //  Is the PrinterAlive?    if (pSS->PrinterIsAlive())  // <- This is only viable if bStatus is TRUE    {        iTotal_SLOW_POLL_Count += iMax_SLOW_POLL_Count;        // -Note that iTotal_SLOW_POLL_Count is a multiple of        //  iMax_SLOW_POLL_Count allowing us to check this        //  on an absolute time limit - not relative to the number        //  of times we happen to have entered ParseError.        // -Also note that we have different thresholds for uni-di & bi-di.        // REVISIT these counts - they are relative to the speed through        // the send loop aren't they?  They may be too long!        if(            ((IOMode.bDevID == FALSE) && (iTotal_SLOW_POLL_Count >= 60)) ||            ((IOMode.bDevID == TRUE)  && (iTotal_SLOW_POLL_Count >= 120))          )        {            return DISPLAY_BUSY;        }        else        {            return DISPLAY_PRINTING;        }    }    else    {        return DISPLAY_COMM_PROBLEM;    }} //ParseErrorDRIVER_ERROR Printer::Encapsulate(    const RASTERDATA* InputRaster,    BOOL bLastPlane){    DRIVER_ERROR    err;    char            scratch[20];    int             scratchLen;    if (bLastPlane)    {		if (VIPPrinter())		{			if (InputRaster->rastersize[COLORTYPE_BLACK] != 0)			{				if (InputRaster->rastersize[COLORTYPE_COLOR] != 0)				{					scratchLen = sprintf (scratch, "\033*b%uV", InputRaster->rastersize[COLORTYPE_BLACK]);					err = Send ((const BYTE*) scratch, scratchLen);					if (err == NO_ERROR)					{						err = Send (InputRaster->rasterdata[COLORTYPE_BLACK], InputRaster->rastersize[COLORTYPE_BLACK]);					}					if (err == NO_ERROR)					{						scratchLen = sprintf (scratch, "\033*b%uW", InputRaster->rastersize[COLORTYPE_COLOR]);						err = Send ((const BYTE*) scratch, scratchLen);						if (err == NO_ERROR)						{							err = Send (InputRaster->rasterdata[COLORTYPE_COLOR], InputRaster->rastersize[COLORTYPE_COLOR]);						}					}				}				else				{					scratchLen = sprintf (scratch, "\033*b%uV", InputRaster->rastersize[COLORTYPE_BLACK]);					err = Send ((const BYTE*) scratch, scratchLen);					if (err == NO_ERROR)					{						err = Send (InputRaster->rasterdata[COLORTYPE_BLACK], InputRaster->rastersize[COLORTYPE_BLACK]);						if (err == NO_ERROR)						{							scratchLen = sprintf (scratch, "\033*b%uW", 0);							err = Send ((const BYTE*) scratch, scratchLen);						}					}				}			}			else			{				scratchLen = sprintf (scratch, "\033*b%uV", 0);				err = Send ((const BYTE*) scratch, scratchLen);				if (err == NO_ERROR)				{					scratchLen = sprintf (scratch, "\033*b%uW", InputRaster->rastersize[COLORTYPE_COLOR]);					err = Send ((const BYTE*) scratch, scratchLen);					if (err == NO_ERROR && InputRaster->rastersize[COLORTYPE_COLOR] != 0)					{

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -