| 
									
										
										
										
											2000-09-18 23:31:44 +00:00
										 |  |  | /*************************************************************************
 | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2005-09-09 12:36:19 +00:00
										 |  |  |  *  OpenOffice.org - a multi-platform office productivity suite | 
					
						
							| 
									
										
										
										
											2000-09-18 23:31:44 +00:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2005-09-09 12:36:19 +00:00
										 |  |  |  *  $RCSfile: xmlehelp.cxx,v $ | 
					
						
							| 
									
										
										
										
											2000-09-18 23:31:44 +00:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2005-09-23 10:44:26 +00:00
										 |  |  |  *  $Revision: 1.9 $ | 
					
						
							| 
									
										
										
										
											2000-09-18 23:31:44 +00:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2005-09-23 10:44:26 +00:00
										 |  |  |  *  last change: $Author: hr $ $Date: 2005-09-23 11:44:26 $ | 
					
						
							| 
									
										
										
										
											2000-09-18 23:31:44 +00:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2005-09-09 12:36:19 +00:00
										 |  |  |  *  The Contents of this file are made available subject to | 
					
						
							|  |  |  |  *  the terms of GNU Lesser General Public License Version 2.1. | 
					
						
							| 
									
										
										
										
											2000-09-18 23:31:44 +00:00
										 |  |  |  * | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2005-09-09 12:36:19 +00:00
										 |  |  |  *    GNU Lesser General Public License Version 2.1 | 
					
						
							|  |  |  |  *    ============================================= | 
					
						
							|  |  |  |  *    Copyright 2005 by Sun Microsystems, Inc. | 
					
						
							|  |  |  |  *    901 San Antonio Road, Palo Alto, CA 94303, USA | 
					
						
							| 
									
										
										
										
											2000-09-18 23:31:44 +00:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2005-09-09 12:36:19 +00:00
										 |  |  |  *    This library is free software; you can redistribute it and/or | 
					
						
							|  |  |  |  *    modify it under the terms of the GNU Lesser General Public | 
					
						
							|  |  |  |  *    License version 2.1, as published by the Free Software Foundation. | 
					
						
							| 
									
										
										
										
											2000-09-18 23:31:44 +00:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2005-09-09 12:36:19 +00:00
										 |  |  |  *    This library is distributed in the hope that it will be useful, | 
					
						
							|  |  |  |  *    but WITHOUT ANY WARRANTY; without even the implied warranty of | 
					
						
							|  |  |  |  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU | 
					
						
							|  |  |  |  *    Lesser General Public License for more details. | 
					
						
							| 
									
										
										
										
											2000-09-18 23:31:44 +00:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2005-09-09 12:36:19 +00:00
										 |  |  |  *    You should have received a copy of the GNU Lesser General Public | 
					
						
							|  |  |  |  *    License along with this library; if not, write to the Free Software | 
					
						
							|  |  |  |  *    Foundation, Inc., 59 Temple Place, Suite 330, Boston, | 
					
						
							|  |  |  |  *    MA  02111-1307  USA | 
					
						
							| 
									
										
										
										
											2000-09-18 23:31:44 +00:00
										 |  |  |  * | 
					
						
							|  |  |  |  ************************************************************************/ | 
					
						
							|  |  |  | #include <limits.h>
 | 
					
						
							|  |  |  | #ifndef _TOOLS_DEBUG_HXX
 | 
					
						
							|  |  |  | #include <tools/debug.hxx>
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | #ifndef _BIGINT_HXX //autogen wg. BigInt
 | 
					
						
							|  |  |  | #include <tools/bigint.hxx>
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | #ifndef _RTL_USTRBUF_HXX_
 | 
					
						
							|  |  |  | #include <rtl/ustrbuf.hxx>
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | #ifndef _SV_OUTDEV_HXX
 | 
					
						
							|  |  |  | #include <vcl/outdev.hxx>
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #ifndef _XMLOFF_XMLEHELP_HXX
 | 
					
						
							|  |  |  | #include "xmlehelp.hxx"
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-06-29 20:07:26 +00:00
										 |  |  | #ifndef _XMLOFF_XMTOKEN_HXX
 | 
					
						
							|  |  |  | #include "xmltoken.hxx"
 | 
					
						
							| 
									
										
										
										
											2000-09-18 23:31:44 +00:00
										 |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | using namespace ::rtl; | 
					
						
							| 
									
										
										
										
											2001-06-29 20:07:26 +00:00
										 |  |  | using namespace ::xmloff::token; | 
					
						
							| 
									
										
										
										
											2000-09-18 23:31:44 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | void SvXMLExportHelper::AddLength( long nValue, MapUnit eValueUnit, | 
					
						
							|  |  |  |                                            OUStringBuffer& rOut, | 
					
						
							|  |  |  |                                    MapUnit eOutUnit ) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     // the sign is processed seperatly
 | 
					
						
							|  |  |  |     if( nValue < 0 ) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         nValue = -nValue; | 
					
						
							|  |  |  |         rOut.append( sal_Unicode('-') ); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // The new length is (nVal * nMul)/(nDiv*nFac*10)
 | 
					
						
							|  |  |  |     long nMul = 1000; | 
					
						
							|  |  |  |     long nDiv = 1; | 
					
						
							|  |  |  |     long nFac = 100; | 
					
						
							| 
									
										
										
										
											2001-06-29 20:07:26 +00:00
										 |  |  |     enum XMLTokenEnum eUnit = XML_TOKEN_INVALID; | 
					
						
							| 
									
										
										
										
											2000-09-18 23:31:44 +00:00
										 |  |  |     switch( eValueUnit ) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |     case MAP_TWIP: | 
					
						
							|  |  |  |         switch( eOutUnit ) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |         case MAP_100TH_MM: | 
					
						
							|  |  |  |         case MAP_10TH_MM: | 
					
						
							|  |  |  |             DBG_ASSERT( MAP_INCH == eOutUnit, | 
					
						
							|  |  |  |                         "output unit not supported for twip values" ); | 
					
						
							|  |  |  |         case MAP_MM: | 
					
						
							|  |  |  |             // 0.01mm = 0.57twip (exactly)
 | 
					
						
							|  |  |  |             nMul = 25400;   // 25.4 * 1000
 | 
					
						
							|  |  |  |             nDiv = 1440;    // 72 * 20;
 | 
					
						
							|  |  |  |             nFac = 100; | 
					
						
							| 
									
										
										
										
											2001-06-29 20:07:26 +00:00
										 |  |  |             eUnit = XML_UNIT_MM; | 
					
						
							| 
									
										
										
										
											2000-09-18 23:31:44 +00:00
										 |  |  |             break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         case MAP_CM: | 
					
						
							|  |  |  |             // 0.001cm = 0.57twip (exactly)
 | 
					
						
							|  |  |  |             nMul = 25400;   // 2.54 * 10000
 | 
					
						
							|  |  |  |             nDiv = 1440;    // 72 * 20;
 | 
					
						
							|  |  |  |             nFac = 1000; | 
					
						
							| 
									
										
										
										
											2001-06-29 20:07:26 +00:00
										 |  |  |             eUnit = XML_UNIT_CM; | 
					
						
							| 
									
										
										
										
											2000-09-18 23:31:44 +00:00
										 |  |  |             break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         case MAP_POINT: | 
					
						
							|  |  |  |             // 0.01pt = 0.2twip (exactly)
 | 
					
						
							|  |  |  |             nMul = 1000; | 
					
						
							|  |  |  |             nDiv = 20; | 
					
						
							|  |  |  |             nFac = 100; | 
					
						
							| 
									
										
										
										
											2001-06-29 20:07:26 +00:00
										 |  |  |             eUnit = XML_UNIT_PT; | 
					
						
							| 
									
										
										
										
											2000-09-18 23:31:44 +00:00
										 |  |  |             break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         case MAP_INCH: | 
					
						
							|  |  |  |         default: | 
					
						
							|  |  |  |             DBG_ASSERT( MAP_INCH == eOutUnit, | 
					
						
							|  |  |  |                         "output unit not supported for twip values" ); | 
					
						
							|  |  |  |             // 0.0001in = 0.144twip (exactly)
 | 
					
						
							|  |  |  |             nMul = 100000; | 
					
						
							|  |  |  |             nDiv = 1440;    // 72 * 20;
 | 
					
						
							|  |  |  |             nFac = 10000; | 
					
						
							| 
									
										
										
										
											2001-06-29 20:07:26 +00:00
										 |  |  |             eUnit = XML_UNIT_INCH; | 
					
						
							| 
									
										
										
										
											2000-09-18 23:31:44 +00:00
										 |  |  |             break; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     case MAP_POINT: | 
					
						
							|  |  |  |         // 1pt = 1pt (exactly)
 | 
					
						
							|  |  |  |         DBG_ASSERT( MAP_POINT == eOutUnit, | 
					
						
							|  |  |  |                     "output unit not supported for pt values" ); | 
					
						
							|  |  |  |         nMul = 10; | 
					
						
							|  |  |  |         nDiv = 1; | 
					
						
							|  |  |  |         nFac = 1; | 
					
						
							| 
									
										
										
										
											2001-06-29 20:07:26 +00:00
										 |  |  |         eUnit = XML_UNIT_PT; | 
					
						
							| 
									
										
										
										
											2000-09-18 23:31:44 +00:00
										 |  |  |         break; | 
					
						
							| 
									
										
										
										
											2005-09-23 10:44:26 +00:00
										 |  |  |     case MAP_10TH_MM: | 
					
						
							| 
									
										
										
										
											2000-09-18 23:31:44 +00:00
										 |  |  |     case MAP_100TH_MM: | 
					
						
							|  |  |  |         { | 
					
						
							| 
									
										
										
										
											2005-09-23 10:44:26 +00:00
										 |  |  |             long nFac2 = (MAP_100TH_MM == eValueUnit) ? 100 : 10; | 
					
						
							|  |  |  |             switch( eOutUnit ) | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |             case MAP_100TH_MM: | 
					
						
							|  |  |  |             case MAP_10TH_MM: | 
					
						
							|  |  |  |                 DBG_ASSERT( MAP_INCH == eOutUnit, | 
					
						
							|  |  |  |                             "output unit not supported for 1/100mm values" ); | 
					
						
							|  |  |  |             case MAP_MM: | 
					
						
							|  |  |  |                 // 0.01mm = 1 mm/100 (exactly)
 | 
					
						
							|  |  |  |                 nMul = 10; | 
					
						
							|  |  |  |                 nDiv = 1; | 
					
						
							|  |  |  |                 nFac = nFac2; | 
					
						
							|  |  |  |                 eUnit = XML_UNIT_MM; | 
					
						
							|  |  |  |                 break; | 
					
						
							| 
									
										
										
										
											2000-09-18 23:31:44 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-09-23 10:44:26 +00:00
										 |  |  |             case MAP_CM: | 
					
						
							|  |  |  |                 // 0.001mm = 1 mm/100 (exactly)
 | 
					
						
							|  |  |  |                 nMul = 10; | 
					
						
							|  |  |  |                 nDiv = 1;   // 72 * 20;
 | 
					
						
							|  |  |  |                 nFac = 10*nFac2; | 
					
						
							|  |  |  |                 eUnit = XML_UNIT_CM; | 
					
						
							|  |  |  |                 break; | 
					
						
							| 
									
										
										
										
											2000-09-18 23:31:44 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-09-23 10:44:26 +00:00
										 |  |  |             case MAP_POINT: | 
					
						
							|  |  |  |                 // 0.01pt = 0.35 mm/100 (exactly)
 | 
					
						
							|  |  |  |                 nMul = 72000; | 
					
						
							|  |  |  |                 nDiv = 2540; | 
					
						
							|  |  |  |                 nFac = nFac2; | 
					
						
							|  |  |  |                 eUnit = XML_UNIT_PT; | 
					
						
							|  |  |  |                 break; | 
					
						
							| 
									
										
										
										
											2000-09-18 23:31:44 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-09-23 10:44:26 +00:00
										 |  |  |             case MAP_INCH: | 
					
						
							|  |  |  |             default: | 
					
						
							|  |  |  |                 DBG_ASSERT( MAP_INCH == eOutUnit, | 
					
						
							|  |  |  |                             "output unit not supported for 1/100mm values" ); | 
					
						
							|  |  |  |                 // 0.0001in = 0.254 mm/100 (exactly)
 | 
					
						
							|  |  |  |                 nMul = 100000; | 
					
						
							|  |  |  |                 nDiv = 2540; | 
					
						
							|  |  |  |                 nFac = 100*nFac2; | 
					
						
							|  |  |  |                 eUnit = XML_UNIT_INCH; | 
					
						
							|  |  |  |                 break; | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2000-09-18 23:31:44 +00:00
										 |  |  |             break; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2005-09-23 10:44:26 +00:00
										 |  |  |            break; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-09-18 23:31:44 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     long nLongVal; | 
					
						
							|  |  |  |     BOOL bOutLongVal = TRUE; | 
					
						
							|  |  |  |     if( nValue > LONG_MAX / nMul ) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         // A big int is required for calculation
 | 
					
						
							|  |  |  |         BigInt nBigVal( nValue ); | 
					
						
							|  |  |  |         BigInt nBigFac( nFac ); | 
					
						
							|  |  |  |         nBigVal *= nMul; | 
					
						
							|  |  |  |         nBigVal /= nDiv; | 
					
						
							|  |  |  |         nBigVal += 5; | 
					
						
							|  |  |  |         nBigVal /= 10; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if( nBigVal.IsLong() ) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             // To convert the value into a string a long is sufficient
 | 
					
						
							|  |  |  |             nLongVal = (long)nBigVal; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         else | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             BigInt nBigFac( nFac ); | 
					
						
							|  |  |  |             BigInt nBig10( 10 ); | 
					
						
							|  |  |  |             rOut.append( (sal_Int32)(nBigVal / nBigFac) ); | 
					
						
							|  |  |  |             if( !(nBigVal % nBigFac).IsZero() ) | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 rOut.append( sal_Unicode('.') ); | 
					
						
							|  |  |  |                 while( nFac > 1 && !(nBigVal % nBigFac).IsZero() ) | 
					
						
							|  |  |  |                 { | 
					
						
							|  |  |  |                     nFac /= 10; | 
					
						
							|  |  |  |                     nBigFac = nFac; | 
					
						
							|  |  |  |                     rOut.append( (sal_Int32)((nBigVal / nBigFac) % nBig10 ) ); | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             bOutLongVal = FALSE; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         nLongVal = nValue * nMul; | 
					
						
							|  |  |  |         nLongVal /= nDiv; | 
					
						
							|  |  |  |         nLongVal += 5; | 
					
						
							|  |  |  |         nLongVal /= 10; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if( bOutLongVal ) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         rOut.append( (sal_Int32)(nLongVal / nFac) ); | 
					
						
							|  |  |  |         if( nFac > 1 && (nLongVal % nFac) != 0 ) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             rOut.append( sal_Unicode('.') ); | 
					
						
							|  |  |  |             while( nFac > 1 && (nLongVal % nFac) != 0 ) | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 nFac /= 10; | 
					
						
							|  |  |  |                 rOut.append( (sal_Int32)((nLongVal / nFac) % 10) ); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-06-29 20:07:26 +00:00
										 |  |  |     if( eUnit != XML_TOKEN_INVALID ) | 
					
						
							|  |  |  |         rOut.append( GetXMLToken(eUnit) ); | 
					
						
							| 
									
										
										
										
											2000-09-18 23:31:44 +00:00
										 |  |  | #if 0
 | 
					
						
							| 
									
										
										
										
											2001-06-29 20:07:26 +00:00
										 |  |  |     enum XMLTokenEnum eUnit; | 
					
						
							| 
									
										
										
										
											2000-09-18 23:31:44 +00:00
										 |  |  |     long nFac = 1; | 
					
						
							|  |  |  |     switch( eOutUnit ) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |     case MAP_100TH_MM: | 
					
						
							|  |  |  |         nFac *= 10L; | 
					
						
							|  |  |  |     case MAP_10TH_MM: | 
					
						
							|  |  |  |         nFac *= 10L; | 
					
						
							|  |  |  |         eOutUnit = MAP_MM; | 
					
						
							|  |  |  |     case MAP_MM: | 
					
						
							|  |  |  |         // 0.01mm
 | 
					
						
							|  |  |  |         nFac *= 100L; | 
					
						
							| 
									
										
										
										
											2001-06-29 20:07:26 +00:00
										 |  |  |         eUnit = XML_UNIT_MM; | 
					
						
							| 
									
										
										
										
											2000-09-18 23:31:44 +00:00
										 |  |  |         break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     case MAP_CM: | 
					
						
							|  |  |  | #ifdef EXACT_VALUES
 | 
					
						
							|  |  |  |         // 0.001cm
 | 
					
						
							|  |  |  |         nFac *= 1000L; | 
					
						
							|  |  |  | #else
 | 
					
						
							|  |  |  |         // 0.01cm
 | 
					
						
							|  |  |  |         nFac *= 100L; | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2001-06-29 20:07:26 +00:00
										 |  |  |         eUnit = XML_UNIT_CM; | 
					
						
							| 
									
										
										
										
											2000-09-18 23:31:44 +00:00
										 |  |  |         break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     case MAP_TWIP: | 
					
						
							|  |  |  |     case MAP_POINT: | 
					
						
							|  |  |  | #ifdef EXACT_VALUES
 | 
					
						
							|  |  |  |         // 0.01pt
 | 
					
						
							|  |  |  |         nFac *= 100L; | 
					
						
							|  |  |  | #else
 | 
					
						
							|  |  |  |         // 0.1pt
 | 
					
						
							|  |  |  |         nFac *= 10L; | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2001-06-29 20:07:26 +00:00
										 |  |  |         eUnit = XML_UNIT_PT; | 
					
						
							| 
									
										
										
										
											2000-09-18 23:31:44 +00:00
										 |  |  |         break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     case MAP_1000TH_INCH: | 
					
						
							|  |  |  |         nFac *= 10L; | 
					
						
							|  |  |  |     case MAP_100TH_INCH: | 
					
						
							|  |  |  |         nFac *= 10L; | 
					
						
							|  |  |  |     case MAP_10TH_INCH: | 
					
						
							|  |  |  |         nFac *= 10L; | 
					
						
							|  |  |  |     case MAP_INCH: | 
					
						
							|  |  |  |     default: | 
					
						
							|  |  |  |         eOutUnit = MAP_INCH; | 
					
						
							|  |  |  | #ifdef EXACT_VALUES
 | 
					
						
							|  |  |  |         // 0.0001in
 | 
					
						
							|  |  |  |         nFac *= 10000L; | 
					
						
							|  |  |  | #else
 | 
					
						
							|  |  |  |         // 0.01in
 | 
					
						
							|  |  |  |         nFac *= 100L; | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2001-06-29 20:07:26 +00:00
										 |  |  |         eUnit = XML_UNIT_INCH; | 
					
						
							| 
									
										
										
										
											2000-09-18 23:31:44 +00:00
										 |  |  |         break; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if( eValueUnit != eOutUnit ) | 
					
						
							|  |  |  |         nValue = OutputDevice::LogicToLogic( nValue, eValueUnit, eOutUnit ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     rOut.append( nValue / nFac ); | 
					
						
							|  |  |  |     if( nFac > 1 && (nValue % nFac) != 0 ) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         rOut.append( sal_Unicode('.') ); | 
					
						
							|  |  |  |         while( nFac > 1 && (nValue % nFac) != 0 ) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             nFac /= 10L; | 
					
						
							|  |  |  |             rOut.append( (nValue / nFac) % 10L ); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-06-29 20:07:26 +00:00
										 |  |  |     rOut.append( GetXMLToken(eUnit) ); | 
					
						
							| 
									
										
										
										
											2000-09-18 23:31:44 +00:00
										 |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void SvXMLExportHelper::AddPercentage( long nValue, OUStringBuffer& rOut ) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     rOut.append( nValue ); | 
					
						
							|  |  |  |     rOut.append( sal_Unicode('%' ) ); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2001-02-26 09:25:38 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | double SvXMLExportHelper::GetConversionFactor(::rtl::OUStringBuffer& rUnit, | 
					
						
							|  |  |  |     const MapUnit eCoreUnit, const MapUnit eDestUnit) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     double fRetval(1.0); | 
					
						
							|  |  |  |     rUnit.setLength(0L); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if(eCoreUnit != eDestUnit) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2001-06-29 20:07:26 +00:00
										 |  |  |         enum XMLTokenEnum eUnit = XML_TOKEN_INVALID; | 
					
						
							| 
									
										
										
										
											2001-02-26 09:25:38 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |         switch(eCoreUnit) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             case MAP_TWIP: | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 switch(eDestUnit) | 
					
						
							|  |  |  |                 { | 
					
						
							|  |  |  |                     case MAP_100TH_MM: | 
					
						
							|  |  |  |                     case MAP_10TH_MM: | 
					
						
							|  |  |  |                     { | 
					
						
							|  |  |  |                         DBG_ASSERT(MAP_INCH == eDestUnit, "output unit not supported for twip values"); | 
					
						
							|  |  |  |                     } | 
					
						
							|  |  |  |                     case MAP_MM: | 
					
						
							|  |  |  |                     { | 
					
						
							|  |  |  |                         // 0.01mm = 0.57twip (exactly)
 | 
					
						
							|  |  |  |                         fRetval = ((25400.0 / 1440.0) / 1000.0); | 
					
						
							| 
									
										
										
										
											2001-06-29 20:07:26 +00:00
										 |  |  |                         eUnit = XML_UNIT_MM; | 
					
						
							| 
									
										
										
										
											2001-02-26 09:25:38 +00:00
										 |  |  |                         break; | 
					
						
							|  |  |  |                     } | 
					
						
							|  |  |  |                     case MAP_CM: | 
					
						
							|  |  |  |                     { | 
					
						
							|  |  |  |                         // 0.001cm = 0.57twip (exactly)
 | 
					
						
							|  |  |  |                         fRetval = ((25400.0 / 1440.0) / 10000.0); | 
					
						
							| 
									
										
										
										
											2001-06-29 20:07:26 +00:00
										 |  |  |                         eUnit = XML_UNIT_CM; | 
					
						
							| 
									
										
										
										
											2001-02-26 09:25:38 +00:00
										 |  |  |                         break; | 
					
						
							|  |  |  |                     } | 
					
						
							|  |  |  |                     case MAP_POINT: | 
					
						
							|  |  |  |                     { | 
					
						
							|  |  |  |                         // 0.01pt = 0.2twip (exactly)
 | 
					
						
							|  |  |  |                         fRetval = ((1000.0 / 20.0) / 1000.0); | 
					
						
							| 
									
										
										
										
											2001-06-29 20:07:26 +00:00
										 |  |  |                         eUnit = XML_UNIT_PT; | 
					
						
							| 
									
										
										
										
											2001-02-26 09:25:38 +00:00
										 |  |  |                         break; | 
					
						
							|  |  |  |                     } | 
					
						
							|  |  |  |                     case MAP_INCH: | 
					
						
							|  |  |  |                     default: | 
					
						
							|  |  |  |                     { | 
					
						
							|  |  |  |                         DBG_ASSERT(MAP_INCH == eDestUnit, "output unit not supported for twip values"); | 
					
						
							|  |  |  |                         // 0.0001in = 0.144twip (exactly)
 | 
					
						
							|  |  |  |                         fRetval = ((100000.0 / 1440.0) / 100000.0); | 
					
						
							| 
									
										
										
										
											2001-06-29 20:07:26 +00:00
										 |  |  |                         eUnit = XML_UNIT_INCH; | 
					
						
							| 
									
										
										
										
											2001-02-26 09:25:38 +00:00
										 |  |  |                         break; | 
					
						
							|  |  |  |                     } | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |                 break; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             case MAP_POINT: | 
					
						
							|  |  |  |             { | 
					
						
							| 
									
										
										
										
											2001-05-21 10:21:28 +00:00
										 |  |  |                 switch(eDestUnit) | 
					
						
							|  |  |  |                 { | 
					
						
							|  |  |  |                     case MAP_MM: | 
					
						
							|  |  |  |                         // 1mm = 72 / 25.4 pt (exactly)
 | 
					
						
							|  |  |  |                         fRetval = ( 25.4 / 72.0 ); | 
					
						
							| 
									
										
										
										
											2001-06-29 20:07:26 +00:00
										 |  |  |                         eUnit = XML_UNIT_MM; | 
					
						
							| 
									
										
										
										
											2001-05-21 10:21:28 +00:00
										 |  |  |                         break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                     case MAP_CM: | 
					
						
							|  |  |  |                         // 1cm = 72 / 2.54 pt (exactly)
 | 
					
						
							|  |  |  |                         fRetval = ( 2.54 / 72.0 ); | 
					
						
							| 
									
										
										
										
											2001-06-29 20:07:26 +00:00
										 |  |  |                         eUnit = XML_UNIT_CM; | 
					
						
							| 
									
										
										
										
											2001-05-21 10:21:28 +00:00
										 |  |  |                         break; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-05-21 11:35:01 +00:00
										 |  |  |                     case MAP_TWIP: | 
					
						
							|  |  |  |                         // 1twip = 72 / 1440 pt (exactly)
 | 
					
						
							|  |  |  |                         fRetval = 20.0;     // 1440.0 / 72.0
 | 
					
						
							| 
									
										
										
										
											2001-06-29 20:07:26 +00:00
										 |  |  |                         eUnit = XML_UNIT_PC; | 
					
						
							| 
									
										
										
										
											2001-05-21 11:35:01 +00:00
										 |  |  |                         break; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-05-21 10:21:28 +00:00
										 |  |  |                     case MAP_INCH: | 
					
						
							| 
									
										
										
										
											2001-05-21 11:35:01 +00:00
										 |  |  |                     default: | 
					
						
							|  |  |  |                         DBG_ASSERT(MAP_INCH == eDestUnit, "output unit not supported for pt values"); | 
					
						
							| 
									
										
										
										
											2001-05-21 10:21:28 +00:00
										 |  |  |                         // 1in = 72 pt (exactly)
 | 
					
						
							|  |  |  |                         fRetval = ( 1.0 / 72.0 ); | 
					
						
							| 
									
										
										
										
											2001-06-29 20:07:26 +00:00
										 |  |  |                         eUnit = XML_UNIT_INCH; | 
					
						
							| 
									
										
										
										
											2001-05-21 10:21:28 +00:00
										 |  |  |                         break; | 
					
						
							|  |  |  |                 } | 
					
						
							| 
									
										
										
										
											2001-02-26 09:25:38 +00:00
										 |  |  |                 break; | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2005-09-23 10:44:26 +00:00
										 |  |  |             case MAP_10TH_MM: | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 switch(eDestUnit) | 
					
						
							|  |  |  |                 { | 
					
						
							|  |  |  |                     case MAP_100TH_MM: | 
					
						
							|  |  |  |                     case MAP_10TH_MM: | 
					
						
							|  |  |  |                     { | 
					
						
							|  |  |  |                         DBG_ASSERT(MAP_INCH == eDestUnit, "output unit not supported for 1/100mm values"); | 
					
						
							|  |  |  |                     } | 
					
						
							|  |  |  |                     case MAP_MM: | 
					
						
							|  |  |  |                     { | 
					
						
							|  |  |  |                         // 0.01mm = 1 mm/100 (exactly)
 | 
					
						
							|  |  |  |                         fRetval = ((10.0 / 1.0) / 100.0); | 
					
						
							|  |  |  |                         eUnit = XML_UNIT_MM; | 
					
						
							|  |  |  |                         break; | 
					
						
							|  |  |  |                     } | 
					
						
							|  |  |  |                     case MAP_CM: | 
					
						
							|  |  |  |                     { | 
					
						
							|  |  |  |                         // 0.001mm = 1 mm/100 (exactly)
 | 
					
						
							|  |  |  |                         fRetval = ((10.0 / 1.0) / 1000.0); | 
					
						
							|  |  |  |                         eUnit = XML_UNIT_CM; | 
					
						
							|  |  |  |                         break; | 
					
						
							|  |  |  |                     } | 
					
						
							|  |  |  |                     case MAP_POINT: | 
					
						
							|  |  |  |                     { | 
					
						
							|  |  |  |                         // 0.01pt = 0.35 mm/100 (exactly)
 | 
					
						
							|  |  |  |                         fRetval = ((72000.0 / 2540.0) / 100.0); | 
					
						
							|  |  |  |                         eUnit = XML_UNIT_PT; | 
					
						
							|  |  |  |                         break; | 
					
						
							|  |  |  |                     } | 
					
						
							|  |  |  |                     case MAP_INCH: | 
					
						
							|  |  |  |                     default: | 
					
						
							|  |  |  |                     { | 
					
						
							|  |  |  |                         DBG_ASSERT(MAP_INCH == eDestUnit, "output unit not supported for 1/100mm values"); | 
					
						
							|  |  |  |                         // 0.0001in = 0.254 mm/100 (exactly)
 | 
					
						
							|  |  |  |                         fRetval = ((100000.0 / 2540.0) / 10000.0); | 
					
						
							|  |  |  |                         eUnit = XML_UNIT_INCH; | 
					
						
							|  |  |  |                         break; | 
					
						
							|  |  |  |                     } | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |                 break; | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2001-02-26 09:25:38 +00:00
										 |  |  |             case MAP_100TH_MM: | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 switch(eDestUnit) | 
					
						
							|  |  |  |                 { | 
					
						
							|  |  |  |                     case MAP_100TH_MM: | 
					
						
							|  |  |  |                     case MAP_10TH_MM: | 
					
						
							|  |  |  |                     { | 
					
						
							|  |  |  |                         DBG_ASSERT(MAP_INCH == eDestUnit, "output unit not supported for 1/100mm values"); | 
					
						
							|  |  |  |                     } | 
					
						
							|  |  |  |                     case MAP_MM: | 
					
						
							|  |  |  |                     { | 
					
						
							|  |  |  |                         // 0.01mm = 1 mm/100 (exactly)
 | 
					
						
							|  |  |  |                         fRetval = ((10.0 / 1.0) / 1000.0); | 
					
						
							| 
									
										
										
										
											2001-06-29 20:07:26 +00:00
										 |  |  |                         eUnit = XML_UNIT_MM; | 
					
						
							| 
									
										
										
										
											2001-02-26 09:25:38 +00:00
										 |  |  |                         break; | 
					
						
							|  |  |  |                     } | 
					
						
							|  |  |  |                     case MAP_CM: | 
					
						
							|  |  |  |                     { | 
					
						
							|  |  |  |                         // 0.001mm = 1 mm/100 (exactly)
 | 
					
						
							|  |  |  |                         fRetval = ((10.0 / 1.0) / 10000.0); | 
					
						
							| 
									
										
										
										
											2001-06-29 20:07:26 +00:00
										 |  |  |                         eUnit = XML_UNIT_CM; | 
					
						
							| 
									
										
										
										
											2001-02-26 09:25:38 +00:00
										 |  |  |                         break; | 
					
						
							|  |  |  |                     } | 
					
						
							|  |  |  |                     case MAP_POINT: | 
					
						
							|  |  |  |                     { | 
					
						
							|  |  |  |                         // 0.01pt = 0.35 mm/100 (exactly)
 | 
					
						
							|  |  |  |                         fRetval = ((72000.0 / 2540.0) / 1000.0); | 
					
						
							| 
									
										
										
										
											2001-06-29 20:07:26 +00:00
										 |  |  |                         eUnit = XML_UNIT_PT; | 
					
						
							| 
									
										
										
										
											2001-02-26 09:25:38 +00:00
										 |  |  |                         break; | 
					
						
							|  |  |  |                     } | 
					
						
							|  |  |  |                     case MAP_INCH: | 
					
						
							|  |  |  |                     default: | 
					
						
							|  |  |  |                     { | 
					
						
							|  |  |  |                         DBG_ASSERT(MAP_INCH == eDestUnit, "output unit not supported for 1/100mm values"); | 
					
						
							|  |  |  |                         // 0.0001in = 0.254 mm/100 (exactly)
 | 
					
						
							|  |  |  |                         fRetval = ((100000.0 / 2540.0) / 100000.0); | 
					
						
							| 
									
										
										
										
											2001-06-29 20:07:26 +00:00
										 |  |  |                         eUnit = XML_UNIT_INCH; | 
					
						
							| 
									
										
										
										
											2001-02-26 09:25:38 +00:00
										 |  |  |                         break; | 
					
						
							|  |  |  |                     } | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |                 break; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-06-29 20:07:26 +00:00
										 |  |  |         if(eUnit != XML_TOKEN_INVALID) | 
					
						
							|  |  |  |             rUnit.append(GetXMLToken(eUnit)); | 
					
						
							| 
									
										
										
										
											2001-02-26 09:25:38 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return fRetval; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | MapUnit SvXMLExportHelper::GetUnitFromString(const ::rtl::OUString& rString, MapUnit eDefaultUnit) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     sal_Int32 nPos = 0L; | 
					
						
							|  |  |  |     sal_Int32 nLen = rString.getLength(); | 
					
						
							|  |  |  |     MapUnit eRetUnit = eDefaultUnit; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // skip white space
 | 
					
						
							|  |  |  |     while( nPos < nLen && sal_Unicode(' ') == rString[nPos] ) | 
					
						
							|  |  |  |         nPos++; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // skip negative
 | 
					
						
							|  |  |  |     if( nPos < nLen && sal_Unicode('-') == rString[nPos] ) | 
					
						
							|  |  |  |         nPos++; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // skip number
 | 
					
						
							|  |  |  |     while( nPos < nLen && sal_Unicode('0') <= rString[nPos] && sal_Unicode('9') >= rString[nPos] ) | 
					
						
							|  |  |  |         nPos++; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if( nPos < nLen && sal_Unicode('.') == rString[nPos] ) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         nPos++; | 
					
						
							|  |  |  |         while( nPos < nLen && sal_Unicode('0') <= rString[nPos] && sal_Unicode('9') >= rString[nPos] ) | 
					
						
							|  |  |  |             nPos++; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // skip white space
 | 
					
						
							|  |  |  |     while( nPos < nLen && sal_Unicode(' ') == rString[nPos] ) | 
					
						
							|  |  |  |         nPos++; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if( nPos < nLen ) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         switch(rString[nPos]) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             case sal_Unicode('%') : | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 eRetUnit = MAP_RELATIVE; | 
					
						
							|  |  |  |                 break; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             case sal_Unicode('c'): | 
					
						
							|  |  |  |             case sal_Unicode('C'): | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 if(nPos+1 < nLen && (rString[nPos+1] == sal_Unicode('m') | 
					
						
							|  |  |  |                     || rString[nPos+1] == sal_Unicode('M'))) | 
					
						
							|  |  |  |                     eRetUnit = MAP_CM; | 
					
						
							|  |  |  |                 break; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             case sal_Unicode('e'): | 
					
						
							|  |  |  |             case sal_Unicode('E'): | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 // CSS1_EMS or CSS1_EMX later
 | 
					
						
							|  |  |  |                 break; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             case sal_Unicode('i'): | 
					
						
							|  |  |  |             case sal_Unicode('I'): | 
					
						
							|  |  |  |             { | 
					
						
							| 
									
										
										
										
											2004-07-13 07:06:29 +00:00
										 |  |  |                 if(nPos+1 < nLen && (rString[nPos+1] == sal_Unicode('n') | 
					
						
							|  |  |  |                     || rString[nPos+1] == sal_Unicode('n'))) | 
					
						
							|  |  |  |                     eRetUnit = MAP_INCH; | 
					
						
							| 
									
										
										
										
											2001-02-26 09:25:38 +00:00
										 |  |  |                 break; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             case sal_Unicode('m'): | 
					
						
							|  |  |  |             case sal_Unicode('M'): | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 if(nPos+1 < nLen && (rString[nPos+1] == sal_Unicode('m') | 
					
						
							|  |  |  |                     || rString[nPos+1] == sal_Unicode('M'))) | 
					
						
							|  |  |  |                     eRetUnit = MAP_MM; | 
					
						
							|  |  |  |                 break; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             case sal_Unicode('p'): | 
					
						
							|  |  |  |             case sal_Unicode('P'): | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 if(nPos+1 < nLen && (rString[nPos+1] == sal_Unicode('t') | 
					
						
							|  |  |  |                     || rString[nPos+1] == sal_Unicode('T'))) | 
					
						
							| 
									
										
										
										
											2001-05-21 10:21:28 +00:00
										 |  |  |                     eRetUnit = MAP_POINT; | 
					
						
							| 
									
										
										
										
											2001-02-26 09:25:38 +00:00
										 |  |  |                 if(nPos+1 < nLen && (rString[nPos+1] == sal_Unicode('c') | 
					
						
							|  |  |  |                     || rString[nPos+1] == sal_Unicode('C'))) | 
					
						
							|  |  |  |                     eRetUnit = MAP_TWIP; | 
					
						
							|  |  |  |                 break; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return eRetUnit; | 
					
						
							|  |  |  | } |