Tizen 2.1 base
[platform/upstream/hplip.git] / prnt / hpijs / context.h
1 /*****************************************************************************\
2   context.h : Interface/Implimentation for the PrintContext class
3
4   Copyright (c) 1996 - 2008, Hewlett-Packard Co.
5   All rights reserved.
6
7   Redistribution and use in source and binary forms, with or without
8   modification, are permitted provided that the following conditions
9   are met:
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.
18
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 \*****************************************************************************/
30
31
32 #ifndef APDK_PRINTCONTEXT_H
33 #define APDK_PRINTCONTEXT_H
34
35 #define MEDIASIZE_PCL 0
36 typedef struct
37 {
38     int      pcl_id;
39     float    fPhysicalWidth;
40     float    fPhysicalHeight;
41     float    fPrintableWidth;
42     float    fPrintableHeight;
43     float    fPrintableStartX;
44     float    fPrintableStartY;
45 } MediaAttributes;
46 typedef struct
47 {
48     MediaAttributes    media_attributes;
49 } JobAttributes;
50
51 #include "printerfactory.h"
52
53 APDK_BEGIN_NAMESPACE
54
55 class PrintMode;
56 class Pipeline;
57 class Compressor;
58 class Header;
59 class Printer;
60 class ModeSet;
61
62 //PrintContext
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.
70
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.
75
76 \sa Job SystemServices
77 ******************************************************************************/
78 class PrintContext
79 {
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;
85 friend class Tester;
86 friend class Header850;
87 friend class LDLEncap;
88 public:
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);
97
98     virtual ~PrintContext();
99
100     DRIVER_ERROR constructor_error;
101
102
103     void Flush(int FlushSize);  // used in connection with SendPrinterReadyData
104
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);
108
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
116     );
117     DRIVER_ERROR SetPenSet(PEN_TYPE ePen);
118
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
122     /*!
123     \deprecated
124     Retrieves an index of the currently selected print mode.
125     */
126     unsigned int CurrentPrintMode();
127
128     // obsolete function retained for compatibility
129     /*!
130     \deprecated
131     Returns the identifying string for the currently selected print mode.
132     This method now returns an empty string for every print mode.
133     */
134     const char *GetModeName ()
135     {
136         return ("");
137     }
138
139     DRIVER_ERROR GetPrintModeSettings(
140         QUALITY_MODE& eQuality,
141         MEDIATYPE& eMedia,
142         COLORMODE& eColorMode,
143         BOOL& bDeviceText
144     );
145
146     PRINTER_TYPE SelectedDevice();
147
148
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); }
158 #endif
159     // return the enum for the next model(UNSUPPORTED when finished)
160     PRINTER_TYPE EnumDevices(FAMILY_HANDLE& familyHandle) const;
161
162     // PerformPrinterFunction (clean pen, etc.)
163     // this is the preferred function to call
164     DRIVER_ERROR PerformPrinterFunction(PRINTER_FUNC eFunc);
165
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);
173     //
174     // routines to query selections ///////////////////////////////////////
175
176     //! Returns TRUE if printer has been selected.
177     BOOL PrinterSelected() { return !(thePrinter==NULL); }
178
179     //! Returns TRUE if the selected printer (and the current build) provides font support.
180     BOOL PrinterFontsAvailable();    // return FALSE if no printer
181         
182         //! Returns TRUE if the selected printer (and the current build) provides separate 1 bit balck channel
183         BOOL SupportSeparateBlack();
184
185     //!Returns the width as set by SetPixelsPerRow.
186     unsigned int InputPixelsPerRow() { return InputWidth; }
187
188     //! Returns the current setting for output width.
189     unsigned int OutputPixelsPerRow() { return OutputWidth; }
190
191     //! Returns the currently set paper size.
192     PAPER_SIZE GetPaperSize();
193
194     //! Returns TRUE if a photo tray is present in printer.
195     BOOL PhotoTrayPresent(BOOL bQueryPrinter);
196
197     //!Returns current state of phototray, one of UNKNOWN, DISENGAGED or ENGAGED.
198
199     PHOTOTRAY_STATE PhotoTrayEngaged (BOOL bQueryPrinter);
200
201     //! Returns TRUE if a hagaki feed is present in printer.
202     BOOL HagakiFeedPresent(BOOL bQueryPrinter);
203
204 #ifdef APDK_AUTODUPLEX
205     //!Returns TRUE if duplexer and hagaki feed (combined) unit is present in printer.
206
207     BOOL HagakiFeedDuplexerPresent(BOOL bQueryPrinter);
208 #endif
209
210     const char* PrinterModel();
211     const char* PrintertypeToString(PRINTER_TYPE pt); // returns string for use in UI
212
213     unsigned int EffectiveResolutionX();       // res we need in current mode
214     unsigned int EffectiveResolutionY();       // res we need in current mode
215
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();
225
226     // SPECIAL API -- NOT TO BE USED IN CONNECTION WITH JOB
227     DRIVER_ERROR SendPrinterReadyData(BYTE* stream, unsigned int size);
228
229     DeviceRegistry* DR;     // unprotected for replay system
230
231     DRIVER_ERROR SetMediaSource(MediaSource num);
232
233         // GetMediaSource
234         //! Return input media source bin
235         /*!
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
239                 1 - Upper Tray
240                 4 - Lower Tray
241                 7 - Auto Select
242         Any value between 1 and 50 is valid where there are more than 2 trays.
243         *****************************************************************************
244         */
245     MediaSource GetMediaSource() { return m_MediaSource; }
246
247     void            SetMediaSubtype (int iMediaSubtype)
248     {
249         m_iMediaSubtype = iMediaSubtype;
250     }
251     int             GetMediaSubtype ()
252     {
253         return m_iMediaSubtype;
254     }
255     void            SetMechOffset (int iMechOffset)
256     {
257         m_iMechOffset = iMechOffset;
258     }
259
260     // needed for testing
261 //    PEN_TYPE GetCompatiblePen(unsigned int num);    // get CompatiblePens of Printer
262
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         *****************************************************************************
271         */   
272     BOOL  SelectDuplexPrinting (DUPLEXMODE duplexmode);
273
274     //! Returns current setting for two-sided printing option
275     DUPLEXMODE QueryDuplexMode ();
276
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         *****************************************************************************
281         */   
282     BOOL  RotateImageForBackPage ();
283 #endif
284
285 #ifdef APDK_EXTENDED_MEDIASIZE
286     BOOL  SetCustomSize (float width, float height);
287 #endif
288     unsigned int GetCurrentDyeCount();
289     PEN_TYPE GetDefaultPenSet();
290     PEN_TYPE GetInstalledPens();
291
292     void    ResetIOMode (BOOL bDevID, BOOL bStatus);
293
294     //! Get number of copies to print
295     int     GetCopyCount ()
296     {
297         return m_iCopyCount;
298     }
299
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         *****************************************************************************
304         */   
305     void    SetCopyCount (int iNumCopies)
306     {
307         m_iCopyCount = iNumCopies;
308     }
309     DRIVER_ERROR    SetPrinterHint (PRINTER_HINT eHint, int iValue);
310
311     //! Returns TRUE if borderless printing is enabled, FALSE otherwise
312     BOOL    IsBorderless () { return bDoFullBleed; }
313
314     //! SetMediaType
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         *****************************************************************************
322         */
323     DRIVER_ERROR    SetMediaType (MEDIATYPE eMediaType);
324     int             GetJobAttributes (int getWhat);
325     void            SetJobAttributes (JobAttributes *pJA);
326
327 private:
328
329     SystemServices* pSS;
330     Printer* thePrinter;
331     PrintMode* CurrentMode;
332 //    unsigned int CurrentModeIndex;
333
334     unsigned int PageWidth;             // pixel width of printable area
335     unsigned int InputWidth;
336     unsigned int OutputWidth;           // after scaling
337     PAPER_SIZE thePaperSize;
338     BOOL UsePageWidth;
339
340     //!\internal
341     struct PaperSizeMetrics
342     {
343         // all values are in inches
344         float   fPhysicalPageX;
345         float   fPhysicalPageY;
346         float   fPrintablePageX;
347         float   fPrintablePageY;
348         float   fPrintableStartY;
349     };
350     static const PaperSizeMetrics PSM[MAX_PAPER_SIZE];  // the size of this struct is directly related to the PAPER_SIZE enum
351
352     // internal versions of public functions
353     float printablewidth();
354     float printableheight();
355     unsigned int printerunitsY();
356
357     DRIVER_ERROR QualitySieve(ModeSet*& Modes, QUALITY_MODE& eQuality);
358     DRIVER_ERROR SetCompGrayMode(PrintMode*& resPM);
359     BOOL ModeAgreesWithHardware(BOOL QueryPrinter);
360
361     DRIVER_ERROR setpixelsperrow(unsigned int InputPixelsPerRow,
362                                  unsigned int OutputPixelsPerRow);
363     DRIVER_ERROR selectprintmode(const unsigned int index);
364
365     BOOL MadeCompGrayMode;
366
367     BOOL bDoFullBleed;
368     BOOL InputIsPageWidth;
369
370     // code savers
371     //DRIVER_ERROR SetMode(unsigned int ModeIndex);
372     DRIVER_ERROR SelectDefaultMode();
373     unsigned int GUITopMargin();
374 /*
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); }
378 */
379
380     MEDIATYPE   m_mtReqMediaType;   // for use by Header - Malibu defect
381     MEDIATYPE   m_eMediaType;
382
383 #ifdef APDK_AUTODUPLEX
384     DUPLEXMODE  DuplexMode;
385 #endif
386
387 #ifdef APDK_EXTENDED_MEDIASIZE
388     float CustomWidth;       // custom physical page width
389     float CustomHeight;      // custom physical page height
390 #endif
391
392     MediaSource m_MediaSource;
393
394     JobAttributes    *m_job_attributes;
395
396 #ifdef APDK_CAPTURE
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();
410
411 #endif
412
413     int m_iCopyCount;
414
415     int         m_iMediaSubtype;
416     int         m_iMechOffset;
417 }; //PrintContext
418
419 APDK_END_NAMESPACE
420
421 #endif //APDK_PRINTCONTEXT_H