Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : : #ifndef _PSPRINT_PPDPARSER_HXX_
29 : : #define _PSPRINT_PPDPARSER_HXX_
30 : :
31 : : #include <list>
32 : : #include <vector>
33 : : #include <boost/unordered_map.hpp>
34 : :
35 : : #include "tools/string.hxx"
36 : : #include "tools/stream.hxx"
37 : : #include "rtl/string.hxx"
38 : :
39 : : #include "vcl/dllapi.h"
40 : :
41 : : #include "com/sun/star/lang/Locale.hpp"
42 : :
43 : : #define PRINTER_PPDDIR "driver"
44 : :
45 : : namespace psp {
46 : :
47 : : class PPDParser;
48 : : class PPDTranslator;
49 : :
50 : : enum PPDValueType { eInvocation, eQuoted, eSymbol, eString, eNo };
51 : :
52 [ + - ][ + - ]: 100380 : struct VCL_DLLPUBLIC PPDValue
53 : : {
54 : : PPDValueType m_eType;
55 : : String m_aOption;
56 : : String m_aValue;
57 : : };
58 : :
59 : : // ----------------------------------------------------------------------
60 : :
61 : : /*
62 : : * PPDKey - a container for the available options (=values) of a PPD keyword
63 : : */
64 : :
65 : : class VCL_DLLPUBLIC PPDKey
66 : : {
67 : : friend class PPDParser;
68 : :
69 : : typedef ::boost::unordered_map< ::rtl::OUString, PPDValue, ::rtl::OUStringHash > hash_type;
70 : : typedef ::std::vector< PPDValue* > value_type;
71 : :
72 : : String m_aKey;
73 : : hash_type m_aValues;
74 : : value_type m_aOrderedValues;
75 : : const PPDValue* m_pDefaultValue;
76 : : bool m_bQueryValue;
77 : : PPDValue m_aQueryValue;
78 : :
79 : : public:
80 : : enum UIType { PickOne, PickMany, Boolean };
81 : : enum SetupType { ExitServer, Prolog, DocumentSetup, PageSetup, JCLSetup, AnySetup };
82 : : private:
83 : :
84 : : bool m_bUIOption;
85 : : UIType m_eUIType;
86 : : int m_nOrderDependency;
87 : : SetupType m_eSetupType;
88 : :
89 : : void eraseValue( const String& rOption );
90 : : public:
91 : : PPDKey( const String& rKey );
92 : : ~PPDKey();
93 : :
94 : : PPDValue* insertValue( const String& rOption );
95 : 18960 : int countValues() const
96 : 18960 : { return m_aValues.size(); }
97 : : // neither getValue will return the query option
98 : : const PPDValue* getValue( int n ) const;
99 : : const PPDValue* getValue( const String& rOption ) const;
100 : : const PPDValue* getValueCaseInsensitive( const String& rOption ) const;
101 : 832 : const PPDValue* getDefaultValue() const { return m_pDefaultValue; }
102 : : const PPDValue* getQueryValue() const { return m_bQueryValue ? &m_aQueryValue : NULL; }
103 : :
104 : 1134 : const String& getKey() const { return m_aKey; }
105 : 0 : bool isUIKey() const { return m_bUIOption; }
106 : : UIType getUIType() const { return m_eUIType; }
107 : 0 : SetupType getSetupType() const { return m_eSetupType; }
108 : 0 : int getOrderDependency() const { return m_nOrderDependency; }
109 : : };
110 : :
111 : : // define a hash for PPDKey
112 : : struct PPDKeyhash
113 : : {
114 : 1012 : size_t operator()( const PPDKey * pKey) const
115 : 1012 : { return (size_t)pKey; }
116 : : };
117 : :
118 : : // ----------------------------------------------------------------------
119 : :
120 : : /*
121 : : * PPDParser - parses a PPD file and contains all available keys from it
122 : : */
123 : :
124 : : class PPDContext;
125 : : class CUPSManager;
126 : :
127 : : class VCL_DLLPUBLIC PPDParser
128 : : {
129 : : friend class PPDContext;
130 : : friend class CUPSManager;
131 : : friend class PPDCache;
132 : :
133 : : typedef ::boost::unordered_map< ::rtl::OUString, PPDKey*, ::rtl::OUStringHash > hash_type;
134 : : typedef ::std::vector< PPDKey* > value_type;
135 : :
136 : : void insertKey( const String& rKey, PPDKey* pKey );
137 : : public:
138 : : struct PPDConstraint
139 : : {
140 : : const PPDKey* m_pKey1;
141 : : const PPDValue* m_pOption1;
142 : : const PPDKey* m_pKey2;
143 : : const PPDValue* m_pOption2;
144 : :
145 : 0 : PPDConstraint() : m_pKey1( NULL ), m_pOption1( NULL ), m_pKey2( NULL ), m_pOption2( NULL ) {}
146 : : };
147 : : private:
148 : : hash_type m_aKeys;
149 : : value_type m_aOrderedKeys;
150 : : ::std::list< PPDConstraint > m_aConstraints;
151 : :
152 : : // some identifying fields
153 : : String m_aPrinterName;
154 : : String m_aNickName;
155 : : // the full path of the PPD file
156 : : String m_aFile;
157 : : // some basic attributes
158 : : bool m_bColorDevice;
159 : : bool m_bType42Capable;
160 : : sal_uLong m_nLanguageLevel;
161 : : rtl_TextEncoding m_aFileEncoding;
162 : :
163 : :
164 : : // shortcuts to important keys and their default values
165 : : // imageable area
166 : : const PPDValue* m_pDefaultImageableArea;
167 : : const PPDKey* m_pImageableAreas;
168 : : // paper dimensions
169 : : const PPDValue* m_pDefaultPaperDimension;
170 : : const PPDKey* m_pPaperDimensions;
171 : : // paper trays
172 : : const PPDValue* m_pDefaultInputSlot;
173 : : const PPDKey* m_pInputSlots;
174 : : // resolutions
175 : : const PPDValue* m_pDefaultResolution;
176 : : const PPDKey* m_pResolutions;
177 : : // duplex commands
178 : : const PPDValue* m_pDefaultDuplexType;
179 : : const PPDKey* m_pDuplexTypes;
180 : :
181 : : // fonts
182 : : const PPDKey* m_pFontList;
183 : :
184 : : // translations
185 : : PPDTranslator* m_pTranslator;
186 : :
187 : : PPDParser( const String& rFile );
188 : : ~PPDParser();
189 : :
190 : : void parseOrderDependency(const rtl::OString& rLine);
191 : : void parseOpenUI(const rtl::OString& rLine);
192 : : void parseConstraint(const rtl::OString& rLine);
193 : : void parse( std::list< rtl::OString >& rLines );
194 : :
195 : : String handleTranslation(const rtl::OString& i_rString, bool i_bIsGlobalized);
196 : :
197 : : static void scanPPDDir( const String& rDir );
198 : : static void initPPDFiles();
199 : : static String getPPDFile( const String& rFile );
200 : : public:
201 : : static const PPDParser* getParser( const String& rFile );
202 : : static String getPPDPrinterName( const String& rFile );
203 : : static void freeAll();
204 : : static void getKnownPPDDrivers( std::list< rtl::OUString >& o_rDrivers, bool bRefresh = false );
205 : :
206 : 0 : const String& getFilename() const { return m_aFile; }
207 : :
208 : : const PPDKey* getKey( int n ) const;
209 : : const PPDKey* getKey( const String& rKey ) const;
210 : 0 : int getKeys() const { return m_aKeys.size(); }
211 : : bool hasKey( const PPDKey* ) const;
212 : :
213 : 144 : const ::std::list< PPDConstraint >& getConstraints() const { return m_aConstraints; }
214 : :
215 : 0 : const String& getPrinterName() const
216 : 0 : { return m_aPrinterName.Len() ? m_aPrinterName : m_aNickName; }
217 : : const String& getNickName() const
218 : : { return m_aNickName.Len() ? m_aNickName : m_aPrinterName; }
219 : :
220 : 109 : bool isColorDevice() const { return m_bColorDevice; }
221 : 109 : bool isType42Capable() const { return m_bType42Capable; }
222 : 109 : sal_uLong getLanguageLevel() const { return m_nLanguageLevel; }
223 : :
224 : : String getDefaultPaperDimension() const;
225 : 0 : void getDefaultPaperDimension( int& rWidth, int& rHeight ) const
226 [ # # ]: 0 : { getPaperDimension( getDefaultPaperDimension(), rWidth, rHeight ); }
227 : : bool getPaperDimension( const String& rPaperName,
228 : : int& rWidth, int& rHeight ) const;
229 : : // width and height in pt
230 : : // returns false if paper not found
231 : : int getPaperDimensions() const
232 : : { return m_pPaperDimensions ? m_pPaperDimensions->countValues() : 0; }
233 : :
234 : : // match the best paper for width and height
235 : : String matchPaper( int nWidth, int nHeight ) const;
236 : :
237 : : bool getMargins( const String& rPaperName,
238 : : int &rLeft, int& rRight,
239 : : int &rUpper, int& rLower ) const;
240 : : // values in pt
241 : : // returns true if paper found
242 : :
243 : : // values int pt
244 : :
245 : : String getDefaultInputSlot() const;
246 : : int getInputSlots() const
247 : : { return m_pInputSlots ? m_pInputSlots->countValues() : 0; }
248 : :
249 : : void getDefaultResolution( int& rXRes, int& rYRes ) const;
250 : : // values in dpi
251 : : void getResolutionFromString( const String&, int&, int& ) const;
252 : : // helper function
253 : :
254 : : int getDuplexTypes() const
255 : : { return m_pDuplexTypes ? m_pDuplexTypes->countValues() : 0; }
256 : :
257 : 114 : int getFonts() const
258 [ + - ]: 114 : { return m_pFontList ? m_pFontList->countValues() : 0; }
259 : : String getFont( int ) const;
260 : :
261 : :
262 : : rtl::OUString translateKey( const rtl::OUString& i_rKey,
263 : : const com::sun::star::lang::Locale& i_rLocale = com::sun::star::lang::Locale() ) const;
264 : : rtl::OUString translateOption( const rtl::OUString& i_rKey,
265 : : const rtl::OUString& i_rOption,
266 : : const com::sun::star::lang::Locale& i_rLocale = com::sun::star::lang::Locale() ) const;
267 : : };
268 : :
269 : : // ----------------------------------------------------------------------
270 : :
271 : : /*
272 : : * PPDContext - a class to manage user definable states based on the
273 : : * contents of a PPDParser.
274 : : */
275 : :
276 : : class VCL_DLLPUBLIC PPDContext
277 : : {
278 : : typedef ::boost::unordered_map< const PPDKey*, const PPDValue*, PPDKeyhash > hash_type;
279 : : hash_type m_aCurrentValues;
280 : : const PPDParser* m_pParser;
281 : :
282 : : // returns false: check failed, new value is constrained
283 : : // true: check succeded, new value can be set
284 : : bool checkConstraints( const PPDKey*, const PPDValue*, bool bDoReset );
285 : : bool resetValue( const PPDKey*, bool bDefaultable = false );
286 : : public:
287 : : PPDContext( const PPDParser* pParser = NULL );
288 : : PPDContext( const PPDContext& rContext ) { operator=( rContext ); }
289 : : PPDContext& operator=( const PPDContext& rContext );
290 : : ~PPDContext();
291 : :
292 : : void setParser( const PPDParser* );
293 : 400 : const PPDParser* getParser() const { return m_pParser; }
294 : :
295 : : const PPDValue* getValue( const PPDKey* ) const;
296 : : const PPDValue* setValue( const PPDKey*, const PPDValue*, bool bDontCareForConstraints = false );
297 : :
298 : 288 : int countValuesModified() const { return m_aCurrentValues.size(); }
299 : : const PPDKey* getModifiedKey( int n ) const;
300 : :
301 : : // public wrapper for the private method
302 : : bool checkConstraints( const PPDKey*, const PPDValue* );
303 : :
304 : : // for printer setup
305 : : char* getStreamableBuffer( sal_uLong& rBytes ) const;
306 : : void rebuildFromStreamBuffer( char* pBuffer, sal_uLong nBytes );
307 : :
308 : : // convenience
309 : : int getRenderResolution() const;
310 : :
311 : : // width, height in points, paper will contain the name of the selected
312 : : // paper after the call
313 : : void getPageSize( rtl::OUString& rPaper, int& rWidth, int& rHeight ) const;
314 : : };
315 : :
316 : : } // namespace
317 : :
318 : : #endif // _PSPRINT_PPDPARSER_HXX_
319 : :
320 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|