1 /*****************************************************************************\
2 context.h : Interface/Implimentation for the PrintContext class
4 Copyright (c) 1996 - 2008, 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 \*****************************************************************************/
32 #ifndef APDK_PRINTCONTEXT_H
33 #define APDK_PRINTCONTEXT_H
35 #define MEDIASIZE_PCL 0
40 float fPhysicalHeight;
41 float fPrintableWidth;
42 float fPrintableHeight;
43 float fPrintableStartX;
44 float fPrintableStartY;
48 MediaAttributes media_attributes;
51 #include "printerfactory.h"
63 //! Allows setting options of a print job based on specific device
64 /*! \class PrintContext context.h "hpprintapi.h"
65 This object serves two purposes. First, it encapsulates knowledge about all
66 devices supported in available driver components. It can be queried at runtime
67 to determine capabilities of the attached device. Second, it allows for
68 setting optional parameters of a print job, such as media size and margins,
69 use of color and data-resolution, etc.
71 The PrintContext is the second item created in the driver calling sequence,
72 following SystemServices. It provides the interface for inquiring about
73 supported devices, and for setting all optional properties of the imaging
74 pipeline as determined by given devices.
76 \sa Job SystemServices
77 ******************************************************************************/
80 friend class Job; // access to private (non-instrumented) versions of routines
81 friend class Header; // access to private (non-instrumented) versions of routines
82 friend class RasterSender; // access to current printmode
83 friend class HeaderDJ990; // to use GUITopMargin
84 friend class Header895;
86 friend class Header850;
87 friend class LDLEncap;
89 PrintContext(SystemServices *pSysServ,
90 unsigned int InputPixelsPerRow=0,
91 unsigned int OutputPixelsPerRow=0,
92 PAPER_SIZE ps = LETTER,
93 QUALITY_MODE eQuality = QUALITY_NORMAL,
94 MEDIATYPE eMedia = MEDIA_PLAIN,
95 COLORMODE eColorMode = COLOR,
96 BOOL bDeviceText = FALSE);
98 virtual ~PrintContext();
100 DRIVER_ERROR constructor_error;
103 void Flush(int FlushSize); // used in connection with SendPrinterReadyData
105 // used when constructor couldn't instantiate printer (no DevID) -- instantiate now
106 DRIVER_ERROR SelectDevice(const PRINTER_TYPE Model);
107 DRIVER_ERROR SelectDevice(const char* szDeviceIDString);
109 unsigned int GetModeCount();
110 DRIVER_ERROR SelectPrintMode(const unsigned int index);
111 DRIVER_ERROR SelectPrintMode(
112 QUALITY_MODE eQuality = QUALITY_NORMAL,
113 MEDIATYPE eMedia = MEDIA_PLAIN,
114 COLORMODE eColorMode = COLOR,
115 BOOL bDeviceText = FALSE
117 DRIVER_ERROR SetPenSet(PEN_TYPE ePen);
119 // need to seriously consider the future of this method. Returning the index of the
120 // current print mode may not always work and certainly won't in the future with
121 // more dynamic print modes. - JLM
124 Retrieves an index of the currently selected print mode.
126 unsigned int CurrentPrintMode();
128 // obsolete function retained for compatibility
131 Returns the identifying string for the currently selected print mode.
132 This method now returns an empty string for every print mode.
134 const char *GetModeName ()
139 DRIVER_ERROR GetPrintModeSettings(
140 QUALITY_MODE& eQuality,
142 COLORMODE& eColorMode,
146 PRINTER_TYPE SelectedDevice();
149 #if defined(APDK_FONTS_NEEDED)
150 ReferenceFont* EnumFont(int& iCurrIdx);
151 // { return thePrinter->EnumFont(iCurrIdx); }
152 virtual Font* RealizeFont(const int index,const BYTE bSize,
153 const TEXTCOLOR eColor=BLACK_TEXT,
154 const BOOL bBold=FALSE,const BOOL bItalic=FALSE,
155 const BOOL bUnderline=FALSE);
156 // { return thePrinter->RealizeFont(eFont,bSize,eColor,
157 // bBold,bItalic,bUnderline); }
159 // return the enum for the next model(UNSUPPORTED when finished)
160 PRINTER_TYPE EnumDevices(FAMILY_HANDLE& familyHandle) const;
162 // PerformPrinterFunction (clean pen, etc.)
163 // this is the preferred function to call
164 DRIVER_ERROR PerformPrinterFunction(PRINTER_FUNC eFunc);
166 DRIVER_ERROR PagesPrinted(unsigned int& count);
167 ///////////////////////////////////////////////////////////////////////
168 // routines to change settings
169 DRIVER_ERROR SetPaperSize(PAPER_SIZE ps, BOOL bFullBleed = FALSE);
170 // these are dependent on printer model in use, thus can err
171 DRIVER_ERROR SetPixelsPerRow(unsigned int InputPixelsPerRow,
172 unsigned int OutputPixelsPerRow=0);
174 // routines to query selections ///////////////////////////////////////
176 //! Returns TRUE if printer has been selected.
177 BOOL PrinterSelected() { return !(thePrinter==NULL); }
179 //! Returns TRUE if the selected printer (and the current build) provides font support.
180 BOOL PrinterFontsAvailable(); // return FALSE if no printer
182 //! Returns TRUE if the selected printer (and the current build) provides separate 1 bit balck channel
183 BOOL SupportSeparateBlack();
185 //!Returns the width as set by SetPixelsPerRow.
186 unsigned int InputPixelsPerRow() { return InputWidth; }
188 //! Returns the current setting for output width.
189 unsigned int OutputPixelsPerRow() { return OutputWidth; }
191 //! Returns the currently set paper size.
192 PAPER_SIZE GetPaperSize();
194 //! Returns TRUE if a photo tray is present in printer.
195 BOOL PhotoTrayPresent(BOOL bQueryPrinter);
197 //!Returns current state of phototray, one of UNKNOWN, DISENGAGED or ENGAGED.
199 PHOTOTRAY_STATE PhotoTrayEngaged (BOOL bQueryPrinter);
201 //! Returns TRUE if a hagaki feed is present in printer.
202 BOOL HagakiFeedPresent(BOOL bQueryPrinter);
204 #ifdef APDK_AUTODUPLEX
205 //!Returns TRUE if duplexer and hagaki feed (combined) unit is present in printer.
207 BOOL HagakiFeedDuplexerPresent(BOOL bQueryPrinter);
210 const char* PrinterModel();
211 const char* PrintertypeToString(PRINTER_TYPE pt); // returns string for use in UI
213 unsigned int EffectiveResolutionX(); // res we need in current mode
214 unsigned int EffectiveResolutionY(); // res we need in current mode
216 // get settings pertaining to the printer
217 // note:these return zero if no printer selected
218 // all results in inches
219 float PrintableWidth();
220 float PrintableHeight();
221 float PhysicalPageSizeX();
222 float PhysicalPageSizeY();
223 float PrintableStartX();
224 float PrintableStartY();
226 // SPECIAL API -- NOT TO BE USED IN CONNECTION WITH JOB
227 DRIVER_ERROR SendPrinterReadyData(BYTE* stream, unsigned int size);
229 DeviceRegistry* DR; // unprotected for replay system
231 DRIVER_ERROR SetMediaSource(MediaSource num);
234 //! Return input media source bin
236 Used to get the bin number from which media will be loaded by the printer. This
237 is relevant for those printers that have multiple input bins. All other printers
238 will ignore the bin number. The typical bin numbers are
242 Any value between 1 and 50 is valid where there are more than 2 trays.
243 *****************************************************************************
245 MediaSource GetMediaSource() { return m_MediaSource; }
247 void SetMediaSubtype (int iMediaSubtype)
249 m_iMediaSubtype = iMediaSubtype;
251 int GetMediaSubtype ()
253 return m_iMediaSubtype;
255 void SetMechOffset (int iMechOffset)
257 m_iMechOffset = iMechOffset;
260 // needed for testing
261 // PEN_TYPE GetCompatiblePen(unsigned int num); // get CompatiblePens of Printer
263 #ifdef APDK_AUTODUPLEX
264 //! Set two-sided printing option.
265 /*! This has no effect on printers that do not support an automatic duplexer mechanism.
266 Two sided-printing option can be one of
267 DUPLEXMODE_NONE - one sided printing
268 DUPLEXMODE_TABLET - binding on short edge
269 DUPLEXMODE_BOOK - binding on long edge
270 *****************************************************************************
272 BOOL SelectDuplexPrinting (DUPLEXMODE duplexmode);
274 //! Returns current setting for two-sided printing option
275 DUPLEXMODE QueryDuplexMode ();
277 //! Does back page needs to be rotated?
278 /*! When automatic two-sided printing is enabled for long edge binging, application may have to
279 rotate the back page by 180 degrees.
280 *****************************************************************************
282 BOOL RotateImageForBackPage ();
285 #ifdef APDK_EXTENDED_MEDIASIZE
286 BOOL SetCustomSize (float width, float height);
288 unsigned int GetCurrentDyeCount();
289 PEN_TYPE GetDefaultPenSet();
290 PEN_TYPE GetInstalledPens();
292 void ResetIOMode (BOOL bDevID, BOOL bStatus);
294 //! Get number of copies to print
300 //! Set number of copies to print.
301 /*! Copy count has no effect on printers that do not support this feature.
302 Typically, most LaserJet printers support multiple copies, whereas, Inkjets do not.
303 *****************************************************************************
305 void SetCopyCount (int iNumCopies)
307 m_iCopyCount = iNumCopies;
309 DRIVER_ERROR SetPrinterHint (PRINTER_HINT eHint, int iValue);
311 //! Returns TRUE if borderless printing is enabled, FALSE otherwise
312 BOOL IsBorderless () { return bDoFullBleed; }
315 /*! Typically, media type is bound to a print mode and is set when a printmode is
316 selected. This is because the mediatype, printmode combination affects colormatching
317 and requires a different colormap data. Some printers do colormatching in firmware
318 and may support multiple mediatypes for a selected printmode.
319 Returns NO_ERROR if requested mediatype is supported for the selected printmode, otherwise
320 returns WARN_PRINTMODE_MISMATCH and the mediatype remains unchanged in the printmode.
321 *****************************************************************************
323 DRIVER_ERROR SetMediaType (MEDIATYPE eMediaType);
324 int GetJobAttributes (int getWhat);
325 void SetJobAttributes (JobAttributes *pJA);
331 PrintMode* CurrentMode;
332 // unsigned int CurrentModeIndex;
334 unsigned int PageWidth; // pixel width of printable area
335 unsigned int InputWidth;
336 unsigned int OutputWidth; // after scaling
337 PAPER_SIZE thePaperSize;
341 struct PaperSizeMetrics
343 // all values are in inches
344 float fPhysicalPageX;
345 float fPhysicalPageY;
346 float fPrintablePageX;
347 float fPrintablePageY;
348 float fPrintableStartY;
350 static const PaperSizeMetrics PSM[MAX_PAPER_SIZE]; // the size of this struct is directly related to the PAPER_SIZE enum
352 // internal versions of public functions
353 float printablewidth();
354 float printableheight();
355 unsigned int printerunitsY();
357 DRIVER_ERROR QualitySieve(ModeSet*& Modes, QUALITY_MODE& eQuality);
358 DRIVER_ERROR SetCompGrayMode(PrintMode*& resPM);
359 BOOL ModeAgreesWithHardware(BOOL QueryPrinter);
361 DRIVER_ERROR setpixelsperrow(unsigned int InputPixelsPerRow,
362 unsigned int OutputPixelsPerRow);
363 DRIVER_ERROR selectprintmode(const unsigned int index);
365 BOOL MadeCompGrayMode;
368 BOOL InputIsPageWidth;
371 //DRIVER_ERROR SetMode(unsigned int ModeIndex);
372 DRIVER_ERROR SelectDefaultMode();
373 unsigned int GUITopMargin();
375 // we take the hard unprintable top to be .04 (see define in Header.cpp)
376 // so here start out at 1/3"-.04" = 88 if dpi=300
377 { return 88 * (EffectiveResolutionY() / 300); }
380 MEDIATYPE m_mtReqMediaType; // for use by Header - Malibu defect
381 MEDIATYPE m_eMediaType;
383 #ifdef APDK_AUTODUPLEX
384 DUPLEXMODE DuplexMode;
387 #ifdef APDK_EXTENDED_MEDIASIZE
388 float CustomWidth; // custom physical page width
389 float CustomHeight; // custom physical page height
392 MediaSource m_MediaSource;
394 JobAttributes *m_job_attributes;
397 void Capture_PrintContext(unsigned int InputPixelsPerRow, unsigned int OutputPixelsPerRow,
398 PAPER_SIZE ps,IO_MODE IOMode);
399 void Capture_SelectDevice(const PRINTER_TYPE Model);
400 void Capture_SelectDevice(const char* szDevIdString);
401 void Capture_SelectPrintMode(unsigned int modenum);
402 void Capture_SetPaperSize(PAPER_SIZE ps, BOOL bFullBleed);
403 void Capture_RealizeFont(const unsigned int ptr,const unsigned int index,const BYTE bSize,
404 const TEXTCOLOR eColor=BLACK_TEXT,
405 const BOOL bBold=FALSE,const BOOL bItalic=FALSE,
406 const BOOL bUnderline=FALSE);
407 void Capture_SetPixelsPerRow(unsigned int InputPixelsPerRow,unsigned int OutputPixelsPerRow);
408 void Capture_SetInputResolution(unsigned int Res);
409 void Capture_dPrintContext();
421 #endif //APDK_PRINTCONTEXT_H