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 "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
57 + aDuration
.NanoSeconds
/ static_cast<double>(::tools::Time::nanoSecPerSec
);
63 SAL_WARN_IF(!rStrImpValue
.isEmpty(), "xmloff", "Invalid duration: " << rStrImpValue
);
68 bool XMLDurationPropertyHdl::exportXML(
69 OUString
& rStrExpValue
,
70 const ::com::sun::star::uno::Any
& rValue
,
71 const SvXMLUnitConverter
& ) const
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
);
82 ::sax::Converter::convertDuration(aOut
, aDuration
);
83 rStrExpValue
= aOut
.makeStringAndClear();
90 // implementation of an opacity property handler
92 XMLOpacityPropertyHdl::XMLOpacityPropertyHdl( SvXMLImport
* pImport
)
97 XMLOpacityPropertyHdl::~XMLOpacityPropertyHdl()
101 bool XMLOpacityPropertyHdl::importXML(
102 const OUString
& rStrImpValue
,
103 ::com::sun::star::uno::Any
& rValue
,
104 const SvXMLUnitConverter
& ) const
107 sal_Int32 nValue
= 0;
109 if( rStrImpValue
.indexOf( '%' ) != -1 )
111 if (::sax::Converter::convertPercent( nValue
, rStrImpValue
))
116 nValue
= sal_Int32( rStrImpValue
.toDouble() * 100.0 );
128 // convert xml opacity to api transparency
129 nValue
= 100 - nValue
;
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
);
149 bool XMLOpacityPropertyHdl::exportXML(
150 OUString
& rStrExpValue
,
151 const ::com::sun::star::uno::Any
& rValue
,
152 const SvXMLUnitConverter
& ) const
155 sal_uInt16 nVal
= sal_uInt16();
157 if( rValue
>>= nVal
)
162 ::sax::Converter::convertPercent( aOut
, nVal
);
163 rStrExpValue
= aOut
.makeStringAndClear();
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
182 sal_Int32 nValue
= 0;
184 const OUString
aPX( "px" );
185 sal_Int32 nPos
= rStrImpValue
.indexOf( aPX
);
188 if (::sax::Converter::convertNumber(nValue
, rStrImpValue
.copy(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 ::com::sun::star::uno::Any
& rValue
,
209 const SvXMLUnitConverter
& rUnitConverter
) const
212 sal_Int16 nVal
= sal_Int16();
214 if( rValue
>>= nVal
)
220 const OUString
aPX( "px" );
221 ::sax::Converter::convertNumber( aOut
, (sal_Int32
)-nVal
);
226 rUnitConverter
.convertMeasureToXML( aOut
, nVal
);
229 rStrExpValue
= aOut
.makeStringAndClear();
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
;
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
);
266 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */