📄 context.cpp
字号:
//! Returns the left margin or distance from the top edge of the page.float PrintContext::PrintableStartX() // returned in inches{ if (thePrinter==NULL) { return 0; } float xOverSpray, yOverSpray; FullbleedType fbType; if (bDoFullBleed && (thePrinter->FullBleedCapable (thePaperSize, &fbType, &xOverSpray, &yOverSpray))) { return (0.0); } // this return value centers the printable page horizontally on the physical page#ifdef APDK_EXTENDED_MEDIASIZE float physwidth = (thePaperSize == CUSTOM_SIZE) ? CustomWidth : PSM[thePaperSize].fPhysicalPageX;#else float physwidth = PSM[thePaperSize].fPhysicalPageX;#endif float printable = printablewidth (); // PSM[ thePaperSize ].fPrintablePageX; return ((physwidth - printable) / (float)2.0 );} //PrintableStartX//! Returns the top margin or distance from the top edge of the page.float PrintContext::PrintableStartY() // returned in inches{ if (thePrinter == NULL) { return 0; } float xOverSpray, yOverSpray; FullbleedType fbType; if (bDoFullBleed && (thePrinter->FullBleedCapable (thePaperSize, &fbType, &xOverSpray, &yOverSpray))) { return (0.0); } float fMargins[4]; // Left, Right, Top, Bottom margin values if ((thePrinter->GetMargins (thePaperSize, fMargins))) { return (fMargins[2]); } return PSM[ thePaperSize ].fPrintableStartY;} //PrintableStartYunsigned int PrintContext::printerunitsY()// internal version{ if (thePrinter == NULL) { return 0; } return CurrentMode->ResolutionY[C];} //printerunitsY/*!Used outside the context of a Job, to perform functions such as pen cleaning.*/DRIVER_ERROR PrintContext::PerformPrinterFunction( PRINTER_FUNC eFunc){ if (thePrinter == NULL) { return NO_PRINTER_SELECTED; } if (eFunc == CLEAN_PEN) { thePrinter->Flush(); return thePrinter->CleanPen(); } DBG1("PerformPrinterFunction: Unknown function\n"); return UNSUPPORTED_FUNCTION;} //PerformPrinterFunction/*!Returns the enum for the next supported model. This method is used whenbi-directional communication is missing, or for dynamic querying of theproperties of a given build. This method is presumably called within a loop,which will exit when the return value equals UNSUPPORTED. Passing this returnvalue to SelectDevice will instantiate this printer object and therefore allowfurther querying of the printer抯 capabilities through other methods inPrintContext.\param familyHandle Caller starts at null; reference variable is incrementedautomatically for next call.\return A value matching an element of the enum PRINTER_TYPE, which can thenbe passed to other methods such as SelectDevice.*/PRINTER_TYPE PrintContext::EnumDevices( FAMILY_HANDLE& familyHandle) const{ return pPFI->EnumDevices(familyHandle);} //EnumDevicesBOOL PrintContext::PrinterFontsAvailable(){#if defined(APDK_FONTS_NEEDED) if (thePrinter == NULL) { return SYSTEM_ERROR; // called too soon } // if a printer exists, so does a printmode; but check anyway if (CurrentMode == NULL) { return SYSTEM_ERROR; } return CurrentMode->bFontCapable;#else return FALSE;#endif} //PrinterFontsAvailable/*! Used by client when SystemServices couldn't get DevID.This is the place where printer gets instantiated for unidi******************************************************************************/DRIVER_ERROR PrintContext::SelectDevice( const PRINTER_TYPE Model){#ifdef APDK_CAPTURECapture_SelectDevice(Model);#endif DRIVER_ERROR err; if (thePrinter) // if printer exists due to bidi or previous call { delete thePrinter; } err = DR->SelectDevice(Model); ERRCHECK; if ( (err = DR->InstantiatePrinter(thePrinter,pSS)) != NO_ERROR) { DBG1("PrintContext - error in InstantiatePrinter\n"); return err; } const char* model; if (strlen(pSS->strModel) > 0) // if bidi so strModel got set in SS { model = pSS->strModel; } else { model = PrintertypeToString(Model); // at least give something } pSS->AdjustIO(thePrinter->IOMode, model); PAPER_SIZE ps = thePrinter->MandatoryPaperSize(); if (ps != UNSUPPORTED_SIZE) { if ((PSM[ps].fPhysicalPageX < PSM[thePaperSize].fPhysicalPageX)) { thePaperSize = ps; } }//end if (p != UNSUPPORTED_SIZE) if ((err = SelectDefaultMode()) == NO_ERROR) { unsigned int iRasterWidth = InputIsPageWidth ? 0 : InputWidth; err = setpixelsperrow(iRasterWidth, OutputWidth); }//end if((err = SelectDefaultMode()) == NO_ERROR) thePrinter->SetPMIndices(); return err;} //SelectDevice//SelectDevice//!Select device type using device id string returned from printer./*! \internalUsed by client when SystemServices couldn't get DevID.This is the place where printer gets instantiated for unidi.This allows a remote system to select a device based on the device IDstring it has when the APDK cannot communicate with the device. I.E.remote rendering.\todo Not implemented yet******************************************************************************/DRIVER_ERROR PrintContext::SelectDevice( const char* szDeviceId){ ASSERT(szDeviceId);#ifdef APDK_CAPTURE Capture_SelectDevice(szDeviceId);#endif DRIVER_ERROR err; if (thePrinter) // if printer exists due to bidi or previous call { delete thePrinter; } FAMILY_HANDLE familyHandle = pPFI->FindDevIdMatch(szDeviceId); if (familyHandle == NULL) { return UNSUPPORTED_PRINTER; } thePrinter = pPFI->CreatePrinter(pSS, familyHandle); const char* model = pPFI->GetFamilyName(familyHandle); pSS->AdjustIO(thePrinter->IOMode, model); PAPER_SIZE ps = thePrinter->MandatoryPaperSize(); if (ps != UNSUPPORTED_SIZE) { if ((PSM[ps].fPhysicalPageX < PSM[thePaperSize].fPhysicalPageX)) { thePaperSize = ps; } }//end if (p != UNSUPPORTED_SIZE) if ((err = SelectDefaultMode()) == NO_ERROR) { unsigned int iRasterWidth = InputIsPageWidth ? 0 : InputWidth; err = setpixelsperrow(iRasterWidth, OutputWidth); }//end if((err = SelectDefaultMode()) == NO_ERROR) thePrinter->SetPMIndices(); return err;} //SelectDevice///////////////////////////////////////////////////////////////////////////DRIVER_ERROR PrintContext::setpixelsperrow( unsigned int InputPixelsPerRow, unsigned int OutputPixelsPerRow)// internal version without printer check{ unsigned int baseres; float printwidth; if (CurrentMode == NULL) { return NO_ERROR; } baseres = CurrentMode->BaseResX; int ResBoost = CurrentMode->BaseResX / CurrentMode->BaseResY; if (ResBoost == 0) { ResBoost = 1; } baseres /= ResBoost; // account for expansion for asymmetrical modes (x!=y) printwidth = printablewidth(); PageWidth = (unsigned int)(int)((float)baseres * printwidth + 0.5); if (InputPixelsPerRow == 0) { if (UsePageWidth) { InputPixelsPerRow = PageWidth; // by convention } else { return BAD_INPUT_WIDTH; } } if (UsePageWidth) { OutputPixelsPerRow = PageWidth; // by convention } if (OutputPixelsPerRow > PageWidth) { return OUTPUTWIDTH_EXCEEDS_PAGEWIDTH; } if (InputPixelsPerRow > OutputPixelsPerRow) { return UNSUPPORTED_SCALING; // no downscaling } // new value is legal InputWidth = InputPixelsPerRow; OutputWidth = OutputPixelsPerRow;/* * Adjust OutputWidth to avoid fractional scaling. */ int iScaleFactor = (int) (((float) OutputWidth / (float) InputWidth) + 0.02); int iDiff = OutputWidth - InputWidth * iScaleFactor; if (iDiff > 0 && iDiff < ((12 * (int) baseres) / 300)) { OutputWidth = InputWidth * iScaleFactor; if (OutputWidth > PageWidth) { OutputWidth = PageWidth; } } return NO_ERROR;} //setpixelsperrow/*!Sets the width of all rows on the page.*/DRIVER_ERROR PrintContext::SetPixelsPerRow( unsigned int InputPixelsPerRow, unsigned int OutputPixelsPerRow)// set new in/out width{#ifdef APDK_CAPTURE Capture_SetPixelsPerRow(InputPixelsPerRow, OutputPixelsPerRow);#endif if (thePrinter == NULL) { return NO_PRINTER_SELECTED; } return setpixelsperrow(InputPixelsPerRow, OutputPixelsPerRow);} //SetPixelsPerRow//! Returns the horizontal printer resolution to be used for currently selected print mode.unsigned int PrintContext::EffectiveResolutionX(){ if (CurrentMode == NULL) { return 0; } return CurrentMode->BaseResX;} //EffectiveResolutionX//! Returns the vertical printer resolution to be used for currently selected print mode.unsigned int PrintContext::EffectiveResolutionY(){ if (CurrentMode == NULL) { return 0; } return CurrentMode->BaseResY;} //EffectiveResolutionY//!\brief Returns number of supported print modes for the select printer model./*!\deprecatedThis method will return the number of print modes. The device must support(and should return a value of) at least two print modes, gray and normal.The general convention for interpretation of the indices is:\li 0 = GrayMode - rendering for black pen\li 1 = the \i basic mode for this printer, usually targeting plain paper and normal quality\li 2,3... = special modes that may be available for this printer\note Do not count on mode counts or mode indexes.\see SelectPrintMode()*/unsigned int PrintContext::GetModeCount(){ if (thePrinter == NULL) { return 0; } return thePrinter->GetModeCount();} //GetModeCountDRIVER_ERROR PrintContext::selectprintmode( const unsigned int index){ DRIVER_ERROR error = NO_ERROR; if (thePrinter == NULL) { return NO_PRINTER_SELECTED; } unsigned int count = GetModeCount(); if (index > (count-1)) { return INDEX_OUT_OF_RANGE; } CurrentMode= thePrinter->GetMode(index);// CurrentModeIndex = index; error = setpixelsperrow(InputWidth,OutputWidth); if (error != NO_ERROR) // could be caused by changing to lower-res mode { error = setpixelsperrow(0,0); // try again with default } if (error > NO_ERROR) { return error; } if (!ModeAgreesWithHardware(FALSE)) { return WARN_MODE_MISMATCH; } // notice that requested mode is set even if it is wrong for the pen return error;} //selectprintmode/*!\deprecatedChooses amongst available print modes. Index of zero is grayscale, index of 1is default mode. Use the new SelectePrintMode interface.*/DRIVER_ERROR PrintContext::SelectPrintMode( const unsigned int index){#ifdef APDK_CAPTURE Capture_SelectPrintMode(index);#endif return selectprintmode(index);} //SelectPrintMode//! Sets or changes the target paper size for a print job./*!This method sets the target paper size to be used by the print job. Thiswould have already been set during PrintContext construction, but may be resetusing this function as long as the job object itself has not yet been created.\see PAPER_SIZE for supported paper sizes.*/DRIVER_ERROR PrintContext::SetPaperSize (PAPER_SIZE ps, BOOL bFullBleed){#ifdef APDK_CAPTURE Capture_SetPaperSize(ps, bFullBleed);#endif DRIVER_ERROR err; if (thePrinter == NULL) { return NO_PRINTER_SELECTED; } // Version 3.0.1 logic for allowing mandatory paper size or smaller PAPER_SIZE psMandatoryPS; DRIVER_ERROR psError = NO_ERROR; if ((psMandatoryPS = thePrinter->MandatoryPaperSize()) != UNSUPPORTED_SIZE) {#ifdef APDK_EXTENDED_MEDIASIZE float ReqPhysWidth = (ps == CUSTOM_SIZE) ? CustomWidth : PSM[ps].fPhysicalPageX;#else float ReqPhysWidth = PSM[ps].fPhysicalPageX;#endif if ((ReqPhysWidth > PSM[psMandatoryPS].fPhysicalPageX)) // only use the page width. We are not so concerned about the height. // if we use both then we have a problem with paper sizes that shorter, // but wider or taller and narrower - example A6 and PHOTO. If you set // one then the other is invalid of both dimentions are checked. JLM// || (PSM[ps].fPhysicalPageY > PSM[thePaperSize].fPhysicalPageY)) { // they asked for a paper size larger then the mandatory size// return ILLEGAL_PAPERSIZE;/* * This is not really an error, but a warning. App may call here again * with a different paper size if they don't like what we forced it to.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -