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 10cdf0e10cSrcweir * 11*63bba73cSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 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. 19cdf0e10cSrcweir * 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 <tools/string.hxx> 27cdf0e10cSrcweir #include <rtl/ustrbuf.hxx> 28cdf0e10cSrcweir #include "propimp0.hxx" 29cdf0e10cSrcweir #include <com/sun/star/drawing/LineDash.hpp> 30cdf0e10cSrcweir #include <com/sun/star/util/DateTime.hpp> 31cdf0e10cSrcweir #include <com/sun/star/uno/Any.hxx> 32cdf0e10cSrcweir #include <xmloff/xmluconv.hxx> 33cdf0e10cSrcweir #include <xmloff/xmlimp.hxx> 34cdf0e10cSrcweir 35cdf0e10cSrcweir using ::rtl::OUString; 36cdf0e10cSrcweir using ::rtl::OUStringBuffer; 37cdf0e10cSrcweir 38cdf0e10cSrcweir using namespace ::com::sun::star; 39cdf0e10cSrcweir 40cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////// 41cdf0e10cSrcweir // implementation of graphic property Stroke 42cdf0e10cSrcweir 43cdf0e10cSrcweir 44cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////// 45cdf0e10cSrcweir // implementation of presentation page property Change 46cdf0e10cSrcweir 47cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////// 48cdf0e10cSrcweir // implementation of an effect duration property handler 49cdf0e10cSrcweir 50cdf0e10cSrcweir 51cdf0e10cSrcweir XMLDurationPropertyHdl::~XMLDurationPropertyHdl() 52cdf0e10cSrcweir { 53cdf0e10cSrcweir } 54cdf0e10cSrcweir 55cdf0e10cSrcweir sal_Bool XMLDurationPropertyHdl::importXML( 56cdf0e10cSrcweir const OUString& rStrImpValue, 57cdf0e10cSrcweir ::com::sun::star::uno::Any& rValue, 58cdf0e10cSrcweir const SvXMLUnitConverter& ) const 59cdf0e10cSrcweir { 60cdf0e10cSrcweir util::DateTime aTime; 61cdf0e10cSrcweir SvXMLUnitConverter::convertTime( aTime, rStrImpValue ); 62cdf0e10cSrcweir 63cdf0e10cSrcweir const sal_Int32 nSeconds = ( aTime.Hours * 60 + aTime.Minutes ) * 60 + aTime.Seconds; 64cdf0e10cSrcweir rValue <<= nSeconds; 65cdf0e10cSrcweir 66cdf0e10cSrcweir return sal_True; 67cdf0e10cSrcweir } 68cdf0e10cSrcweir 69cdf0e10cSrcweir sal_Bool XMLDurationPropertyHdl::exportXML( 70cdf0e10cSrcweir OUString& rStrExpValue, 71cdf0e10cSrcweir const ::com::sun::star::uno::Any& rValue, 72cdf0e10cSrcweir const SvXMLUnitConverter& ) const 73cdf0e10cSrcweir { 74cdf0e10cSrcweir sal_Int32 nVal = 0; 75cdf0e10cSrcweir 76cdf0e10cSrcweir if(rValue >>= nVal) 77cdf0e10cSrcweir { 78cdf0e10cSrcweir util::DateTime aTime( 0, (sal_uInt16)nVal, 0, 0, 0, 0, 0 ); 79cdf0e10cSrcweir 80cdf0e10cSrcweir OUStringBuffer aOut; 81cdf0e10cSrcweir SvXMLUnitConverter::convertTime( aOut, aTime ); 82cdf0e10cSrcweir rStrExpValue = aOut.makeStringAndClear(); 83cdf0e10cSrcweir return sal_True; 84cdf0e10cSrcweir } 85cdf0e10cSrcweir 86cdf0e10cSrcweir return sal_False; 87cdf0e10cSrcweir } 88cdf0e10cSrcweir 89cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////// 90cdf0e10cSrcweir // implementation of an opacity property handler 91cdf0e10cSrcweir 92cdf0e10cSrcweir 93cdf0e10cSrcweir XMLOpacityPropertyHdl::XMLOpacityPropertyHdl( SvXMLImport* pImport ) 94cdf0e10cSrcweir : mpImport( pImport ) 95cdf0e10cSrcweir { 96cdf0e10cSrcweir } 97cdf0e10cSrcweir 98cdf0e10cSrcweir XMLOpacityPropertyHdl::~XMLOpacityPropertyHdl() 99cdf0e10cSrcweir { 100cdf0e10cSrcweir } 101cdf0e10cSrcweir 102cdf0e10cSrcweir sal_Bool XMLOpacityPropertyHdl::importXML( 103cdf0e10cSrcweir const OUString& rStrImpValue, 104cdf0e10cSrcweir ::com::sun::star::uno::Any& rValue, 105cdf0e10cSrcweir const SvXMLUnitConverter& ) const 106cdf0e10cSrcweir { 107cdf0e10cSrcweir sal_Bool bRet = sal_False; 108cdf0e10cSrcweir sal_Int32 nValue = 0; 109cdf0e10cSrcweir 110cdf0e10cSrcweir if( rStrImpValue.indexOf( sal_Unicode('%') ) != -1 ) 111cdf0e10cSrcweir { 112cdf0e10cSrcweir if( SvXMLUnitConverter::convertPercent( nValue, rStrImpValue ) ) 113cdf0e10cSrcweir bRet = sal_True; 114cdf0e10cSrcweir } 115cdf0e10cSrcweir else 116cdf0e10cSrcweir { 117cdf0e10cSrcweir nValue = sal_Int32( rStrImpValue.toDouble() * 100.0 ); 118cdf0e10cSrcweir bRet = sal_True; 119cdf0e10cSrcweir } 120cdf0e10cSrcweir 121cdf0e10cSrcweir if( bRet ) 122cdf0e10cSrcweir { 123cdf0e10cSrcweir // check ranges 124cdf0e10cSrcweir if( nValue < 0 ) 125cdf0e10cSrcweir nValue = 0; 126cdf0e10cSrcweir if( nValue > 100 ) 127cdf0e10cSrcweir nValue = 100; 128cdf0e10cSrcweir 129cdf0e10cSrcweir // convert xml opacity to api transparency 130cdf0e10cSrcweir nValue = 100 - nValue; 131cdf0e10cSrcweir 132cdf0e10cSrcweir // #i42959# 133cdf0e10cSrcweir if( mpImport ) 134cdf0e10cSrcweir { 135cdf0e10cSrcweir sal_Int32 nUPD, nBuild; 136cdf0e10cSrcweir if( mpImport->getBuildIds( nUPD, nBuild ) ) 137cdf0e10cSrcweir { 138cdf0e10cSrcweir // correct import of documents written prior to StarOffice 8/OOO 2.0 final 139cdf0e10cSrcweir if( (nUPD == 680) && (nBuild < 8951) ) 140cdf0e10cSrcweir nValue = 100 - nValue; 141cdf0e10cSrcweir } 142cdf0e10cSrcweir } 143cdf0e10cSrcweir 144cdf0e10cSrcweir rValue <<= sal_uInt16(nValue); 145cdf0e10cSrcweir } 146cdf0e10cSrcweir 147cdf0e10cSrcweir return bRet; 148cdf0e10cSrcweir } 149cdf0e10cSrcweir 150cdf0e10cSrcweir sal_Bool XMLOpacityPropertyHdl::exportXML( 151cdf0e10cSrcweir OUString& rStrExpValue, 152cdf0e10cSrcweir const ::com::sun::star::uno::Any& rValue, 153cdf0e10cSrcweir const SvXMLUnitConverter& ) const 154cdf0e10cSrcweir { 155cdf0e10cSrcweir sal_Bool bRet = sal_False; 156cdf0e10cSrcweir sal_uInt16 nVal = sal_uInt16(); 157cdf0e10cSrcweir 158cdf0e10cSrcweir if( rValue >>= nVal ) 159cdf0e10cSrcweir { 160cdf0e10cSrcweir OUStringBuffer aOut; 161cdf0e10cSrcweir 162cdf0e10cSrcweir nVal = 100 - nVal; 163cdf0e10cSrcweir SvXMLUnitConverter::convertPercent( aOut, nVal ); 164cdf0e10cSrcweir rStrExpValue = aOut.makeStringAndClear(); 165cdf0e10cSrcweir bRet = sal_True; 166cdf0e10cSrcweir } 167cdf0e10cSrcweir 168cdf0e10cSrcweir return bRet; 169cdf0e10cSrcweir } 170cdf0e10cSrcweir 171cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////// 172cdf0e10cSrcweir // implementation of an text animation step amount 173cdf0e10cSrcweir 174cdf0e10cSrcweir XMLTextAnimationStepPropertyHdl::~XMLTextAnimationStepPropertyHdl() 175cdf0e10cSrcweir { 176cdf0e10cSrcweir } 177cdf0e10cSrcweir 178cdf0e10cSrcweir sal_Bool XMLTextAnimationStepPropertyHdl::importXML( 179cdf0e10cSrcweir const OUString& rStrImpValue, 180cdf0e10cSrcweir ::com::sun::star::uno::Any& rValue, 181cdf0e10cSrcweir const SvXMLUnitConverter& rUnitConverter ) const 182cdf0e10cSrcweir { 183cdf0e10cSrcweir sal_Bool bRet = sal_False; 184cdf0e10cSrcweir sal_Int32 nValue = 0; 185cdf0e10cSrcweir 186cdf0e10cSrcweir const OUString aPX( RTL_CONSTASCII_USTRINGPARAM( "px" ) ); 187cdf0e10cSrcweir sal_Int32 nPos = rStrImpValue.indexOf( aPX ); 188cdf0e10cSrcweir if( nPos != -1 ) 189cdf0e10cSrcweir { 190cdf0e10cSrcweir if( rUnitConverter.convertNumber( nValue, rStrImpValue.copy( 0, nPos ) ) ) 191cdf0e10cSrcweir { 192cdf0e10cSrcweir rValue <<= sal_Int16( -nValue ); 193cdf0e10cSrcweir bRet = sal_True; 194cdf0e10cSrcweir } 195cdf0e10cSrcweir } 196cdf0e10cSrcweir else 197cdf0e10cSrcweir { 198cdf0e10cSrcweir if( rUnitConverter.convertMeasure( nValue, rStrImpValue ) ) 199cdf0e10cSrcweir { 200cdf0e10cSrcweir rValue <<= sal_Int16( nValue ); 201cdf0e10cSrcweir bRet = sal_True; 202cdf0e10cSrcweir } 203cdf0e10cSrcweir } 204cdf0e10cSrcweir 205cdf0e10cSrcweir return bRet; 206cdf0e10cSrcweir } 207cdf0e10cSrcweir 208cdf0e10cSrcweir sal_Bool XMLTextAnimationStepPropertyHdl::exportXML( 209cdf0e10cSrcweir OUString& rStrExpValue, 210cdf0e10cSrcweir const ::com::sun::star::uno::Any& rValue, 211cdf0e10cSrcweir const SvXMLUnitConverter& rUnitConverter ) const 212cdf0e10cSrcweir { 213cdf0e10cSrcweir sal_Bool bRet = sal_False; 214cdf0e10cSrcweir sal_Int16 nVal = sal_Int16(); 215cdf0e10cSrcweir 216cdf0e10cSrcweir if( rValue >>= nVal ) 217cdf0e10cSrcweir { 218cdf0e10cSrcweir OUStringBuffer aOut; 219cdf0e10cSrcweir 220cdf0e10cSrcweir if( nVal < 0 ) 221cdf0e10cSrcweir { 222cdf0e10cSrcweir const OUString aPX( RTL_CONSTASCII_USTRINGPARAM( "px" ) ); 223cdf0e10cSrcweir rUnitConverter.convertNumber( aOut, (sal_Int32)-nVal ); 224cdf0e10cSrcweir aOut.append( aPX ); 225cdf0e10cSrcweir } 226cdf0e10cSrcweir else 227cdf0e10cSrcweir { 228cdf0e10cSrcweir rUnitConverter.convertMeasure( aOut, nVal ); 229cdf0e10cSrcweir } 230cdf0e10cSrcweir 231cdf0e10cSrcweir rStrExpValue = aOut.makeStringAndClear(); 232cdf0e10cSrcweir bRet = sal_True; 233cdf0e10cSrcweir } 234cdf0e10cSrcweir 235cdf0e10cSrcweir return bRet; 236cdf0e10cSrcweir } 237cdf0e10cSrcweir 238cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////// 239cdf0e10cSrcweir 240cdf0e10cSrcweir #include "sdxmlexp_impl.hxx" 241cdf0e10cSrcweir 242cdf0e10cSrcweir XMLDateTimeFormatHdl::XMLDateTimeFormatHdl( SvXMLExport* pExport ) 243cdf0e10cSrcweir : mpExport( pExport ) 244cdf0e10cSrcweir { 245cdf0e10cSrcweir } 246cdf0e10cSrcweir 247cdf0e10cSrcweir XMLDateTimeFormatHdl::~XMLDateTimeFormatHdl() 248cdf0e10cSrcweir { 249cdf0e10cSrcweir } 250cdf0e10cSrcweir 251cdf0e10cSrcweir sal_Bool XMLDateTimeFormatHdl::importXML( const rtl::OUString& rStrImpValue, ::com::sun::star::uno::Any& rValue, const SvXMLUnitConverter& ) const 252cdf0e10cSrcweir { 253cdf0e10cSrcweir rValue <<= rStrImpValue; 254cdf0e10cSrcweir return true; 255cdf0e10cSrcweir } 256cdf0e10cSrcweir 257cdf0e10cSrcweir sal_Bool XMLDateTimeFormatHdl::exportXML( rtl::OUString& rStrExpValue, const ::com::sun::star::uno::Any& rValue, const SvXMLUnitConverter& ) const 258cdf0e10cSrcweir { 259cdf0e10cSrcweir sal_Int32 nNumberFormat = 0; 260cdf0e10cSrcweir if( mpExport && (rValue >>= nNumberFormat) ) 261cdf0e10cSrcweir { 262cdf0e10cSrcweir mpExport->addDataStyle( nNumberFormat ); 263cdf0e10cSrcweir rStrExpValue = mpExport->getDataStyleName( nNumberFormat ); 264cdf0e10cSrcweir return sal_True; 265cdf0e10cSrcweir } 266cdf0e10cSrcweir 267cdf0e10cSrcweir return sal_False; 268cdf0e10cSrcweir } 269