xref: /aoo42x/main/xmloff/source/core/xmlehelp.cxx (revision 63bba73c)
1*63bba73cSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*63bba73cSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*63bba73cSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*63bba73cSAndrew Rist  * distributed with this work for additional information
6*63bba73cSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*63bba73cSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*63bba73cSAndrew Rist  * "License"); you may not use this file except in compliance
9*63bba73cSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*63bba73cSAndrew Rist  *
11*63bba73cSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*63bba73cSAndrew Rist  *
13*63bba73cSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*63bba73cSAndrew Rist  * software distributed under the License is distributed on an
15*63bba73cSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*63bba73cSAndrew Rist  * KIND, either express or implied.  See the License for the
17*63bba73cSAndrew Rist  * specific language governing permissions and limitations
18*63bba73cSAndrew Rist  * under the License.
19*63bba73cSAndrew Rist  *
20*63bba73cSAndrew Rist  *************************************************************/
21*63bba73cSAndrew Rist 
22*63bba73cSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_xmloff.hxx"
26cdf0e10cSrcweir #include <limits.h>
27cdf0e10cSrcweir #include <tools/debug.hxx>
28cdf0e10cSrcweir #include <tools/bigint.hxx>
29cdf0e10cSrcweir #include <rtl/ustrbuf.hxx>
30cdf0e10cSrcweir #include "xmlehelp.hxx"
31cdf0e10cSrcweir 
32cdf0e10cSrcweir #ifndef _XMLOFF_XMTOKEN_HXX
33cdf0e10cSrcweir #include <xmloff/xmltoken.hxx>
34cdf0e10cSrcweir #endif
35cdf0e10cSrcweir 
36cdf0e10cSrcweir using ::rtl::OUString;
37cdf0e10cSrcweir using ::rtl::OUStringBuffer;
38cdf0e10cSrcweir 
39cdf0e10cSrcweir using namespace ::xmloff::token;
40cdf0e10cSrcweir 
AddLength(sal_Int32 nValue,MapUnit eValueUnit,OUStringBuffer & rOut,MapUnit eOutUnit)41cdf0e10cSrcweir void SvXMLExportHelper::AddLength( sal_Int32 nValue, MapUnit eValueUnit,
42cdf0e10cSrcweir 		   			  	   		   OUStringBuffer& rOut,
43cdf0e10cSrcweir 								   MapUnit eOutUnit )
44cdf0e10cSrcweir {
45cdf0e10cSrcweir 	// the sign is processed seperatly
46cdf0e10cSrcweir 	if( nValue < 0 )
47cdf0e10cSrcweir 	{
48cdf0e10cSrcweir 		nValue = -nValue;
49cdf0e10cSrcweir 		rOut.append( sal_Unicode('-') );
50cdf0e10cSrcweir 	}
51cdf0e10cSrcweir 
52cdf0e10cSrcweir 	// The new length is (nVal * nMul)/(nDiv*nFac*10)
53cdf0e10cSrcweir 	sal_Int32 nMul = 1000;
54cdf0e10cSrcweir 	sal_Int32 nDiv = 1;
55cdf0e10cSrcweir 	sal_Int32 nFac = 100;
56cdf0e10cSrcweir 	enum XMLTokenEnum eUnit = XML_TOKEN_INVALID;
57cdf0e10cSrcweir 	switch( eValueUnit )
58cdf0e10cSrcweir 	{
59cdf0e10cSrcweir 	case MAP_TWIP:
60cdf0e10cSrcweir 		switch( eOutUnit )
61cdf0e10cSrcweir 		{
62cdf0e10cSrcweir 		case MAP_100TH_MM:
63cdf0e10cSrcweir 		case MAP_10TH_MM:
64cdf0e10cSrcweir 			DBG_ASSERT( MAP_INCH == eOutUnit,
65cdf0e10cSrcweir 						"output unit not supported for twip values" );
66cdf0e10cSrcweir 		case MAP_MM:
67cdf0e10cSrcweir 			// 0.01mm = 0.57twip (exactly)
68cdf0e10cSrcweir 			nMul = 25400;	// 25.4 * 1000
69cdf0e10cSrcweir 			nDiv = 1440;	// 72 * 20;
70cdf0e10cSrcweir 			nFac = 100;
71cdf0e10cSrcweir 			eUnit = XML_UNIT_MM;
72cdf0e10cSrcweir 			break;
73cdf0e10cSrcweir 
74cdf0e10cSrcweir 		case MAP_CM:
75cdf0e10cSrcweir 			// 0.001cm = 0.57twip (exactly)
76cdf0e10cSrcweir 			nMul = 25400;	// 2.54 * 10000
77cdf0e10cSrcweir 			nDiv = 1440;	// 72 * 20;
78cdf0e10cSrcweir 			nFac = 1000;
79cdf0e10cSrcweir 			eUnit = XML_UNIT_CM;
80cdf0e10cSrcweir 			break;
81cdf0e10cSrcweir 
82cdf0e10cSrcweir 		case MAP_POINT:
83cdf0e10cSrcweir 			// 0.01pt = 0.2twip (exactly)
84cdf0e10cSrcweir 			nMul = 1000;
85cdf0e10cSrcweir 			nDiv = 20;
86cdf0e10cSrcweir 			nFac = 100;
87cdf0e10cSrcweir 			eUnit = XML_UNIT_PT;
88cdf0e10cSrcweir 			break;
89cdf0e10cSrcweir 
90cdf0e10cSrcweir 		case MAP_INCH:
91cdf0e10cSrcweir 		default:
92cdf0e10cSrcweir 			DBG_ASSERT( MAP_INCH == eOutUnit,
93cdf0e10cSrcweir 						"output unit not supported for twip values" );
94cdf0e10cSrcweir 			// 0.0001in = 0.144twip (exactly)
95cdf0e10cSrcweir 			nMul = 100000;
96cdf0e10cSrcweir 			nDiv = 1440;	// 72 * 20;
97cdf0e10cSrcweir 			nFac = 10000;
98cdf0e10cSrcweir 			eUnit = XML_UNIT_INCH;
99cdf0e10cSrcweir 			break;
100cdf0e10cSrcweir 		}
101cdf0e10cSrcweir 		break;
102cdf0e10cSrcweir 
103cdf0e10cSrcweir 	case MAP_POINT:
104cdf0e10cSrcweir 		// 1pt = 1pt (exactly)
105cdf0e10cSrcweir 		DBG_ASSERT( MAP_POINT == eOutUnit,
106cdf0e10cSrcweir 					"output unit not supported for pt values" );
107cdf0e10cSrcweir 		nMul = 10;
108cdf0e10cSrcweir 		nDiv = 1;
109cdf0e10cSrcweir 		nFac = 1;
110cdf0e10cSrcweir 		eUnit = XML_UNIT_PT;
111cdf0e10cSrcweir 		break;
112cdf0e10cSrcweir     case MAP_10TH_MM:
113cdf0e10cSrcweir 	case MAP_100TH_MM:
114cdf0e10cSrcweir         {
115cdf0e10cSrcweir             long nFac2 = (MAP_100TH_MM == eValueUnit) ? 100 : 10;
116cdf0e10cSrcweir 		    switch( eOutUnit )
117cdf0e10cSrcweir 		    {
118cdf0e10cSrcweir 		    case MAP_100TH_MM:
119cdf0e10cSrcweir 		    case MAP_10TH_MM:
120cdf0e10cSrcweir 			    DBG_ASSERT( MAP_INCH == eOutUnit,
121cdf0e10cSrcweir 						    "output unit not supported for 1/100mm values" );
122cdf0e10cSrcweir 		    case MAP_MM:
123cdf0e10cSrcweir 			    // 0.01mm = 1 mm/100 (exactly)
124cdf0e10cSrcweir 			    nMul = 10;
125cdf0e10cSrcweir 			    nDiv = 1;
126cdf0e10cSrcweir 			    nFac = nFac2;
127cdf0e10cSrcweir 			    eUnit = XML_UNIT_MM;
128cdf0e10cSrcweir 			    break;
129cdf0e10cSrcweir 
130cdf0e10cSrcweir 		    case MAP_CM:
131cdf0e10cSrcweir 			    // 0.001mm = 1 mm/100 (exactly)
132cdf0e10cSrcweir 			    nMul = 10;
133cdf0e10cSrcweir 			    nDiv = 1;	// 72 * 20;
134cdf0e10cSrcweir 			    nFac = 10*nFac2;
135cdf0e10cSrcweir 			    eUnit = XML_UNIT_CM;
136cdf0e10cSrcweir 			    break;
137cdf0e10cSrcweir 
138cdf0e10cSrcweir 		    case MAP_POINT:
139cdf0e10cSrcweir 			    // 0.01pt = 0.35 mm/100 (exactly)
140cdf0e10cSrcweir 			    nMul = 72000;
141cdf0e10cSrcweir 			    nDiv = 2540;
142cdf0e10cSrcweir 			    nFac = nFac2;
143cdf0e10cSrcweir 			    eUnit = XML_UNIT_PT;
144cdf0e10cSrcweir 			    break;
145cdf0e10cSrcweir 
146cdf0e10cSrcweir 		    case MAP_INCH:
147cdf0e10cSrcweir 		    default:
148cdf0e10cSrcweir 			    DBG_ASSERT( MAP_INCH == eOutUnit,
149cdf0e10cSrcweir 						    "output unit not supported for 1/100mm values" );
150cdf0e10cSrcweir 			    // 0.0001in = 0.254 mm/100 (exactly)
151cdf0e10cSrcweir 			    nMul = 100000;
152cdf0e10cSrcweir 			    nDiv = 2540;
153cdf0e10cSrcweir 			    nFac = 100*nFac2;
154cdf0e10cSrcweir 			    eUnit = XML_UNIT_INCH;
155cdf0e10cSrcweir 			    break;
156cdf0e10cSrcweir 		    }
157cdf0e10cSrcweir 		    break;
158cdf0e10cSrcweir         }
159cdf0e10cSrcweir         default:
160cdf0e10cSrcweir             DBG_ASSERT( 0, "input unit not handled" );
161cdf0e10cSrcweir             break;
162cdf0e10cSrcweir 	}
163cdf0e10cSrcweir 
164cdf0e10cSrcweir 
165cdf0e10cSrcweir 	sal_Int32 nLongVal = 0;
166cdf0e10cSrcweir 	sal_Bool bOutLongVal = sal_True;
167cdf0e10cSrcweir 	if( nValue > SAL_MAX_INT32 / nMul )
168cdf0e10cSrcweir 	{
169cdf0e10cSrcweir 		// A big int is required for calculation
170cdf0e10cSrcweir 		BigInt nBigVal( nValue );
171cdf0e10cSrcweir 		nBigVal *= nMul;
172cdf0e10cSrcweir 		nBigVal /= nDiv;
173cdf0e10cSrcweir 		nBigVal += 5;
174cdf0e10cSrcweir 		nBigVal /= 10;
175cdf0e10cSrcweir 
176cdf0e10cSrcweir 		if( nBigVal.IsLong() )
177cdf0e10cSrcweir 		{
178cdf0e10cSrcweir 			// To convert the value into a string a sal_Int32 is sufficient
179cdf0e10cSrcweir 			nLongVal = sal_Int32( nBigVal );
180cdf0e10cSrcweir 		}
181cdf0e10cSrcweir 		else
182cdf0e10cSrcweir 		{
183cdf0e10cSrcweir 			BigInt nBigFac( nFac );
184cdf0e10cSrcweir 			BigInt nBig10( 10 );
185cdf0e10cSrcweir 			rOut.append( (sal_Int32)(nBigVal / nBigFac) );
186cdf0e10cSrcweir 			if( !(nBigVal % nBigFac).IsZero() )
187cdf0e10cSrcweir 			{
188cdf0e10cSrcweir 				rOut.append( sal_Unicode('.') );
189cdf0e10cSrcweir 				while( nFac > 1 && !(nBigVal % nBigFac).IsZero() )
190cdf0e10cSrcweir 				{
191cdf0e10cSrcweir 					nFac /= 10;
192cdf0e10cSrcweir 					nBigFac = nFac;
193cdf0e10cSrcweir 					rOut.append( (sal_Int32)((nBigVal / nBigFac) % nBig10 ) );
194cdf0e10cSrcweir 				}
195cdf0e10cSrcweir 			}
196cdf0e10cSrcweir 			bOutLongVal = sal_False;
197cdf0e10cSrcweir 		}
198cdf0e10cSrcweir 	}
199cdf0e10cSrcweir 	else
200cdf0e10cSrcweir 	{
201cdf0e10cSrcweir 		nLongVal = nValue * nMul;
202cdf0e10cSrcweir 		nLongVal /= nDiv;
203cdf0e10cSrcweir 		nLongVal += 5;
204cdf0e10cSrcweir 		nLongVal /= 10;
205cdf0e10cSrcweir 	}
206cdf0e10cSrcweir 
207cdf0e10cSrcweir 	if( bOutLongVal )
208cdf0e10cSrcweir 	{
209cdf0e10cSrcweir 		rOut.append( (sal_Int32)(nLongVal / nFac) );
210cdf0e10cSrcweir 		if( nFac > 1 && (nLongVal % nFac) != 0 )
211cdf0e10cSrcweir 		{
212cdf0e10cSrcweir 			rOut.append( sal_Unicode('.') );
213cdf0e10cSrcweir 			while( nFac > 1 && (nLongVal % nFac) != 0 )
214cdf0e10cSrcweir 			{
215cdf0e10cSrcweir 				nFac /= 10;
216cdf0e10cSrcweir 				rOut.append( (sal_Int32)((nLongVal / nFac) % 10) );
217cdf0e10cSrcweir 			}
218cdf0e10cSrcweir 		}
219cdf0e10cSrcweir 	}
220cdf0e10cSrcweir 
221cdf0e10cSrcweir 	if( eUnit != XML_TOKEN_INVALID )
222cdf0e10cSrcweir 		rOut.append( GetXMLToken(eUnit) );
223cdf0e10cSrcweir }
224cdf0e10cSrcweir 
AddPercentage(sal_Int32 nValue,OUStringBuffer & rOut)225cdf0e10cSrcweir void SvXMLExportHelper::AddPercentage( sal_Int32 nValue, OUStringBuffer& rOut )
226cdf0e10cSrcweir {
227cdf0e10cSrcweir 	rOut.append( nValue );
228cdf0e10cSrcweir 	rOut.append( sal_Unicode('%' ) );
229cdf0e10cSrcweir }
230cdf0e10cSrcweir 
GetConversionFactor(::rtl::OUStringBuffer & rUnit,const MapUnit eCoreUnit,const MapUnit eDestUnit)231cdf0e10cSrcweir double SvXMLExportHelper::GetConversionFactor(::rtl::OUStringBuffer& rUnit,
232cdf0e10cSrcweir 	const MapUnit eCoreUnit, const MapUnit eDestUnit)
233cdf0e10cSrcweir {
234cdf0e10cSrcweir 	double fRetval(1.0);
235cdf0e10cSrcweir 	rUnit.setLength(0L);
236cdf0e10cSrcweir 
237cdf0e10cSrcweir 	if(eCoreUnit != eDestUnit)
238cdf0e10cSrcweir 	{
239cdf0e10cSrcweir 		enum XMLTokenEnum eUnit = XML_TOKEN_INVALID;
240cdf0e10cSrcweir 
241cdf0e10cSrcweir 		switch(eCoreUnit)
242cdf0e10cSrcweir 		{
243cdf0e10cSrcweir 			case MAP_TWIP:
244cdf0e10cSrcweir 			{
245cdf0e10cSrcweir 				switch(eDestUnit)
246cdf0e10cSrcweir 				{
247cdf0e10cSrcweir 					case MAP_100TH_MM:
248cdf0e10cSrcweir 					case MAP_10TH_MM:
249cdf0e10cSrcweir 					{
250cdf0e10cSrcweir 						DBG_ASSERT(MAP_INCH == eDestUnit, "output unit not supported for twip values");
251cdf0e10cSrcweir 					}
252cdf0e10cSrcweir 					case MAP_MM:
253cdf0e10cSrcweir 					{
254cdf0e10cSrcweir 						// 0.01mm = 0.57twip (exactly)
255cdf0e10cSrcweir 						fRetval = ((25400.0 / 1440.0) / 1000.0);
256cdf0e10cSrcweir 						eUnit = XML_UNIT_MM;
257cdf0e10cSrcweir 						break;
258cdf0e10cSrcweir 					}
259cdf0e10cSrcweir 					case MAP_CM:
260cdf0e10cSrcweir 					{
261cdf0e10cSrcweir 						// 0.001cm = 0.57twip (exactly)
262cdf0e10cSrcweir 						fRetval = ((25400.0 / 1440.0) / 10000.0);
263cdf0e10cSrcweir 						eUnit = XML_UNIT_CM;
264cdf0e10cSrcweir 						break;
265cdf0e10cSrcweir 					}
266cdf0e10cSrcweir 					case MAP_POINT:
267cdf0e10cSrcweir 					{
268cdf0e10cSrcweir 						// 0.01pt = 0.2twip (exactly)
269cdf0e10cSrcweir 						fRetval = ((1000.0 / 20.0) / 1000.0);
270cdf0e10cSrcweir 						eUnit = XML_UNIT_PT;
271cdf0e10cSrcweir 						break;
272cdf0e10cSrcweir 					}
273cdf0e10cSrcweir 					case MAP_INCH:
274cdf0e10cSrcweir 					default:
275cdf0e10cSrcweir 					{
276cdf0e10cSrcweir 						DBG_ASSERT(MAP_INCH == eDestUnit, "output unit not supported for twip values");
277cdf0e10cSrcweir 						// 0.0001in = 0.144twip (exactly)
278cdf0e10cSrcweir 						fRetval = ((100000.0 / 1440.0) / 100000.0);
279cdf0e10cSrcweir 						eUnit = XML_UNIT_INCH;
280cdf0e10cSrcweir 						break;
281cdf0e10cSrcweir 					}
282cdf0e10cSrcweir 				}
283cdf0e10cSrcweir 				break;
284cdf0e10cSrcweir 			}
285cdf0e10cSrcweir 			case MAP_POINT:
286cdf0e10cSrcweir 			{
287cdf0e10cSrcweir                 switch(eDestUnit)
288cdf0e10cSrcweir                 {
289cdf0e10cSrcweir                     case MAP_MM:
290cdf0e10cSrcweir                         // 1mm = 72 / 25.4 pt (exactly)
291cdf0e10cSrcweir                         fRetval = ( 25.4 / 72.0 );
292cdf0e10cSrcweir                         eUnit = XML_UNIT_MM;
293cdf0e10cSrcweir                         break;
294cdf0e10cSrcweir 
295cdf0e10cSrcweir                     case MAP_CM:
296cdf0e10cSrcweir                         // 1cm = 72 / 2.54 pt (exactly)
297cdf0e10cSrcweir                         fRetval = ( 2.54 / 72.0 );
298cdf0e10cSrcweir                         eUnit = XML_UNIT_CM;
299cdf0e10cSrcweir                         break;
300cdf0e10cSrcweir 
301cdf0e10cSrcweir                     case MAP_TWIP:
302cdf0e10cSrcweir                         // 1twip = 72 / 1440 pt (exactly)
303cdf0e10cSrcweir                         fRetval = 20.0;     // 1440.0 / 72.0
304cdf0e10cSrcweir                         eUnit = XML_UNIT_PC;
305cdf0e10cSrcweir                         break;
306cdf0e10cSrcweir 
307cdf0e10cSrcweir                     case MAP_INCH:
308cdf0e10cSrcweir                     default:
309cdf0e10cSrcweir                         DBG_ASSERT(MAP_INCH == eDestUnit, "output unit not supported for pt values");
310cdf0e10cSrcweir                         // 1in = 72 pt (exactly)
311cdf0e10cSrcweir                         fRetval = ( 1.0 / 72.0 );
312cdf0e10cSrcweir                         eUnit = XML_UNIT_INCH;
313cdf0e10cSrcweir                         break;
314cdf0e10cSrcweir                 }
315cdf0e10cSrcweir                 break;
316cdf0e10cSrcweir 			}
317cdf0e10cSrcweir             case MAP_10TH_MM:
318cdf0e10cSrcweir 			{
319cdf0e10cSrcweir 				switch(eDestUnit)
320cdf0e10cSrcweir 				{
321cdf0e10cSrcweir 					case MAP_100TH_MM:
322cdf0e10cSrcweir 					case MAP_10TH_MM:
323cdf0e10cSrcweir 					{
324cdf0e10cSrcweir 						DBG_ASSERT(MAP_INCH == eDestUnit, "output unit not supported for 1/100mm values");
325cdf0e10cSrcweir 					}
326cdf0e10cSrcweir 					case MAP_MM:
327cdf0e10cSrcweir 					{
328cdf0e10cSrcweir 						// 0.01mm = 1 mm/100 (exactly)
329cdf0e10cSrcweir 						fRetval = ((10.0 / 1.0) / 100.0);
330cdf0e10cSrcweir 						eUnit = XML_UNIT_MM;
331cdf0e10cSrcweir 						break;
332cdf0e10cSrcweir 					}
333cdf0e10cSrcweir 					case MAP_CM:
334cdf0e10cSrcweir 					{
335cdf0e10cSrcweir 						// 0.001mm = 1 mm/100 (exactly)
336cdf0e10cSrcweir 						fRetval = ((10.0 / 1.0) / 1000.0);
337cdf0e10cSrcweir 						eUnit = XML_UNIT_CM;
338cdf0e10cSrcweir 						break;
339cdf0e10cSrcweir 					}
340cdf0e10cSrcweir 					case MAP_POINT:
341cdf0e10cSrcweir 					{
342cdf0e10cSrcweir 						// 0.01pt = 0.35 mm/100 (exactly)
343cdf0e10cSrcweir 						fRetval = ((72000.0 / 2540.0) / 100.0);
344cdf0e10cSrcweir 						eUnit = XML_UNIT_PT;
345cdf0e10cSrcweir 						break;
346cdf0e10cSrcweir 					}
347cdf0e10cSrcweir 					case MAP_INCH:
348cdf0e10cSrcweir 					default:
349cdf0e10cSrcweir 					{
350cdf0e10cSrcweir 						DBG_ASSERT(MAP_INCH == eDestUnit, "output unit not supported for 1/100mm values");
351cdf0e10cSrcweir 						// 0.0001in = 0.254 mm/100 (exactly)
352cdf0e10cSrcweir 						fRetval = ((100000.0 / 2540.0) / 10000.0);
353cdf0e10cSrcweir 						eUnit = XML_UNIT_INCH;
354cdf0e10cSrcweir 						break;
355cdf0e10cSrcweir 					}
356cdf0e10cSrcweir 				}
357cdf0e10cSrcweir 				break;
358cdf0e10cSrcweir             }
359cdf0e10cSrcweir 			case MAP_100TH_MM:
360cdf0e10cSrcweir 			{
361cdf0e10cSrcweir 				switch(eDestUnit)
362cdf0e10cSrcweir 				{
363cdf0e10cSrcweir 					case MAP_100TH_MM:
364cdf0e10cSrcweir 					case MAP_10TH_MM:
365cdf0e10cSrcweir 					{
366cdf0e10cSrcweir 						DBG_ASSERT(MAP_INCH == eDestUnit, "output unit not supported for 1/100mm values");
367cdf0e10cSrcweir 					}
368cdf0e10cSrcweir 					case MAP_MM:
369cdf0e10cSrcweir 					{
370cdf0e10cSrcweir 						// 0.01mm = 1 mm/100 (exactly)
371cdf0e10cSrcweir 						fRetval = ((10.0 / 1.0) / 1000.0);
372cdf0e10cSrcweir 						eUnit = XML_UNIT_MM;
373cdf0e10cSrcweir 						break;
374cdf0e10cSrcweir 					}
375cdf0e10cSrcweir 					case MAP_CM:
376cdf0e10cSrcweir 					{
377cdf0e10cSrcweir 						// 0.001mm = 1 mm/100 (exactly)
378cdf0e10cSrcweir 						fRetval = ((10.0 / 1.0) / 10000.0);
379cdf0e10cSrcweir 						eUnit = XML_UNIT_CM;
380cdf0e10cSrcweir 						break;
381cdf0e10cSrcweir 					}
382cdf0e10cSrcweir 					case MAP_POINT:
383cdf0e10cSrcweir 					{
384cdf0e10cSrcweir 						// 0.01pt = 0.35 mm/100 (exactly)
385cdf0e10cSrcweir 						fRetval = ((72000.0 / 2540.0) / 1000.0);
386cdf0e10cSrcweir 						eUnit = XML_UNIT_PT;
387cdf0e10cSrcweir 						break;
388cdf0e10cSrcweir 					}
389cdf0e10cSrcweir 					case MAP_INCH:
390cdf0e10cSrcweir 					default:
391cdf0e10cSrcweir 					{
392cdf0e10cSrcweir 						DBG_ASSERT(MAP_INCH == eDestUnit, "output unit not supported for 1/100mm values");
393cdf0e10cSrcweir 						// 0.0001in = 0.254 mm/100 (exactly)
394cdf0e10cSrcweir 						fRetval = ((100000.0 / 2540.0) / 100000.0);
395cdf0e10cSrcweir 						eUnit = XML_UNIT_INCH;
396cdf0e10cSrcweir 						break;
397cdf0e10cSrcweir 					}
398cdf0e10cSrcweir 				}
399cdf0e10cSrcweir 				break;
400cdf0e10cSrcweir 			}
401cdf0e10cSrcweir 			default:
402cdf0e10cSrcweir 				DBG_ERROR("xmloff::SvXMLExportHelper::GetConversionFactor(), illegal eCoreUnit value!");
403cdf0e10cSrcweir 				break;
404cdf0e10cSrcweir 		}
405cdf0e10cSrcweir 
406cdf0e10cSrcweir 		if(eUnit != XML_TOKEN_INVALID)
407cdf0e10cSrcweir 			rUnit.append(GetXMLToken(eUnit));
408cdf0e10cSrcweir 	}
409cdf0e10cSrcweir 
410cdf0e10cSrcweir 	return fRetval;
411cdf0e10cSrcweir }
412cdf0e10cSrcweir 
GetUnitFromString(const::rtl::OUString & rString,MapUnit eDefaultUnit)413cdf0e10cSrcweir MapUnit SvXMLExportHelper::GetUnitFromString(const ::rtl::OUString& rString, MapUnit eDefaultUnit)
414cdf0e10cSrcweir {
415cdf0e10cSrcweir     sal_Int32 nPos = 0;
416cdf0e10cSrcweir 	sal_Int32 nLen = rString.getLength();
417cdf0e10cSrcweir 	MapUnit eRetUnit = eDefaultUnit;
418cdf0e10cSrcweir 
419cdf0e10cSrcweir 	// skip white space
420cdf0e10cSrcweir 	while( nPos < nLen && sal_Unicode(' ') == rString[nPos] )
421cdf0e10cSrcweir 		nPos++;
422cdf0e10cSrcweir 
423cdf0e10cSrcweir 	// skip negative
424cdf0e10cSrcweir 	if( nPos < nLen && sal_Unicode('-') == rString[nPos] )
425cdf0e10cSrcweir 		nPos++;
426cdf0e10cSrcweir 
427cdf0e10cSrcweir 	// skip number
428cdf0e10cSrcweir 	while( nPos < nLen && sal_Unicode('0') <= rString[nPos] && sal_Unicode('9') >= rString[nPos] )
429cdf0e10cSrcweir 		nPos++;
430cdf0e10cSrcweir 
431cdf0e10cSrcweir 	if( nPos < nLen && sal_Unicode('.') == rString[nPos] )
432cdf0e10cSrcweir 	{
433cdf0e10cSrcweir 		nPos++;
434cdf0e10cSrcweir 		while( nPos < nLen && sal_Unicode('0') <= rString[nPos] && sal_Unicode('9') >= rString[nPos] )
435cdf0e10cSrcweir 			nPos++;
436cdf0e10cSrcweir 	}
437cdf0e10cSrcweir 
438cdf0e10cSrcweir 	// skip white space
439cdf0e10cSrcweir 	while( nPos < nLen && sal_Unicode(' ') == rString[nPos] )
440cdf0e10cSrcweir 		nPos++;
441cdf0e10cSrcweir 
442cdf0e10cSrcweir 	if( nPos < nLen )
443cdf0e10cSrcweir 	{
444cdf0e10cSrcweir 		switch(rString[nPos])
445cdf0e10cSrcweir 		{
446cdf0e10cSrcweir 			case sal_Unicode('%') :
447cdf0e10cSrcweir 			{
448cdf0e10cSrcweir 				eRetUnit = MAP_RELATIVE;
449cdf0e10cSrcweir 				break;
450cdf0e10cSrcweir 			}
451cdf0e10cSrcweir 			case sal_Unicode('c'):
452cdf0e10cSrcweir 			case sal_Unicode('C'):
453cdf0e10cSrcweir 			{
454cdf0e10cSrcweir 				if(nPos+1 < nLen && (rString[nPos+1] == sal_Unicode('m')
455cdf0e10cSrcweir 					|| rString[nPos+1] == sal_Unicode('M')))
456cdf0e10cSrcweir 					eRetUnit = MAP_CM;
457cdf0e10cSrcweir 				break;
458cdf0e10cSrcweir 			}
459cdf0e10cSrcweir 			case sal_Unicode('e'):
460cdf0e10cSrcweir 			case sal_Unicode('E'):
461cdf0e10cSrcweir 			{
462cdf0e10cSrcweir 				// CSS1_EMS or CSS1_EMX later
463cdf0e10cSrcweir 				break;
464cdf0e10cSrcweir 			}
465cdf0e10cSrcweir 			case sal_Unicode('i'):
466cdf0e10cSrcweir 			case sal_Unicode('I'):
467cdf0e10cSrcweir 			{
468cdf0e10cSrcweir 				if(nPos+1 < nLen && (rString[nPos+1] == sal_Unicode('n')
469cdf0e10cSrcweir 					|| rString[nPos+1] == sal_Unicode('n')))
470cdf0e10cSrcweir 					eRetUnit = MAP_INCH;
471cdf0e10cSrcweir 				break;
472cdf0e10cSrcweir 			}
473cdf0e10cSrcweir 			case sal_Unicode('m'):
474cdf0e10cSrcweir 			case sal_Unicode('M'):
475cdf0e10cSrcweir 			{
476cdf0e10cSrcweir 				if(nPos+1 < nLen && (rString[nPos+1] == sal_Unicode('m')
477cdf0e10cSrcweir 					|| rString[nPos+1] == sal_Unicode('M')))
478cdf0e10cSrcweir 					eRetUnit = MAP_MM;
479cdf0e10cSrcweir 				break;
480cdf0e10cSrcweir 			}
481cdf0e10cSrcweir 			case sal_Unicode('p'):
482cdf0e10cSrcweir 			case sal_Unicode('P'):
483cdf0e10cSrcweir 			{
484cdf0e10cSrcweir 				if(nPos+1 < nLen && (rString[nPos+1] == sal_Unicode('t')
485cdf0e10cSrcweir 					|| rString[nPos+1] == sal_Unicode('T')))
486cdf0e10cSrcweir 					eRetUnit = MAP_POINT;
487cdf0e10cSrcweir 				if(nPos+1 < nLen && (rString[nPos+1] == sal_Unicode('c')
488cdf0e10cSrcweir 					|| rString[nPos+1] == sal_Unicode('C')))
489cdf0e10cSrcweir 					eRetUnit = MAP_TWIP;
490cdf0e10cSrcweir 				break;
491cdf0e10cSrcweir 			}
492cdf0e10cSrcweir 		}
493cdf0e10cSrcweir 	}
494cdf0e10cSrcweir 
495cdf0e10cSrcweir 	return eRetUnit;
496cdf0e10cSrcweir }
497