nss: upgrade to release 3.73
[LibreOffice.git] / include / xmloff / xmluconv.hxx
blobb9800b02a805de8066ddbac84abd17bb50a25f56
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 .
20 #ifndef INCLUDED_XMLOFF_XMLUCONV_HXX
21 #define INCLUDED_XMLOFF_XMLUCONV_HXX
23 #include <sal/config.h>
24 #include <xmloff/dllapi.h>
25 #include <sal/types.h>
27 #include <memory>
29 #include <rtl/ustring.hxx>
30 #include <rtl/ustrbuf.hxx>
31 #include <xmloff/xmltoken.hxx>
33 #include <unotools/saveopt.hxx>
35 #include <tools/fldunit.hxx>
37 namespace com::sun::star {
38 namespace text { class XNumberingTypeInfo; }
41 namespace basegfx
43 class B3DVector;
46 namespace com::sun::star::beans { class XPropertySet; }
47 namespace com::sun::star::beans { struct PropertyValue; }
48 namespace com::sun::star::drawing { struct Position3D; }
49 namespace com::sun::star::frame { class XModel; }
50 namespace com::sun::star::uno { class XComponentContext; }
51 namespace com::sun::star::uno { template <class E> class Sequence; }
52 namespace com::sun::star::util { struct Date; }
53 template <typename EnumT> struct SvXMLEnumMapEntry;
54 template <typename EnumT> struct SvXMLEnumStringMapEntry;
56 class XMLOFF_DLLPUBLIC SvXMLTokenEnumerator
58 private:
59 const OUString& maTokenString;
60 sal_Int32 mnNextTokenPos;
61 sal_Unicode mcSeparator;
63 public:
64 SvXMLTokenEnumerator( const OUString& rString, sal_Unicode cSeparator = u' ' );
66 bool getNextToken( OUString& rToken );
69 /** the SvXMLTypeConverter converts values of various types from
70 their internal representation to the textual form used in xml
71 and back.
72 Most of the methods are static but the SvXMLTypeConverter can
73 also store default units for both numerical and textual measures.
75 @attention:
76 a lot of the methods here have been moved to <sax/tools/converter.hxx>!
79 class XMLOFF_DLLPUBLIC SvXMLUnitConverter final
81 private:
82 SvXMLUnitConverter(const SvXMLUnitConverter&) = delete;
83 SvXMLUnitConverter& operator=(const SvXMLUnitConverter&) = delete;
85 struct SAL_DLLPRIVATE Impl;
86 ::std::unique_ptr<Impl> m_pImpl;
88 public:
89 /** constructs a SvXMLUnitConverter. The core measure unit is the
90 default unit for numerical measures, the XML measure unit is
91 the default unit for textual measures */
92 SvXMLUnitConverter(
93 const css::uno::Reference< css::uno::XComponentContext >& xContext,
94 sal_Int16 eCoreMeasureUnit /*css::util::MeasureUnit*/,
95 sal_Int16 eXMLMeasureUnit /*css::util::MeasureUnit*/,
96 SvtSaveOptions::ODFSaneDefaultVersion const nODFVersion);
98 ~SvXMLUnitConverter();
100 static sal_Int16 GetMeasureUnit(FieldUnit const nFieldUnit);
102 /** sets the default unit for numerical measures */
103 void SetCoreMeasureUnit( sal_Int16 const eCoreMeasureUnit /*css::util::MeasureUnit*/);
105 /** sets the default unit for textual measures */
106 void SetXMLMeasureUnit( sal_Int16 const eXMLMeasureUnit /*css::util::MeasureUnit*/);
108 /** gets the default unit for textual measures */
109 sal_Int16 GetXMLMeasureUnit() const;
111 /// ODF version, only when exporting
112 SvtSaveOptions::ODFSaneDefaultVersion getSaneDefaultVersion() const;
113 void overrideSaneDefaultVersion(SvtSaveOptions::ODFSaneDefaultVersion const);
115 /** gets XNumberingTypeInfo */
116 const css::uno::Reference< css::text::XNumberingTypeInfo >& getNumTypeInfo() const;
118 /** convert string to measure with meCoreMeasureUnit,
119 using optional min and max values*/
120 bool convertMeasureToCore( sal_Int32& rValue,
121 const OUString& rString,
122 sal_Int32 nMin = SAL_MIN_INT32,
123 sal_Int32 nMax = SAL_MAX_INT32) const;
125 /** convert measure to string: from meCoreMeasureUnit to meXMLMeasureUnit */
126 void convertMeasureToXML( OUStringBuffer& rBuffer,
127 sal_Int32 nMeasure ) const;
129 /** convert measure to string: from meCoreMeasureUnit to meXMLMeasureUnit */
130 OUString convertMeasureToXML( sal_Int32 nMeasure ) const;
132 /** convert string to enum using given enum map, if the enum is
133 not found in the map, this method will return false */
134 template<typename EnumT>
135 static bool convertEnum( EnumT& rEnum,
136 const OUString& rValue,
137 const SvXMLEnumMapEntry<EnumT> *pMap )
139 sal_uInt16 nTmp;
140 bool bRet = convertEnumImpl(nTmp, rValue,
141 reinterpret_cast<const SvXMLEnumMapEntry<sal_uInt16>*>(pMap));
142 if (bRet)
143 rEnum = static_cast<EnumT>(nTmp);
144 return bRet;
147 /** convert string to enum using given token map, if the enum is
148 not found in the map, this method will return false */
149 template<typename EnumT>
150 static bool convertEnum( EnumT& rEnum,
151 const OUString& rValue,
152 const SvXMLEnumStringMapEntry<EnumT> *pMap )
154 sal_uInt16 nTmp;
155 bool bRet = convertEnumImpl(nTmp, rValue,
156 reinterpret_cast<const SvXMLEnumStringMapEntry<sal_uInt16>*>(pMap));
157 if (bRet)
158 rEnum = static_cast<EnumT>(nTmp);
159 return bRet;
162 /** convert enum to string using given enum map with an optional
163 default token. If the enum is not found in the map,
164 this method will either use the given default or return
165 false if not default is set */
166 template<typename EnumT>
167 static bool convertEnum( OUStringBuffer& rBuffer,
168 EnumT nValue,
169 const SvXMLEnumMapEntry<EnumT> *pMap,
170 enum ::xmloff::token::XMLTokenEnum eDefault =
171 ::xmloff::token::XML_TOKEN_INVALID )
173 return convertEnumImpl(rBuffer, static_cast<sal_uInt16>(nValue),
174 reinterpret_cast<const SvXMLEnumMapEntry<sal_uInt16>*>(pMap), eDefault);
177 /** convert double number to string (using ::rtl::math) and DO
178 convert to export MapUnit using meCoreMeasureUnit/meXMLMeasureUnit */
179 void convertDouble(OUStringBuffer& rBuffer,
180 double fNumber) const;
182 /** convert string to double number (using ::rtl::math) and DO convert. */
183 bool convertDouble(double& rValue, const OUString& rString) const;
185 /** get the Null Date of the XModel and set it to the UnitConverter */
186 bool setNullDate (
187 const css::uno::Reference <css::frame::XModel>& xModel);
189 /** convert double to ISO Date Time String */
190 void convertDateTime( OUStringBuffer& rBuffer,
191 const double& fDateTime,
192 bool const bAddTimeIf0AM = false);
194 /** convert ISO Date Time String to double */
195 bool convertDateTime(double& fDateTime,
196 const OUString& rString);
198 /// these 2 functions use tools Date, so they're not yet moved to sax
200 /** convert double to ISO Date Time String */
201 static void convertDateTime( OUStringBuffer& rBuffer,
202 const double& fDateTime,
203 const css::util::Date& aNullDate,
204 bool bAddTimeIf0AM = false);
205 /** convert ISO Date Time String to double */
206 static bool convertDateTime( double& fDateTime,
207 const OUString& rString,
208 const css::util::Date& aNullDate);
211 /** convert string to ::basegfx::B3DVector */
212 static bool convertB3DVector( ::basegfx::B3DVector& rVector,
213 const OUString& rValue );
215 /** convert B3DVector to string */
216 static void convertB3DVector( OUStringBuffer &rBuffer,
217 const ::basegfx::B3DVector& rVector );
219 /** convert string to Position3D */
220 bool convertPosition3D( css::drawing::Position3D& rPosition,
221 const OUString& rValue );
223 /** convert Position3D to string */
224 void convertPosition3D( OUStringBuffer &rBuffer,
225 const css::drawing::Position3D& rVector );
228 /** convert num-format and num-letter-sync values to NumberingType */
229 bool convertNumFormat( sal_Int16& rType,
230 const OUString& rNumFormat,
231 const OUString& rNumLetterSync,
232 bool bNumberNone = false ) const;
234 /** convert NumberingType to num-format and num-letter-sync values */
235 void convertNumFormat( OUStringBuffer& rBuffer,
236 sal_Int16 nType ) const;
237 static void convertNumLetterSync( OUStringBuffer& rBuffer,
238 sal_Int16 nType );
240 static void convertPropertySet(css::uno::Sequence<css::beans::PropertyValue>& rProps,
241 const css::uno::Reference<css::beans::XPropertySet>& aProperties);
242 static void convertPropertySet(css::uno::Reference<css::beans::XPropertySet> const & rProperties,
243 const css::uno::Sequence<css::beans::PropertyValue>& aProps);
245 OUString encodeStyleName( const OUString& rName,
246 bool *pEncoded=nullptr ) const;
247 /** convert string (hex) to number (sal_uInt32) */
248 static bool convertHex( sal_uInt32& nVal,
249 const OUString& rValue );
251 /** convert number (sal_uInt32) to string (hex) */
252 static void convertHex( OUStringBuffer& rBuffer,
253 sal_uInt32 nVal );
255 private:
256 static bool convertEnumImpl( sal_uInt16& rEnum,
257 const OUString& rValue,
258 const SvXMLEnumMapEntry<sal_uInt16> *pMap );
260 static bool convertEnumImpl( sal_uInt16& rEnum,
261 const OUString& rValue,
262 const SvXMLEnumStringMapEntry<sal_uInt16> *pMap );
264 static bool convertEnumImpl( OUStringBuffer& rBuffer,
265 sal_uInt16 nValue,
266 const SvXMLEnumMapEntry<sal_uInt16> *pMap,
267 enum ::xmloff::token::XMLTokenEnum eDefault );
270 #endif // INCLUDED_XMLOFF_XMLUCONV_HXX
272 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */