xref: /aoo42x/main/xmloff/source/core/xmluconv.cxx (revision 63bba73c)
1*63bba73cSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*63bba73cSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*63bba73cSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*63bba73cSAndrew Rist  * distributed with this work for additional information
6*63bba73cSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*63bba73cSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*63bba73cSAndrew Rist  * "License"); you may not use this file except in compliance
9*63bba73cSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*63bba73cSAndrew Rist  *
11*63bba73cSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*63bba73cSAndrew Rist  *
13*63bba73cSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*63bba73cSAndrew Rist  * software distributed under the License is distributed on an
15*63bba73cSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*63bba73cSAndrew Rist  * KIND, either express or implied.  See the License for the
17*63bba73cSAndrew Rist  * specific language governing permissions and limitations
18*63bba73cSAndrew Rist  * under the License.
19*63bba73cSAndrew Rist  *
20*63bba73cSAndrew Rist  *************************************************************/
21*63bba73cSAndrew Rist 
22*63bba73cSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_xmloff.hxx"
26cdf0e10cSrcweir #include <com/sun/star/util/DateTime.hpp>
27cdf0e10cSrcweir #include <com/sun/star/util/Date.hpp>
28cdf0e10cSrcweir #include <com/sun/star/util/Time.hpp>
29cdf0e10cSrcweir #include <tools/debug.hxx>
30cdf0e10cSrcweir #include <rtl/ustrbuf.hxx>
31cdf0e10cSrcweir #include "xmlehelp.hxx"
32cdf0e10cSrcweir #include <xmloff/xmlement.hxx>
33cdf0e10cSrcweir #include <xmloff/xmluconv.hxx>
34cdf0e10cSrcweir #include <xmloff/xmltoken.hxx>
35cdf0e10cSrcweir #include <rtl/math.hxx>
36cdf0e10cSrcweir #include <rtl/logfile.hxx>
37cdf0e10cSrcweir 
38cdf0e10cSrcweir #ifndef _TOOLS_DATE_HXX
39cdf0e10cSrcweir #include <tools/date.hxx>
40cdf0e10cSrcweir 
41cdf0e10cSrcweir #include <tools/string.hxx>
42cdf0e10cSrcweir 
43cdf0e10cSrcweir #endif
44cdf0e10cSrcweir 
45cdf0e10cSrcweir #include <tools/time.hxx>
46cdf0e10cSrcweir #include <tools/fldunit.hxx>
47cdf0e10cSrcweir 
48cdf0e10cSrcweir // #110680#
49cdf0e10cSrcweir //#ifndef _COMPHELPER_PROCESSFACTORY_HXX_
50cdf0e10cSrcweir //#include <comphelper/processfactory.hxx>
51cdf0e10cSrcweir //#endif
52cdf0e10cSrcweir #include <com/sun/star/util/XNumberFormatsSupplier.hpp>
53cdf0e10cSrcweir #include <com/sun/star/style/NumberingType.hpp>
54cdf0e10cSrcweir #include <com/sun/star/text/XNumberingTypeInfo.hpp>
55cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp>
56cdf0e10cSrcweir #include <com/sun/star/i18n/XCharacterClassification.hpp>
57cdf0e10cSrcweir #include <com/sun/star/i18n/UnicodeType.hpp>
58cdf0e10cSrcweir #include <basegfx/vector/b3dvector.hxx>
59cdf0e10cSrcweir 
60cdf0e10cSrcweir using namespace rtl;
61cdf0e10cSrcweir using namespace com::sun::star;
62cdf0e10cSrcweir using namespace com::sun::star::uno;
63cdf0e10cSrcweir using namespace com::sun::star::lang;
64cdf0e10cSrcweir using namespace com::sun::star::text;
65cdf0e10cSrcweir using namespace com::sun::star::style;
66cdf0e10cSrcweir using namespace ::com::sun::star::i18n;
67cdf0e10cSrcweir using namespace ::xmloff::token;
68cdf0e10cSrcweir 
69cdf0e10cSrcweir const sal_Int8 XML_MAXDIGITSCOUNT_TIME = 11;
70cdf0e10cSrcweir const sal_Int8 XML_MAXDIGITSCOUNT_DATETIME = 6;
71cdf0e10cSrcweir #define XML_NULLDATE "NullDate"
72cdf0e10cSrcweir 
73cdf0e10cSrcweir OUString SvXMLUnitConverter::msXML_true;
74cdf0e10cSrcweir OUString SvXMLUnitConverter::msXML_false;
75cdf0e10cSrcweir 
initXMLStrings()76cdf0e10cSrcweir void SvXMLUnitConverter::initXMLStrings()
77cdf0e10cSrcweir {
78cdf0e10cSrcweir     if( msXML_true.getLength() == 0 )
79cdf0e10cSrcweir     {
80cdf0e10cSrcweir         msXML_true = GetXMLToken(XML_TRUE);
81cdf0e10cSrcweir         msXML_false = GetXMLToken(XML_FALSE);
82cdf0e10cSrcweir     }
83cdf0e10cSrcweir }
84cdf0e10cSrcweir 
createNumTypeInfo() const85cdf0e10cSrcweir void SvXMLUnitConverter::createNumTypeInfo() const
86cdf0e10cSrcweir {
87cdf0e10cSrcweir 	// #110680#
88cdf0e10cSrcweir     //Reference< lang::XMultiServiceFactory > xServiceFactory =
89cdf0e10cSrcweir     //        comphelper::getProcessServiceFactory();
90cdf0e10cSrcweir     //OSL_ENSURE( xServiceFactory.is(),
91cdf0e10cSrcweir     //        "XMLUnitConverter: got no service factory" );
92cdf0e10cSrcweir 
93cdf0e10cSrcweir 	if( mxServiceFactory.is() )
94cdf0e10cSrcweir     {
95cdf0e10cSrcweir         ((SvXMLUnitConverter *)this)->xNumTypeInfo =
96cdf0e10cSrcweir             Reference < XNumberingTypeInfo > (
97cdf0e10cSrcweir                 mxServiceFactory->createInstance(
98cdf0e10cSrcweir                     OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.DefaultNumberingProvider") ) ), UNO_QUERY );
99cdf0e10cSrcweir     }
100cdf0e10cSrcweir }
101cdf0e10cSrcweir 
102cdf0e10cSrcweir /** constructs a SvXMLUnitConverter. The core measure unit is the
103cdf0e10cSrcweir     default unit for numerical measures, the XML measure unit is
104cdf0e10cSrcweir     the default unit for textual measures
105cdf0e10cSrcweir */
106cdf0e10cSrcweir 
107cdf0e10cSrcweir // #110680#
108cdf0e10cSrcweir //SvXMLUnitConverter::SvXMLUnitConverter( MapUnit eCoreMeasureUnit,
109cdf0e10cSrcweir //                                        MapUnit eXMLMeasureUnit ) :
SvXMLUnitConverter(MapUnit eCoreMeasureUnit,MapUnit eXMLMeasureUnit,const uno::Reference<lang::XMultiServiceFactory> & xServiceFactory)110cdf0e10cSrcweir SvXMLUnitConverter::SvXMLUnitConverter(
111cdf0e10cSrcweir 	MapUnit eCoreMeasureUnit,
112cdf0e10cSrcweir 	MapUnit eXMLMeasureUnit,
113cdf0e10cSrcweir 	const uno::Reference<lang::XMultiServiceFactory>& xServiceFactory ) :
114cdf0e10cSrcweir     aNullDate(30, 12, 1899),
115cdf0e10cSrcweir 	mxServiceFactory( xServiceFactory )
116cdf0e10cSrcweir {
117cdf0e10cSrcweir 	DBG_ASSERT( mxServiceFactory.is(), "got no service manager" );
118cdf0e10cSrcweir 
119cdf0e10cSrcweir 	meCoreMeasureUnit = eCoreMeasureUnit;
120cdf0e10cSrcweir     meXMLMeasureUnit = eXMLMeasureUnit;
121cdf0e10cSrcweir }
122cdf0e10cSrcweir 
~SvXMLUnitConverter()123cdf0e10cSrcweir SvXMLUnitConverter::~SvXMLUnitConverter()
124cdf0e10cSrcweir {
125cdf0e10cSrcweir }
126cdf0e10cSrcweir 
GetMapUnit(sal_Int16 nFieldUnit)127cdf0e10cSrcweir MapUnit SvXMLUnitConverter::GetMapUnit(sal_Int16 nFieldUnit)
128cdf0e10cSrcweir {
129cdf0e10cSrcweir     MapUnit eUnit = MAP_INCH;
130cdf0e10cSrcweir     switch( nFieldUnit )
131cdf0e10cSrcweir     {
132cdf0e10cSrcweir     case FUNIT_MM:
133cdf0e10cSrcweir         eUnit = MAP_MM;
134cdf0e10cSrcweir         break;
135cdf0e10cSrcweir     case FUNIT_CM:
136cdf0e10cSrcweir     case FUNIT_M:
137cdf0e10cSrcweir     case FUNIT_KM:
138cdf0e10cSrcweir         eUnit = MAP_CM;
139cdf0e10cSrcweir         break;
140cdf0e10cSrcweir     case FUNIT_TWIP:
141cdf0e10cSrcweir         eUnit = MAP_TWIP;
142cdf0e10cSrcweir         break;
143cdf0e10cSrcweir     case FUNIT_POINT:
144cdf0e10cSrcweir     case FUNIT_PICA:
145cdf0e10cSrcweir         eUnit = MAP_POINT;
146cdf0e10cSrcweir         break;
147cdf0e10cSrcweir //  case FUNIT_INCH:
148cdf0e10cSrcweir //  case FUNIT_FOOT:
149cdf0e10cSrcweir //  case FUNIT_MILE:
150cdf0e10cSrcweir //      eUnit = MAP_INCH;
151cdf0e10cSrcweir //      break;
152cdf0e10cSrcweir     case FUNIT_100TH_MM:
153cdf0e10cSrcweir         eUnit = MAP_100TH_MM;
154cdf0e10cSrcweir         break;
155cdf0e10cSrcweir     }
156cdf0e10cSrcweir     return eUnit;
157cdf0e10cSrcweir }
158cdf0e10cSrcweir 
159cdf0e10cSrcweir /** convert string to measure using optional min and max values*/
convertMeasure(sal_Int32 & nValue,const OUString & rString,sal_Int32 nMin,sal_Int32 nMax) const160cdf0e10cSrcweir sal_Bool SvXMLUnitConverter::convertMeasure( sal_Int32& nValue,
161cdf0e10cSrcweir                                          const OUString& rString,
162cdf0e10cSrcweir                                          sal_Int32 nMin, sal_Int32 nMax ) const
163cdf0e10cSrcweir {
164cdf0e10cSrcweir     return SvXMLUnitConverter::convertMeasure( nValue, rString,
165cdf0e10cSrcweir                                                meCoreMeasureUnit,
166cdf0e10cSrcweir                                                nMin, nMax );
167cdf0e10cSrcweir }
168cdf0e10cSrcweir 
169cdf0e10cSrcweir /** convert measure to string */
convertMeasure(OUStringBuffer & rString,sal_Int32 nMeasure) const170cdf0e10cSrcweir void SvXMLUnitConverter::convertMeasure( OUStringBuffer& rString,
171cdf0e10cSrcweir                                          sal_Int32 nMeasure ) const
172cdf0e10cSrcweir {
173cdf0e10cSrcweir     SvXMLUnitConverter::convertMeasure( rString, nMeasure,
174cdf0e10cSrcweir                                         meCoreMeasureUnit,
175cdf0e10cSrcweir                                         meXMLMeasureUnit );
176cdf0e10cSrcweir }
177cdf0e10cSrcweir 
178cdf0e10cSrcweir /** convert measure with given unit to string */
convertMeasure(OUStringBuffer & rString,sal_Int32 nMeasure,MapUnit eSrcUnit) const179cdf0e10cSrcweir void SvXMLUnitConverter::convertMeasure( OUStringBuffer& rString,
180cdf0e10cSrcweir                                          sal_Int32 nMeasure,
181cdf0e10cSrcweir                                          MapUnit eSrcUnit ) const
182cdf0e10cSrcweir {
183cdf0e10cSrcweir     SvXMLUnitConverter::convertMeasure( rString, nMeasure,
184cdf0e10cSrcweir                                         eSrcUnit,
185cdf0e10cSrcweir                                         meXMLMeasureUnit );
186cdf0e10cSrcweir }
187cdf0e10cSrcweir 
188cdf0e10cSrcweir /** convert the value from the given string to an int value
189cdf0e10cSrcweir     with the given map unit using optional min and max values
190cdf0e10cSrcweir */
convertMeasure(sal_Int32 & rValue,const OUString & rString,MapUnit eDstUnit,sal_Int32 nMin,sal_Int32 nMax)191cdf0e10cSrcweir sal_Bool SvXMLUnitConverter::convertMeasure( sal_Int32& rValue,
192cdf0e10cSrcweir                                          const OUString& rString,
193cdf0e10cSrcweir                                          MapUnit eDstUnit,
194cdf0e10cSrcweir                                          sal_Int32 nMin, sal_Int32 nMax )
195cdf0e10cSrcweir {
196cdf0e10cSrcweir     sal_Bool bNeg = sal_False;
197cdf0e10cSrcweir     double nVal = 0;
198cdf0e10cSrcweir 
199cdf0e10cSrcweir     sal_Int32 nPos = 0;
200cdf0e10cSrcweir     const sal_Int32 nLen = rString.getLength();
201cdf0e10cSrcweir 
202cdf0e10cSrcweir     // skip white space
203cdf0e10cSrcweir     while( (nPos < nLen) && (rString[nPos] <= sal_Unicode(' ')) )
204cdf0e10cSrcweir         nPos++;
205cdf0e10cSrcweir 
206cdf0e10cSrcweir     if( nPos < nLen && sal_Unicode('-') == rString[nPos] )
207cdf0e10cSrcweir     {
208cdf0e10cSrcweir         bNeg = sal_True;
209cdf0e10cSrcweir         ++nPos;
210cdf0e10cSrcweir     }
211cdf0e10cSrcweir 
212cdf0e10cSrcweir     // get number
213cdf0e10cSrcweir     while( nPos < nLen &&
214cdf0e10cSrcweir            sal_Unicode('0') <= rString[nPos] &&
215cdf0e10cSrcweir            sal_Unicode('9') >= rString[nPos] )
216cdf0e10cSrcweir     {
217cdf0e10cSrcweir         // TODO: check overflow!
218cdf0e10cSrcweir         nVal *= 10;
219cdf0e10cSrcweir         nVal += (rString[nPos] - sal_Unicode('0'));
220cdf0e10cSrcweir         ++nPos;
221cdf0e10cSrcweir     }
222cdf0e10cSrcweir     double nDiv = 1.;
223cdf0e10cSrcweir     if( nPos < nLen && sal_Unicode('.') == rString[nPos] )
224cdf0e10cSrcweir     {
225cdf0e10cSrcweir         ++nPos;
226cdf0e10cSrcweir 
227cdf0e10cSrcweir         while( nPos < nLen &&
228cdf0e10cSrcweir                sal_Unicode('0') <= rString[nPos] &&
229cdf0e10cSrcweir                sal_Unicode('9') >= rString[nPos] )
230cdf0e10cSrcweir         {
231cdf0e10cSrcweir             // TODO: check overflow!
232cdf0e10cSrcweir             nDiv *= 10;
233cdf0e10cSrcweir             nVal += ( ((double)(rString[nPos] - sal_Unicode('0'))) / nDiv );
234cdf0e10cSrcweir             ++nPos;
235cdf0e10cSrcweir         }
236cdf0e10cSrcweir     }
237cdf0e10cSrcweir 
238cdf0e10cSrcweir     // skip white space
239cdf0e10cSrcweir     while( (nPos < nLen) && (rString[nPos] <= sal_Unicode(' ')) )
240cdf0e10cSrcweir         ++nPos;
241cdf0e10cSrcweir 
242cdf0e10cSrcweir     if( nPos < nLen )
243cdf0e10cSrcweir     {
244cdf0e10cSrcweir 
245cdf0e10cSrcweir         if( MAP_RELATIVE == eDstUnit )
246cdf0e10cSrcweir         {
247cdf0e10cSrcweir             if( sal_Unicode('%') != rString[nPos] )
248cdf0e10cSrcweir                 return sal_False;
249cdf0e10cSrcweir         }
250cdf0e10cSrcweir         else if( MAP_PIXEL == eDstUnit )
251cdf0e10cSrcweir         {
252cdf0e10cSrcweir             if( nPos + 1 >= nLen ||
253cdf0e10cSrcweir                 (sal_Unicode('p') != rString[nPos] &&
254cdf0e10cSrcweir                  sal_Unicode('P') != rString[nPos])||
255cdf0e10cSrcweir                 (sal_Unicode('x') != rString[nPos+1] &&
256cdf0e10cSrcweir                  sal_Unicode('X') != rString[nPos+1]) )
257cdf0e10cSrcweir                 return sal_False;
258cdf0e10cSrcweir         }
259cdf0e10cSrcweir         else
260cdf0e10cSrcweir         {
261cdf0e10cSrcweir             DBG_ASSERT( MAP_TWIP == eDstUnit || MAP_POINT == eDstUnit ||
262cdf0e10cSrcweir                         MAP_100TH_MM == eDstUnit || MAP_10TH_MM == eDstUnit, "unit is not supported");
263cdf0e10cSrcweir             const sal_Char *aCmpsL[2] = { 0, 0 };
264cdf0e10cSrcweir             const sal_Char *aCmpsU[2] = { 0, 0 };
265cdf0e10cSrcweir             double aScales[2] = { 1., 1. };
266cdf0e10cSrcweir 
267cdf0e10cSrcweir             if( MAP_TWIP == eDstUnit )
268cdf0e10cSrcweir             {
269cdf0e10cSrcweir                 switch( rString[nPos] )
270cdf0e10cSrcweir                 {
271cdf0e10cSrcweir                 case sal_Unicode('c'):
272cdf0e10cSrcweir                 case sal_Unicode('C'):
273cdf0e10cSrcweir                     aCmpsL[0] = "cm";
274cdf0e10cSrcweir                     aCmpsU[0] = "CM";
275cdf0e10cSrcweir                     aScales[0] = (72.*20.)/2.54; // twip
276cdf0e10cSrcweir                     break;
277cdf0e10cSrcweir                 case sal_Unicode('e'):
278cdf0e10cSrcweir                 case sal_Unicode('E'):
279cdf0e10cSrcweir         //          pCmp1 = sXML_unit_em;
280cdf0e10cSrcweir         //          nToken1 = CSS1_EMS;
281cdf0e10cSrcweir 
282cdf0e10cSrcweir         //          pCmp2 = sXML_unit_ex;
283cdf0e10cSrcweir         //          nToken2 = CSS1_EMX;
284cdf0e10cSrcweir                     break;
285cdf0e10cSrcweir                 case sal_Unicode('i'):
286cdf0e10cSrcweir                 case sal_Unicode('I'):
287cdf0e10cSrcweir                     aCmpsL[0] = "in";
288cdf0e10cSrcweir                     aCmpsU[0] = "IN";
289cdf0e10cSrcweir                     aScales[0] = 72.*20.; // twip
290cdf0e10cSrcweir                     break;
291cdf0e10cSrcweir                 case sal_Unicode('m'):
292cdf0e10cSrcweir                 case sal_Unicode('M'):
293cdf0e10cSrcweir                     aCmpsL[0] = "mm";
294cdf0e10cSrcweir                     aCmpsU[0] = "MM";
295cdf0e10cSrcweir                     aScales[0] = (72.*20.)/25.4; // twip
296cdf0e10cSrcweir                     break;
297cdf0e10cSrcweir                 case sal_Unicode('p'):
298cdf0e10cSrcweir                 case sal_Unicode('P'):
299cdf0e10cSrcweir                     aCmpsL[0] = "pt";
300cdf0e10cSrcweir                     aCmpsU[0] = "PT";
301cdf0e10cSrcweir                     aScales[0] = 20.; // twip
302cdf0e10cSrcweir 
303cdf0e10cSrcweir                     aCmpsL[1] = "pc";
304cdf0e10cSrcweir                     aCmpsU[1] = "PC";
305cdf0e10cSrcweir                     aScales[1] = 12.*20.; // twip
306cdf0e10cSrcweir 
307cdf0e10cSrcweir         //          pCmp3 = sXML_unit_px;
308cdf0e10cSrcweir         //          nToken3 = CSS1_PIXLENGTH;
309cdf0e10cSrcweir                     break;
310cdf0e10cSrcweir                 }
311cdf0e10cSrcweir             }
312cdf0e10cSrcweir             else if( MAP_100TH_MM == eDstUnit || MAP_10TH_MM == eDstUnit )
313cdf0e10cSrcweir             {
314cdf0e10cSrcweir 				double nScaleFactor = (MAP_100TH_MM == eDstUnit) ? 100.0 : 10.0;
315cdf0e10cSrcweir                 switch( rString[nPos] )
316cdf0e10cSrcweir                 {
317cdf0e10cSrcweir                 case sal_Unicode('c'):
318cdf0e10cSrcweir                 case sal_Unicode('C'):
319cdf0e10cSrcweir                     aCmpsL[0] = "cm";
320cdf0e10cSrcweir                     aCmpsU[0] = "CM";
321cdf0e10cSrcweir                     aScales[0] = 10.0 * nScaleFactor; // mm/100
322cdf0e10cSrcweir                     break;
323cdf0e10cSrcweir                 case sal_Unicode('e'):
324cdf0e10cSrcweir                 case sal_Unicode('E'):
325cdf0e10cSrcweir         //          pCmp1 = sXML_unit_em;
326cdf0e10cSrcweir         //          nToken1 = CSS1_EMS;
327cdf0e10cSrcweir 
328cdf0e10cSrcweir         //          pCmp2 = sXML_unit_ex;
329cdf0e10cSrcweir         //          nToken2 = CSS1_EMX;
330cdf0e10cSrcweir                     break;
331cdf0e10cSrcweir                 case sal_Unicode('i'):
332cdf0e10cSrcweir                 case sal_Unicode('I'):
333cdf0e10cSrcweir                     aCmpsL[0] = "in";
334cdf0e10cSrcweir                     aCmpsU[0] = "IN";
335cdf0e10cSrcweir                     aScales[0] = 1000.*2.54; // mm/100
336cdf0e10cSrcweir                     break;
337cdf0e10cSrcweir                 case sal_Unicode('m'):
338cdf0e10cSrcweir                 case sal_Unicode('M'):
339cdf0e10cSrcweir                     aCmpsL[0] = "mm";
340cdf0e10cSrcweir                     aCmpsU[0] = "MM";
341cdf0e10cSrcweir                     aScales[0] = 1.0 * nScaleFactor; // mm/100
342cdf0e10cSrcweir                     break;
343cdf0e10cSrcweir                 case sal_Unicode('p'):
344cdf0e10cSrcweir                 case sal_Unicode('P'):
345cdf0e10cSrcweir                     aCmpsL[0] = "pt";
346cdf0e10cSrcweir                     aCmpsU[0] = "PT";
347cdf0e10cSrcweir                     aScales[0] = (10.0 * nScaleFactor*2.54)/72.; // mm/100
348cdf0e10cSrcweir 
349cdf0e10cSrcweir                     aCmpsL[1] = "pc";
350cdf0e10cSrcweir                     aCmpsU[1] = "PC";
351cdf0e10cSrcweir                     aScales[1] = (10.0 * nScaleFactor*2.54)/12.; // mm/100
352cdf0e10cSrcweir 
353cdf0e10cSrcweir         //          pCmp3 = sXML_unit_px;
354cdf0e10cSrcweir         //          nToken3 = CSS1_PIXLENGTH;
355cdf0e10cSrcweir                     break;
356cdf0e10cSrcweir                 }
357cdf0e10cSrcweir             }
358cdf0e10cSrcweir             else if( MAP_POINT == eDstUnit )
359cdf0e10cSrcweir             {
360cdf0e10cSrcweir                 if( rString[nPos] == 'p' || rString[nPos] == 'P' )
361cdf0e10cSrcweir                 {
362cdf0e10cSrcweir                     aCmpsL[0] = "pt";
363cdf0e10cSrcweir                     aCmpsU[0] = "PT";
364cdf0e10cSrcweir                     aScales[0] = 1;
365cdf0e10cSrcweir                 }
366cdf0e10cSrcweir             }
367cdf0e10cSrcweir 
368cdf0e10cSrcweir             if( aCmpsL[0] == NULL )
369cdf0e10cSrcweir                 return sal_False;
370cdf0e10cSrcweir 
371cdf0e10cSrcweir             double nScale = 0.;
372cdf0e10cSrcweir             for( sal_uInt16 i= 0; i < 2; ++i )
373cdf0e10cSrcweir             {
374cdf0e10cSrcweir                 const sal_Char *pL = aCmpsL[i];
375cdf0e10cSrcweir                 if( pL )
376cdf0e10cSrcweir                 {
377cdf0e10cSrcweir                     const sal_Char *pU = aCmpsU[i];
378cdf0e10cSrcweir                     while( nPos < nLen && *pL )
379cdf0e10cSrcweir                     {
380cdf0e10cSrcweir                         sal_Unicode c = rString[nPos];
381cdf0e10cSrcweir                         if( c != *pL && c != *pU )
382cdf0e10cSrcweir                             break;
383cdf0e10cSrcweir                         ++pL;
384cdf0e10cSrcweir                         ++pU;
385cdf0e10cSrcweir                         ++nPos;
386cdf0e10cSrcweir                     }
387cdf0e10cSrcweir                     if( !*pL && (nPos == nLen || ' ' == rString[nPos]) )
388cdf0e10cSrcweir                     {
389cdf0e10cSrcweir                         nScale = aScales[i];
390cdf0e10cSrcweir                         break;
391cdf0e10cSrcweir                     }
392cdf0e10cSrcweir                 }
393cdf0e10cSrcweir             }
394cdf0e10cSrcweir 
395cdf0e10cSrcweir             if( 0. == nScale )
396cdf0e10cSrcweir                 return sal_False;
397cdf0e10cSrcweir 
398cdf0e10cSrcweir             // TODO: check overflow
399cdf0e10cSrcweir             if( nScale != 1. )
400cdf0e10cSrcweir                 nVal *= nScale;
401cdf0e10cSrcweir         }
402cdf0e10cSrcweir     }
403cdf0e10cSrcweir 
404cdf0e10cSrcweir     nVal += .5;
405cdf0e10cSrcweir     if( bNeg )
406cdf0e10cSrcweir         nVal = -nVal;
407cdf0e10cSrcweir 
408cdf0e10cSrcweir     if( nVal <= (double)nMin )
409cdf0e10cSrcweir         rValue = nMin;
410cdf0e10cSrcweir     else if( nVal >= (double)nMax )
411cdf0e10cSrcweir         rValue = nMax;
412cdf0e10cSrcweir     else
413cdf0e10cSrcweir         rValue = (sal_Int32)nVal;
414cdf0e10cSrcweir 
415cdf0e10cSrcweir     return sal_True;
416cdf0e10cSrcweir }
417cdf0e10cSrcweir 
418cdf0e10cSrcweir /** convert measure in given unit to string with given unit */
convertMeasure(OUStringBuffer & rBuffer,sal_Int32 nMeasure,MapUnit eSrcUnit,MapUnit eDstUnit)419cdf0e10cSrcweir void SvXMLUnitConverter::convertMeasure( OUStringBuffer& rBuffer,
420cdf0e10cSrcweir                                          sal_Int32 nMeasure,
421cdf0e10cSrcweir                                          MapUnit eSrcUnit,
422cdf0e10cSrcweir                                          MapUnit eDstUnit )
423cdf0e10cSrcweir {
424cdf0e10cSrcweir     if( eSrcUnit == MAP_RELATIVE )
425cdf0e10cSrcweir     {
426cdf0e10cSrcweir         DBG_ASSERT( eDstUnit == MAP_RELATIVE,
427cdf0e10cSrcweir                     "MAP_RELATIVE only maps to MAP_RELATIVE!" );
428cdf0e10cSrcweir 
429cdf0e10cSrcweir         rBuffer.append( nMeasure );
430cdf0e10cSrcweir         rBuffer.append( sal_Unicode('%' ) );
431cdf0e10cSrcweir     }
432cdf0e10cSrcweir     else
433cdf0e10cSrcweir     {
434cdf0e10cSrcweir         SvXMLExportHelper::AddLength( nMeasure, eSrcUnit,
435cdf0e10cSrcweir                                       rBuffer, eDstUnit );
436cdf0e10cSrcweir     }
437cdf0e10cSrcweir }
438cdf0e10cSrcweir 
439cdf0e10cSrcweir /** convert string to boolean */
convertBool(sal_Bool & rBool,const OUString & rString)440cdf0e10cSrcweir sal_Bool SvXMLUnitConverter::convertBool( sal_Bool& rBool,
441cdf0e10cSrcweir                                       const OUString& rString )
442cdf0e10cSrcweir {
443cdf0e10cSrcweir     rBool = IsXMLToken(rString, XML_TRUE);
444cdf0e10cSrcweir 
445cdf0e10cSrcweir     return rBool || IsXMLToken(rString, XML_FALSE);
446cdf0e10cSrcweir }
447cdf0e10cSrcweir 
448cdf0e10cSrcweir /** convert boolean to string */
convertBool(OUStringBuffer & rBuffer,sal_Bool bValue)449cdf0e10cSrcweir void SvXMLUnitConverter::convertBool( OUStringBuffer& rBuffer,
450cdf0e10cSrcweir                                       sal_Bool bValue )
451cdf0e10cSrcweir {
452cdf0e10cSrcweir     rBuffer.append( GetXMLToken( bValue ? XML_TRUE : XML_FALSE ) );
453cdf0e10cSrcweir }
454cdf0e10cSrcweir 
455cdf0e10cSrcweir /** convert string to percent */
convertPercent(sal_Int32 & rPercent,const OUString & rString)456cdf0e10cSrcweir sal_Bool SvXMLUnitConverter::convertPercent( sal_Int32& rPercent,
457cdf0e10cSrcweir                                          const OUString& rString )
458cdf0e10cSrcweir {
459cdf0e10cSrcweir     return convertMeasure( rPercent, rString, MAP_RELATIVE );
460cdf0e10cSrcweir }
461cdf0e10cSrcweir 
462cdf0e10cSrcweir /** convert percent to string */
convertPercent(OUStringBuffer & rBuffer,sal_Int32 nValue)463cdf0e10cSrcweir void SvXMLUnitConverter::convertPercent( OUStringBuffer& rBuffer,
464cdf0e10cSrcweir                                          sal_Int32 nValue )
465cdf0e10cSrcweir {
466cdf0e10cSrcweir     rBuffer.append( nValue );
467cdf0e10cSrcweir     rBuffer.append( sal_Unicode('%' ) );
468cdf0e10cSrcweir }
469cdf0e10cSrcweir 
470cdf0e10cSrcweir /** convert string to pixel measure */
convertMeasurePx(sal_Int32 & rPixel,const OUString & rString)471cdf0e10cSrcweir sal_Bool SvXMLUnitConverter::convertMeasurePx( sal_Int32& rPixel,
472cdf0e10cSrcweir                                          const OUString& rString )
473cdf0e10cSrcweir {
474cdf0e10cSrcweir     return convertMeasure( rPixel, rString, MAP_PIXEL );
475cdf0e10cSrcweir }
476cdf0e10cSrcweir 
477cdf0e10cSrcweir /** convert pixel measure to string */
convertMeasurePx(OUStringBuffer & rBuffer,sal_Int32 nValue)478cdf0e10cSrcweir void SvXMLUnitConverter::convertMeasurePx( OUStringBuffer& rBuffer,
479cdf0e10cSrcweir                                          sal_Int32 nValue )
480cdf0e10cSrcweir {
481cdf0e10cSrcweir     rBuffer.append( nValue );
482cdf0e10cSrcweir     rBuffer.append( sal_Unicode('p' ) );
483cdf0e10cSrcweir     rBuffer.append( sal_Unicode('x' ) );
484cdf0e10cSrcweir }
485cdf0e10cSrcweir 
486cdf0e10cSrcweir /** convert string to enum using given enum map, if the enum is
487cdf0e10cSrcweir     not found in the map, this method will return false
488cdf0e10cSrcweir */
convertEnum(sal_uInt16 & rEnum,const OUString & rValue,const SvXMLEnumStringMapEntry * pMap)489cdf0e10cSrcweir sal_Bool SvXMLUnitConverter::convertEnum( sal_uInt16& rEnum,
490cdf0e10cSrcweir                                       const OUString& rValue,
491cdf0e10cSrcweir                                       const SvXMLEnumStringMapEntry *pMap )
492cdf0e10cSrcweir {
493cdf0e10cSrcweir     while( pMap->pName )
494cdf0e10cSrcweir     {
495cdf0e10cSrcweir         if( rValue.equalsAsciiL( pMap->pName, pMap->nNameLength ) )
496cdf0e10cSrcweir         {
497cdf0e10cSrcweir             rEnum = pMap->nValue;
498cdf0e10cSrcweir             return sal_True;
499cdf0e10cSrcweir         }
500cdf0e10cSrcweir         ++pMap;
501cdf0e10cSrcweir     }
502cdf0e10cSrcweir 
503cdf0e10cSrcweir     return sal_False;
504cdf0e10cSrcweir }
505cdf0e10cSrcweir 
506cdf0e10cSrcweir /** convert string to enum using given token map, if the enum is
507cdf0e10cSrcweir     not found in the map, this method will return false */
convertEnum(sal_uInt16 & rEnum,const OUString & rValue,const SvXMLEnumMapEntry * pMap)508cdf0e10cSrcweir sal_Bool SvXMLUnitConverter::convertEnum(
509cdf0e10cSrcweir     sal_uInt16& rEnum,
510cdf0e10cSrcweir     const OUString& rValue,
511cdf0e10cSrcweir     const SvXMLEnumMapEntry *pMap )
512cdf0e10cSrcweir {
513cdf0e10cSrcweir     while( pMap->eToken != XML_TOKEN_INVALID )
514cdf0e10cSrcweir     {
515cdf0e10cSrcweir         if( IsXMLToken( rValue, pMap->eToken ) )
516cdf0e10cSrcweir         {
517cdf0e10cSrcweir             rEnum = pMap->nValue;
518cdf0e10cSrcweir             return sal_True;
519cdf0e10cSrcweir         }
520cdf0e10cSrcweir         ++pMap;
521cdf0e10cSrcweir     }
522cdf0e10cSrcweir     return sal_False;
523cdf0e10cSrcweir }
524cdf0e10cSrcweir 
525cdf0e10cSrcweir /** convert enum to string using given enum map with optional
526cdf0e10cSrcweir     default string. If the enum is not found in the map,
527cdf0e10cSrcweir     this method will either use the given default or return
528cdf0e10cSrcweir     false if not default is set
529cdf0e10cSrcweir */
convertEnum(OUStringBuffer & rBuffer,sal_uInt16 nValue,const SvXMLEnumStringMapEntry * pMap,sal_Char * pDefault)530cdf0e10cSrcweir sal_Bool SvXMLUnitConverter::convertEnum( OUStringBuffer& rBuffer,
531cdf0e10cSrcweir                                       sal_uInt16 nValue,
532cdf0e10cSrcweir                                       const SvXMLEnumStringMapEntry *pMap,
533cdf0e10cSrcweir                                       sal_Char * pDefault /* = NULL */ )
534cdf0e10cSrcweir {
535cdf0e10cSrcweir     const sal_Char *pStr = pDefault;
536cdf0e10cSrcweir 
537cdf0e10cSrcweir     while( pMap->pName )
538cdf0e10cSrcweir     {
539cdf0e10cSrcweir         if( pMap->nValue == nValue )
540cdf0e10cSrcweir         {
541cdf0e10cSrcweir             pStr = pMap->pName;
542cdf0e10cSrcweir             break;
543cdf0e10cSrcweir         }
544cdf0e10cSrcweir         ++pMap;
545cdf0e10cSrcweir     }
546cdf0e10cSrcweir 
547cdf0e10cSrcweir     if( NULL == pStr )
548cdf0e10cSrcweir         pStr = pDefault;
549cdf0e10cSrcweir 
550cdf0e10cSrcweir     if( NULL != pStr )
551cdf0e10cSrcweir         rBuffer.appendAscii( pStr );
552cdf0e10cSrcweir 
553cdf0e10cSrcweir     return NULL != pStr;
554cdf0e10cSrcweir }
555cdf0e10cSrcweir 
556cdf0e10cSrcweir /** convert enum to string using given token map with an optional
557cdf0e10cSrcweir     default token. If the enum is not found in the map,
558cdf0e10cSrcweir     this method will either use the given default or return
559cdf0e10cSrcweir     false if no default is set */
convertEnum(OUStringBuffer & rBuffer,unsigned int nValue,const SvXMLEnumMapEntry * pMap,enum XMLTokenEnum eDefault)560cdf0e10cSrcweir sal_Bool SvXMLUnitConverter::convertEnum(
561cdf0e10cSrcweir     OUStringBuffer& rBuffer,
562cdf0e10cSrcweir     unsigned int nValue,
563cdf0e10cSrcweir     const SvXMLEnumMapEntry *pMap,
564cdf0e10cSrcweir     enum XMLTokenEnum eDefault)
565cdf0e10cSrcweir {
566cdf0e10cSrcweir     enum XMLTokenEnum eTok = eDefault;
567cdf0e10cSrcweir 
568cdf0e10cSrcweir     while( pMap->eToken != XML_TOKEN_INVALID )
569cdf0e10cSrcweir     {
570cdf0e10cSrcweir         if( pMap->nValue == nValue )
571cdf0e10cSrcweir         {
572cdf0e10cSrcweir             eTok = pMap->eToken;
573cdf0e10cSrcweir             break;
574cdf0e10cSrcweir         }
575cdf0e10cSrcweir         ++pMap;
576cdf0e10cSrcweir     }
577cdf0e10cSrcweir 
578cdf0e10cSrcweir     // the map may have contained XML_TOKEN_INVALID
579cdf0e10cSrcweir     if( eTok == XML_TOKEN_INVALID )
580cdf0e10cSrcweir         eTok = eDefault;
581cdf0e10cSrcweir 
582cdf0e10cSrcweir     if( eTok != XML_TOKEN_INVALID )
583cdf0e10cSrcweir         rBuffer.append( GetXMLToken(eTok) );
584cdf0e10cSrcweir 
585cdf0e10cSrcweir     return (eTok != XML_TOKEN_INVALID);
586cdf0e10cSrcweir }
587cdf0e10cSrcweir 
lcl_gethex(int nChar)588cdf0e10cSrcweir int lcl_gethex( int nChar )
589cdf0e10cSrcweir {
590cdf0e10cSrcweir     if( nChar >= '0' && nChar <= '9' )
591cdf0e10cSrcweir         return nChar - '0';
592cdf0e10cSrcweir     else if( nChar >= 'a' && nChar <= 'f' )
593cdf0e10cSrcweir         return nChar - 'a' + 10;
594cdf0e10cSrcweir     else if( nChar >= 'A' && nChar <= 'F' )
595cdf0e10cSrcweir         return nChar - 'A' + 10;
596cdf0e10cSrcweir     else
597cdf0e10cSrcweir         return 0;
598cdf0e10cSrcweir }
599cdf0e10cSrcweir 
600cdf0e10cSrcweir /** convert string to color */
convertColor(Color & rColor,const OUString & rValue)601cdf0e10cSrcweir sal_Bool SvXMLUnitConverter::convertColor( Color& rColor,
602cdf0e10cSrcweir                                        const OUString& rValue )
603cdf0e10cSrcweir {
604cdf0e10cSrcweir     if( rValue.getLength() != 7 || rValue[0] != '#' )
605cdf0e10cSrcweir         return sal_False;
606cdf0e10cSrcweir 
607cdf0e10cSrcweir     rColor.SetRed(
608cdf0e10cSrcweir         sal::static_int_cast< sal_uInt8 >(
609cdf0e10cSrcweir             lcl_gethex( rValue[1] ) * 16 + lcl_gethex( rValue[2] ) ) );
610cdf0e10cSrcweir 
611cdf0e10cSrcweir     rColor.SetGreen(
612cdf0e10cSrcweir         sal::static_int_cast< sal_uInt8 >(
613cdf0e10cSrcweir             lcl_gethex( rValue[3] ) * 16 + lcl_gethex( rValue[4] ) ) );
614cdf0e10cSrcweir 
615cdf0e10cSrcweir     rColor.SetBlue(
616cdf0e10cSrcweir         sal::static_int_cast< sal_uInt8 >(
617cdf0e10cSrcweir             lcl_gethex( rValue[5] ) * 16 + lcl_gethex( rValue[6] ) ) );
618cdf0e10cSrcweir 
619cdf0e10cSrcweir     return sal_True;
620cdf0e10cSrcweir }
621cdf0e10cSrcweir 
622cdf0e10cSrcweir static sal_Char aHexTab[] = "0123456789abcdef";
623cdf0e10cSrcweir 
624cdf0e10cSrcweir /** convert color to string */
convertColor(OUStringBuffer & rBuffer,const Color & rCol)625cdf0e10cSrcweir void SvXMLUnitConverter::convertColor( OUStringBuffer& rBuffer,
626cdf0e10cSrcweir                                        const Color& rCol )
627cdf0e10cSrcweir {
628cdf0e10cSrcweir     rBuffer.append( sal_Unicode( '#' ) );
629cdf0e10cSrcweir 
630cdf0e10cSrcweir     sal_uInt8 nCol = rCol.GetRed();
631cdf0e10cSrcweir     rBuffer.append( sal_Unicode( aHexTab[ nCol >> 4 ] ) );
632cdf0e10cSrcweir     rBuffer.append( sal_Unicode( aHexTab[ nCol & 0xf ] ) );
633cdf0e10cSrcweir 
634cdf0e10cSrcweir     nCol = rCol.GetGreen();
635cdf0e10cSrcweir     rBuffer.append( sal_Unicode( aHexTab[ nCol >> 4 ] ) );
636cdf0e10cSrcweir     rBuffer.append( sal_Unicode( aHexTab[ nCol & 0xf ] ) );
637cdf0e10cSrcweir 
638cdf0e10cSrcweir     nCol = rCol.GetBlue();
639cdf0e10cSrcweir     rBuffer.append( sal_Unicode( aHexTab[ nCol >> 4 ] ) );
640cdf0e10cSrcweir     rBuffer.append( sal_Unicode( aHexTab[ nCol & 0xf ] ) );
641cdf0e10cSrcweir }
642cdf0e10cSrcweir 
643cdf0e10cSrcweir /** convert number to string */
convertNumber(OUStringBuffer & rBuffer,sal_Int32 nNumber)644cdf0e10cSrcweir void SvXMLUnitConverter::convertNumber( OUStringBuffer& rBuffer,
645cdf0e10cSrcweir                                         sal_Int32 nNumber )
646cdf0e10cSrcweir {
647cdf0e10cSrcweir     rBuffer.append( sal_Int32( nNumber ) );
648cdf0e10cSrcweir }
649cdf0e10cSrcweir 
650cdf0e10cSrcweir /** convert string to number with optional min and max values */
convertNumber(sal_Int32 & rValue,const OUString & rString,sal_Int32 nMin,sal_Int32 nMax)651cdf0e10cSrcweir sal_Bool SvXMLUnitConverter::convertNumber( sal_Int32& rValue,
652cdf0e10cSrcweir                                         const OUString& rString,
653cdf0e10cSrcweir                                         sal_Int32 nMin, sal_Int32 nMax )
654cdf0e10cSrcweir {
655cdf0e10cSrcweir     rValue = 0;
656cdf0e10cSrcweir     sal_Int64 nNumber = 0;
657cdf0e10cSrcweir     sal_Bool bRet = convertNumber64(nNumber,rString,nMin,nMax);
658cdf0e10cSrcweir     if ( bRet )
659cdf0e10cSrcweir         rValue = static_cast<sal_Int32>(nNumber);
660cdf0e10cSrcweir     return bRet;
661cdf0e10cSrcweir }
662cdf0e10cSrcweir 
663cdf0e10cSrcweir /** convert 64-bit number to string */
convertNumber64(OUStringBuffer & rBuffer,sal_Int64 nNumber)664cdf0e10cSrcweir void SvXMLUnitConverter::convertNumber64( OUStringBuffer& rBuffer,
665cdf0e10cSrcweir                                         sal_Int64 nNumber )
666cdf0e10cSrcweir {
667cdf0e10cSrcweir     rBuffer.append( nNumber );
668cdf0e10cSrcweir }
669cdf0e10cSrcweir 
670cdf0e10cSrcweir /** convert string to 64-bit number with optional min and max values */
convertNumber64(sal_Int64 & rValue,const OUString & rString,sal_Int64 nMin,sal_Int64 nMax)671cdf0e10cSrcweir sal_Bool SvXMLUnitConverter::convertNumber64( sal_Int64& rValue,
672cdf0e10cSrcweir                                         const OUString& rString,
673cdf0e10cSrcweir                                         sal_Int64 nMin, sal_Int64 nMax )
674cdf0e10cSrcweir {
675cdf0e10cSrcweir     sal_Bool bNeg = sal_False;
676cdf0e10cSrcweir     rValue = 0;
677cdf0e10cSrcweir 
678cdf0e10cSrcweir     sal_Int32 nPos = 0;
679cdf0e10cSrcweir     const sal_Int32 nLen = rString.getLength();
680cdf0e10cSrcweir 
681cdf0e10cSrcweir     // skip white space
682cdf0e10cSrcweir     while( (nPos < nLen) && (rString[nPos] <= sal_Unicode(' ')) )
683cdf0e10cSrcweir         ++nPos;
684cdf0e10cSrcweir 
685cdf0e10cSrcweir     if( nPos < nLen && sal_Unicode('-') == rString[nPos] )
686cdf0e10cSrcweir     {
687cdf0e10cSrcweir         bNeg = sal_True;
688cdf0e10cSrcweir         ++nPos;
689cdf0e10cSrcweir     }
690cdf0e10cSrcweir 
691cdf0e10cSrcweir     // get number
692cdf0e10cSrcweir     while( nPos < nLen &&
693cdf0e10cSrcweir            sal_Unicode('0') <= rString[nPos] &&
694cdf0e10cSrcweir            sal_Unicode('9') >= rString[nPos] )
695cdf0e10cSrcweir     {
696cdf0e10cSrcweir         // TODO: check overflow!
697cdf0e10cSrcweir         rValue *= 10;
698cdf0e10cSrcweir         rValue += (rString[nPos] - sal_Unicode('0'));
699cdf0e10cSrcweir         ++nPos;
700cdf0e10cSrcweir     }
701cdf0e10cSrcweir 
702cdf0e10cSrcweir     if( bNeg )
703cdf0e10cSrcweir         rValue *= -1;
704cdf0e10cSrcweir 
705cdf0e10cSrcweir     return ( nPos == nLen && rValue >= nMin && rValue <= nMax );
706cdf0e10cSrcweir }
707cdf0e10cSrcweir 
708cdf0e10cSrcweir /** convert double number to string (using ::rtl::math) */
convertDouble(::rtl::OUStringBuffer & rBuffer,double fNumber,sal_Bool bWriteUnits) const709cdf0e10cSrcweir void SvXMLUnitConverter::convertDouble(::rtl::OUStringBuffer& rBuffer,
710cdf0e10cSrcweir     double fNumber, sal_Bool bWriteUnits) const
711cdf0e10cSrcweir {
712cdf0e10cSrcweir     SvXMLUnitConverter::convertDouble(rBuffer, fNumber,
713cdf0e10cSrcweir         bWriteUnits, meCoreMeasureUnit, meXMLMeasureUnit);
714cdf0e10cSrcweir }
715cdf0e10cSrcweir 
716cdf0e10cSrcweir /** convert double number to string (using ::rtl::math) */
convertDouble(::rtl::OUStringBuffer & rBuffer,double fNumber,sal_Bool bWriteUnits,MapUnit eCoreUnit,MapUnit eDstUnit)717cdf0e10cSrcweir void SvXMLUnitConverter::convertDouble( ::rtl::OUStringBuffer& rBuffer,
718cdf0e10cSrcweir     double fNumber, sal_Bool bWriteUnits, MapUnit eCoreUnit, MapUnit eDstUnit)
719cdf0e10cSrcweir {
720cdf0e10cSrcweir     if(MAP_RELATIVE == eCoreUnit)
721cdf0e10cSrcweir     {
722cdf0e10cSrcweir         DBG_ASSERT(eDstUnit == MAP_RELATIVE, "MAP_RELATIVE only maps to MAP_RELATIVE!" );
723cdf0e10cSrcweir         ::rtl::math::doubleToUStringBuffer( rBuffer, fNumber, rtl_math_StringFormat_Automatic, rtl_math_DecimalPlaces_Max, '.', sal_True);
724cdf0e10cSrcweir         if(bWriteUnits)
725cdf0e10cSrcweir             rBuffer.append(sal_Unicode('%'));
726cdf0e10cSrcweir     }
727cdf0e10cSrcweir     else
728cdf0e10cSrcweir     {
729cdf0e10cSrcweir         OUStringBuffer sUnit;
730cdf0e10cSrcweir         double fFactor = SvXMLExportHelper::GetConversionFactor(sUnit, eCoreUnit, eDstUnit);
731cdf0e10cSrcweir         if(fFactor != 1.0)
732cdf0e10cSrcweir             fNumber *= fFactor;
733cdf0e10cSrcweir         ::rtl::math::doubleToUStringBuffer( rBuffer, fNumber, rtl_math_StringFormat_Automatic, rtl_math_DecimalPlaces_Max, '.', sal_True);
734cdf0e10cSrcweir         if(bWriteUnits)
735cdf0e10cSrcweir             rBuffer.append(sUnit);
736cdf0e10cSrcweir     }
737cdf0e10cSrcweir }
738cdf0e10cSrcweir 
739cdf0e10cSrcweir /** convert double number to string (using ::rtl::math) */
convertDouble(::rtl::OUStringBuffer & rBuffer,double fNumber)740cdf0e10cSrcweir void SvXMLUnitConverter::convertDouble( ::rtl::OUStringBuffer& rBuffer, double fNumber)
741cdf0e10cSrcweir {
742cdf0e10cSrcweir     ::rtl::math::doubleToUStringBuffer( rBuffer, fNumber, rtl_math_StringFormat_Automatic, rtl_math_DecimalPlaces_Max, '.', sal_True);
743cdf0e10cSrcweir }
744cdf0e10cSrcweir 
745cdf0e10cSrcweir /** convert string to double number (using ::rtl::math) */
convertDouble(double & rValue,const::rtl::OUString & rString,sal_Bool bLookForUnits) const746cdf0e10cSrcweir sal_Bool SvXMLUnitConverter::convertDouble(double& rValue,
747cdf0e10cSrcweir     const ::rtl::OUString& rString, sal_Bool bLookForUnits) const
748cdf0e10cSrcweir {
749cdf0e10cSrcweir     if(bLookForUnits)
750cdf0e10cSrcweir     {
751cdf0e10cSrcweir         MapUnit eSrcUnit = SvXMLExportHelper::GetUnitFromString(rString, meCoreMeasureUnit);
752cdf0e10cSrcweir 
753cdf0e10cSrcweir         return SvXMLUnitConverter::convertDouble(rValue, rString,
754cdf0e10cSrcweir             eSrcUnit, meCoreMeasureUnit);
755cdf0e10cSrcweir     }
756cdf0e10cSrcweir     else
757cdf0e10cSrcweir     {
758cdf0e10cSrcweir         return SvXMLUnitConverter::convertDouble(rValue, rString);
759cdf0e10cSrcweir     }
760cdf0e10cSrcweir }
761cdf0e10cSrcweir 
762cdf0e10cSrcweir /** convert string to double number (using ::rtl::math) */
convertDouble(double & rValue,const::rtl::OUString & rString,MapUnit eSrcUnit,MapUnit eCoreUnit)763cdf0e10cSrcweir sal_Bool SvXMLUnitConverter::convertDouble(double& rValue,
764cdf0e10cSrcweir     const ::rtl::OUString& rString, MapUnit eSrcUnit, MapUnit eCoreUnit)
765cdf0e10cSrcweir {
766cdf0e10cSrcweir     rtl_math_ConversionStatus eStatus;
767cdf0e10cSrcweir     rValue = ::rtl::math::stringToDouble( rString, (sal_Unicode)('.'), (sal_Unicode)(','), &eStatus, NULL );
768cdf0e10cSrcweir 
769cdf0e10cSrcweir     if(eStatus == rtl_math_ConversionStatus_Ok)
770cdf0e10cSrcweir     {
771cdf0e10cSrcweir         OUStringBuffer sUnit;
772cdf0e10cSrcweir         const double fFactor = SvXMLExportHelper::GetConversionFactor(sUnit, eCoreUnit, eSrcUnit);
773cdf0e10cSrcweir         if(fFactor != 1.0 && fFactor != 0.0)
774cdf0e10cSrcweir             rValue /= fFactor;
775cdf0e10cSrcweir     }
776cdf0e10cSrcweir 
777cdf0e10cSrcweir     return ( eStatus == rtl_math_ConversionStatus_Ok );
778cdf0e10cSrcweir }
779cdf0e10cSrcweir 
780cdf0e10cSrcweir /** convert string to double number (using ::rtl::math) */
convertDouble(double & rValue,const::rtl::OUString & rString)781cdf0e10cSrcweir sal_Bool SvXMLUnitConverter::convertDouble(double& rValue, const ::rtl::OUString& rString)
782cdf0e10cSrcweir {
783cdf0e10cSrcweir     rtl_math_ConversionStatus eStatus;
784cdf0e10cSrcweir     rValue = ::rtl::math::stringToDouble( rString, (sal_Unicode)('.'), (sal_Unicode)(','), &eStatus, NULL );
785cdf0e10cSrcweir     return ( eStatus == rtl_math_ConversionStatus_Ok );
786cdf0e10cSrcweir }
787cdf0e10cSrcweir 
788cdf0e10cSrcweir /** get the Null Date of the XModel and set it to the UnitConverter */
setNullDate(const com::sun::star::uno::Reference<com::sun::star::frame::XModel> & xModel)789cdf0e10cSrcweir sal_Bool SvXMLUnitConverter::setNullDate(const com::sun::star::uno::Reference <com::sun::star::frame::XModel>& xModel)
790cdf0e10cSrcweir {
791cdf0e10cSrcweir     com::sun::star::uno::Reference <com::sun::star::util::XNumberFormatsSupplier> xNumberFormatsSupplier (xModel, com::sun::star::uno::UNO_QUERY);
792cdf0e10cSrcweir     if (xNumberFormatsSupplier.is())
793cdf0e10cSrcweir     {
794cdf0e10cSrcweir         const com::sun::star::uno::Reference <com::sun::star::beans::XPropertySet> xPropertySet = xNumberFormatsSupplier->getNumberFormatSettings();
795cdf0e10cSrcweir         return xPropertySet.is() && (xPropertySet->getPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(XML_NULLDATE))) >>= aNullDate);
796cdf0e10cSrcweir     }
797cdf0e10cSrcweir     return sal_False;
798cdf0e10cSrcweir }
799cdf0e10cSrcweir 
800cdf0e10cSrcweir /** convert double to ISO Time String; negative durations allowed */
convertTime(::rtl::OUStringBuffer & rBuffer,const double & fTime)801cdf0e10cSrcweir void SvXMLUnitConverter::convertTime( ::rtl::OUStringBuffer& rBuffer,
802cdf0e10cSrcweir                             const double& fTime)
803cdf0e10cSrcweir {
804cdf0e10cSrcweir 
805cdf0e10cSrcweir     double fValue = fTime;
806cdf0e10cSrcweir 
807cdf0e10cSrcweir     // take care of negative durations as specified in:
808cdf0e10cSrcweir     // XML Schema, W3C Working Draft 07 April 2000, section 3.2.6.1
809cdf0e10cSrcweir     if (fValue < 0.0)
810cdf0e10cSrcweir     {
811cdf0e10cSrcweir         rBuffer.append(sal_Unicode('-'));
812cdf0e10cSrcweir         fValue = - fValue;
813cdf0e10cSrcweir     }
814cdf0e10cSrcweir 
815cdf0e10cSrcweir     rBuffer.appendAscii(RTL_CONSTASCII_STRINGPARAM( "PT" ));
816cdf0e10cSrcweir     fValue *= 24;
817cdf0e10cSrcweir     double fHoursValue = ::rtl::math::approxFloor (fValue);
818cdf0e10cSrcweir     fValue -= fHoursValue;
819cdf0e10cSrcweir     fValue *= 60;
820cdf0e10cSrcweir     double fMinsValue = ::rtl::math::approxFloor (fValue);
821cdf0e10cSrcweir     fValue -= fMinsValue;
822cdf0e10cSrcweir     fValue *= 60;
823cdf0e10cSrcweir     double fSecsValue = ::rtl::math::approxFloor (fValue);
824cdf0e10cSrcweir     fValue -= fSecsValue;
825cdf0e10cSrcweir     double f100SecsValue;
826cdf0e10cSrcweir     if (fValue > 0.00001)
827cdf0e10cSrcweir         f100SecsValue = ::rtl::math::round( fValue, XML_MAXDIGITSCOUNT_TIME - 5);
828cdf0e10cSrcweir     else
829cdf0e10cSrcweir         f100SecsValue = 0.0;
830cdf0e10cSrcweir 
831cdf0e10cSrcweir     if (f100SecsValue == 1.0)
832cdf0e10cSrcweir     {
833cdf0e10cSrcweir         f100SecsValue = 0.0;
834cdf0e10cSrcweir         fSecsValue += 1.0;
835cdf0e10cSrcweir     }
836cdf0e10cSrcweir     if (fSecsValue >= 60.0)
837cdf0e10cSrcweir     {
838cdf0e10cSrcweir         fSecsValue -= 60.0;
839cdf0e10cSrcweir         fMinsValue += 1.0;
840cdf0e10cSrcweir     }
841cdf0e10cSrcweir     if (fMinsValue >= 60.0)
842cdf0e10cSrcweir     {
843cdf0e10cSrcweir         fMinsValue -= 60.0;
844cdf0e10cSrcweir         fHoursValue += 1.0;
845cdf0e10cSrcweir     }
846cdf0e10cSrcweir 
847cdf0e10cSrcweir     if (fHoursValue < 10)
848cdf0e10cSrcweir         rBuffer.append( sal_Unicode('0'));
849cdf0e10cSrcweir     rBuffer.append( sal_Int32( fHoursValue));
850cdf0e10cSrcweir     rBuffer.append( sal_Unicode('H'));
851cdf0e10cSrcweir     if (fMinsValue < 10)
852cdf0e10cSrcweir         rBuffer.append( sal_Unicode('0'));
853cdf0e10cSrcweir     rBuffer.append( sal_Int32( fMinsValue));
854cdf0e10cSrcweir     rBuffer.append( sal_Unicode('M'));
855cdf0e10cSrcweir     if (fSecsValue < 10)
856cdf0e10cSrcweir         rBuffer.append( sal_Unicode('0'));
857cdf0e10cSrcweir     rBuffer.append( sal_Int32( fSecsValue));
858cdf0e10cSrcweir     if (f100SecsValue > 0.0)
859cdf0e10cSrcweir     {
860cdf0e10cSrcweir         ::rtl::OUString a100th( ::rtl::math::doubleToUString( fValue,
861cdf0e10cSrcweir                     rtl_math_StringFormat_F, XML_MAXDIGITSCOUNT_TIME - 5, '.',
862cdf0e10cSrcweir                     sal_True));
863cdf0e10cSrcweir         if ( a100th.getLength() > 2 )
864cdf0e10cSrcweir         {
865cdf0e10cSrcweir             rBuffer.append( sal_Unicode('.'));
866cdf0e10cSrcweir             rBuffer.append( a100th.copy( 2 ) );     // strip 0.
867cdf0e10cSrcweir         }
868cdf0e10cSrcweir     }
869cdf0e10cSrcweir     rBuffer.append( sal_Unicode('S'));
870cdf0e10cSrcweir }
871cdf0e10cSrcweir 
872cdf0e10cSrcweir /** convert ISO Time String to double; negative durations allowed */
lcl_convertTime(const::rtl::OUString & rString,sal_Int32 & o_rDays,sal_Int32 & o_rHours,sal_Int32 & o_rMins,sal_Int32 & o_rSecs,sal_Bool & o_rIsNegativeTime,double & o_rFractionalSecs)873cdf0e10cSrcweir static bool lcl_convertTime( const ::rtl::OUString& rString, sal_Int32& o_rDays, sal_Int32& o_rHours, sal_Int32& o_rMins,
874cdf0e10cSrcweir                         sal_Int32& o_rSecs, sal_Bool& o_rIsNegativeTime, double& o_rFractionalSecs )
875cdf0e10cSrcweir {
876cdf0e10cSrcweir     rtl::OUString aTrimmed = rString.trim().toAsciiUpperCase();
877cdf0e10cSrcweir     const sal_Unicode* pStr = aTrimmed.getStr();
878cdf0e10cSrcweir 
879cdf0e10cSrcweir     // negative time duration?
880cdf0e10cSrcweir     if ( sal_Unicode('-') == (*pStr) )
881cdf0e10cSrcweir     {
882cdf0e10cSrcweir         o_rIsNegativeTime = sal_True;
883cdf0e10cSrcweir         pStr++;
884cdf0e10cSrcweir     }
885cdf0e10cSrcweir 
886cdf0e10cSrcweir     if ( *(pStr++) != sal_Unicode('P') )            // duration must start with "P"
887cdf0e10cSrcweir         return false;
888cdf0e10cSrcweir 
889cdf0e10cSrcweir     ::rtl::OUString sDoubleStr;
890cdf0e10cSrcweir     sal_Bool bSuccess = true;
891cdf0e10cSrcweir     sal_Bool bDone = sal_False;
892cdf0e10cSrcweir     sal_Bool bTimePart = sal_False;
893cdf0e10cSrcweir     sal_Bool bIsFraction = sal_False;
894cdf0e10cSrcweir     sal_Int32 nTemp = 0;
895cdf0e10cSrcweir 
896cdf0e10cSrcweir     while ( bSuccess && !bDone )
897cdf0e10cSrcweir     {
898cdf0e10cSrcweir         sal_Unicode c = *(pStr++);
899cdf0e10cSrcweir         if ( !c )                               // end
900cdf0e10cSrcweir             bDone = sal_True;
901cdf0e10cSrcweir         else if ( sal_Unicode('0') <= c && sal_Unicode('9') >= c )
902cdf0e10cSrcweir         {
903cdf0e10cSrcweir             if ( nTemp >= SAL_MAX_INT32 / 10 )
904cdf0e10cSrcweir                 bSuccess = false;
905cdf0e10cSrcweir             else
906cdf0e10cSrcweir             {
907cdf0e10cSrcweir                 if ( !bIsFraction )
908cdf0e10cSrcweir                 {
909cdf0e10cSrcweir                     nTemp *= 10;
910cdf0e10cSrcweir                     nTemp += (c - sal_Unicode('0'));
911cdf0e10cSrcweir                 }
912cdf0e10cSrcweir                 else
913cdf0e10cSrcweir                 {
914cdf0e10cSrcweir                     sDoubleStr += OUString::valueOf(c);
915cdf0e10cSrcweir                 }
916cdf0e10cSrcweir             }
917cdf0e10cSrcweir         }
918cdf0e10cSrcweir         else if ( bTimePart )
919cdf0e10cSrcweir         {
920cdf0e10cSrcweir             if ( c == sal_Unicode('H') )
921cdf0e10cSrcweir             {
922cdf0e10cSrcweir                 o_rHours = nTemp;
923cdf0e10cSrcweir                 nTemp = 0;
924cdf0e10cSrcweir             }
925cdf0e10cSrcweir             else if ( c == sal_Unicode('M') )
926cdf0e10cSrcweir             {
927cdf0e10cSrcweir                 o_rMins = nTemp;
928cdf0e10cSrcweir                 nTemp = 0;
929cdf0e10cSrcweir             }
930cdf0e10cSrcweir             else if ( (c == sal_Unicode(',')) || (c == sal_Unicode('.')) )
931cdf0e10cSrcweir             {
932cdf0e10cSrcweir                 o_rSecs = nTemp;
933cdf0e10cSrcweir                 nTemp = 0;
934cdf0e10cSrcweir                 bIsFraction = sal_True;
935cdf0e10cSrcweir                 sDoubleStr = OUString(RTL_CONSTASCII_USTRINGPARAM("0."));
936cdf0e10cSrcweir             }
937cdf0e10cSrcweir             else if ( c == sal_Unicode('S') )
938cdf0e10cSrcweir             {
939cdf0e10cSrcweir                 if ( !bIsFraction )
940cdf0e10cSrcweir                 {
941cdf0e10cSrcweir                     o_rSecs = nTemp;
942cdf0e10cSrcweir                     nTemp = 0;
943cdf0e10cSrcweir                     sDoubleStr = OUString(RTL_CONSTASCII_USTRINGPARAM("0.0"));
944cdf0e10cSrcweir                 }
945cdf0e10cSrcweir             }
946cdf0e10cSrcweir             else
947cdf0e10cSrcweir                 bSuccess = false;                   // invalid character
948cdf0e10cSrcweir         }
949cdf0e10cSrcweir         else
950cdf0e10cSrcweir         {
951cdf0e10cSrcweir             if ( c == sal_Unicode('T') )            // "T" starts time part
952cdf0e10cSrcweir                 bTimePart = sal_True;
953cdf0e10cSrcweir             else if ( c == sal_Unicode('D') )
954cdf0e10cSrcweir             {
955cdf0e10cSrcweir                 o_rDays = nTemp;
956cdf0e10cSrcweir                 nTemp = 0;
957cdf0e10cSrcweir             }
958cdf0e10cSrcweir             else if ( c == sal_Unicode('Y') || c == sal_Unicode('M') )
959cdf0e10cSrcweir             {
960cdf0e10cSrcweir                 //! how many days is a year or month?
961cdf0e10cSrcweir 
962cdf0e10cSrcweir                 DBG_ERROR("years or months in duration: not implemented");
963cdf0e10cSrcweir                 bSuccess = false;
964cdf0e10cSrcweir             }
965cdf0e10cSrcweir             else
966cdf0e10cSrcweir                 bSuccess = false;                   // invalid character
967cdf0e10cSrcweir         }
968cdf0e10cSrcweir     }
969cdf0e10cSrcweir 
970cdf0e10cSrcweir     if ( bSuccess )
971cdf0e10cSrcweir         o_rFractionalSecs = sDoubleStr.toDouble();
972cdf0e10cSrcweir     return bSuccess;
973cdf0e10cSrcweir }
974cdf0e10cSrcweir 
convertTime(double & fTime,const::rtl::OUString & rString)975cdf0e10cSrcweir sal_Bool SvXMLUnitConverter::convertTime( double& fTime,
976cdf0e10cSrcweir                             const ::rtl::OUString& rString)
977cdf0e10cSrcweir {
978cdf0e10cSrcweir     sal_Int32 nDays  = 0;
979cdf0e10cSrcweir     sal_Int32 nHours = 0;
980cdf0e10cSrcweir     sal_Int32 nMins  = 0;
981cdf0e10cSrcweir     sal_Int32 nSecs  = 0;
982cdf0e10cSrcweir     sal_Bool bIsNegativeDuration = sal_False;
983cdf0e10cSrcweir     double fFractionalSecs = 0.0;
984cdf0e10cSrcweir     if ( lcl_convertTime( rString, nDays, nHours, nMins, nSecs, bIsNegativeDuration, fFractionalSecs ) )
985cdf0e10cSrcweir     {
986cdf0e10cSrcweir         if ( nDays )
987cdf0e10cSrcweir             nHours += nDays * 24;               // add the days to the hours part
988cdf0e10cSrcweir         double fTempTime = 0.0;
989cdf0e10cSrcweir         double fHour = nHours;
990cdf0e10cSrcweir         double fMin = nMins;
991cdf0e10cSrcweir         double fSec = nSecs;
992cdf0e10cSrcweir         double fSec100 = 0.0;
993cdf0e10cSrcweir         fTempTime = fHour / 24;
994cdf0e10cSrcweir         fTempTime += fMin / (24 * 60);
995cdf0e10cSrcweir         fTempTime += fSec / (24 * 60 * 60);
996cdf0e10cSrcweir         fTempTime += fSec100 / (24 * 60 * 60 * 60);
997cdf0e10cSrcweir         fTempTime += fFractionalSecs / (24 * 60 * 60);
998cdf0e10cSrcweir 
999cdf0e10cSrcweir         // negative duration?
1000cdf0e10cSrcweir         if ( bIsNegativeDuration )
1001cdf0e10cSrcweir         {
1002cdf0e10cSrcweir             fTempTime = -fTempTime;
1003cdf0e10cSrcweir         }
1004cdf0e10cSrcweir 
1005cdf0e10cSrcweir         fTime = fTempTime;
1006cdf0e10cSrcweir         return sal_True;
1007cdf0e10cSrcweir     }
1008cdf0e10cSrcweir     return sal_False;
1009cdf0e10cSrcweir }
1010cdf0e10cSrcweir 
1011cdf0e10cSrcweir /** convert util::DateTime to ISO Time String */
convertTime(::rtl::OUStringBuffer & rBuffer,const::com::sun::star::util::DateTime & rDateTime)1012cdf0e10cSrcweir void SvXMLUnitConverter::convertTime( ::rtl::OUStringBuffer& rBuffer,
1013cdf0e10cSrcweir                             const ::com::sun::star::util::DateTime& rDateTime )
1014cdf0e10cSrcweir {
1015cdf0e10cSrcweir     double fHour = rDateTime.Hours;
1016cdf0e10cSrcweir     double fMin = rDateTime.Minutes;
1017cdf0e10cSrcweir     double fSec = rDateTime.Seconds;
1018cdf0e10cSrcweir     double fSec100 = rDateTime.HundredthSeconds;
1019cdf0e10cSrcweir     double fTempTime = fHour / 24;
1020cdf0e10cSrcweir     fTempTime += fMin / (24 * 60);
1021cdf0e10cSrcweir     fTempTime += fSec / (24 * 60 * 60);
1022cdf0e10cSrcweir     fTempTime += fSec100 / (24 * 60 * 60 * 100);
1023cdf0e10cSrcweir     convertTime( rBuffer, fTempTime );
1024cdf0e10cSrcweir }
1025cdf0e10cSrcweir 
1026cdf0e10cSrcweir /** convert ISO Time String to util::DateTime */
convertTime(::com::sun::star::util::DateTime & rDateTime,const::rtl::OUString & rString)1027cdf0e10cSrcweir sal_Bool SvXMLUnitConverter::convertTime( ::com::sun::star::util::DateTime& rDateTime,
1028cdf0e10cSrcweir                              const ::rtl::OUString& rString )
1029cdf0e10cSrcweir {
1030cdf0e10cSrcweir     sal_Int32 nDays = 0, nHours = 0, nMins = 0, nSecs = 0;
1031cdf0e10cSrcweir     sal_Bool bIsNegativeDuration = sal_False;
1032cdf0e10cSrcweir     double fFractionalSecs = 0.0;
1033cdf0e10cSrcweir     if ( lcl_convertTime( rString, nDays, nHours, nMins, nSecs, bIsNegativeDuration, fFractionalSecs ) )
1034cdf0e10cSrcweir     {
1035cdf0e10cSrcweir         rDateTime.Year = 0;
1036cdf0e10cSrcweir         rDateTime.Month = 0;
1037cdf0e10cSrcweir         rDateTime.Day = 0;
1038cdf0e10cSrcweir         rDateTime.Hours = static_cast < sal_uInt16 > ( nHours );
1039cdf0e10cSrcweir         rDateTime.Minutes = static_cast < sal_uInt16 > ( nMins );
1040cdf0e10cSrcweir         rDateTime.Seconds = static_cast < sal_uInt16 > ( nSecs );
1041cdf0e10cSrcweir         rDateTime.HundredthSeconds = static_cast < sal_uInt16 > ( fFractionalSecs * 100.0 );
1042cdf0e10cSrcweir 
1043cdf0e10cSrcweir         return sal_True;
1044cdf0e10cSrcweir     }
1045cdf0e10cSrcweir     return sal_False;
1046cdf0e10cSrcweir }
1047cdf0e10cSrcweir 
1048cdf0e10cSrcweir /** convert double to ISO Date Time String */
convertDateTime(::rtl::OUStringBuffer & rBuffer,const double & fDateTime,const com::sun::star::util::Date & aTempNullDate,sal_Bool bAddTimeIf0AM)1049cdf0e10cSrcweir void SvXMLUnitConverter::convertDateTime( ::rtl::OUStringBuffer& rBuffer,
1050cdf0e10cSrcweir         const double& fDateTime,
1051cdf0e10cSrcweir 		const com::sun::star::util::Date& aTempNullDate,
1052cdf0e10cSrcweir 		sal_Bool bAddTimeIf0AM )
1053cdf0e10cSrcweir {
1054cdf0e10cSrcweir     double fValue = fDateTime;
1055cdf0e10cSrcweir     sal_Int32 nValue = static_cast <sal_Int32> (::rtl::math::approxFloor (fValue));
1056cdf0e10cSrcweir     Date aDate (aTempNullDate.Day, aTempNullDate.Month, aTempNullDate.Year);
1057cdf0e10cSrcweir     aDate += nValue;
1058cdf0e10cSrcweir     fValue -= nValue;
1059cdf0e10cSrcweir     double fCount;
1060cdf0e10cSrcweir     if (nValue > 0)
1061cdf0e10cSrcweir          fCount = ::rtl::math::approxFloor (log10((double)nValue)) + 1;
1062cdf0e10cSrcweir     else if (nValue < 0)
1063cdf0e10cSrcweir          fCount = ::rtl::math::approxFloor (log10((double)(nValue * -1))) + 1;
1064cdf0e10cSrcweir     else
1065cdf0e10cSrcweir         fCount = 0.0;
1066cdf0e10cSrcweir     sal_Int16 nCount = sal_Int16(fCount);
1067cdf0e10cSrcweir     sal_Bool bHasTime(sal_False);
1068cdf0e10cSrcweir     double fHoursValue = 0;
1069cdf0e10cSrcweir     double fMinsValue = 0;
1070cdf0e10cSrcweir     double fSecsValue = 0;
1071cdf0e10cSrcweir     double f100SecsValue = 0;
1072cdf0e10cSrcweir     if (fValue > 0.0)
1073cdf0e10cSrcweir     {
1074cdf0e10cSrcweir         bHasTime = sal_True;
1075cdf0e10cSrcweir         fValue *= 24;
1076cdf0e10cSrcweir         fHoursValue = ::rtl::math::approxFloor (fValue);
1077cdf0e10cSrcweir         fValue -= fHoursValue;
1078cdf0e10cSrcweir         fValue *= 60;
1079cdf0e10cSrcweir         fMinsValue = ::rtl::math::approxFloor (fValue);
1080cdf0e10cSrcweir         fValue -= fMinsValue;
1081cdf0e10cSrcweir         fValue *= 60;
1082cdf0e10cSrcweir         fSecsValue = ::rtl::math::approxFloor (fValue);
1083cdf0e10cSrcweir         fValue -= fSecsValue;
1084cdf0e10cSrcweir         if (fValue > 0.0)
1085cdf0e10cSrcweir             f100SecsValue = ::rtl::math::round( fValue, XML_MAXDIGITSCOUNT_TIME - nCount);
1086cdf0e10cSrcweir         else
1087cdf0e10cSrcweir             f100SecsValue = 0.0;
1088cdf0e10cSrcweir 
1089cdf0e10cSrcweir         if (f100SecsValue == 1.0)
1090cdf0e10cSrcweir         {
1091cdf0e10cSrcweir             f100SecsValue = 0.0;
1092cdf0e10cSrcweir             fSecsValue += 1.0;
1093cdf0e10cSrcweir         }
1094cdf0e10cSrcweir         if (fSecsValue >= 60.0)
1095cdf0e10cSrcweir         {
1096cdf0e10cSrcweir             fSecsValue -= 60.0;
1097cdf0e10cSrcweir             fMinsValue += 1.0;
1098cdf0e10cSrcweir         }
1099cdf0e10cSrcweir         if (fMinsValue >= 60.0)
1100cdf0e10cSrcweir         {
1101cdf0e10cSrcweir             fMinsValue -= 60.0;
1102cdf0e10cSrcweir             fHoursValue += 1.0;
1103cdf0e10cSrcweir         }
1104cdf0e10cSrcweir         if (fHoursValue >= 24.0)
1105cdf0e10cSrcweir         {
1106cdf0e10cSrcweir             fHoursValue -= 24.0;
1107cdf0e10cSrcweir             aDate += 1;
1108cdf0e10cSrcweir         }
1109cdf0e10cSrcweir     }
1110cdf0e10cSrcweir     rBuffer.append( sal_Int32( aDate.GetYear()));
1111cdf0e10cSrcweir     rBuffer.append( sal_Unicode('-'));
1112cdf0e10cSrcweir     sal_uInt16 nTemp = aDate.GetMonth();
1113cdf0e10cSrcweir     if (nTemp < 10)
1114cdf0e10cSrcweir         rBuffer.append( sal_Unicode('0'));
1115cdf0e10cSrcweir     rBuffer.append( sal_Int32( nTemp));
1116cdf0e10cSrcweir     rBuffer.append( sal_Unicode('-'));
1117cdf0e10cSrcweir     nTemp = aDate.GetDay();
1118cdf0e10cSrcweir     if (nTemp < 10)
1119cdf0e10cSrcweir         rBuffer.append( sal_Unicode('0'));
1120cdf0e10cSrcweir     rBuffer.append( sal_Int32( nTemp));
1121cdf0e10cSrcweir     if(bHasTime || bAddTimeIf0AM)
1122cdf0e10cSrcweir     {
1123cdf0e10cSrcweir         rBuffer.append( sal_Unicode('T'));
1124cdf0e10cSrcweir         if (fHoursValue < 10)
1125cdf0e10cSrcweir             rBuffer.append( sal_Unicode('0'));
1126cdf0e10cSrcweir         rBuffer.append( sal_Int32( fHoursValue));
1127cdf0e10cSrcweir         rBuffer.append( sal_Unicode(':'));
1128cdf0e10cSrcweir         if (fMinsValue < 10)
1129cdf0e10cSrcweir             rBuffer.append( sal_Unicode('0'));
1130cdf0e10cSrcweir         rBuffer.append( sal_Int32( fMinsValue));
1131cdf0e10cSrcweir         rBuffer.append( sal_Unicode(':'));
1132cdf0e10cSrcweir         if (fSecsValue < 10)
1133cdf0e10cSrcweir             rBuffer.append( sal_Unicode('0'));
1134cdf0e10cSrcweir         rBuffer.append( sal_Int32( fSecsValue));
1135cdf0e10cSrcweir         if (f100SecsValue > 0.0)
1136cdf0e10cSrcweir         {
1137cdf0e10cSrcweir             ::rtl::OUString a100th( ::rtl::math::doubleToUString( fValue,
1138cdf0e10cSrcweir                         rtl_math_StringFormat_F,
1139cdf0e10cSrcweir                         XML_MAXDIGITSCOUNT_TIME - nCount, '.', sal_True));
1140cdf0e10cSrcweir             if ( a100th.getLength() > 2 )
1141cdf0e10cSrcweir             {
1142cdf0e10cSrcweir                 rBuffer.append( sal_Unicode('.'));
1143cdf0e10cSrcweir                 rBuffer.append( a100th.copy( 2 ) );     // strip 0.
1144cdf0e10cSrcweir             }
1145cdf0e10cSrcweir         }
1146cdf0e10cSrcweir     }
1147cdf0e10cSrcweir }
1148cdf0e10cSrcweir 
1149cdf0e10cSrcweir /** convert ISO Date Time String to double */
convertDateTime(double & fDateTime,const::rtl::OUString & rString,const com::sun::star::util::Date & aTempNullDate)1150cdf0e10cSrcweir sal_Bool SvXMLUnitConverter::convertDateTime( double& fDateTime,
1151cdf0e10cSrcweir                             const ::rtl::OUString& rString, const com::sun::star::util::Date& aTempNullDate)
1152cdf0e10cSrcweir {
1153cdf0e10cSrcweir     com::sun::star::util::DateTime aDateTime;
1154cdf0e10cSrcweir     sal_Bool bSuccess = convertDateTime(aDateTime,rString);
1155cdf0e10cSrcweir 
1156cdf0e10cSrcweir     if (bSuccess)
1157cdf0e10cSrcweir     {
1158cdf0e10cSrcweir         double fTempDateTime = 0.0;
1159cdf0e10cSrcweir         const Date aTmpNullDate(aTempNullDate.Day, aTempNullDate.Month, aTempNullDate.Year);
1160cdf0e10cSrcweir         const Date aTempDate((sal_uInt16)aDateTime.Day, (sal_uInt16)aDateTime.Month, (sal_uInt16)aDateTime.Year);
1161cdf0e10cSrcweir         const sal_Int32 nTage = aTempDate - aTmpNullDate;
1162cdf0e10cSrcweir         fTempDateTime = nTage;
1163cdf0e10cSrcweir         double Hour = aDateTime.Hours;
1164cdf0e10cSrcweir         double Min = aDateTime.Minutes;
1165cdf0e10cSrcweir         double Sec = aDateTime.Seconds;
1166cdf0e10cSrcweir         double Sec100 = aDateTime.HundredthSeconds;
1167cdf0e10cSrcweir         fTempDateTime += Hour / 24;
1168cdf0e10cSrcweir         fTempDateTime += Min / (24 * 60);
1169cdf0e10cSrcweir         fTempDateTime += Sec / (24 * 60 * 60);
1170cdf0e10cSrcweir         fTempDateTime += Sec100 / (24 * 60 * 60 * 100);
1171cdf0e10cSrcweir         fDateTime = fTempDateTime;
1172cdf0e10cSrcweir     }
1173cdf0e10cSrcweir     return bSuccess;
1174cdf0e10cSrcweir }
1175cdf0e10cSrcweir 
1176cdf0e10cSrcweir /** convert util::DateTime to ISO Date String */
convertDateTime(::rtl::OUStringBuffer & rBuffer,const com::sun::star::util::DateTime & rDateTime,sal_Bool bAddTimeIf0AM)1177cdf0e10cSrcweir void SvXMLUnitConverter::convertDateTime(
1178cdf0e10cSrcweir 				::rtl::OUStringBuffer& rBuffer,
1179cdf0e10cSrcweir                 const com::sun::star::util::DateTime& rDateTime,
1180cdf0e10cSrcweir 				sal_Bool bAddTimeIf0AM )
1181cdf0e10cSrcweir {
1182cdf0e10cSrcweir     String aString( String::CreateFromInt32( rDateTime.Year ) );
1183cdf0e10cSrcweir     aString += '-';
1184cdf0e10cSrcweir     if( rDateTime.Month < 10 )
1185cdf0e10cSrcweir         aString += '0';
1186cdf0e10cSrcweir     aString += String::CreateFromInt32( rDateTime.Month );
1187cdf0e10cSrcweir     aString += '-';
1188cdf0e10cSrcweir     if( rDateTime.Day < 10 )
1189cdf0e10cSrcweir         aString += '0';
1190cdf0e10cSrcweir     aString += String::CreateFromInt32( rDateTime.Day );
1191cdf0e10cSrcweir 
1192cdf0e10cSrcweir     if( rDateTime.Seconds != 0 ||
1193cdf0e10cSrcweir         rDateTime.Minutes != 0 ||
1194cdf0e10cSrcweir         rDateTime.Hours   != 0 ||
1195cdf0e10cSrcweir 		bAddTimeIf0AM )
1196cdf0e10cSrcweir     {
1197cdf0e10cSrcweir         aString += 'T';
1198cdf0e10cSrcweir         if( rDateTime.Hours < 10 )
1199cdf0e10cSrcweir             aString += '0';
1200cdf0e10cSrcweir         aString += String::CreateFromInt32( rDateTime.Hours );
1201cdf0e10cSrcweir         aString += ':';
1202cdf0e10cSrcweir         if( rDateTime.Minutes < 10 )
1203cdf0e10cSrcweir             aString += '0';
1204cdf0e10cSrcweir         aString += String::CreateFromInt32( rDateTime.Minutes );
1205cdf0e10cSrcweir         aString += ':';
1206cdf0e10cSrcweir         if( rDateTime.Seconds < 10 )
1207cdf0e10cSrcweir             aString += '0';
1208cdf0e10cSrcweir         aString += String::CreateFromInt32( rDateTime.Seconds );
1209cdf0e10cSrcweir 		if ( rDateTime.HundredthSeconds > 0)
1210cdf0e10cSrcweir 		{
1211cdf0e10cSrcweir 	        aString += '.';
1212cdf0e10cSrcweir 			if (rDateTime.HundredthSeconds < 10)
1213cdf0e10cSrcweir 				aString += '0';
1214cdf0e10cSrcweir 			aString += String::CreateFromInt32( rDateTime.HundredthSeconds );
1215cdf0e10cSrcweir 		}
1216cdf0e10cSrcweir     }
1217cdf0e10cSrcweir 
1218cdf0e10cSrcweir     rBuffer.append( aString );
1219cdf0e10cSrcweir }
1220cdf0e10cSrcweir 
1221cdf0e10cSrcweir /** convert ISO Date String to util::DateTime */
convertDateTime(com::sun::star::util::DateTime & rDateTime,const::rtl::OUString & rString)1222cdf0e10cSrcweir sal_Bool SvXMLUnitConverter::convertDateTime( com::sun::star::util::DateTime& rDateTime,
1223cdf0e10cSrcweir                                      const ::rtl::OUString& rString )
1224cdf0e10cSrcweir {
1225cdf0e10cSrcweir     sal_Bool bSuccess = sal_True;
1226cdf0e10cSrcweir 
1227cdf0e10cSrcweir     rtl::OUString aDateStr, aTimeStr, sDoubleStr;
1228cdf0e10cSrcweir     sal_Int32 nPos = rString.indexOf( (sal_Unicode) 'T' );
1229cdf0e10cSrcweir     sal_Int32 nPos2 = rString.indexOf( (sal_Unicode) ',' );
1230cdf0e10cSrcweir     if (nPos2 < 0)
1231cdf0e10cSrcweir         nPos2 = rString.indexOf( (sal_Unicode) '.' );
1232cdf0e10cSrcweir     if ( nPos >= 0 )
1233cdf0e10cSrcweir     {
1234cdf0e10cSrcweir         aDateStr = rString.copy( 0, nPos );
1235cdf0e10cSrcweir         if ( nPos2 >= 0 )
1236cdf0e10cSrcweir         {
1237cdf0e10cSrcweir             aTimeStr = rString.copy( nPos + 1, nPos2 - nPos - 1 );
1238cdf0e10cSrcweir             sDoubleStr = OUString(RTL_CONSTASCII_USTRINGPARAM("0."));
1239cdf0e10cSrcweir             sDoubleStr += rString.copy( nPos2 + 1 );
1240cdf0e10cSrcweir         }
1241cdf0e10cSrcweir         else
1242cdf0e10cSrcweir         {
1243cdf0e10cSrcweir             aTimeStr = rString.copy(nPos + 1);
1244cdf0e10cSrcweir             sDoubleStr = OUString(RTL_CONSTASCII_USTRINGPARAM("0.0"));
1245cdf0e10cSrcweir         }
1246cdf0e10cSrcweir     }
1247cdf0e10cSrcweir     else
1248cdf0e10cSrcweir         aDateStr = rString;         // no separator: only date part
1249cdf0e10cSrcweir 
1250cdf0e10cSrcweir     sal_Int32 nYear  = 1899;
1251cdf0e10cSrcweir     sal_Int32 nMonth = 12;
1252cdf0e10cSrcweir     sal_Int32 nDay   = 30;
1253cdf0e10cSrcweir     sal_Int32 nHour  = 0;
1254cdf0e10cSrcweir     sal_Int32 nMin   = 0;
1255cdf0e10cSrcweir     sal_Int32 nSec   = 0;
1256cdf0e10cSrcweir 
1257cdf0e10cSrcweir     const sal_Unicode* pStr = aDateStr.getStr();
1258cdf0e10cSrcweir     sal_Int32 nDateTokens = 1;
1259cdf0e10cSrcweir     while ( *pStr )
1260cdf0e10cSrcweir     {
1261cdf0e10cSrcweir         if ( *pStr == '-' )
1262cdf0e10cSrcweir             nDateTokens++;
1263cdf0e10cSrcweir         pStr++;
1264cdf0e10cSrcweir     }
1265cdf0e10cSrcweir     if ( nDateTokens > 3 || aDateStr.getLength() == 0 )
1266cdf0e10cSrcweir         bSuccess = sal_False;
1267cdf0e10cSrcweir     else
1268cdf0e10cSrcweir     {
1269cdf0e10cSrcweir         sal_Int32 n = 0;
1270cdf0e10cSrcweir         if ( !convertNumber( nYear, aDateStr.getToken( 0, '-', n ), 0, 9999 ) )
1271cdf0e10cSrcweir             bSuccess = sal_False;
1272cdf0e10cSrcweir         if ( nDateTokens >= 2 )
1273cdf0e10cSrcweir             if ( !convertNumber( nMonth, aDateStr.getToken( 0, '-', n ), 0, 12 ) )
1274cdf0e10cSrcweir                 bSuccess = sal_False;
1275cdf0e10cSrcweir         if ( nDateTokens >= 3 )
1276cdf0e10cSrcweir             if ( !convertNumber( nDay, aDateStr.getToken( 0, '-', n ), 0, 31 ) )
1277cdf0e10cSrcweir                 bSuccess = sal_False;
1278cdf0e10cSrcweir     }
1279cdf0e10cSrcweir 
1280cdf0e10cSrcweir     if ( aTimeStr.getLength() > 0 )           // time is optional
1281cdf0e10cSrcweir     {
1282cdf0e10cSrcweir         pStr = aTimeStr.getStr();
1283cdf0e10cSrcweir         sal_Int32 nTimeTokens = 1;
1284cdf0e10cSrcweir         while ( *pStr )
1285cdf0e10cSrcweir         {
1286cdf0e10cSrcweir             if ( *pStr == ':' )
1287cdf0e10cSrcweir                 nTimeTokens++;
1288cdf0e10cSrcweir             pStr++;
1289cdf0e10cSrcweir         }
1290cdf0e10cSrcweir         if ( nTimeTokens > 3 )
1291cdf0e10cSrcweir             bSuccess = sal_False;
1292cdf0e10cSrcweir         else
1293cdf0e10cSrcweir         {
1294cdf0e10cSrcweir             sal_Int32 n = 0;
1295cdf0e10cSrcweir             if ( !convertNumber( nHour, aTimeStr.getToken( 0, ':', n ), 0, 23 ) )
1296cdf0e10cSrcweir                 bSuccess = sal_False;
1297cdf0e10cSrcweir             if ( nTimeTokens >= 2 )
1298cdf0e10cSrcweir                 if ( !convertNumber( nMin, aTimeStr.getToken( 0, ':', n ), 0, 59 ) )
1299cdf0e10cSrcweir                     bSuccess = sal_False;
1300cdf0e10cSrcweir             if ( nTimeTokens >= 3 )
1301cdf0e10cSrcweir                 if ( !convertNumber( nSec, aTimeStr.getToken( 0, ':', n ), 0, 59 ) )
1302cdf0e10cSrcweir                     bSuccess = sal_False;
1303cdf0e10cSrcweir         }
1304cdf0e10cSrcweir     }
1305cdf0e10cSrcweir 
1306cdf0e10cSrcweir     if (bSuccess)
1307cdf0e10cSrcweir     {
1308cdf0e10cSrcweir         rDateTime.Year = (sal_uInt16)nYear;
1309cdf0e10cSrcweir         rDateTime.Month = (sal_uInt16)nMonth;
1310cdf0e10cSrcweir         rDateTime.Day = (sal_uInt16)nDay;
1311cdf0e10cSrcweir         rDateTime.Hours = (sal_uInt16)nHour;
1312cdf0e10cSrcweir         rDateTime.Minutes = (sal_uInt16)nMin;
1313cdf0e10cSrcweir         rDateTime.Seconds = (sal_uInt16)nSec;
1314cdf0e10cSrcweir         rDateTime.HundredthSeconds = (sal_uInt16)(sDoubleStr.toDouble() * 100);
1315cdf0e10cSrcweir     }
1316cdf0e10cSrcweir     return bSuccess;
1317cdf0e10cSrcweir }
1318cdf0e10cSrcweir 
1319cdf0e10cSrcweir /** gets the position of the first comma after npos in the string
1320cdf0e10cSrcweir     rStr. Commas inside '"' pairs are not matched */
indexOfComma(const OUString & rStr,sal_Int32 nPos)1321cdf0e10cSrcweir sal_Int32 SvXMLUnitConverter::indexOfComma( const OUString& rStr,
1322cdf0e10cSrcweir                                             sal_Int32 nPos )
1323cdf0e10cSrcweir {
1324cdf0e10cSrcweir     sal_Unicode cQuote = 0;
1325cdf0e10cSrcweir     sal_Int32 nLen = rStr.getLength();
1326cdf0e10cSrcweir     for( ; nPos < nLen; nPos++ )
1327cdf0e10cSrcweir     {
1328cdf0e10cSrcweir         sal_Unicode c = rStr[nPos];
1329cdf0e10cSrcweir         switch( c )
1330cdf0e10cSrcweir         {
1331cdf0e10cSrcweir         case sal_Unicode('\''):
1332cdf0e10cSrcweir             if( 0 == cQuote )
1333cdf0e10cSrcweir                 cQuote = c;
1334cdf0e10cSrcweir             else if( '\'' == cQuote )
1335cdf0e10cSrcweir                 cQuote = 0;
1336cdf0e10cSrcweir             break;
1337cdf0e10cSrcweir 
1338cdf0e10cSrcweir         case sal_Unicode('"'):
1339cdf0e10cSrcweir             if( 0 == cQuote )
1340cdf0e10cSrcweir                 cQuote = c;
1341cdf0e10cSrcweir             else if( '\"' == cQuote )
1342cdf0e10cSrcweir                 cQuote = 0;
1343cdf0e10cSrcweir             break;
1344cdf0e10cSrcweir 
1345cdf0e10cSrcweir         case sal_Unicode(','):
1346cdf0e10cSrcweir             if( 0 == cQuote )
1347cdf0e10cSrcweir                 return nPos;
1348cdf0e10cSrcweir             break;
1349cdf0e10cSrcweir         }
1350cdf0e10cSrcweir     }
1351cdf0e10cSrcweir 
1352cdf0e10cSrcweir     return -1;
1353cdf0e10cSrcweir }
1354cdf0e10cSrcweir 
1355cdf0e10cSrcweir // ---
1356cdf0e10cSrcweir 
SvXMLTokenEnumerator(const OUString & rString,sal_Unicode cSeperator)1357cdf0e10cSrcweir SvXMLTokenEnumerator::SvXMLTokenEnumerator( const OUString& rString, sal_Unicode cSeperator /* = sal_Unicode(' ') */ )
1358cdf0e10cSrcweir : maTokenString( rString ), mnNextTokenPos(0), mcSeperator( cSeperator )
1359cdf0e10cSrcweir {
1360cdf0e10cSrcweir }
1361cdf0e10cSrcweir 
getNextToken(OUString & rToken)1362cdf0e10cSrcweir sal_Bool SvXMLTokenEnumerator::getNextToken( OUString& rToken )
1363cdf0e10cSrcweir {
1364cdf0e10cSrcweir     if( -1 == mnNextTokenPos )
1365cdf0e10cSrcweir         return sal_False;
1366cdf0e10cSrcweir 
1367cdf0e10cSrcweir     int nTokenEndPos = maTokenString.indexOf( mcSeperator, mnNextTokenPos );
1368cdf0e10cSrcweir     if( nTokenEndPos != -1 )
1369cdf0e10cSrcweir     {
1370cdf0e10cSrcweir         rToken = maTokenString.copy( mnNextTokenPos,
1371cdf0e10cSrcweir                                      nTokenEndPos - mnNextTokenPos );
1372cdf0e10cSrcweir         mnNextTokenPos = nTokenEndPos + 1;
1373cdf0e10cSrcweir 
1374cdf0e10cSrcweir         // if the mnNextTokenPos is at the end of the string, we have
1375cdf0e10cSrcweir         // to deliver an empty token
1376cdf0e10cSrcweir         if( mnNextTokenPos > maTokenString.getLength() )
1377cdf0e10cSrcweir             mnNextTokenPos = -1;
1378cdf0e10cSrcweir     }
1379cdf0e10cSrcweir     else
1380cdf0e10cSrcweir     {
1381cdf0e10cSrcweir         rToken = maTokenString.copy( mnNextTokenPos );
1382cdf0e10cSrcweir         mnNextTokenPos = -1;
1383cdf0e10cSrcweir     }
1384cdf0e10cSrcweir 
1385cdf0e10cSrcweir     return sal_True;
1386cdf0e10cSrcweir }
1387cdf0e10cSrcweir 
1388cdf0e10cSrcweir // ---
lcl_getPositions(const OUString & _sValue,OUString & _rContentX,OUString & _rContentY,OUString & _rContentZ)1389cdf0e10cSrcweir bool lcl_getPositions(const OUString& _sValue,OUString& _rContentX,OUString& _rContentY,OUString& _rContentZ)
1390cdf0e10cSrcweir {
1391cdf0e10cSrcweir     if(!_sValue.getLength() || _sValue[0] != '(')
1392cdf0e10cSrcweir         return false;
1393cdf0e10cSrcweir 
1394cdf0e10cSrcweir     sal_Int32 nPos(1L);
1395cdf0e10cSrcweir     sal_Int32 nFound = _sValue.indexOf(sal_Unicode(' '), nPos);
1396cdf0e10cSrcweir 
1397cdf0e10cSrcweir     if(nFound == -1 || nFound <= nPos)
1398cdf0e10cSrcweir         return false;
1399cdf0e10cSrcweir 
1400cdf0e10cSrcweir     _rContentX = _sValue.copy(nPos, nFound - nPos);
1401cdf0e10cSrcweir 
1402cdf0e10cSrcweir     nPos = nFound + 1;
1403cdf0e10cSrcweir     nFound = _sValue.indexOf(sal_Unicode(' '), nPos);
1404cdf0e10cSrcweir 
1405cdf0e10cSrcweir     if(nFound == -1 || nFound <= nPos)
1406cdf0e10cSrcweir         return false;
1407cdf0e10cSrcweir 
1408cdf0e10cSrcweir     _rContentY = _sValue.copy(nPos, nFound - nPos);
1409cdf0e10cSrcweir 
1410cdf0e10cSrcweir     nPos = nFound + 1;
1411cdf0e10cSrcweir     nFound = _sValue.indexOf(sal_Unicode(')'), nPos);
1412cdf0e10cSrcweir 
1413cdf0e10cSrcweir     if(nFound == -1 || nFound <= nPos)
1414cdf0e10cSrcweir         return false;
1415cdf0e10cSrcweir 
1416cdf0e10cSrcweir     _rContentZ = _sValue.copy(nPos, nFound - nPos);
1417cdf0e10cSrcweir     return true;
1418cdf0e10cSrcweir 
1419cdf0e10cSrcweir }
1420cdf0e10cSrcweir /** convert string to ::basegfx::B3DVector */
convertB3DVector(::basegfx::B3DVector & rVector,const OUString & rValue)1421cdf0e10cSrcweir sal_Bool SvXMLUnitConverter::convertB3DVector( ::basegfx::B3DVector& rVector, const OUString& rValue )
1422cdf0e10cSrcweir {
1423cdf0e10cSrcweir     OUString aContentX,aContentY,aContentZ;
1424cdf0e10cSrcweir     if ( !lcl_getPositions(rValue,aContentX,aContentY,aContentZ) )
1425cdf0e10cSrcweir         return sal_False;
1426cdf0e10cSrcweir 
1427cdf0e10cSrcweir     rtl_math_ConversionStatus eStatus;
1428cdf0e10cSrcweir 
1429cdf0e10cSrcweir     rVector.setX(::rtl::math::stringToDouble(aContentX, sal_Unicode('.'),
1430cdf0e10cSrcweir             sal_Unicode(','), &eStatus, NULL));
1431cdf0e10cSrcweir 
1432cdf0e10cSrcweir     if( eStatus != rtl_math_ConversionStatus_Ok )
1433cdf0e10cSrcweir         return sal_False;
1434cdf0e10cSrcweir 
1435cdf0e10cSrcweir     rVector.setY(::rtl::math::stringToDouble(aContentY, sal_Unicode('.'),
1436cdf0e10cSrcweir             sal_Unicode(','), &eStatus, NULL));
1437cdf0e10cSrcweir 
1438cdf0e10cSrcweir     if( eStatus != rtl_math_ConversionStatus_Ok )
1439cdf0e10cSrcweir         return sal_False;
1440cdf0e10cSrcweir 
1441cdf0e10cSrcweir     rVector.setZ(::rtl::math::stringToDouble(aContentZ, sal_Unicode('.'),
1442cdf0e10cSrcweir             sal_Unicode(','), &eStatus, NULL));
1443cdf0e10cSrcweir 
1444cdf0e10cSrcweir 
1445cdf0e10cSrcweir     return ( eStatus == rtl_math_ConversionStatus_Ok );
1446cdf0e10cSrcweir }
1447cdf0e10cSrcweir 
1448cdf0e10cSrcweir /** convert ::basegfx::B3DVector to string */
convertB3DVector(OUStringBuffer & rBuffer,const::basegfx::B3DVector & rVector)1449cdf0e10cSrcweir void SvXMLUnitConverter::convertB3DVector( OUStringBuffer &rBuffer, const ::basegfx::B3DVector& rVector )
1450cdf0e10cSrcweir {
1451cdf0e10cSrcweir     rBuffer.append(sal_Unicode('('));
1452cdf0e10cSrcweir     convertDouble(rBuffer, rVector.getX());
1453cdf0e10cSrcweir     rBuffer.append(sal_Unicode(' '));
1454cdf0e10cSrcweir     convertDouble(rBuffer, rVector.getY());
1455cdf0e10cSrcweir     rBuffer.append(sal_Unicode(' '));
1456cdf0e10cSrcweir     convertDouble(rBuffer, rVector.getZ());
1457cdf0e10cSrcweir     rBuffer.append(sal_Unicode(')'));
1458cdf0e10cSrcweir }
1459cdf0e10cSrcweir 
1460cdf0e10cSrcweir /** convert string to Position3D */
convertPosition3D(drawing::Position3D & rPosition,const OUString & rValue)1461cdf0e10cSrcweir sal_Bool SvXMLUnitConverter::convertPosition3D( drawing::Position3D& rPosition,
1462cdf0e10cSrcweir     const OUString& rValue )
1463cdf0e10cSrcweir {
1464cdf0e10cSrcweir     OUString aContentX,aContentY,aContentZ;
1465cdf0e10cSrcweir     if ( !lcl_getPositions(rValue,aContentX,aContentY,aContentZ) )
1466cdf0e10cSrcweir         return sal_False;
1467cdf0e10cSrcweir 
1468cdf0e10cSrcweir 	if ( !convertDouble( rPosition.PositionX, aContentX, sal_True ) )
1469cdf0e10cSrcweir 		return sal_False;
1470cdf0e10cSrcweir 	if ( !convertDouble( rPosition.PositionY, aContentY, sal_True ) )
1471cdf0e10cSrcweir 		return sal_False;
1472cdf0e10cSrcweir 	return convertDouble( rPosition.PositionZ, aContentZ, sal_True );
1473cdf0e10cSrcweir }
1474cdf0e10cSrcweir 
1475cdf0e10cSrcweir /** convert Position3D to string */
convertPosition3D(OUStringBuffer & rBuffer,const drawing::Position3D & rPosition)1476cdf0e10cSrcweir void SvXMLUnitConverter::convertPosition3D( OUStringBuffer &rBuffer,
1477cdf0e10cSrcweir 										   const drawing::Position3D& rPosition )
1478cdf0e10cSrcweir {
1479cdf0e10cSrcweir     rBuffer.append( sal_Unicode('(') );
1480cdf0e10cSrcweir     convertDouble( rBuffer, rPosition.PositionX, sal_True );
1481cdf0e10cSrcweir     rBuffer.append( sal_Unicode(' ') );
1482cdf0e10cSrcweir     convertDouble( rBuffer, rPosition.PositionY, sal_True );
1483cdf0e10cSrcweir     rBuffer.append( sal_Unicode(' ') );
1484cdf0e10cSrcweir     convertDouble( rBuffer, rPosition.PositionZ, sal_True );
1485cdf0e10cSrcweir     rBuffer.append( sal_Unicode(')') );
1486cdf0e10cSrcweir }
1487cdf0e10cSrcweir 
1488cdf0e10cSrcweir const
1489cdf0e10cSrcweir   sal_Char aBase64EncodeTable[] =
1490cdf0e10cSrcweir     { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
1491cdf0e10cSrcweir       'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
1492cdf0e10cSrcweir       'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
1493cdf0e10cSrcweir       'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
1494cdf0e10cSrcweir       '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/' };
1495cdf0e10cSrcweir 
1496cdf0e10cSrcweir const
1497cdf0e10cSrcweir   sal_uInt8 aBase64DecodeTable[]  =
1498cdf0e10cSrcweir     {											 62,255,255,255, 63, // 43-47
1499cdf0e10cSrcweir //                                                +               /
1500cdf0e10cSrcweir 
1501cdf0e10cSrcweir      52, 53, 54, 55, 56, 57, 58, 59, 60, 61,255,255,255,  0,255,255, // 48-63
1502cdf0e10cSrcweir //    0   1   2   3   4   5   6   7   8   9               =
1503cdf0e10cSrcweir 
1504cdf0e10cSrcweir     255,  0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, // 64-79
1505cdf0e10cSrcweir //        A   B   C   D   E   F   G   H   I   J   K   L   M   N   O
1506cdf0e10cSrcweir 
1507cdf0e10cSrcweir      15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25,255,255,255,255,255, // 80-95
1508cdf0e10cSrcweir //    P   Q   R   S   T   U   V   W   X   Y   Z
1509cdf0e10cSrcweir 
1510cdf0e10cSrcweir       0, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, // 96-111
1511cdf0e10cSrcweir //        a   b   c   d   e   f   g   h   i   j   k   l   m   n   o
1512cdf0e10cSrcweir 
1513cdf0e10cSrcweir      41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51 }; // 112-123
1514cdf0e10cSrcweir //    p   q   r   s   t   u   v   w   x   y   z
1515cdf0e10cSrcweir 
1516cdf0e10cSrcweir 
1517cdf0e10cSrcweir 
ThreeByteToFourByte(const sal_Int8 * pBuffer,const sal_Int32 nStart,const sal_Int32 nFullLen,rtl::OUStringBuffer & sBuffer)1518cdf0e10cSrcweir void ThreeByteToFourByte (const sal_Int8* pBuffer, const sal_Int32 nStart, const sal_Int32 nFullLen, rtl::OUStringBuffer& sBuffer)
1519cdf0e10cSrcweir {
1520cdf0e10cSrcweir     sal_Int32 nLen(nFullLen - nStart);
1521cdf0e10cSrcweir     if (nLen > 3)
1522cdf0e10cSrcweir         nLen = 3;
1523cdf0e10cSrcweir     if (nLen == 0)
1524cdf0e10cSrcweir     {
1525cdf0e10cSrcweir         sBuffer.setLength(0);
1526cdf0e10cSrcweir         return;
1527cdf0e10cSrcweir     }
1528cdf0e10cSrcweir 
1529cdf0e10cSrcweir     sal_Int32 nBinaer;
1530cdf0e10cSrcweir     switch (nLen)
1531cdf0e10cSrcweir     {
1532cdf0e10cSrcweir         case 1:
1533cdf0e10cSrcweir         {
1534cdf0e10cSrcweir             nBinaer = ((sal_uInt8)pBuffer[nStart + 0]) << 16;
1535cdf0e10cSrcweir         }
1536cdf0e10cSrcweir         break;
1537cdf0e10cSrcweir         case 2:
1538cdf0e10cSrcweir         {
1539cdf0e10cSrcweir             nBinaer = (((sal_uInt8)pBuffer[nStart + 0]) << 16) +
1540cdf0e10cSrcweir                     (((sal_uInt8)pBuffer[nStart + 1]) <<  8);
1541cdf0e10cSrcweir         }
1542cdf0e10cSrcweir         break;
1543cdf0e10cSrcweir         default:
1544cdf0e10cSrcweir         {
1545cdf0e10cSrcweir             nBinaer = (((sal_uInt8)pBuffer[nStart + 0]) << 16) +
1546cdf0e10cSrcweir                     (((sal_uInt8)pBuffer[nStart + 1]) <<  8) +
1547cdf0e10cSrcweir                     ((sal_uInt8)pBuffer[nStart + 2]);
1548cdf0e10cSrcweir         }
1549cdf0e10cSrcweir         break;
1550cdf0e10cSrcweir     }
1551cdf0e10cSrcweir 
1552cdf0e10cSrcweir     sBuffer.appendAscii("====");
1553cdf0e10cSrcweir 
1554cdf0e10cSrcweir     sal_uInt8 nIndex (static_cast<sal_uInt8>((nBinaer & 0xFC0000) >> 18));
1555cdf0e10cSrcweir     sBuffer.setCharAt(0, aBase64EncodeTable [nIndex]);
1556cdf0e10cSrcweir 
1557cdf0e10cSrcweir     nIndex = static_cast<sal_uInt8>((nBinaer & 0x3F000) >> 12);
1558cdf0e10cSrcweir     sBuffer.setCharAt(1, aBase64EncodeTable [nIndex]);
1559cdf0e10cSrcweir     if (nLen == 1)
1560cdf0e10cSrcweir         return;
1561cdf0e10cSrcweir 
1562cdf0e10cSrcweir     nIndex = static_cast<sal_uInt8>((nBinaer & 0xFC0) >> 6);
1563cdf0e10cSrcweir     sBuffer.setCharAt(2, aBase64EncodeTable [nIndex]);
1564cdf0e10cSrcweir     if (nLen == 2)
1565cdf0e10cSrcweir         return;
1566cdf0e10cSrcweir 
1567cdf0e10cSrcweir     nIndex = static_cast<sal_uInt8>((nBinaer & 0x3F));
1568cdf0e10cSrcweir     sBuffer.setCharAt(3, aBase64EncodeTable [nIndex]);
1569cdf0e10cSrcweir }
1570cdf0e10cSrcweir 
encodeBase64(rtl::OUStringBuffer & aStrBuffer,const uno::Sequence<sal_Int8> & aPass)1571cdf0e10cSrcweir void SvXMLUnitConverter::encodeBase64(rtl::OUStringBuffer& aStrBuffer, const uno::Sequence<sal_Int8>& aPass)
1572cdf0e10cSrcweir {
1573cdf0e10cSrcweir 	sal_Int32 i(0);
1574cdf0e10cSrcweir 	sal_Int32 nBufferLength(aPass.getLength());
1575cdf0e10cSrcweir 	const sal_Int8* pBuffer = aPass.getConstArray();
1576cdf0e10cSrcweir 	while (i < nBufferLength)
1577cdf0e10cSrcweir 	{
1578cdf0e10cSrcweir 		rtl::OUStringBuffer sBuffer;
1579cdf0e10cSrcweir 		ThreeByteToFourByte (pBuffer, i, nBufferLength, sBuffer);
1580cdf0e10cSrcweir 		aStrBuffer.append(sBuffer);
1581cdf0e10cSrcweir 		i += 3;
1582cdf0e10cSrcweir 	}
1583cdf0e10cSrcweir }
1584cdf0e10cSrcweir 
decodeBase64(uno::Sequence<sal_Int8> & aBuffer,const rtl::OUString & sBuffer)1585cdf0e10cSrcweir void SvXMLUnitConverter::decodeBase64(uno::Sequence<sal_Int8>& aBuffer, const rtl::OUString& sBuffer)
1586cdf0e10cSrcweir {
1587cdf0e10cSrcweir 	sal_Int32 nCharsDecoded = decodeBase64SomeChars( aBuffer, sBuffer );
1588cdf0e10cSrcweir 	OSL_ENSURE( nCharsDecoded == sBuffer.getLength(),
1589cdf0e10cSrcweir 				"some bytes left in base64 decoding!" );
1590cdf0e10cSrcweir 	(void)nCharsDecoded;
1591cdf0e10cSrcweir }
1592cdf0e10cSrcweir 
decodeBase64SomeChars(uno::Sequence<sal_Int8> & rOutBuffer,const rtl::OUString & rInBuffer)1593cdf0e10cSrcweir sal_Int32 SvXMLUnitConverter::decodeBase64SomeChars(
1594cdf0e10cSrcweir 		uno::Sequence<sal_Int8>& rOutBuffer,
1595cdf0e10cSrcweir 		const rtl::OUString& rInBuffer)
1596cdf0e10cSrcweir {
1597cdf0e10cSrcweir 	sal_Int32 nInBufferLen = rInBuffer.getLength();
1598cdf0e10cSrcweir 	sal_Int32 nMinOutBufferLen = (nInBufferLen / 4) * 3;
1599cdf0e10cSrcweir 	if( rOutBuffer.getLength() < nMinOutBufferLen )
1600cdf0e10cSrcweir 		rOutBuffer.realloc( nMinOutBufferLen );
1601cdf0e10cSrcweir 
1602cdf0e10cSrcweir 	const sal_Unicode *pInBuffer = rInBuffer.getStr();
1603cdf0e10cSrcweir 	sal_Int8 *pOutBuffer = rOutBuffer.getArray();
1604cdf0e10cSrcweir 	sal_Int8 *pOutBufferStart = pOutBuffer;
1605cdf0e10cSrcweir 	sal_Int32 nCharsDecoded = 0;
1606cdf0e10cSrcweir 
1607cdf0e10cSrcweir 	sal_uInt8 aDecodeBuffer[4];
1608cdf0e10cSrcweir 	sal_Int32 nBytesToDecode = 0;
1609cdf0e10cSrcweir 	sal_Int32 nBytesGotFromDecoding = 3;
1610cdf0e10cSrcweir 	sal_Int32 nInBufferPos= 0;
1611cdf0e10cSrcweir 	while( nInBufferPos < nInBufferLen )
1612cdf0e10cSrcweir 	{
1613cdf0e10cSrcweir 		sal_Unicode cChar = *pInBuffer;
1614cdf0e10cSrcweir 		if( cChar >= '+' && cChar <= 'z' )
1615cdf0e10cSrcweir 		{
1616cdf0e10cSrcweir 			sal_uInt8 nByte = aBase64DecodeTable[cChar-'+'];
1617cdf0e10cSrcweir 			if( nByte != 255 )
1618cdf0e10cSrcweir 			{
1619cdf0e10cSrcweir 				// We have found a valid character!
1620cdf0e10cSrcweir 				aDecodeBuffer[nBytesToDecode++] = nByte;
1621cdf0e10cSrcweir 
1622cdf0e10cSrcweir 				// One '=' character at the end means 2 out bytes
1623cdf0e10cSrcweir 				// Two '=' characters at the end mean 1 out bytes
1624cdf0e10cSrcweir 				if( '=' == cChar && nBytesToDecode > 2 )
1625cdf0e10cSrcweir 					nBytesGotFromDecoding--;
1626cdf0e10cSrcweir 				if( 4 == nBytesToDecode )
1627cdf0e10cSrcweir 				{
1628cdf0e10cSrcweir 					// Four characters found, so we may convert now!
1629cdf0e10cSrcweir 					sal_uInt32 nOut = (aDecodeBuffer[0] << 18) +
1630cdf0e10cSrcweir 									  (aDecodeBuffer[1] << 12) +
1631cdf0e10cSrcweir 									  (aDecodeBuffer[2] << 6) +
1632cdf0e10cSrcweir 									   aDecodeBuffer[3];
1633cdf0e10cSrcweir 
1634cdf0e10cSrcweir 					*pOutBuffer++  = (sal_Int8)((nOut & 0xff0000) >> 16);
1635cdf0e10cSrcweir 					if( nBytesGotFromDecoding > 1 )
1636cdf0e10cSrcweir 						*pOutBuffer++  = (sal_Int8)((nOut & 0xff00) >> 8);
1637cdf0e10cSrcweir 					if( nBytesGotFromDecoding > 2 )
1638cdf0e10cSrcweir 						*pOutBuffer++  = (sal_Int8)(nOut & 0xff);
1639cdf0e10cSrcweir 					nCharsDecoded = nInBufferPos + 1;
1640cdf0e10cSrcweir 					nBytesToDecode = 0;
1641cdf0e10cSrcweir 					nBytesGotFromDecoding = 3;
1642cdf0e10cSrcweir 				}
1643cdf0e10cSrcweir 			}
1644cdf0e10cSrcweir 			else
1645cdf0e10cSrcweir 			{
1646cdf0e10cSrcweir 				nCharsDecoded++;
1647cdf0e10cSrcweir 			}
1648cdf0e10cSrcweir 		}
1649cdf0e10cSrcweir 		else
1650cdf0e10cSrcweir 		{
1651cdf0e10cSrcweir 			nCharsDecoded++;
1652cdf0e10cSrcweir 		}
1653cdf0e10cSrcweir 
1654cdf0e10cSrcweir 		nInBufferPos++;
1655cdf0e10cSrcweir 		pInBuffer++;
1656cdf0e10cSrcweir 	}
1657cdf0e10cSrcweir 	if( (pOutBuffer - pOutBufferStart) != rOutBuffer.getLength() )
1658cdf0e10cSrcweir 		rOutBuffer.realloc( pOutBuffer - pOutBufferStart );
1659cdf0e10cSrcweir 
1660cdf0e10cSrcweir 	return nCharsDecoded;
1661cdf0e10cSrcweir }
1662cdf0e10cSrcweir 
convertNumFormat(sal_Int16 & rType,const OUString & rNumFmt,const OUString & rNumLetterSync,sal_Bool bNumberNone) const1663cdf0e10cSrcweir sal_Bool SvXMLUnitConverter::convertNumFormat(
1664cdf0e10cSrcweir         sal_Int16& rType,
1665cdf0e10cSrcweir         const OUString& rNumFmt,
1666cdf0e10cSrcweir         const OUString& rNumLetterSync,
1667cdf0e10cSrcweir         sal_Bool bNumberNone ) const
1668cdf0e10cSrcweir {
1669cdf0e10cSrcweir     sal_Bool bRet = sal_True;
1670cdf0e10cSrcweir     sal_Bool bExt = sal_False;
1671cdf0e10cSrcweir 
1672cdf0e10cSrcweir     sal_Int32 nLen = rNumFmt.getLength();
1673cdf0e10cSrcweir     if( 0 == nLen )
1674cdf0e10cSrcweir     {
1675cdf0e10cSrcweir         if( bNumberNone )
1676cdf0e10cSrcweir             rType = NumberingType::NUMBER_NONE;
1677cdf0e10cSrcweir         else
1678cdf0e10cSrcweir             bRet = sal_False;
1679cdf0e10cSrcweir     }
1680cdf0e10cSrcweir     else if( 1 == nLen )
1681cdf0e10cSrcweir     {
1682cdf0e10cSrcweir         switch( rNumFmt[0] )
1683cdf0e10cSrcweir         {
1684cdf0e10cSrcweir         case sal_Unicode('1'):  rType = NumberingType::ARABIC;          break;
1685cdf0e10cSrcweir         case sal_Unicode('a'):  rType = NumberingType::CHARS_LOWER_LETTER;  break;
1686cdf0e10cSrcweir         case sal_Unicode('A'):  rType = NumberingType::CHARS_UPPER_LETTER;  break;
1687cdf0e10cSrcweir         case sal_Unicode('i'):  rType = NumberingType::ROMAN_LOWER; break;
1688cdf0e10cSrcweir         case sal_Unicode('I'):  rType = NumberingType::ROMAN_UPPER; break;
1689cdf0e10cSrcweir         default:                bExt = sal_True; break;
1690cdf0e10cSrcweir         }
1691cdf0e10cSrcweir         if( !bExt && IsXMLToken( rNumLetterSync, XML_TRUE ) )
1692cdf0e10cSrcweir         {
1693cdf0e10cSrcweir             switch( rType )
1694cdf0e10cSrcweir             {
1695cdf0e10cSrcweir             case NumberingType::CHARS_LOWER_LETTER:
1696cdf0e10cSrcweir                 rType = NumberingType::CHARS_LOWER_LETTER_N;
1697cdf0e10cSrcweir                 break;
1698cdf0e10cSrcweir             case NumberingType::CHARS_UPPER_LETTER:
1699cdf0e10cSrcweir                 rType = NumberingType::CHARS_UPPER_LETTER_N;
1700cdf0e10cSrcweir                 break;
1701cdf0e10cSrcweir             }
1702cdf0e10cSrcweir         }
1703cdf0e10cSrcweir     }
1704cdf0e10cSrcweir     else
1705cdf0e10cSrcweir     {
1706cdf0e10cSrcweir         bExt = sal_True;
1707cdf0e10cSrcweir     }
1708cdf0e10cSrcweir     if( bExt )
1709cdf0e10cSrcweir     {
1710cdf0e10cSrcweir         Reference < XNumberingTypeInfo > xInfo = getNumTypeInfo();
1711cdf0e10cSrcweir         if( xInfo.is() && xInfo->hasNumberingType( rNumFmt ) )
1712cdf0e10cSrcweir         {
1713cdf0e10cSrcweir             rType = xInfo->getNumberingType( rNumFmt );
1714cdf0e10cSrcweir         }
1715cdf0e10cSrcweir         else
1716cdf0e10cSrcweir         {
1717cdf0e10cSrcweir             rType = NumberingType::ARABIC;
1718cdf0e10cSrcweir         }
1719cdf0e10cSrcweir     }
1720cdf0e10cSrcweir 
1721cdf0e10cSrcweir     return bRet;
1722cdf0e10cSrcweir }
1723cdf0e10cSrcweir 
convertNumFormat(OUStringBuffer & rBuffer,sal_Int16 nType) const1724cdf0e10cSrcweir void SvXMLUnitConverter::convertNumFormat( OUStringBuffer& rBuffer,
1725cdf0e10cSrcweir                            sal_Int16 nType ) const
1726cdf0e10cSrcweir {
1727cdf0e10cSrcweir     enum XMLTokenEnum eFormat = XML_TOKEN_INVALID;
1728cdf0e10cSrcweir     sal_Bool bExt = sal_False;
1729cdf0e10cSrcweir     switch( nType )
1730cdf0e10cSrcweir     {
1731cdf0e10cSrcweir     case NumberingType::CHARS_UPPER_LETTER:     eFormat = XML_A_UPCASE; break;
1732cdf0e10cSrcweir     case NumberingType::CHARS_LOWER_LETTER:     eFormat = XML_A; break;
1733cdf0e10cSrcweir     case NumberingType::ROMAN_UPPER:            eFormat = XML_I_UPCASE; break;
1734cdf0e10cSrcweir     case NumberingType::ROMAN_LOWER:            eFormat = XML_I; break;
1735cdf0e10cSrcweir     case NumberingType::ARABIC:                 eFormat = XML_1; break;
1736cdf0e10cSrcweir     case NumberingType::CHARS_UPPER_LETTER_N:   eFormat = XML_A_UPCASE; break;
1737cdf0e10cSrcweir     case NumberingType::CHARS_LOWER_LETTER_N:   eFormat = XML_A; break;
1738cdf0e10cSrcweir     case NumberingType::NUMBER_NONE:            eFormat = XML__EMPTY; break;
1739cdf0e10cSrcweir 
1740cdf0e10cSrcweir     case NumberingType::CHAR_SPECIAL:
1741cdf0e10cSrcweir     case NumberingType::PAGE_DESCRIPTOR:
1742cdf0e10cSrcweir     case NumberingType::BITMAP:
1743cdf0e10cSrcweir         DBG_ASSERT( eFormat != XML_TOKEN_INVALID, "invalid number format" );
1744cdf0e10cSrcweir         break;
1745cdf0e10cSrcweir     default:
1746cdf0e10cSrcweir         bExt = sal_True;
1747cdf0e10cSrcweir         break;
1748cdf0e10cSrcweir     }
1749cdf0e10cSrcweir 
1750cdf0e10cSrcweir     if( eFormat != XML_TOKEN_INVALID )
1751cdf0e10cSrcweir     {
1752cdf0e10cSrcweir         rBuffer.append( GetXMLToken(eFormat) );
1753cdf0e10cSrcweir     }
1754cdf0e10cSrcweir     else
1755cdf0e10cSrcweir     {
1756cdf0e10cSrcweir         Reference < XNumberingTypeInfo > xInfo = getNumTypeInfo();
1757cdf0e10cSrcweir         if( xInfo.is() )
1758cdf0e10cSrcweir             rBuffer.append( xInfo->getNumberingIdentifier( nType ) );
1759cdf0e10cSrcweir     }
1760cdf0e10cSrcweir }
1761cdf0e10cSrcweir 
convertNumLetterSync(OUStringBuffer & rBuffer,sal_Int16 nType) const1762cdf0e10cSrcweir void SvXMLUnitConverter::convertNumLetterSync( OUStringBuffer& rBuffer,
1763cdf0e10cSrcweir                                sal_Int16 nType ) const
1764cdf0e10cSrcweir {
1765cdf0e10cSrcweir     enum XMLTokenEnum eSync = XML_TOKEN_INVALID;
1766cdf0e10cSrcweir     switch( nType )
1767cdf0e10cSrcweir     {
1768cdf0e10cSrcweir     case NumberingType::CHARS_UPPER_LETTER:
1769cdf0e10cSrcweir     case NumberingType::CHARS_LOWER_LETTER:
1770cdf0e10cSrcweir     case NumberingType::ROMAN_UPPER:
1771cdf0e10cSrcweir     case NumberingType::ROMAN_LOWER:
1772cdf0e10cSrcweir     case NumberingType::ARABIC:
1773cdf0e10cSrcweir     case NumberingType::NUMBER_NONE:
1774cdf0e10cSrcweir         // default
1775cdf0e10cSrcweir         // eSync = XML_FALSE;
1776cdf0e10cSrcweir         break;
1777cdf0e10cSrcweir 
1778cdf0e10cSrcweir     case NumberingType::CHARS_UPPER_LETTER_N:
1779cdf0e10cSrcweir     case NumberingType::CHARS_LOWER_LETTER_N:
1780cdf0e10cSrcweir         eSync = XML_TRUE;
1781cdf0e10cSrcweir         break;
1782cdf0e10cSrcweir 
1783cdf0e10cSrcweir     case NumberingType::CHAR_SPECIAL:
1784cdf0e10cSrcweir     case NumberingType::PAGE_DESCRIPTOR:
1785cdf0e10cSrcweir     case NumberingType::BITMAP:
1786cdf0e10cSrcweir         DBG_ASSERT( eSync != XML_TOKEN_INVALID, "invalid number format" );
1787cdf0e10cSrcweir         break;
1788cdf0e10cSrcweir     }
1789cdf0e10cSrcweir     if( eSync != XML_TOKEN_INVALID )
1790cdf0e10cSrcweir         rBuffer.append( GetXMLToken(eSync) );
1791cdf0e10cSrcweir }
1792cdf0e10cSrcweir 
convertPropertySet(uno::Sequence<beans::PropertyValue> & rProps,const uno::Reference<beans::XPropertySet> & aProperties)1793cdf0e10cSrcweir void SvXMLUnitConverter::convertPropertySet(uno::Sequence<beans::PropertyValue>& rProps,
1794cdf0e10cSrcweir                     const uno::Reference<beans::XPropertySet>& aProperties)
1795cdf0e10cSrcweir {
1796cdf0e10cSrcweir     uno::Reference< beans::XPropertySetInfo > xPropertySetInfo = aProperties->getPropertySetInfo();
1797cdf0e10cSrcweir     if (xPropertySetInfo.is())
1798cdf0e10cSrcweir     {
1799cdf0e10cSrcweir         uno::Sequence< beans::Property > aProps = xPropertySetInfo->getProperties();
1800cdf0e10cSrcweir         const sal_Int32 nCount(aProps.getLength());
1801cdf0e10cSrcweir         if (nCount)
1802cdf0e10cSrcweir         {
1803cdf0e10cSrcweir             rProps.realloc(nCount);
1804cdf0e10cSrcweir             beans::PropertyValue* pProps = rProps.getArray();
1805cdf0e10cSrcweir             for (sal_Int32 i = 0; i < nCount; i++, ++pProps)
1806cdf0e10cSrcweir             {
1807cdf0e10cSrcweir                 pProps->Name = aProps[i].Name;
1808cdf0e10cSrcweir                 pProps->Value = aProperties->getPropertyValue(aProps[i].Name);
1809cdf0e10cSrcweir             }
1810cdf0e10cSrcweir         }
1811cdf0e10cSrcweir     }
1812cdf0e10cSrcweir }
1813cdf0e10cSrcweir 
convertPropertySet(uno::Reference<beans::XPropertySet> & rProperties,const uno::Sequence<beans::PropertyValue> & aProps)1814cdf0e10cSrcweir void SvXMLUnitConverter::convertPropertySet(uno::Reference<beans::XPropertySet>& rProperties,
1815cdf0e10cSrcweir                     const uno::Sequence<beans::PropertyValue>& aProps)
1816cdf0e10cSrcweir {
1817cdf0e10cSrcweir     sal_Int32 nCount(aProps.getLength());
1818cdf0e10cSrcweir     if (nCount)
1819cdf0e10cSrcweir     {
1820cdf0e10cSrcweir         uno::Reference< beans::XPropertySetInfo > xPropertySetInfo = rProperties->getPropertySetInfo();
1821cdf0e10cSrcweir         if (xPropertySetInfo.is())
1822cdf0e10cSrcweir         {
1823cdf0e10cSrcweir             for (sal_Int32 i = 0; i < nCount; i++)
1824cdf0e10cSrcweir             {
1825cdf0e10cSrcweir                 if (xPropertySetInfo->hasPropertyByName(aProps[i].Name))
1826cdf0e10cSrcweir                     rProperties->setPropertyValue(aProps[i].Name, aProps[i].Value);
1827cdf0e10cSrcweir             }
1828cdf0e10cSrcweir         }
1829cdf0e10cSrcweir     }
1830cdf0e10cSrcweir }
1831cdf0e10cSrcweir 
clearUndefinedChars(rtl::OUString & rTarget,const rtl::OUString & rSource)1832cdf0e10cSrcweir void SvXMLUnitConverter::clearUndefinedChars(rtl::OUString& rTarget, const rtl::OUString& rSource)
1833cdf0e10cSrcweir {
1834cdf0e10cSrcweir 	sal_uInt32 nLength(rSource.getLength());
1835cdf0e10cSrcweir 	rtl::OUStringBuffer sBuffer(nLength);
1836cdf0e10cSrcweir 	for (sal_uInt32 i = 0; i < nLength; i++)
1837cdf0e10cSrcweir 	{
1838cdf0e10cSrcweir 		sal_Unicode cChar = rSource[i];
1839cdf0e10cSrcweir 		if (!(cChar < 0x0020) ||
1840cdf0e10cSrcweir 			(cChar == 0x0009) ||		// TAB
1841cdf0e10cSrcweir 			(cChar == 0x000A) ||		// LF
1842cdf0e10cSrcweir 			(cChar == 0x000D))			// legal character
1843cdf0e10cSrcweir 			sBuffer.append(cChar);
1844cdf0e10cSrcweir 	}
1845cdf0e10cSrcweir 	rTarget = sBuffer.makeStringAndClear();
1846cdf0e10cSrcweir }
1847cdf0e10cSrcweir 
encodeStyleName(const OUString & rName,sal_Bool * pEncoded) const1848cdf0e10cSrcweir OUString SvXMLUnitConverter::encodeStyleName(
1849cdf0e10cSrcweir 		const OUString& rName,
1850cdf0e10cSrcweir 	    sal_Bool *pEncoded ) const
1851cdf0e10cSrcweir {
1852cdf0e10cSrcweir 	if( pEncoded )
1853cdf0e10cSrcweir 		*pEncoded = sal_False;
1854cdf0e10cSrcweir 
1855cdf0e10cSrcweir 	sal_Int32 nLen = rName.getLength();
1856cdf0e10cSrcweir 	OUStringBuffer aBuffer( nLen );
1857cdf0e10cSrcweir 
1858cdf0e10cSrcweir 	for( sal_Int32 i = 0; i < nLen; i++ )
1859cdf0e10cSrcweir 	{
1860cdf0e10cSrcweir 		sal_Unicode c = rName[i];
1861cdf0e10cSrcweir 		sal_Bool bValidChar = sal_False;
1862cdf0e10cSrcweir 		if( c < 0x00ffU )
1863cdf0e10cSrcweir 		{
1864cdf0e10cSrcweir 			bValidChar =
1865cdf0e10cSrcweir 				(c >= 0x0041 && c <= 0x005a) ||
1866cdf0e10cSrcweir 				(c >= 0x0061 && c <= 0x007a) ||
1867cdf0e10cSrcweir 				(c >= 0x00c0 && c <= 0x00d6) ||
1868cdf0e10cSrcweir 				(c >= 0x00d8 && c <= 0x00f6) ||
1869cdf0e10cSrcweir 				(c >= 0x00f8 && c <= 0x00ff) ||
1870cdf0e10cSrcweir 				( i > 0 && ( (c >= 0x0030 && c <= 0x0039) ||
1871cdf0e10cSrcweir 							 c == 0x00b7 || c == '-' || c == '.') );
1872cdf0e10cSrcweir 		}
1873cdf0e10cSrcweir 		else
1874cdf0e10cSrcweir 		{
1875cdf0e10cSrcweir 			if( (c >= 0xf900U && c <= 0xfffeU) ||
1876cdf0e10cSrcweir 			 	(c >= 0x20ddU && c <= 0x20e0U))
1877cdf0e10cSrcweir 			{
1878cdf0e10cSrcweir 				bValidChar = sal_False;
1879cdf0e10cSrcweir 			}
1880cdf0e10cSrcweir 			else if( (c >= 0x02bbU && c <= 0x02c1U) || c == 0x0559 ||
1881cdf0e10cSrcweir 					 c == 0x06e5 || c == 0x06e6 )
1882cdf0e10cSrcweir 			{
1883cdf0e10cSrcweir 				bValidChar = sal_True;
1884cdf0e10cSrcweir 			}
1885cdf0e10cSrcweir 			else if( c == 0x0387 )
1886cdf0e10cSrcweir 			{
1887cdf0e10cSrcweir 				bValidChar = i > 0;
1888cdf0e10cSrcweir 			}
1889cdf0e10cSrcweir 			else
1890cdf0e10cSrcweir 			{
1891cdf0e10cSrcweir 				if( !xCharClass.is() )
1892cdf0e10cSrcweir 				{
1893cdf0e10cSrcweir 					if( mxServiceFactory.is() )
1894cdf0e10cSrcweir 					{
1895cdf0e10cSrcweir 						try
1896cdf0e10cSrcweir 						{
1897cdf0e10cSrcweir 							const_cast < SvXMLUnitConverter * >(this)
1898cdf0e10cSrcweir 								->xCharClass =
1899cdf0e10cSrcweir 									Reference < XCharacterClassification >(
1900cdf0e10cSrcweir 								mxServiceFactory->createInstance(
1901cdf0e10cSrcweir 									OUString::createFromAscii(
1902cdf0e10cSrcweir 						"com.sun.star.i18n.CharacterClassification_Unicode") ),
1903cdf0e10cSrcweir 								UNO_QUERY );
1904cdf0e10cSrcweir 
1905cdf0e10cSrcweir 							OSL_ENSURE( xCharClass.is(),
1906cdf0e10cSrcweir 					"can't instantiate character clossification component" );
1907cdf0e10cSrcweir 						}
1908cdf0e10cSrcweir 						catch( com::sun::star::uno::Exception& )
1909cdf0e10cSrcweir 						{
1910cdf0e10cSrcweir 						}
1911cdf0e10cSrcweir 					}
1912cdf0e10cSrcweir 				}
1913cdf0e10cSrcweir 				if( xCharClass.is() )
1914cdf0e10cSrcweir 				{
1915cdf0e10cSrcweir 					sal_Int16 nType = xCharClass->getType( rName, i );
1916cdf0e10cSrcweir 
1917cdf0e10cSrcweir 					switch( nType )
1918cdf0e10cSrcweir 					{
1919cdf0e10cSrcweir 					case UnicodeType::UPPERCASE_LETTER:		// Lu
1920cdf0e10cSrcweir 					case UnicodeType::LOWERCASE_LETTER:		// Ll
1921cdf0e10cSrcweir 					case UnicodeType::TITLECASE_LETTER:		// Lt
1922cdf0e10cSrcweir 					case UnicodeType::OTHER_LETTER:			// Lo
1923cdf0e10cSrcweir 					case UnicodeType::LETTER_NUMBER: 		// Nl
1924cdf0e10cSrcweir 						bValidChar = sal_True;
1925cdf0e10cSrcweir 						break;
1926cdf0e10cSrcweir 					case UnicodeType::NON_SPACING_MARK:		// Ms
1927cdf0e10cSrcweir 					case UnicodeType::ENCLOSING_MARK:		// Me
1928cdf0e10cSrcweir 					case UnicodeType::COMBINING_SPACING_MARK:	//Mc
1929cdf0e10cSrcweir 					case UnicodeType::MODIFIER_LETTER:		// Lm
1930cdf0e10cSrcweir 					case UnicodeType::DECIMAL_DIGIT_NUMBER:	// Nd
1931cdf0e10cSrcweir 						bValidChar = i > 0;
1932cdf0e10cSrcweir 						break;
1933cdf0e10cSrcweir 					}
1934cdf0e10cSrcweir 				}
1935cdf0e10cSrcweir 			}
1936cdf0e10cSrcweir 		}
1937cdf0e10cSrcweir 		if( bValidChar )
1938cdf0e10cSrcweir 		{
1939cdf0e10cSrcweir 			aBuffer.append( c );
1940cdf0e10cSrcweir 		}
1941cdf0e10cSrcweir 		else
1942cdf0e10cSrcweir 		{
1943cdf0e10cSrcweir 			aBuffer.append( static_cast< sal_Unicode >( '_' ) );
1944cdf0e10cSrcweir 			if( c > 0x0fff )
1945cdf0e10cSrcweir 				aBuffer.append( static_cast< sal_Unicode >(
1946cdf0e10cSrcweir 							aHexTab[ (c >> 12) & 0x0f ]  ) );
1947cdf0e10cSrcweir 			if( c > 0x00ff )
1948cdf0e10cSrcweir 				aBuffer.append( static_cast< sal_Unicode >(
1949cdf0e10cSrcweir 						aHexTab[ (c >> 8) & 0x0f ] ) );
1950cdf0e10cSrcweir 			if( c > 0x000f )
1951cdf0e10cSrcweir 				aBuffer.append( static_cast< sal_Unicode >(
1952cdf0e10cSrcweir 						aHexTab[ (c >> 4) & 0x0f ] ) );
1953cdf0e10cSrcweir 			aBuffer.append( static_cast< sal_Unicode >(
1954cdf0e10cSrcweir 						aHexTab[ c & 0x0f ] ) );
1955cdf0e10cSrcweir 			aBuffer.append( static_cast< sal_Unicode >( '_' ) );
1956cdf0e10cSrcweir 			if( pEncoded )
1957cdf0e10cSrcweir 				*pEncoded = sal_True;
1958cdf0e10cSrcweir 		}
1959cdf0e10cSrcweir 	}
1960cdf0e10cSrcweir 
1961cdf0e10cSrcweir 	// check for length
1962cdf0e10cSrcweir 	if( aBuffer.getLength() > ((1<<15)-1) )
1963cdf0e10cSrcweir 	{
1964cdf0e10cSrcweir 		aBuffer = rName;
1965cdf0e10cSrcweir 		if( pEncoded )
1966cdf0e10cSrcweir 			*pEncoded = sal_False;
1967cdf0e10cSrcweir 	}
1968cdf0e10cSrcweir 
1969cdf0e10cSrcweir 
1970cdf0e10cSrcweir 	return aBuffer.makeStringAndClear();
1971cdf0e10cSrcweir }
1972cdf0e10cSrcweir 
1973cdf0e10cSrcweir // static
convertTimeDuration(const Time & rTime,sal_Int32 nSecondsFraction)1974cdf0e10cSrcweir rtl::OUString SvXMLUnitConverter::convertTimeDuration( const Time& rTime, sal_Int32 nSecondsFraction )
1975cdf0e10cSrcweir {
1976cdf0e10cSrcweir     //  return ISO time period string
1977cdf0e10cSrcweir     rtl::OUStringBuffer sTmp;
1978cdf0e10cSrcweir     sTmp.append( sal_Unicode('P') );                // "period"
1979cdf0e10cSrcweir 
1980cdf0e10cSrcweir     sal_uInt16 nHours = rTime.GetHour();
1981cdf0e10cSrcweir     sal_Bool bHasHours = ( nHours > 0 );
1982cdf0e10cSrcweir     if ( nHours >= 24 )
1983cdf0e10cSrcweir     {
1984cdf0e10cSrcweir         //  add days
1985cdf0e10cSrcweir 
1986cdf0e10cSrcweir         sal_uInt16 nDays = nHours / 24;
1987cdf0e10cSrcweir         sTmp.append( (sal_Int32) nDays );
1988cdf0e10cSrcweir         sTmp.append( sal_Unicode('D') );            // "days"
1989cdf0e10cSrcweir 
1990cdf0e10cSrcweir         nHours -= nDays * 24;
1991cdf0e10cSrcweir     }
1992cdf0e10cSrcweir     sTmp.append( sal_Unicode('T') );                // "time"
1993cdf0e10cSrcweir 
1994cdf0e10cSrcweir     if ( bHasHours )
1995cdf0e10cSrcweir     {
1996cdf0e10cSrcweir         sTmp.append( (sal_Int32) nHours );
1997cdf0e10cSrcweir         sTmp.append( sal_Unicode('H') );            // "hours"
1998cdf0e10cSrcweir     }
1999cdf0e10cSrcweir     sal_uInt16 nMinutes = rTime.GetMin();
2000cdf0e10cSrcweir     if ( bHasHours || nMinutes > 0 )
2001cdf0e10cSrcweir     {
2002cdf0e10cSrcweir         sTmp.append( (sal_Int32) nMinutes );
2003cdf0e10cSrcweir         sTmp.append( sal_Unicode('M') );            // "minutes"
2004cdf0e10cSrcweir     }
2005cdf0e10cSrcweir     sal_uInt16 nSeconds = rTime.GetSec();
2006cdf0e10cSrcweir     sTmp.append( (sal_Int32) nSeconds );
2007cdf0e10cSrcweir     if ( nSecondsFraction )
2008cdf0e10cSrcweir     {
2009cdf0e10cSrcweir         sTmp.append( sal_Unicode( '.' ) );
2010cdf0e10cSrcweir         ::rtl::OUStringBuffer aFractional;
2011cdf0e10cSrcweir         convertNumber( aFractional, nSecondsFraction );
2012cdf0e10cSrcweir         sTmp.append( aFractional.getStr() );
2013cdf0e10cSrcweir     }
2014cdf0e10cSrcweir     sTmp.append( sal_Unicode('S') );            // "seconds"
2015cdf0e10cSrcweir 
2016cdf0e10cSrcweir     return sTmp.makeStringAndClear();
2017cdf0e10cSrcweir }
2018cdf0e10cSrcweir 
2019cdf0e10cSrcweir // static
convertTimeDuration(const rtl::OUString & rString,Time & rTime,sal_Int32 * pSecondsFraction)2020cdf0e10cSrcweir bool SvXMLUnitConverter::convertTimeDuration( const rtl::OUString& rString, Time& rTime, sal_Int32* pSecondsFraction )
2021cdf0e10cSrcweir {
2022cdf0e10cSrcweir     rtl::OUString aTrimmed = rString.trim().toAsciiUpperCase();
2023cdf0e10cSrcweir     const sal_Unicode* pStr = aTrimmed.getStr();
2024cdf0e10cSrcweir 
2025cdf0e10cSrcweir     if ( *(pStr++) != sal_Unicode('P') )            // duration must start with "P"
2026cdf0e10cSrcweir         return false;
2027cdf0e10cSrcweir 
2028cdf0e10cSrcweir     bool bSuccess = true;
2029cdf0e10cSrcweir     sal_Bool bDone = sal_False;
2030cdf0e10cSrcweir     sal_Bool bTimePart = sal_False;
2031cdf0e10cSrcweir     sal_Bool bFractional = sal_False;
2032cdf0e10cSrcweir     sal_Int32 nDays  = 0;
2033cdf0e10cSrcweir     sal_Int32 nHours = 0;
2034cdf0e10cSrcweir     sal_Int32 nMins  = 0;
2035cdf0e10cSrcweir     sal_Int32 nSecs  = 0;
2036cdf0e10cSrcweir     sal_Int32 nTemp = 0;
2037cdf0e10cSrcweir     sal_Int32 nSecondsFraction = 0;
2038cdf0e10cSrcweir 
2039cdf0e10cSrcweir     while ( bSuccess && !bDone )
2040cdf0e10cSrcweir     {
2041cdf0e10cSrcweir         sal_Unicode c = *(pStr++);
2042cdf0e10cSrcweir         if ( !c )                               // end
2043cdf0e10cSrcweir             bDone = sal_True;
2044cdf0e10cSrcweir         else if ( sal_Unicode('0') <= c && sal_Unicode('9') >= c )
2045cdf0e10cSrcweir         {
2046cdf0e10cSrcweir             if ( bFractional )
2047cdf0e10cSrcweir             {
2048cdf0e10cSrcweir                 if ( nSecondsFraction >= SAL_MAX_INT32 / 10 )
2049cdf0e10cSrcweir                     bSuccess = false;
2050cdf0e10cSrcweir                 else
2051cdf0e10cSrcweir                 {
2052cdf0e10cSrcweir                     nSecondsFraction *= 10;
2053cdf0e10cSrcweir                     nSecondsFraction += (c - sal_Unicode('0'));
2054cdf0e10cSrcweir                 }
2055cdf0e10cSrcweir             }
2056cdf0e10cSrcweir             else
2057cdf0e10cSrcweir             {
2058cdf0e10cSrcweir                 if ( nTemp >= SAL_MAX_INT32 / 10 )
2059cdf0e10cSrcweir                     bSuccess = false;
2060cdf0e10cSrcweir                 else
2061cdf0e10cSrcweir                 {
2062cdf0e10cSrcweir                     nTemp *= 10;
2063cdf0e10cSrcweir                     nTemp += (c - sal_Unicode('0'));
2064cdf0e10cSrcweir                 }
2065cdf0e10cSrcweir             }
2066cdf0e10cSrcweir         }
2067cdf0e10cSrcweir         else if ( bTimePart )
2068cdf0e10cSrcweir         {
2069cdf0e10cSrcweir             if ( c == sal_Unicode('H') )
2070cdf0e10cSrcweir             {
2071cdf0e10cSrcweir                 nHours = nTemp;
2072cdf0e10cSrcweir                 nTemp = 0;
2073cdf0e10cSrcweir             }
2074cdf0e10cSrcweir             else if ( c == sal_Unicode('M') )
2075cdf0e10cSrcweir             {
2076cdf0e10cSrcweir                 nMins = nTemp;
2077cdf0e10cSrcweir                 nTemp = 0;
2078cdf0e10cSrcweir             }
2079cdf0e10cSrcweir             else if ( c == sal_Unicode('S') )
2080cdf0e10cSrcweir             {
2081cdf0e10cSrcweir                 nSecs = nTemp;
2082cdf0e10cSrcweir                 nTemp = 0;
2083cdf0e10cSrcweir             }
2084cdf0e10cSrcweir             else if ( c == '.' )
2085cdf0e10cSrcweir             {
2086cdf0e10cSrcweir                 bFractional = sal_True;
2087cdf0e10cSrcweir             }
2088cdf0e10cSrcweir             else
2089cdf0e10cSrcweir                 bSuccess = false;               // invalid characted
2090cdf0e10cSrcweir         }
2091cdf0e10cSrcweir         else
2092cdf0e10cSrcweir         {
2093cdf0e10cSrcweir             if ( c == sal_Unicode('T') )            // "T" starts time part
2094cdf0e10cSrcweir                 bTimePart = sal_True;
2095cdf0e10cSrcweir             else if ( c == sal_Unicode('D') )
2096cdf0e10cSrcweir             {
2097cdf0e10cSrcweir                 nDays = nTemp;
2098cdf0e10cSrcweir                 nTemp = 0;
2099cdf0e10cSrcweir             }
2100cdf0e10cSrcweir             else if ( c == sal_Unicode('Y') || c == sal_Unicode('M') )
2101cdf0e10cSrcweir             {
2102cdf0e10cSrcweir                 //! how many days is a year or month?
2103cdf0e10cSrcweir 
2104cdf0e10cSrcweir                 DBG_ERROR("years or months in duration: not implemented");
2105cdf0e10cSrcweir                 bSuccess = false;
2106cdf0e10cSrcweir             }
2107cdf0e10cSrcweir             else
2108cdf0e10cSrcweir                 bSuccess = false;               // invalid characted
2109cdf0e10cSrcweir         }
2110cdf0e10cSrcweir     }
2111cdf0e10cSrcweir 
2112cdf0e10cSrcweir     if ( bSuccess )
2113cdf0e10cSrcweir     {
2114cdf0e10cSrcweir         if ( nDays )
2115cdf0e10cSrcweir             nHours += nDays * 24;               // add the days to the hours part
2116cdf0e10cSrcweir         rTime = Time( nHours, nMins, nSecs );
2117cdf0e10cSrcweir         if ( pSecondsFraction )
2118cdf0e10cSrcweir             *pSecondsFraction = nSecondsFraction % 1000;
2119cdf0e10cSrcweir     }
2120cdf0e10cSrcweir     return bSuccess;
2121cdf0e10cSrcweir }
2122cdf0e10cSrcweir 
convertAny(::rtl::OUStringBuffer & sValue,::rtl::OUStringBuffer & sType,const com::sun::star::uno::Any & aValue)2123cdf0e10cSrcweir sal_Bool SvXMLUnitConverter::convertAny(      ::rtl::OUStringBuffer&    sValue,
2124cdf0e10cSrcweir                                               ::rtl::OUStringBuffer&    sType ,
2125cdf0e10cSrcweir                                         const com::sun::star::uno::Any& aValue)
2126cdf0e10cSrcweir {
2127cdf0e10cSrcweir     sal_Bool bConverted = sal_False;
2128cdf0e10cSrcweir 
2129cdf0e10cSrcweir     sValue.setLength(0);
2130cdf0e10cSrcweir     sType.setLength (0);
2131cdf0e10cSrcweir 
2132cdf0e10cSrcweir     switch(aValue.getValueTypeClass())
2133cdf0e10cSrcweir     {
2134cdf0e10cSrcweir         case com::sun::star::uno::TypeClass_BYTE :
2135cdf0e10cSrcweir         case com::sun::star::uno::TypeClass_SHORT :
2136cdf0e10cSrcweir         case com::sun::star::uno::TypeClass_UNSIGNED_SHORT :
2137cdf0e10cSrcweir         case com::sun::star::uno::TypeClass_LONG :
2138cdf0e10cSrcweir         case com::sun::star::uno::TypeClass_UNSIGNED_LONG :
2139cdf0e10cSrcweir             {
2140cdf0e10cSrcweir                 sal_Int32 nTempValue = 0;
2141cdf0e10cSrcweir                 if (aValue >>= nTempValue)
2142cdf0e10cSrcweir                 {
2143cdf0e10cSrcweir                     sType.appendAscii("integer");
2144cdf0e10cSrcweir                     bConverted = sal_True;
2145cdf0e10cSrcweir                     SvXMLUnitConverter::convertNumber(sValue, nTempValue);
2146cdf0e10cSrcweir                 }
2147cdf0e10cSrcweir             }
2148cdf0e10cSrcweir             break;
2149cdf0e10cSrcweir 
2150cdf0e10cSrcweir         case com::sun::star::uno::TypeClass_BOOLEAN :
2151cdf0e10cSrcweir             {
2152cdf0e10cSrcweir                 sal_Bool bTempValue = sal_False;
2153cdf0e10cSrcweir                 if (aValue >>= bTempValue)
2154cdf0e10cSrcweir                 {
2155cdf0e10cSrcweir                     sType.appendAscii("boolean");
2156cdf0e10cSrcweir                     bConverted = sal_True;
2157cdf0e10cSrcweir                     SvXMLUnitConverter::convertBool(sValue, bTempValue);
2158cdf0e10cSrcweir                 }
2159cdf0e10cSrcweir             }
2160cdf0e10cSrcweir             break;
2161cdf0e10cSrcweir 
2162cdf0e10cSrcweir         case com::sun::star::uno::TypeClass_FLOAT :
2163cdf0e10cSrcweir         case com::sun::star::uno::TypeClass_DOUBLE :
2164cdf0e10cSrcweir             {
2165cdf0e10cSrcweir                 double fTempValue = 0.0;
2166cdf0e10cSrcweir                 if (aValue >>= fTempValue)
2167cdf0e10cSrcweir                 {
2168cdf0e10cSrcweir                     sType.appendAscii("float");
2169cdf0e10cSrcweir                     bConverted = sal_True;
2170cdf0e10cSrcweir                     SvXMLUnitConverter::convertDouble(sValue, fTempValue);
2171cdf0e10cSrcweir                 }
2172cdf0e10cSrcweir             }
2173cdf0e10cSrcweir             break;
2174cdf0e10cSrcweir 
2175cdf0e10cSrcweir         case com::sun::star::uno::TypeClass_STRING :
2176cdf0e10cSrcweir             {
2177cdf0e10cSrcweir                 ::rtl::OUString sTempValue;
2178cdf0e10cSrcweir                 if (aValue >>= sTempValue)
2179cdf0e10cSrcweir                 {
2180cdf0e10cSrcweir                     sType.appendAscii("string");
2181cdf0e10cSrcweir                     bConverted = sal_True;
2182cdf0e10cSrcweir                     sValue.append(sTempValue);
2183cdf0e10cSrcweir                 }
2184cdf0e10cSrcweir             }
2185cdf0e10cSrcweir             break;
2186cdf0e10cSrcweir 
2187cdf0e10cSrcweir         case com::sun::star::uno::TypeClass_STRUCT :
2188cdf0e10cSrcweir             {
2189cdf0e10cSrcweir                 com::sun::star::util::Date     aDate    ;
2190cdf0e10cSrcweir                 com::sun::star::util::Time     aTime    ;
2191cdf0e10cSrcweir                 com::sun::star::util::DateTime aDateTime;
2192cdf0e10cSrcweir 
2193cdf0e10cSrcweir                 if (aValue >>= aDate)
2194cdf0e10cSrcweir                 {
2195cdf0e10cSrcweir                     sType.appendAscii("date");
2196cdf0e10cSrcweir                     bConverted = sal_True;
2197cdf0e10cSrcweir                     com::sun::star::util::DateTime aTempValue;
2198cdf0e10cSrcweir                     aTempValue.Day              = aDate.Day;
2199cdf0e10cSrcweir                     aTempValue.Month            = aDate.Month;
2200cdf0e10cSrcweir                     aTempValue.Year             = aDate.Year;
2201cdf0e10cSrcweir                     aTempValue.HundredthSeconds = 0;
2202cdf0e10cSrcweir                     aTempValue.Seconds          = 0;
2203cdf0e10cSrcweir                     aTempValue.Minutes          = 0;
2204cdf0e10cSrcweir                     aTempValue.Hours            = 0;
2205cdf0e10cSrcweir                     SvXMLUnitConverter::convertDateTime(sValue, aTempValue);
2206cdf0e10cSrcweir                 }
2207cdf0e10cSrcweir                 else
2208cdf0e10cSrcweir                 if (aValue >>= aTime)
2209cdf0e10cSrcweir                 {
2210cdf0e10cSrcweir                     sType.appendAscii("time");
2211cdf0e10cSrcweir                     bConverted = sal_True;
2212cdf0e10cSrcweir                     com::sun::star::util::DateTime aTempValue;
2213cdf0e10cSrcweir                     aTempValue.Day              = 0;
2214cdf0e10cSrcweir                     aTempValue.Month            = 0;
2215cdf0e10cSrcweir                     aTempValue.Year             = 0;
2216cdf0e10cSrcweir                     aTempValue.HundredthSeconds = aTime.HundredthSeconds;
2217cdf0e10cSrcweir                     aTempValue.Seconds          = aTime.Seconds;
2218cdf0e10cSrcweir                     aTempValue.Minutes          = aTime.Minutes;
2219cdf0e10cSrcweir                     aTempValue.Hours            = aTime.Hours;
2220cdf0e10cSrcweir                     SvXMLUnitConverter::convertTime(sValue, aTempValue);
2221cdf0e10cSrcweir                 }
2222cdf0e10cSrcweir                 else
2223cdf0e10cSrcweir                 if (aValue >>= aDateTime)
2224cdf0e10cSrcweir                 {
2225cdf0e10cSrcweir                     sType.appendAscii("date");
2226cdf0e10cSrcweir                     bConverted = sal_True;
2227cdf0e10cSrcweir                     SvXMLUnitConverter::convertDateTime(sValue, aDateTime);
2228cdf0e10cSrcweir                 }
2229cdf0e10cSrcweir             }
2230cdf0e10cSrcweir             break;
2231cdf0e10cSrcweir 		default:
2232cdf0e10cSrcweir 			break;
2233cdf0e10cSrcweir     }
2234cdf0e10cSrcweir 
2235cdf0e10cSrcweir     return bConverted;
2236cdf0e10cSrcweir }
2237cdf0e10cSrcweir 
convertAny(com::sun::star::uno::Any & aValue,const::rtl::OUString & sType,const::rtl::OUString & sValue)2238cdf0e10cSrcweir sal_Bool SvXMLUnitConverter::convertAny(      com::sun::star::uno::Any& aValue,
2239cdf0e10cSrcweir                                         const ::rtl::OUString&          sType ,
2240cdf0e10cSrcweir                                         const ::rtl::OUString&          sValue)
2241cdf0e10cSrcweir {
2242cdf0e10cSrcweir     sal_Bool bConverted = sal_False;
2243cdf0e10cSrcweir 
2244cdf0e10cSrcweir     if (sType.equalsAscii("boolean"))
2245cdf0e10cSrcweir     {
2246cdf0e10cSrcweir         sal_Bool bTempValue = sal_False;
2247cdf0e10cSrcweir         SvXMLUnitConverter::convertBool(bTempValue, sValue);
2248cdf0e10cSrcweir         aValue <<= bTempValue;
2249cdf0e10cSrcweir         bConverted = sal_True;
2250cdf0e10cSrcweir     }
2251cdf0e10cSrcweir     else
2252cdf0e10cSrcweir     if (sType.equalsAscii("integer"))
2253cdf0e10cSrcweir     {
2254cdf0e10cSrcweir         sal_Int32 nTempValue = 0;
2255cdf0e10cSrcweir         SvXMLUnitConverter::convertNumber(nTempValue, sValue);
2256cdf0e10cSrcweir         aValue <<= nTempValue;
2257cdf0e10cSrcweir         bConverted = sal_True;
2258cdf0e10cSrcweir     }
2259cdf0e10cSrcweir     else
2260cdf0e10cSrcweir     if (sType.equalsAscii("float"))
2261cdf0e10cSrcweir     {
2262cdf0e10cSrcweir         double fTempValue = 0.0;
2263cdf0e10cSrcweir         SvXMLUnitConverter::convertDouble(fTempValue, sValue);
2264cdf0e10cSrcweir         aValue <<= fTempValue;
2265cdf0e10cSrcweir         bConverted = sal_True;
2266cdf0e10cSrcweir     }
2267cdf0e10cSrcweir     else
2268cdf0e10cSrcweir     if (sType.equalsAscii("string"))
2269cdf0e10cSrcweir     {
2270cdf0e10cSrcweir         aValue <<= sValue;
2271cdf0e10cSrcweir         bConverted = sal_True;
2272cdf0e10cSrcweir     }
2273cdf0e10cSrcweir     else
2274cdf0e10cSrcweir     if (sType.equalsAscii("date"))
2275cdf0e10cSrcweir     {
2276cdf0e10cSrcweir         com::sun::star::util::DateTime aTempValue;
2277cdf0e10cSrcweir         SvXMLUnitConverter::convertDateTime(aTempValue, sValue);
2278cdf0e10cSrcweir         aValue <<= aTempValue;
2279cdf0e10cSrcweir         bConverted = sal_True;
2280cdf0e10cSrcweir     }
2281cdf0e10cSrcweir     else
2282cdf0e10cSrcweir     if (sType.equalsAscii("time"))
2283cdf0e10cSrcweir     {
2284cdf0e10cSrcweir         com::sun::star::util::DateTime aTempValue;
2285cdf0e10cSrcweir         com::sun::star::util::Time     aConvValue;
2286cdf0e10cSrcweir         SvXMLUnitConverter::convertTime(aTempValue, sValue);
2287cdf0e10cSrcweir         aConvValue.HundredthSeconds = aTempValue.HundredthSeconds;
2288cdf0e10cSrcweir         aConvValue.Seconds          = aTempValue.Seconds;
2289cdf0e10cSrcweir         aConvValue.Minutes          = aTempValue.Minutes;
2290cdf0e10cSrcweir         aConvValue.Hours            = aTempValue.Hours;
2291cdf0e10cSrcweir         aValue <<= aConvValue;
2292cdf0e10cSrcweir         bConverted = sal_True;
2293cdf0e10cSrcweir     }
2294cdf0e10cSrcweir 
2295cdf0e10cSrcweir     return bConverted;
2296cdf0e10cSrcweir }
2297