Bump version to 6.4-15
[LibreOffice.git] / include / xmloff / xmluconv.hxx
blobd791f6cb633d016a083d90ea6aead25a1445fe97
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 <tools/fldunit.hxx>
35 namespace com { namespace sun { namespace star {
36 namespace text { class XNumberingTypeInfo; }
37 }}}
39 namespace basegfx
41 class B3DVector;
44 namespace com { namespace sun { namespace star { namespace beans { class XPropertySet; } } } }
45 namespace com { namespace sun { namespace star { namespace beans { struct PropertyValue; } } } }
46 namespace com { namespace sun { namespace star { namespace drawing { struct Position3D; } } } }
47 namespace com { namespace sun { namespace star { namespace frame { class XModel; } } } }
48 namespace com { namespace sun { namespace star { namespace uno { class XComponentContext; } } } }
49 namespace com { namespace sun { namespace star { namespace uno { template <class E> class Sequence; } } } }
50 namespace com { namespace sun { namespace star { namespace util { struct Date; } } } }
51 template <typename EnumT> struct SvXMLEnumMapEntry;
52 template <typename EnumT> struct SvXMLEnumStringMapEntry;
54 class XMLOFF_DLLPUBLIC SvXMLTokenEnumerator
56 private:
57 const OUString& maTokenString;
58 sal_Int32 mnNextTokenPos;
59 sal_Unicode const mcSeparator;
61 public:
62 SvXMLTokenEnumerator( const OUString& rString, sal_Unicode cSeparator = u' ' );
64 bool getNextToken( OUString& rToken );
67 /** the SvXMLTypeConverter converts values of various types from
68 their internal representation to the textual form used in xml
69 and back.
70 Most of the methods are static but the SvXMLTypeConverter can
71 also store default units for both numerical and textual measures.
73 @attention:
74 a lot of the methods here have been moved to <sax/tools/converter.hxx>!
77 class XMLOFF_DLLPUBLIC SvXMLUnitConverter final
79 private:
80 SvXMLUnitConverter(const SvXMLUnitConverter&) = delete;
81 SvXMLUnitConverter& operator=(const SvXMLUnitConverter&) = delete;
83 struct Impl;
84 ::std::unique_ptr<Impl> m_pImpl;
86 public:
87 /** constructs a SvXMLUnitConverter. The core measure unit is the
88 default unit for numerical measures, the XML measure unit is
89 the default unit for textual measures */
90 SvXMLUnitConverter(
91 const css::uno::Reference< css::uno::XComponentContext >& xContext,
92 sal_Int16 eCoreMeasureUnit /*css::util::MeasureUnit*/,
93 sal_Int16 eXMLMeasureUnit /*css::util::MeasureUnit*/);
95 ~SvXMLUnitConverter();
97 static sal_Int16 GetMeasureUnit(FieldUnit const nFieldUnit);
99 /** sets the default unit for numerical measures */
100 void SetCoreMeasureUnit( sal_Int16 const eCoreMeasureUnit /*css::util::MeasureUnit*/);
102 /** sets the default unit for textual measures */
103 void SetXMLMeasureUnit( sal_Int16 const eXMLMeasureUnit /*css::util::MeasureUnit*/);
105 /** gets the default unit for textual measures */
106 sal_Int16 GetXMLMeasureUnit() const;
108 /** gets XNumberingTypeInfo */
109 const css::uno::Reference< css::text::XNumberingTypeInfo >& getNumTypeInfo() const;
111 /** convert string to measure with meCoreMeasureUnit,
112 using optional min and max values*/
113 bool convertMeasureToCore( sal_Int32& rValue,
114 const OUString& rString,
115 sal_Int32 nMin = SAL_MIN_INT32,
116 sal_Int32 nMax = SAL_MAX_INT32) const;
118 /** convert measure to string: from meCoreMeasureUnit to meXMLMeasureUnit */
119 void convertMeasureToXML( OUStringBuffer& rBuffer,
120 sal_Int32 nMeasure ) const;
122 /** convert measure to string: from meCoreMeasureUnit to meXMLMeasureUnit */
123 OUString convertMeasureToXML( sal_Int32 nMeasure ) const;
125 /** convert string to enum using given enum map, if the enum is
126 not found in the map, this method will return false */
127 template<typename EnumT>
128 static bool convertEnum( EnumT& rEnum,
129 const OUString& rValue,
130 const SvXMLEnumMapEntry<EnumT> *pMap )
132 sal_uInt16 nTmp;
133 bool bRet = convertEnumImpl(nTmp, rValue,
134 reinterpret_cast<const SvXMLEnumMapEntry<sal_uInt16>*>(pMap));
135 if (bRet)
136 rEnum = static_cast<EnumT>(nTmp);
137 return bRet;
140 /** convert string to enum using given token map, if the enum is
141 not found in the map, this method will return false */
142 template<typename EnumT>
143 static bool convertEnum( EnumT& rEnum,
144 const OUString& rValue,
145 const SvXMLEnumStringMapEntry<EnumT> *pMap )
147 sal_uInt16 nTmp;
148 bool bRet = convertEnumImpl(nTmp, rValue,
149 reinterpret_cast<const SvXMLEnumStringMapEntry<sal_uInt16>*>(pMap));
150 if (bRet)
151 rEnum = static_cast<EnumT>(nTmp);
152 return bRet;
155 /** convert enum to string using given enum map with an optional
156 default token. If the enum is not found in the map,
157 this method will either use the given default or return
158 false if not default is set */
159 template<typename EnumT>
160 static bool convertEnum( OUStringBuffer& rBuffer,
161 EnumT nValue,
162 const SvXMLEnumMapEntry<EnumT> *pMap,
163 enum ::xmloff::token::XMLTokenEnum eDefault =
164 ::xmloff::token::XML_TOKEN_INVALID )
166 return convertEnumImpl(rBuffer, static_cast<sal_uInt16>(nValue),
167 reinterpret_cast<const SvXMLEnumMapEntry<sal_uInt16>*>(pMap), eDefault);
170 /** convert double number to string (using ::rtl::math) and DO
171 convert to export MapUnit using meCoreMeasureUnit/meXMLMeasureUnit */
172 void convertDouble(OUStringBuffer& rBuffer,
173 double fNumber) const;
175 /** convert string to double number (using ::rtl::math) and DO convert. */
176 bool convertDouble(double& rValue, const OUString& rString) const;
178 /** get the Null Date of the XModel and set it to the UnitConverter */
179 bool setNullDate (
180 const css::uno::Reference <css::frame::XModel>& xModel);
182 /** convert double to ISO Date Time String */
183 void convertDateTime( OUStringBuffer& rBuffer,
184 const double& fDateTime,
185 bool const bAddTimeIf0AM = false);
187 /** convert ISO Date Time String to double */
188 bool convertDateTime(double& fDateTime,
189 const OUString& rString);
191 /// these 2 functions use tools Date, so they're not yet moved to sax
193 /** convert double to ISO Date Time String */
194 static void convertDateTime( OUStringBuffer& rBuffer,
195 const double& fDateTime,
196 const css::util::Date& aNullDate,
197 bool bAddTimeIf0AM = false);
198 /** convert ISO Date Time String to double */
199 static bool convertDateTime( double& fDateTime,
200 const OUString& rString,
201 const css::util::Date& aNullDate);
204 /** convert string to ::basegfx::B3DVector */
205 static bool convertB3DVector( ::basegfx::B3DVector& rVector,
206 const OUString& rValue );
208 /** convert B3DVector to string */
209 static void convertB3DVector( OUStringBuffer &rBuffer,
210 const ::basegfx::B3DVector& rVector );
212 /** convert string to Position3D */
213 bool convertPosition3D( css::drawing::Position3D& rPosition,
214 const OUString& rValue );
216 /** convert Position3D to string */
217 void convertPosition3D( OUStringBuffer &rBuffer,
218 const css::drawing::Position3D& rVector );
221 /** convert num-format and num-letter-sync values to NumberingType */
222 bool convertNumFormat( sal_Int16& rType,
223 const OUString& rNumFormat,
224 const OUString& rNumLetterSync,
225 bool bNumberNone = false ) const;
227 /** convert NumberingType to num-format and num-letter-sync values */
228 void convertNumFormat( OUStringBuffer& rBuffer,
229 sal_Int16 nType ) const;
230 static void convertNumLetterSync( OUStringBuffer& rBuffer,
231 sal_Int16 nType );
233 static void convertPropertySet(css::uno::Sequence<css::beans::PropertyValue>& rProps,
234 const css::uno::Reference<css::beans::XPropertySet>& aProperties);
235 static void convertPropertySet(css::uno::Reference<css::beans::XPropertySet> const & rProperties,
236 const css::uno::Sequence<css::beans::PropertyValue>& aProps);
238 OUString encodeStyleName( const OUString& rName,
239 bool *pEncoded=nullptr ) const;
240 /** convert string (hex) to number (sal_uInt32) */
241 static bool convertHex( sal_uInt32& nVal,
242 const OUString& rValue );
244 /** convert number (sal_uInt32) to string (hex) */
245 static void convertHex( OUStringBuffer& rBuffer,
246 sal_uInt32 nVal );
248 private:
249 static bool convertEnumImpl( sal_uInt16& rEnum,
250 const OUString& rValue,
251 const SvXMLEnumMapEntry<sal_uInt16> *pMap );
253 static bool convertEnumImpl( sal_uInt16& rEnum,
254 const OUString& rValue,
255 const SvXMLEnumStringMapEntry<sal_uInt16> *pMap );
257 static bool convertEnumImpl( OUStringBuffer& rBuffer,
258 sal_uInt16 nValue,
259 const SvXMLEnumMapEntry<sal_uInt16> *pMap,
260 enum ::xmloff::token::XMLTokenEnum eDefault );
263 #endif // INCLUDED_XMLOFF_XMLUCONV_HXX
265 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */