1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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
58 + aDuration
.NanoSeconds
/ static_cast<double>(::tools::Time::nanoSecPerSec
);
64 SAL_WARN_IF(!rStrImpValue
.isEmpty(), "xmloff", "Invalid duration: " << rStrImpValue
);
69 bool XMLDurationPropertyHdl::exportXML(
70 OUString
& rStrExpValue
,
71 const css::uno::Any
& rValue
,
72 const SvXMLUnitConverter
& ) const
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
);
83 ::sax::Converter::convertDuration(aOut
, aDuration
);
84 rStrExpValue
= aOut
.makeStringAndClear();
91 // implementation of an opacity property handler
93 XMLOpacityPropertyHdl::XMLOpacityPropertyHdl( SvXMLImport
* pImport
)
98 XMLOpacityPropertyHdl::~XMLOpacityPropertyHdl()
102 bool XMLOpacityPropertyHdl::importXML(
103 const OUString
& rStrImpValue
,
104 css::uno::Any
& rValue
,
105 const SvXMLUnitConverter
& ) const
108 sal_Int32 nValue
= 0;
110 if( rStrImpValue
.indexOf( '%' ) != -1 )
112 if (::sax::Converter::convertPercent( nValue
, rStrImpValue
))
117 nValue
= sal_Int32( rStrImpValue
.toDouble() * 100.0 );
129 // convert xml opacity to api transparency
130 nValue
= 100 - nValue
;
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
);
150 bool XMLOpacityPropertyHdl::exportXML(
151 OUString
& rStrExpValue
,
152 const css::uno::Any
& rValue
,
153 const SvXMLUnitConverter
& ) const
156 sal_uInt16 nVal
= sal_uInt16();
158 if( rValue
>>= nVal
)
163 ::sax::Converter::convertPercent( aOut
, nVal
);
164 rStrExpValue
= aOut
.makeStringAndClear();
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
183 sal_Int32 nValue
= 0;
185 sal_Int32 nPos
= rStrImpValue
.indexOf( "px" );
188 if (::sax::Converter::convertNumber(nValue
, rStrImpValue
.subView(0, nPos
)))
190 rValue
<<= sal_Int16( -nValue
);
196 if (rUnitConverter
.convertMeasureToCore( nValue
, rStrImpValue
))
198 rValue
<<= sal_Int16( nValue
);
206 bool XMLTextAnimationStepPropertyHdl::exportXML(
207 OUString
& rStrExpValue
,
208 const css::uno::Any
& rValue
,
209 const SvXMLUnitConverter
& rUnitConverter
) const
212 sal_Int16 nVal
= sal_Int16();
214 if( rValue
>>= nVal
)
220 aOut
.append( OUString::number(static_cast<sal_Int32
>(-nVal
) ) + "px" );
224 rUnitConverter
.convertMeasureToXML( aOut
, nVal
);
227 rStrExpValue
= aOut
.makeStringAndClear();
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
;
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
);
262 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */