bump product version to 5.0.4.1
[LibreOffice.git] / xmloff / source / draw / propimp0.cxx
blob0ac8bf33b07491d181c04e1eb06847e999355c1c
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <rtl/ustrbuf.hxx>
21 #include "propimp0.hxx"
22 #include <com/sun/star/drawing/LineDash.hpp>
23 #include <com/sun/star/util/Duration.hpp>
24 #include <com/sun/star/uno/Any.hxx>
26 #include <sax/tools/converter.hxx>
28 #include <xmloff/xmluconv.hxx>
29 #include <xmloff/xmlimp.hxx>
31 #include <tools/time.hxx>
33 using namespace ::com::sun::star;
35 // implementation of graphic property Stroke
37 // implementation of presentation page property Change
39 // implementation of an effect duration property handler
41 XMLDurationPropertyHdl::~XMLDurationPropertyHdl()
45 bool XMLDurationPropertyHdl::importXML(
46 const OUString& rStrImpValue,
47 ::com::sun::star::uno::Any& rValue,
48 const SvXMLUnitConverter& ) const
50 util::Duration aDuration;
52 if (::sax::Converter::convertDuration(aDuration, rStrImpValue))
54 const double fSeconds = ((aDuration.Days * 24 + aDuration.Hours) * 60
55 + aDuration.Minutes) * 60
56 + aDuration.Seconds
57 + aDuration.NanoSeconds / static_cast<double>(::tools::Time::nanoSecPerSec);
58 rValue <<= fSeconds;
60 return true;
63 SAL_WARN_IF(!rStrImpValue.isEmpty(), "xmloff", "Invalid duration: " << rStrImpValue);
65 return false;
68 bool XMLDurationPropertyHdl::exportXML(
69 OUString& rStrExpValue,
70 const ::com::sun::star::uno::Any& rValue,
71 const SvXMLUnitConverter& ) const
73 double nVal = 0;
75 if(rValue >>= nVal)
77 util::Duration aDuration;
78 aDuration.Seconds = static_cast<sal_uInt16>(nVal);
79 aDuration.NanoSeconds = static_cast<sal_uInt32>((nVal - aDuration.Seconds) * ::tools::Time::nanoSecPerSec);
81 OUStringBuffer aOut;
82 ::sax::Converter::convertDuration(aOut, aDuration);
83 rStrExpValue = aOut.makeStringAndClear();
84 return true;
87 return false;
90 // implementation of an opacity property handler
92 XMLOpacityPropertyHdl::XMLOpacityPropertyHdl( SvXMLImport* pImport )
93 : mpImport( pImport )
97 XMLOpacityPropertyHdl::~XMLOpacityPropertyHdl()
101 bool XMLOpacityPropertyHdl::importXML(
102 const OUString& rStrImpValue,
103 ::com::sun::star::uno::Any& rValue,
104 const SvXMLUnitConverter& ) const
106 bool bRet = false;
107 sal_Int32 nValue = 0;
109 if( rStrImpValue.indexOf( '%' ) != -1 )
111 if (::sax::Converter::convertPercent( nValue, rStrImpValue ))
112 bRet = true;
114 else
116 nValue = sal_Int32( rStrImpValue.toDouble() * 100.0 );
117 bRet = true;
120 if( bRet )
122 // check ranges
123 if( nValue < 0 )
124 nValue = 0;
125 if( nValue > 100 )
126 nValue = 100;
128 // convert xml opacity to api transparency
129 nValue = 100 - nValue;
131 // #i42959#
132 if( mpImport )
134 sal_Int32 nUPD, nBuild;
135 if( mpImport->getBuildIds( nUPD, nBuild ) )
137 // correct import of documents written prior to StarOffice 8/OOO 2.0 final
138 if( (nUPD == 680) && (nBuild < 8951) )
139 nValue = 100 - nValue;
143 rValue <<= sal_uInt16(nValue);
146 return bRet;
149 bool XMLOpacityPropertyHdl::exportXML(
150 OUString& rStrExpValue,
151 const ::com::sun::star::uno::Any& rValue,
152 const SvXMLUnitConverter& ) const
154 bool bRet = false;
155 sal_uInt16 nVal = sal_uInt16();
157 if( rValue >>= nVal )
159 OUStringBuffer aOut;
161 nVal = 100 - nVal;
162 ::sax::Converter::convertPercent( aOut, nVal );
163 rStrExpValue = aOut.makeStringAndClear();
164 bRet = true;
167 return bRet;
170 // implementation of an text animation step amount
172 XMLTextAnimationStepPropertyHdl::~XMLTextAnimationStepPropertyHdl()
176 bool XMLTextAnimationStepPropertyHdl::importXML(
177 const OUString& rStrImpValue,
178 ::com::sun::star::uno::Any& rValue,
179 const SvXMLUnitConverter& rUnitConverter ) const
181 bool bRet = false;
182 sal_Int32 nValue = 0;
184 const OUString aPX( "px" );
185 sal_Int32 nPos = rStrImpValue.indexOf( aPX );
186 if( nPos != -1 )
188 if (::sax::Converter::convertNumber(nValue, rStrImpValue.copy(0, nPos)))
190 rValue <<= sal_Int16( -nValue );
191 bRet = true;
194 else
196 if (rUnitConverter.convertMeasureToCore( nValue, rStrImpValue ))
198 rValue <<= sal_Int16( nValue );
199 bRet = true;
203 return bRet;
206 bool XMLTextAnimationStepPropertyHdl::exportXML(
207 OUString& rStrExpValue,
208 const ::com::sun::star::uno::Any& rValue,
209 const SvXMLUnitConverter& rUnitConverter ) const
211 bool bRet = false;
212 sal_Int16 nVal = sal_Int16();
214 if( rValue >>= nVal )
216 OUStringBuffer aOut;
218 if( nVal < 0 )
220 const OUString aPX( "px" );
221 ::sax::Converter::convertNumber( aOut, (sal_Int32)-nVal );
222 aOut.append( aPX );
224 else
226 rUnitConverter.convertMeasureToXML( aOut, nVal );
229 rStrExpValue = aOut.makeStringAndClear();
230 bRet = true;
233 return bRet;
236 #include "sdxmlexp_impl.hxx"
238 XMLDateTimeFormatHdl::XMLDateTimeFormatHdl( SvXMLExport* pExport )
239 : mpExport( pExport )
243 XMLDateTimeFormatHdl::~XMLDateTimeFormatHdl()
247 bool XMLDateTimeFormatHdl::importXML( const OUString& rStrImpValue, ::com::sun::star::uno::Any& rValue, const SvXMLUnitConverter& ) const
249 rValue <<= rStrImpValue;
250 return true;
253 bool XMLDateTimeFormatHdl::exportXML( OUString& rStrExpValue, const ::com::sun::star::uno::Any& rValue, const SvXMLUnitConverter& ) const
255 sal_Int32 nNumberFormat = 0;
256 if( mpExport && (rValue >>= nNumberFormat) )
258 mpExport->addDataStyle( nNumberFormat );
259 rStrExpValue = mpExport->getDataStyleName( nNumberFormat );
260 return true;
263 return false;
266 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */