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