lok: calc - send other views our selection in their co-ordinates.
[LibreOffice.git] / include / vcl / ppdparser.hxx
blob2d0701c4a8590ee3700c9d22a5350538f9330529
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 <memory>
23 #include <unordered_map>
24 #include <vector>
26 #include <rtl/string.hxx>
27 #include <rtl/ustring.hxx>
28 #include <tools/solar.h>
29 #include <vcl/dllapi.h>
31 #define PRINTER_PPDDIR "driver"
33 namespace psp {
35 class PPDCache;
36 class PPDTranslator;
38 enum PPDValueType { eInvocation, eQuoted, eSymbol, eString, eNo };
40 struct VCL_DLLPUBLIC PPDValue
42 PPDValueType m_eType;
43 //CustomOption stuff for fdo#43049
44 //see http://www.cups.org/documentation.php/spec-ppd.html#OPTIONS
45 //for full specs, only the basics are implemented here
46 bool m_bCustomOption;
47 mutable OUString m_aCustomOption;
48 OUString m_aOption;
49 OUString m_aValue;
54 * PPDKey - a container for the available options (=values) of a PPD keyword
57 class PPDKey
59 friend class PPDParser;
60 friend class CPDManager;
62 typedef std::unordered_map< OUString, PPDValue > hash_type;
63 typedef std::vector< PPDValue* > value_type;
65 OUString const m_aKey;
66 hash_type m_aValues;
67 value_type m_aOrderedValues;
68 const PPDValue* m_pDefaultValue;
69 bool m_bQueryValue;
70 OUString m_aGroup;
72 public:
73 enum class SetupType { ExitServer, Prolog, DocumentSetup, PageSetup, JCLSetup, AnySetup };
74 private:
76 bool m_bUIOption;
77 int m_nOrderDependency;
78 SetupType m_eSetupType;
80 void eraseValue( const OUString& rOption );
81 public:
82 PPDKey( const OUString& rKey );
83 ~PPDKey();
85 PPDValue* insertValue(const OUString& rOption, PPDValueType eType, bool bCustomOption = false);
86 int countValues() const
87 { return m_aValues.size(); }
88 // neither getValue will return the query option
89 const PPDValue* getValue( int n ) const;
90 const PPDValue* getValue( const OUString& rOption ) const;
91 const PPDValue* getValueCaseInsensitive( const OUString& rOption ) const;
92 const PPDValue* getDefaultValue() const { return m_pDefaultValue; }
93 const OUString& getGroup() const { return m_aGroup; }
95 const OUString& getKey() const { return m_aKey; }
96 bool isUIKey() const { return m_bUIOption; }
97 SetupType getSetupType() const { return m_eSetupType; }
98 int getOrderDependency() const { return m_nOrderDependency; }
101 // define a hash for PPDKey
102 struct PPDKeyhash
104 size_t operator()( const PPDKey * pKey) const
105 { return reinterpret_cast<size_t>(pKey); }
110 * PPDParser - parses a PPD file and contains all available keys from it
113 class PPDParser
115 friend class PPDContext;
116 friend class CUPSManager;
117 friend class CPDManager;
118 friend class PPDCache;
120 typedef std::unordered_map< OUString, std::unique_ptr<PPDKey> > hash_type;
121 typedef std::vector< PPDKey* > value_type;
123 void insertKey( std::unique_ptr<PPDKey> pKey );
124 public:
125 struct PPDConstraint
127 const PPDKey* m_pKey1;
128 const PPDValue* m_pOption1;
129 const PPDKey* m_pKey2;
130 const PPDValue* m_pOption2;
132 PPDConstraint() : m_pKey1( nullptr ), m_pOption1( nullptr ), m_pKey2( nullptr ), m_pOption2( nullptr ) {}
134 private:
135 hash_type m_aKeys;
136 value_type m_aOrderedKeys;
137 ::std::vector< PPDConstraint > m_aConstraints;
139 // the full path of the PPD file
140 OUString m_aFile;
141 // some basic attributes
142 bool m_bColorDevice;
143 bool m_bType42Capable;
144 sal_uLong m_nLanguageLevel;
145 rtl_TextEncoding m_aFileEncoding;
148 // shortcuts to important keys and their default values
149 // imageable area
150 const PPDKey* m_pImageableAreas;
151 // paper dimensions
152 const PPDValue* m_pDefaultPaperDimension;
153 const PPDKey* m_pPaperDimensions;
154 // paper trays
155 const PPDValue* m_pDefaultInputSlot;
156 // resolutions
157 const PPDValue* m_pDefaultResolution;
159 // translations
160 std::unique_ptr<PPDTranslator> m_pTranslator;
162 PPDParser( const OUString& rFile );
163 PPDParser(const OUString& rFile, const std::vector<PPDKey*>& keys);
165 void parseOrderDependency(const OString& rLine);
166 void parseOpenUI(const OString& rLine, const OString& rPPDGroup);
167 void parseConstraint(const OString& rLine);
168 void parse( std::vector< OString >& rLines );
170 OUString handleTranslation(const OString& i_rString, bool i_bIsGlobalized);
172 static void scanPPDDir( const OUString& rDir );
173 static void initPPDFiles(PPDCache &rPPDCache);
174 static OUString getPPDFile( const OUString& rFile );
175 public:
176 ~PPDParser();
177 static const PPDParser* getParser( const OUString& rFile );
179 const PPDKey* getKey( int n ) const;
180 const PPDKey* getKey( const OUString& rKey ) const;
181 int getKeys() const { return m_aKeys.size(); }
182 bool hasKey( const PPDKey* ) const;
184 const ::std::vector< PPDConstraint >& getConstraints() const { return m_aConstraints; }
186 bool isColorDevice() const { return m_bColorDevice; }
187 bool isType42Capable() const { return m_bType42Capable; }
188 sal_uLong getLanguageLevel() const { return m_nLanguageLevel; }
190 OUString getDefaultPaperDimension() const;
191 void getDefaultPaperDimension( int& rWidth, int& rHeight ) const
192 { getPaperDimension( getDefaultPaperDimension(), rWidth, rHeight ); }
193 bool getPaperDimension( const OUString& rPaperName,
194 int& rWidth, int& rHeight ) const;
195 // width and height in pt
196 // returns false if paper not found
198 // match the best paper for width and height
199 OUString matchPaper( int nWidth, int nHeight ) const;
201 bool getMargins( const OUString& rPaperName,
202 int &rLeft, int& rRight,
203 int &rUpper, int& rLower ) const;
204 // values in pt
205 // returns true if paper found
207 // values int pt
209 OUString getDefaultInputSlot() const;
211 void getDefaultResolution( int& rXRes, int& rYRes ) const;
212 // values in dpi
213 static void getResolutionFromString( const OUString&, int&, int& );
214 // helper function
216 OUString translateKey( const OUString& i_rKey ) const;
217 OUString translateOption( const OUString& i_rKey,
218 const OUString& i_rOption ) const;
223 * PPDContext - a class to manage user definable states based on the
224 * contents of a PPDParser.
227 class PPDContext
229 typedef std::unordered_map< const PPDKey*, const PPDValue*, PPDKeyhash > hash_type;
230 hash_type m_aCurrentValues;
231 const PPDParser* m_pParser;
233 // returns false: check failed, new value is constrained
234 // true: check succeeded, new value can be set
235 bool checkConstraints( const PPDKey*, const PPDValue*, bool bDoReset );
236 bool resetValue( const PPDKey*, bool bDefaultable = false );
237 public:
238 PPDContext();
239 PPDContext( const PPDContext& rContext ) { operator=( rContext ); }
240 PPDContext& operator=( const PPDContext& rContext ) = default;
241 PPDContext& operator=( PPDContext&& rContext );
243 void setParser( const PPDParser* );
244 const PPDParser* getParser() const { return m_pParser; }
246 const PPDValue* getValue( const PPDKey* ) const;
247 const PPDValue* setValue( const PPDKey*, const PPDValue*, bool bDontCareForConstraints = false );
249 int countValuesModified() const { return m_aCurrentValues.size(); }
250 const PPDKey* getModifiedKey( int n ) const;
252 // public wrapper for the private method
253 bool checkConstraints( const PPDKey*, const PPDValue* );
255 // for printer setup
256 char* getStreamableBuffer( sal_uLong& rBytes ) const;
257 void rebuildFromStreamBuffer(const std::vector<char> &rBuffer);
259 // convenience
260 int getRenderResolution() const;
262 // width, height in points, paper will contain the name of the selected
263 // paper after the call
264 void getPageSize( OUString& rPaper, int& rWidth, int& rHeight ) const;
267 } // namespace
269 #endif // INCLUDED_VCL_PPDPARSER_HXX
271 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */