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