nss: upgrade to release 3.73
[LibreOffice.git] / vcl / inc / ppdparser.hxx
blobb5bf309ed91730c043f2c578b295aaa1cd8a8176
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 #ifndef INCLUDED_VCL_PPDPARSER_HXX
20 #define INCLUDED_VCL_PPDPARSER_HXX
22 #include <sal/config.h>
24 #include <cstddef>
25 #include <memory>
26 #include <unordered_map>
27 #include <vector>
29 #include <rtl/string.hxx>
30 #include <rtl/ustring.hxx>
31 #include <tools/solar.h>
32 #include <vcl/dllapi.h>
34 #define PRINTER_PPDDIR "driver"
36 namespace psp {
38 class PPDCache;
39 class PPDTranslator;
41 enum PPDValueType { eInvocation, eQuoted, eSymbol, eString, eNo };
43 struct VCL_DLLPUBLIC PPDValue
45 PPDValueType m_eType;
46 //CustomOption stuff for fdo#43049
47 //see http://www.cups.org/documentation.php/spec-ppd.html#OPTIONS
48 //for full specs, only the basics are implemented here
49 bool m_bCustomOption;
50 mutable OUString m_aCustomOption;
51 OUString m_aOption;
52 OUString m_aValue;
57 * PPDKey - a container for the available options (=values) of a PPD keyword
60 class PPDKey
62 friend class PPDParser;
63 friend class CPDManager;
65 typedef std::unordered_map< OUString, PPDValue > hash_type;
66 typedef std::vector< PPDValue* > value_type;
68 OUString m_aKey;
69 hash_type m_aValues;
70 value_type m_aOrderedValues;
71 const PPDValue* m_pDefaultValue;
72 bool m_bQueryValue;
73 OUString m_aGroup;
75 public:
76 enum class SetupType { ExitServer, Prolog, DocumentSetup, PageSetup, JCLSetup, AnySetup };
77 private:
79 bool m_bUIOption;
80 int m_nOrderDependency;
81 SetupType m_eSetupType;
83 void eraseValue( const OUString& rOption );
84 public:
85 PPDKey( const OUString& rKey );
86 ~PPDKey();
88 PPDValue* insertValue(const OUString& rOption, PPDValueType eType, bool bCustomOption = false);
89 int countValues() const
90 { return m_aValues.size(); }
91 // neither getValue will return the query option
92 const PPDValue* getValue( int n ) const;
93 const PPDValue* getValue( const OUString& rOption ) const;
94 const PPDValue* getValueCaseInsensitive( const OUString& rOption ) const;
95 const PPDValue* getDefaultValue() const { return m_pDefaultValue; }
96 const OUString& getGroup() const { return m_aGroup; }
98 const OUString& getKey() const { return m_aKey; }
99 bool isUIKey() const { return m_bUIOption; }
100 SetupType getSetupType() const { return m_eSetupType; }
101 int getOrderDependency() const { return m_nOrderDependency; }
104 // define a hash for PPDKey
105 struct PPDKeyhash
107 size_t operator()( const PPDKey * pKey) const
108 { return reinterpret_cast<size_t>(pKey); }
113 * PPDParser - parses a PPD file and contains all available keys from it
116 class PPDParser
118 friend class PPDContext;
119 friend class CUPSManager;
120 friend class CPDManager;
121 friend class PPDCache;
123 typedef std::unordered_map< OUString, std::unique_ptr<PPDKey> > hash_type;
124 typedef std::vector< PPDKey* > value_type;
126 void insertKey( std::unique_ptr<PPDKey> pKey );
127 public:
128 struct PPDConstraint
130 const PPDKey* m_pKey1;
131 const PPDValue* m_pOption1;
132 const PPDKey* m_pKey2;
133 const PPDValue* m_pOption2;
135 PPDConstraint() : m_pKey1( nullptr ), m_pOption1( nullptr ), m_pKey2( nullptr ), m_pOption2( nullptr ) {}
137 private:
138 hash_type m_aKeys;
139 value_type m_aOrderedKeys;
140 ::std::vector< PPDConstraint > m_aConstraints;
142 // the full path of the PPD file
143 OUString m_aFile;
144 // some basic attributes
145 bool m_bColorDevice;
146 bool m_bType42Capable;
147 sal_uLong m_nLanguageLevel;
148 rtl_TextEncoding m_aFileEncoding;
151 // shortcuts to important keys and their default values
152 // imageable area
153 const PPDKey* m_pImageableAreas;
154 // paper dimensions
155 const PPDValue* m_pDefaultPaperDimension;
156 const PPDKey* m_pPaperDimensions;
157 // paper trays
158 const PPDValue* m_pDefaultInputSlot;
159 // resolutions
160 const PPDValue* m_pDefaultResolution;
162 // translations
163 std::unique_ptr<PPDTranslator> m_pTranslator;
165 PPDParser( const OUString& rFile );
166 PPDParser(const OUString& rFile, const std::vector<PPDKey*>& keys);
168 void parseOrderDependency(const OString& rLine);
169 void parseOpenUI(const OString& rLine, const OString& rPPDGroup);
170 void parseConstraint(const OString& rLine);
171 void parse( std::vector< OString >& rLines );
173 OUString handleTranslation(const OString& i_rString, bool i_bIsGlobalized);
175 static void scanPPDDir( const OUString& rDir );
176 static void initPPDFiles(PPDCache &rPPDCache);
177 static OUString getPPDFile( const OUString& rFile );
178 public:
179 ~PPDParser();
180 static const PPDParser* getParser( const OUString& rFile );
182 const PPDKey* getKey( int n ) const;
183 const PPDKey* getKey( const OUString& rKey ) const;
184 int getKeys() const { return m_aKeys.size(); }
185 bool hasKey( const PPDKey* ) const;
187 const ::std::vector< PPDConstraint >& getConstraints() const { return m_aConstraints; }
189 bool isColorDevice() const { return m_bColorDevice; }
190 bool isType42Capable() const { return m_bType42Capable; }
191 sal_uLong getLanguageLevel() const { return m_nLanguageLevel; }
193 OUString getDefaultPaperDimension() const;
194 void getDefaultPaperDimension( int& rWidth, int& rHeight ) const
195 { getPaperDimension( getDefaultPaperDimension(), rWidth, rHeight ); }
196 bool getPaperDimension( const OUString& rPaperName,
197 int& rWidth, int& rHeight ) const;
198 // width and height in pt
199 // returns false if paper not found
201 // match the best paper for width and height
202 OUString matchPaper( int nWidth, int nHeight ) const;
204 bool getMargins( const OUString& rPaperName,
205 int &rLeft, int& rRight,
206 int &rUpper, int& rLower ) const;
207 // values in pt
208 // returns true if paper found
210 // values int pt
212 OUString getDefaultInputSlot() const;
214 void getDefaultResolution( int& rXRes, int& rYRes ) const;
215 // values in dpi
216 static void getResolutionFromString( const OUString&, int&, int& );
217 // helper function
219 OUString translateKey( const OUString& i_rKey ) const;
220 OUString translateOption( const OUString& i_rKey,
221 const OUString& i_rOption ) const;
226 * PPDContext - a class to manage user definable states based on the
227 * contents of a PPDParser.
230 class PPDContext
232 typedef std::unordered_map< const PPDKey*, const PPDValue*, PPDKeyhash > hash_type;
233 hash_type m_aCurrentValues;
234 const PPDParser* m_pParser;
236 // returns false: check failed, new value is constrained
237 // true: check succeeded, new value can be set
238 bool checkConstraints( const PPDKey*, const PPDValue*, bool bDoReset );
239 bool resetValue( const PPDKey*, bool bDefaultable = false );
240 public:
241 PPDContext();
242 PPDContext( const PPDContext& rContext ) { operator=( rContext ); }
243 PPDContext& operator=( const PPDContext& rContext ) = default;
244 PPDContext& operator=( PPDContext&& rContext );
246 void setParser( const PPDParser* );
247 const PPDParser* getParser() const { return m_pParser; }
249 const PPDValue* getValue( const PPDKey* ) const;
250 const PPDValue* setValue( const PPDKey*, const PPDValue*, bool bDontCareForConstraints = false );
252 std::size_t countValuesModified() const { return m_aCurrentValues.size(); }
253 const PPDKey* getModifiedKey( std::size_t n ) const;
255 // public wrapper for the private method
256 bool checkConstraints( const PPDKey*, const PPDValue* );
258 // for printer setup
259 char* getStreamableBuffer( sal_uLong& rBytes ) const;
260 void rebuildFromStreamBuffer(const std::vector<char> &rBuffer);
262 // convenience
263 int getRenderResolution() const;
265 // width, height in points, paper will contain the name of the selected
266 // paper after the call
267 void getPageSize( OUString& rPaper, int& rWidth, int& rHeight ) const;
270 } // namespace
272 #endif // INCLUDED_VCL_PPDPARSER_HXX
274 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */