xref: /aoo42x/main/vcl/inc/aqua/salprn.h (revision 24f6443d)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef _SV_SALPRN_H
25 #define _SV_SALPRN_H
26 
27 #include "aqua/aquavcltypes.h"
28 
29 #include "salprn.hxx"
30 
31 #include <boost/shared_array.hpp>
32 
33 
34 // ---------------------
35 // - AquaSalInfoPrinter -
36 // ---------------------
37 
38 class AquaSalGraphics;
39 
40 class AquaSalInfoPrinter : public SalInfoPrinter
41 {
42     /// Printer graphics
43 	AquaSalGraphics*		mpGraphics;
44     /// is Graphics used
45 	bool					mbGraphics;
46     /// job active ?
47     bool                    mbJob;
48 
49     /// cocoa printer object
50     NSPrinter*              mpPrinter;
51     /// cocoa print info object
52     NSPrintInfo*            mpPrintInfo;
53 
54     /// FIXME: get real printer context for infoprinter if possible
55     /// fake context for info printer
56     /// graphics context for Quartz 2D
57 	CGContextRef		                    mrContext;
58     /// memory for graphics bitmap context for querying metrics
59     boost::shared_array< sal_uInt8 >        maContextMemory;
60 
61     // since changes to NSPrintInfo during a job are ignored
62     // we have to care for some settings ourselves
63     // currently we do this for orientation;
64     // really needed however is a solution for paper formats
65     Orientation               mePageOrientation;
66 
67     int                       mnStartPageOffsetX;
68     int                       mnStartPageOffsetY;
69     sal_Int32                 mnCurPageRangeStart;
70     sal_Int32                 mnCurPageRangeCount;
71 
72     public:
73     AquaSalInfoPrinter( const SalPrinterQueueInfo& pInfo );
74     virtual ~AquaSalInfoPrinter();
75 
76     void                        SetupPrinterGraphics( CGContextRef i_xContext ) const;
77 
78 	virtual SalGraphics*		GetGraphics();
79 	virtual void				ReleaseGraphics( SalGraphics* i_pGraphics );
80 	virtual sal_Bool				Setup( SalFrame* i_pFrame, ImplJobSetup* i_pSetupData );
81 	virtual sal_Bool				SetPrinterData( ImplJobSetup* pSetupData );
82 	virtual sal_Bool				SetData( sal_uLong i_nFlags, ImplJobSetup* i_pSetupData );
83 	virtual void				GetPageInfo( const ImplJobSetup* i_pSetupData,
84                                              long& o_rOutWidth, long& o_rOutHeight,
85                                              long& o_rPageOffX, long& o_rPageOffY,
86                                              long& o_rPageWidth, long& o_rPageHeight );
87 	virtual sal_uLong				GetCapabilities( const ImplJobSetup* i_pSetupData, sal_uInt16 i_nType );
88 	virtual sal_uLong				GetPaperBinCount( const ImplJobSetup* i_pSetupData );
89 	virtual String				GetPaperBinName( const ImplJobSetup* i_pSetupData, sal_uLong i_nPaperBin );
90     virtual void				InitPaperFormats( const ImplJobSetup* i_pSetupData );
91     virtual int					GetLandscapeAngle( const ImplJobSetup* i_pSetupData );
92 
93     // the artificial separation between InfoPrinter and Printer
94     // is not really useful for us
95     // so let's make AquaSalPrinter just a forwarder to AquaSalInfoPrinter
96     // and concentrate the real work in one class
97     // implement pull model print system
98     sal_Bool                        StartJob( const String* i_pFileName,
99                                           const String& rJobName,
100                                           const String& i_rAppName,
101                                           ImplJobSetup* i_pSetupData,
102                                           vcl::PrinterController& i_rController );
103     sal_Bool					    EndJob();
104 	sal_Bool    					AbortJob();
105 	SalGraphics*    			StartPage( ImplJobSetup* i_pSetupData, sal_Bool i_bNewJobData );
106 	sal_Bool    					EndPage();
107 	sal_uLong	    				GetErrorCode() const;
108 
getPrintInfo() const109     NSPrintInfo* getPrintInfo() const { return mpPrintInfo; }
setStartPageOffset(int nOffsetX,int nOffsetY)110     void setStartPageOffset( int nOffsetX, int nOffsetY ) { mnStartPageOffsetX = nOffsetX; mnStartPageOffsetY = nOffsetY; }
getCurPageRangeStart() const111     sal_Int32 getCurPageRangeStart() const { return mnCurPageRangeStart; }
getCurPageRangeCount() const112     sal_Int32 getCurPageRangeCount() const { return mnCurPageRangeCount; }
113 
114     // match width/height against known paper formats, possibly switching orientation
115     const PaperInfo* matchPaper( long i_nWidth, long i_nHeight, Orientation& o_rOrientation ) const;
116     void setPaperSize( long i_nWidth, long i_nHeight, Orientation i_eSetOrientation );
117 
118     private:
119     AquaSalInfoPrinter( const AquaSalInfoPrinter& );
120     AquaSalInfoPrinter& operator=(const AquaSalInfoPrinter&);
121 };
122 
123 // -----------------
124 // - AquaSalPrinter -
125 // -----------------
126 
127 class AquaSalPrinter : public SalPrinter
128 {
129 	AquaSalInfoPrinter* 		mpInfoPrinter;			// pointer to the compatible InfoPrinter
130     public:
131     AquaSalPrinter( AquaSalInfoPrinter* i_pInfoPrinter );
132     virtual ~AquaSalPrinter();
133 
134 	virtual sal_Bool					StartJob( const XubString* i_pFileName,
135                                               const XubString& i_rJobName,
136                                               const XubString& i_rAppName,
137                                               sal_uLong i_nCopies,
138                                               bool i_bCollate,
139                                               bool i_bDirect,
140                                               ImplJobSetup* i_pSetupData );
141     // implement pull model print system
142     virtual sal_Bool                    StartJob( const String* i_pFileName,
143                                               const String& rJobName,
144                                               const String& i_rAppName,
145                                               ImplJobSetup* i_pSetupData,
146                                               vcl::PrinterController& i_rListener );
147 
148 	virtual sal_Bool					EndJob();
149 	virtual sal_Bool					AbortJob();
150 	virtual SalGraphics*			StartPage( ImplJobSetup* i_pSetupData, sal_Bool i_bNewJobData );
151 	virtual sal_Bool					EndPage();
152 	virtual sal_uLong					GetErrorCode();
153 
154     private:
155     AquaSalPrinter( const AquaSalPrinter& );
156     AquaSalPrinter& operator=(const AquaSalPrinter&);
157 };
158 
159 const double fPtTo100thMM = 35.27777778;
160 
PtTo10Mu(double nPoints)161 inline int PtTo10Mu( double nPoints ) { return (int)(((nPoints)*fPtTo100thMM)+0.5); }
162 
TenMuToPt(double nUnits)163 inline double TenMuToPt( double nUnits ) { return floor(((nUnits)/fPtTo100thMM)+0.5); }
164 
165 
166 
167 #endif // _SV_SALPRN_H
168