1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
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
; }
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
57 const OUString
& maTokenString
;
58 sal_Int32 mnNextTokenPos
;
59 sal_Unicode
const mcSeparator
;
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
70 Most of the methods are static but the SvXMLTypeConverter can
71 also store default units for both numerical and textual measures.
74 a lot of the methods here have been moved to <sax/tools/converter.hxx>!
77 class XMLOFF_DLLPUBLIC SvXMLUnitConverter final
80 SvXMLUnitConverter(const SvXMLUnitConverter
&) = delete;
81 SvXMLUnitConverter
& operator=(const SvXMLUnitConverter
&) = delete;
84 ::std::unique_ptr
<Impl
> m_pImpl
;
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 */
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 string to enum using given enum map, if the enum is
123 not found in the map, this method will return false */
124 template<typename EnumT
>
125 static bool convertEnum( EnumT
& rEnum
,
126 const OUString
& rValue
,
127 const SvXMLEnumMapEntry
<EnumT
> *pMap
)
130 bool bRet
= convertEnumImpl(nTmp
, rValue
,
131 reinterpret_cast<const SvXMLEnumMapEntry
<sal_uInt16
>*>(pMap
));
133 rEnum
= static_cast<EnumT
>(nTmp
);
137 /** convert string to enum using given token map, if the enum is
138 not found in the map, this method will return false */
139 template<typename EnumT
>
140 static bool convertEnum( EnumT
& rEnum
,
141 const OUString
& rValue
,
142 const SvXMLEnumStringMapEntry
<EnumT
> *pMap
)
145 bool bRet
= convertEnumImpl(nTmp
, rValue
,
146 reinterpret_cast<const SvXMLEnumStringMapEntry
<sal_uInt16
>*>(pMap
));
148 rEnum
= static_cast<EnumT
>(nTmp
);
152 /** convert enum to string using given enum map with an optional
153 default token. If the enum is not found in the map,
154 this method will either use the given default or return
155 false if not default is set */
156 template<typename EnumT
>
157 static bool convertEnum( OUStringBuffer
& rBuffer
,
159 const SvXMLEnumMapEntry
<EnumT
> *pMap
,
160 enum ::xmloff::token::XMLTokenEnum eDefault
=
161 ::xmloff::token::XML_TOKEN_INVALID
)
163 return convertEnumImpl(rBuffer
, static_cast<sal_uInt16
>(nValue
),
164 reinterpret_cast<const SvXMLEnumMapEntry
<sal_uInt16
>*>(pMap
), eDefault
);
167 /** convert double number to string (using ::rtl::math) and DO
168 convert to export MapUnit using meCoreMeasureUnit/meXMLMeasureUnit */
169 void convertDouble(OUStringBuffer
& rBuffer
,
170 double fNumber
) const;
172 /** convert string to double number (using ::rtl::math) and DO convert. */
173 bool convertDouble(double& rValue
, const OUString
& rString
) const;
175 /** get the Null Date of the XModel and set it to the UnitConverter */
177 const css::uno::Reference
<css::frame::XModel
>& xModel
);
179 /** convert double to ISO Date Time String */
180 void convertDateTime( OUStringBuffer
& rBuffer
,
181 const double& fDateTime
,
182 bool const bAddTimeIf0AM
= false);
184 /** convert ISO Date Time String to double */
185 bool convertDateTime(double& fDateTime
,
186 const OUString
& rString
);
188 /// these 2 functions use tools Date, so they're not yet moved to sax
190 /** convert double to ISO Date Time String */
191 static void convertDateTime( OUStringBuffer
& rBuffer
,
192 const double& fDateTime
,
193 const css::util::Date
& aNullDate
,
194 bool bAddTimeIf0AM
= false);
195 /** convert ISO Date Time String to double */
196 static bool convertDateTime( double& fDateTime
,
197 const OUString
& rString
,
198 const css::util::Date
& aNullDate
);
201 /** convert string to ::basegfx::B3DVector */
202 static bool convertB3DVector( ::basegfx::B3DVector
& rVector
,
203 const OUString
& rValue
);
205 /** convert B3DVector to string */
206 static void convertB3DVector( OUStringBuffer
&rBuffer
,
207 const ::basegfx::B3DVector
& rVector
);
209 /** convert string to Position3D */
210 bool convertPosition3D( css::drawing::Position3D
& rPosition
,
211 const OUString
& rValue
);
213 /** convert Position3D to string */
214 void convertPosition3D( OUStringBuffer
&rBuffer
,
215 const css::drawing::Position3D
& rVector
);
218 /** convert num-format and num-letter-sync values to NumberingType */
219 bool convertNumFormat( sal_Int16
& rType
,
220 const OUString
& rNumFormat
,
221 const OUString
& rNumLetterSync
,
222 bool bNumberNone
= false ) const;
224 /** convert NumberingType to num-format and num-letter-sync values */
225 void convertNumFormat( OUStringBuffer
& rBuffer
,
226 sal_Int16 nType
) const;
227 static void convertNumLetterSync( OUStringBuffer
& rBuffer
,
230 static void convertPropertySet(css::uno::Sequence
<css::beans::PropertyValue
>& rProps
,
231 const css::uno::Reference
<css::beans::XPropertySet
>& aProperties
);
232 static void convertPropertySet(css::uno::Reference
<css::beans::XPropertySet
> const & rProperties
,
233 const css::uno::Sequence
<css::beans::PropertyValue
>& aProps
);
235 OUString
encodeStyleName( const OUString
& rName
,
236 bool *pEncoded
=nullptr ) const;
237 /** convert string (hex) to number (sal_uInt32) */
238 static bool convertHex( sal_uInt32
& nVal
,
239 const OUString
& rValue
);
241 /** convert number (sal_uInt32) to string (hex) */
242 static void convertHex( OUStringBuffer
& rBuffer
,
246 static bool convertEnumImpl( sal_uInt16
& rEnum
,
247 const OUString
& rValue
,
248 const SvXMLEnumMapEntry
<sal_uInt16
> *pMap
);
250 static bool convertEnumImpl( sal_uInt16
& rEnum
,
251 const OUString
& rValue
,
252 const SvXMLEnumStringMapEntry
<sal_uInt16
> *pMap
);
254 static bool convertEnumImpl( OUStringBuffer
& rBuffer
,
256 const SvXMLEnumMapEntry
<sal_uInt16
> *pMap
,
257 enum ::xmloff::token::XMLTokenEnum eDefault
);
260 #endif // INCLUDED_XMLOFF_XMLUCONV_HXX
262 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */