📄 context.cpp
字号:
/*****************************************************************************\ context.cpp : Implimentation for the PrintContext 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.\*****************************************************************************/// PrintContext#include "header.h"#include "pmselect.h"#include "printerfactory.h"#include "halftoner.h"#include "colormatch.h"APDK_BEGIN_NAMESPACEextern ColorMatcher* Create_ColorMatcher( SystemServices* pSys, ColorMap cm, unsigned int DyeCount, unsigned int iInputWidth);APDK_END_NAMESPACEAPDK_BEGIN_NAMESPACEextern PAPER_SIZE MediaSizeToPaper(MediaSize msize);extern MediaSize PaperToMediaSize(PAPER_SIZE psize);// this array is directly linked to PAPER_SIZE enum// note: fPrintablePageY is related to fPrintableStartY to allow for a 2/3" bottom margin.// If fPrintableStartY is altered, fPrintablePageY should be correspondingly updated.//// Changed PrintableStartY from 1/3" to 1/8". Also changed PrintablePageY to allow// a 1/2" bottom margin. Note, on the 6xx series bottom margin is .46" for black and .587"// for color. So, for 6xx series color printing to within 1/2" bottom margin is not guaranteed. desconst PrintContext::PaperSizeMetrics PrintContext::PSM[MAX_PAPER_SIZE] ={ //PhysicalPageX, PhysicalPageY, PrintablePageX, PrintablePageY, PrintableStartY // LETTER { (float)8.5, (float)11.0, (float)8.0, (float)10.375, (float)0.125 }, // A4 = 210 x 297mm = 8.27 x 11.69 in. { (float)8.27, (float)11.69, (float)8.0, (float)11.065, (float)0.125 }, // LEGAL { (float)8.5, (float)14.0, (float)8.0, (float)13.375, (float)0.125 }, // PHOTO_SIZE // Corresponds to 4x6" photo paper used in the 9xx series photo tray. // The apparent 1/8" bottom margin is allowed because of a pull-off tab on the media. { (float)4.0, (float)6.0, (float)3.75, (float)5.75, (float)0.125 }, // A6 = 105mm x 148mm = 4.13 x 5.83 in. // postcards -- dimensions are half A4 { (float)4.13, (float)5.83, (float)3.88, (float)5.205, (float)0.125 }, // CARD_4x6 - 4x6 index card/photo without tear-off tab { (float)4.0, (float)6.0, (float)3.75, (float)5.375, (float)0.125 }, // B4 = 257 x 364 mm. = 10.126 x 14.342 in. { (float)10.126, (float)14.342, (float)9.626, (float)13.717, (float)0.125 }, // B5 = 182 x 257 mm. = 7.17 x 10.126 in. { (float)7.17, (float)10.126, (float)6.67, (float)9.5, (float)0.125 }, // OUFUKU Oufuku-Hagaki = 148 x 200 mm = 5.83 x 7.87 in. { (float)5.83, (float)7.87, (float)5.33, (float)7.37, (float)0.125 }, // HAGAKI = 100 x 148mm = 3.94 x 5.83 in. { (float)3.94, (float)5.83, (float)3.69, (float)5.58, (float)0.125 }, // A6_WITH_TEAR_OFF_TAB = 105mm x 148mm = 4.13 x 5.83 in. { (float)4.13, (float)5.83, (float)3.88, (float)5.705, (float)0.125 }#ifdef APDK_EXTENDED_MEDIASIZE , // A3 = 294mm x 419.8mm = 11.69 x 16.53 in. { (float)11.69, (float)16.53, (float)11.29, (float)15.905, (float)0.125 }, // A5 = 148mm x 210mm = 5.83 x 8.27 in. { (float)5.83, (float)8.27, (float)5.58, (float)7.645, (float)0.125 }, // LEDGER = 11 x 17 in. { (float)11.00, (float)17.00, (float)10.6, (float)16.375, (float)0.125 }, // SUPERB = 13 x 19 in. { (float)13.00, (float)19.00, (float)12.6, (float)18.375, (float)0.125 }, // EXECUTIVE = 7.25 x 10.5 in. { (float)7.25, (float)10.5, (float)6.75, (float)9.875, (float)0.125 }, // FLSA = 8.5 x 13 in. { (float)8.5, (float)13, (float)8.00, (float)12.375, (float)0.125 }, // CUSTOM_SIZE { (float)0.0, (float)0.0, (float)0.0, (float)0.0, (float)0.125 }, // No. 10 Envelope (4.12 x 9.5 in.) { (float)4.12, (float)9.5, (float)3.875, (float)8.875, (float)0.125 }, // A2 Envelope (4.37 x 5.75 in.) { (float)4.37, (float)5.75, (float)4.12, (float)5.125, (float)0.125 }, // C6 Envelope (114 x 162 mm) { (float)4.49, (float)6.38, (float)4.24, (float)5.755, (float)0.125 }, // DL Envelope (110 x 220 mm) { (float)4.33, (float)8.66, (float)4.08, (float)8.035, (float)0.125 }, // Japanese Envelope #3 (120 x 235 mm) { (float)4.72, (float)9.25, (float)4.47, (float)8.625, (float)0.125 }, // Japanese Envelope #4 (90 x 205 mm) { (float)3.54, (float)8.07, (float)3.29, (float)7.445, (float)0.125 }#endif}; //PSM//PrintContext::PrintContext//! Construct a context for the print device/*!In the normal case where bidirectional communication was established bySystemServices, successful construction results in instantiation of theproper Printer class; otherwise client will have to complete the processwith a subsequent call to SelectDevice. The next two parameters are optional.In the case where InputPixelsPerRow has the default setting of zero, the valueof printablewith will be used. If the desired print mode is known in advance,(i.e. The user won't be selecting a print mode at any point) and the imagesize is also known, then the print mode can be selected at during construction.The reason why the last four parameters were added was because if InputPixelsPerRowand OutputPixelsPerRow were in a resolution greater than 300 dpi, it mightcause the constructor to set constructor_error to ILLEGAL_COORDS. The constructorchecks to see if the OutputPixelsPerRow will fit on the default print mode'spage width (via a call to SelectPrintMode where the real check is done),and if it doesn't fit, the error was given even if it was still a legal output size inthe resolution. Using the last four parameters will ensure that the imagesize is checked using the proper print mode.******************************************************************************/PrintContext::PrintContext( SystemServices * pSysServ, //!< Your previously created SystemServices unsigned int InputPixelsPerRow, //!< Input pixel witdth per row (do not exceed pagewidth * resolution) unsigned int OutputPixelsPerRow, //!< Usually set to 0 (zero) for scaling up to pagewidth PAPER_SIZE ps, //!< Paper size that will be used QUALITY_MODE eQuality, //!< Quality of output: DRAFT, NORMAL, BEST (default NORMAL) MEDIATYPE eMedia, //!< Media type: PLAIN, PREMIUM, PHOTO (default PLAIN) COLORMODE eColorMode, //!< Color Mode: GREY_K, GREY_CMY, COLOR (default COLOR) BOOL bDeviceText //!< Support Device Text: TRUE, FALSE (dafault FALSE)) : constructor_error(NO_ERROR), pSS(pSysServ), thePrinter((Printer*)NULL), CurrentMode((PrintMode*)NULL), InputWidth(InputPixelsPerRow), OutputWidth(OutputPixelsPerRow), thePaperSize(ps), MadeCompGrayMode(FALSE)#ifdef APDK_AUTODUPLEX , DuplexMode(DUPLEXMODE_NONE)#endif#ifdef APDK_EXTENDED_MEDIASIZE , CustomWidth(0.0), CustomHeight(0.0)#endif{#ifdef APDK_CAPTURE Capture_PrintContext(InputPixelsPerRow,OutputPixelsPerRow,ps,pSS->IOMode);#endif DR = pSS->DR; bDoFullBleed = FALSE; UsePageWidth = (OutputPixelsPerRow == 0); // flag to set width to width of page InputIsPageWidth = (InputPixelsPerRow == 0); // InputWidth defaults to current page width m_mtReqMediaType = eMedia; // for use by Header - Malibu defect m_MediaSource = sourceTrayAuto; if (!pSS->IOMode.bDevID) // SystemServices couldn't establish good DevID { // changed - DWK & JLM setpixelsperrow always returns NO_ERROR when CurrentMode // is NULL - which it always is at this point. //constructor_error = setpixelsperrow(InputWidth,OutputWidth); return; // leave in incomplete state - constructor_error = NO_ERROR } if ( (constructor_error = DR->SelectDevice(pSS->strModel,&(pSS->VIPVersion),pSS->strPens,pSS)) != NO_ERROR) { if (constructor_error == UNSUPPORTED_PRINTER) { pSS->DisplayPrinterStatus(DISPLAY_PRINTER_NOT_SUPPORTED); //wait to read message while (pSS->BusyWait(500) != JOB_CANCELED) {; // nothing..... } return; } else { DBG1("PrintContext - error in SelectDevice\n"); return; } } // Device selected... now instantiate a printer object if ( (constructor_error = DR->InstantiatePrinter(thePrinter,pSS)) != NO_ERROR) { DBG1("PrintContext - error in InstantiatePrinter\n"); return; } pSS->AdjustIO(thePrinter->IOMode); //at this point, papersize has already been set. However, if there is a manditory papersize //(like one enforced by a photo tray) we need to check to see if the size the user //wants is smaller than or equal to the papersize that is manditory. DWK PAPER_SIZE mandatoryPS = thePrinter->MandatoryPaperSize(); if (mandatoryPS != UNSUPPORTED_SIZE) { if ((PSM[mandatoryPS].fPhysicalPageX < PSM[thePaperSize].fPhysicalPageX)) { // they asked for a paper size larger then the mandatory size thePaperSize = mandatoryPS; //set the papersize to the manditory size -DWK } //end if }//end if thePrinter->SetPMIndices(); constructor_error = SelectPrintMode(eQuality, eMedia, eColorMode, bDeviceText); CERRCHECK; constructor_error = thePrinter->CheckInkLevel();} //PrintContext//CurrentPrintMode//! Returns the current print mode index/*!******************************************************************************/unsigned int PrintContext::CurrentPrintMode(){ ASSERT(CurrentMode); // It can't be NULL if (CurrentMode != NULL) { return CurrentMode->myIndex; } else { return 0; // will be confused with Mode 0 }} //CurrentPrintMode/*DRIVER_ERROR PrintContext::SetMode(unsigned int ModeIndex){ if (ModeIndex>=GetModeCount()) return INDEX_OUT_OF_RANGE; CurrentModeIndex=ModeIndex; CurrentMode = thePrinter->GetMode(ModeIndex); if (CurrentMode==NULL) return SYSTEM_ERROR; return NO_ERROR;}*///SelectDefaultMode//! Selects the default print mode for the printer/*!\return DRIVER_ERROR\sa SelectPrintMode******************************************************************************/DRIVER_ERROR PrintContext::SelectDefaultMode(){// return SelectPrintMode(QUALITY_NORMAL, MEDIA_PLAIN, COLOR, FALSE); DRIVER_ERROR err = SelectPrintMode (QUALITY_NORMAL, MEDIA_PLAIN, COLOR, FALSE); if (err == WARN_MODE_MISMATCH) { QUALITY_MODE eq; MEDIATYPE em; BOOL bText; COLORMODE eColorMode = COLOR; GetPrintModeSettings (eq, em, eColorMode, bText); if (eColorMode == GREY_K) err = NO_ERROR; } return err;} //SelectDefaultMode//SelectPrintMode//!Select a print mode based on independent parameters/*!Select a print mode base on Quality, Media, ColorMode, and support ofDeviceText. Method may change parameters depending on what the printersupports.\sa GetPrintModeSettings******************************************************************************/DRIVER_ERROR PrintContext::SelectPrintMode( QUALITY_MODE eQuality, //!< Quality of output: DRAFT, NORMAL, BEST MEDIATYPE eMedia, //!< Media type: PLAIN, PREMIUM, PHOTO COLORMODE eColorMode, //!< Color Mode: GREY_K, GREY_CMY, COLOR BOOL bDeviceText //!< Support Device Text: TRUE, FALSE){ if (thePrinter == NULL) { return NO_PRINTER_SELECTED; } // variables of printmode container class ModeSet* Modes; ModeSet* tempModeSet; ModeSet* oldModeSet; // save so we can return warning if any changed QUALITY_MODE requestedQuality = eQuality; MEDIATYPE requestedMedia = eMedia; COLORMODE requestedColor = eColorMode; BOOL requestedText = bDeviceText; PEN_TYPE pens; DRIVER_ERROR err; PrintMode* tmpPM = NULL;// This is for use by Header - full-bleed and autodetect defect in Malibu m_mtReqMediaType = eMedia;// cleanup in case of repeated calls to SPM using same PC// might have extra compgraymode hanging around if (MadeCompGrayMode) { pSS->FreeMem((BYTE*)CurrentMode->cmap.ulMap1); delete CurrentMode; CurrentMode = NULL; MadeCompGrayMode = FALSE; }// initialize list of possible modes based on Printer Modes = new ModeSet; unsigned int mc = thePrinter->GetModeCount(); for (unsigned int i = 0; i < mc; i++) { if (Modes->Append(thePrinter->GetMode(i))) { return ALLOCMEM_ERROR; } } pens = thePrinter->ActualPens(); // either set through bidi or explicitly if (pens == NO_PEN) // unidi and no penset call { thePrinter->SetPens(thePrinter->DefaultPenSet()); } tempModeSet = Modes->PenCompatibleSubset(pens); if (tempModeSet == NULL) { return ALLOCMEM_ERROR; } if (tempModeSet->IsEmpty()) // should never get here { delete Modes; delete tempModeSet; ASSERT(0); // If we should never get here then assert when debugging return SYSTEM_ERROR; } else // we found modes for the specified penset { delete Modes; Modes = tempModeSet; } // colormode adjustment if (pens == BLACK_PEN || pens == MDL_PEN) { eColorMode = GREY_K; } else if ((pens == COLOR_PEN) && (eColorMode == GREY_K)) { eColorMode = GREY_CMY; } tempModeSet = Modes->ColorCompatibleSubset(eColorMode); if (tempModeSet == NULL) { return ALLOCMEM_ERROR; } if (tempModeSet->IsEmpty()) { delete tempModeSet; // may be lacking GREY_CMY if (eColorMode == GREY_CMY) { if (thePrinter->CMYMap != NULL) { err=SetCompGrayMode(tmpPM); // tmpPM points to new map ERRCHECK; // possible memory leak ??? Modes->Append(tmpPM); } else // can't do it without a CMYMap, so change colormode if (pens == BLACK_PEN) { eColorMode = GREY_K; } else {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -