Bump version to 24.04.3.4
[LibreOffice.git] / xmloff / source / draw / propimp0.cxx
blob92bb46bdacbc45750cd1325222f0f628fa9d7242
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 <sal/log.hxx>
22 #include <propimp0.hxx>
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/xmlexp.hxx>
29 #include <xmloff/xmluconv.hxx>
30 #include <xmloff/xmlimp.hxx>
32 #include <tools/time.hxx>
34 using namespace ::com::sun::star;
36 // implementation of graphic property Stroke
38 // implementation of presentation page property Change
40 // implementation of an effect duration property handler
42 XMLDurationPropertyHdl::~XMLDurationPropertyHdl()
46 bool XMLDurationPropertyHdl::importXML(
47 const OUString& rStrImpValue,
48 css::uno::Any& rValue,
49 const SvXMLUnitConverter& ) const
51 util::Duration aDuration;
53 if (::sax::Converter::convertDuration(aDuration, rStrImpValue))
55 const double fSeconds = ((aDuration.Days * 24 + aDuration.Hours) * 60
56 + aDuration.Minutes) * 60
57 + aDuration.Seconds
58 + aDuration.NanoSeconds / static_cast<double>(::tools::Time::nanoSecPerSec);
59 rValue <<= fSeconds;
61 return true;
64 SAL_WARN_IF(!rStrImpValue.isEmpty(), "xmloff", "Invalid duration: " << rStrImpValue);
66 return false;
69 bool XMLDurationPropertyHdl::exportXML(
70 OUString& rStrExpValue,
71 const css::uno::Any& rValue,
72 const SvXMLUnitConverter& ) const
74 double nVal = 0;
76 if(rValue >>= nVal)
78 util::Duration aDuration;
79 aDuration.Seconds = static_cast<sal_uInt16>(nVal);
80 aDuration.NanoSeconds = static_cast<sal_uInt32>((nVal - aDuration.Seconds) * ::tools::Time::nanoSecPerSec);
82 OUStringBuffer aOut;
83 ::sax::Converter::convertDuration(aOut, aDuration);
84 rStrExpValue = aOut.makeStringAndClear();
85 return true;
88 return false;
91 // implementation of an opacity property handler
93 XMLOpacityPropertyHdl::XMLOpacityPropertyHdl( SvXMLImport* pImport )
94 : mpImport( pImport )
98 XMLOpacityPropertyHdl::~XMLOpacityPropertyHdl()
102 bool XMLOpacityPropertyHdl::importXML(
103 const OUString& rStrImpValue,
104 css::uno::Any& rValue,
105 const SvXMLUnitConverter& ) const
107 bool bRet = false;
108 sal_Int32 nValue = 0;
110 if( rStrImpValue.indexOf( '%' ) != -1 )
112 if (::sax::Converter::convertPercent( nValue, rStrImpValue ))
113 bRet = true;
115 else
117 nValue = sal_Int32( rStrImpValue.toDouble() * 100.0 );
118 bRet = true;
121 if( bRet )
123 // check ranges
124 if( nValue < 0 )
125 nValue = 0;
126 if( nValue > 100 )
127 nValue = 100;
129 // convert xml opacity to api transparency
130 nValue = 100 - nValue;
132 // #i42959#
133 if( mpImport )
135 sal_Int32 nUPD, nBuild;
136 if( mpImport->getBuildIds( nUPD, nBuild ) )
138 // correct import of documents written prior to StarOffice 8/OOO 2.0 final
139 if( (nUPD == 680) && (nBuild < 8951) )
140 nValue = 100 - nValue;
144 rValue <<= sal_uInt16(nValue);
147 return bRet;
150 bool XMLOpacityPropertyHdl::exportXML(
151 OUString& rStrExpValue,
152 const css::uno::Any& rValue,
153 const SvXMLUnitConverter& ) const
155 bool bRet = false;
156 sal_uInt16 nVal = sal_uInt16();
158 if( rValue >>= nVal )
160 OUStringBuffer aOut;
162 nVal = 100 - nVal;
163 ::sax::Converter::convertPercent( aOut, nVal );
164 rStrExpValue = aOut.makeStringAndClear();
165 bRet = true;
168 return bRet;
171 // implementation of a text animation step amount
173 XMLTextAnimationStepPropertyHdl::~XMLTextAnimationStepPropertyHdl()
177 bool XMLTextAnimationStepPropertyHdl::importXML(
178 const OUString& rStrImpValue,
179 css::uno::Any& rValue,
180 const SvXMLUnitConverter& rUnitConverter ) const
182 bool bRet = false;
183 sal_Int32 nValue = 0;
185 sal_Int32 nPos = rStrImpValue.indexOf( "px" );
186 if( nPos != -1 )
188 if (::sax::Converter::convertNumber(nValue, rStrImpValue.subView(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 css::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 aOut.append( OUString::number(static_cast<sal_Int32>(-nVal) ) + "px" );
222 else
224 rUnitConverter.convertMeasureToXML( aOut, nVal );
227 rStrExpValue = aOut.makeStringAndClear();
228 bRet = true;
231 return bRet;
234 XMLDateTimeFormatHdl::XMLDateTimeFormatHdl( SvXMLExport* pExport )
235 : mpExport( pExport )
239 XMLDateTimeFormatHdl::~XMLDateTimeFormatHdl()
243 bool XMLDateTimeFormatHdl::importXML( const OUString& rStrImpValue, css::uno::Any& rValue, const SvXMLUnitConverter& ) const
245 rValue <<= rStrImpValue;
246 return true;
249 bool XMLDateTimeFormatHdl::exportXML( OUString& rStrExpValue, const css::uno::Any& rValue, const SvXMLUnitConverter& ) const
251 sal_Int32 nNumberFormat = 0;
252 if( mpExport && (rValue >>= nNumberFormat) )
254 mpExport->addDataStyle( nNumberFormat );
255 rStrExpValue = mpExport->getDataStyleName( nNumberFormat );
256 return true;
259 return false;
262 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */