LibreOffice Module xmloff (master) 1
propimp0.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
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>
25
27
28#include <xmloff/xmlexp.hxx>
29#include <xmloff/xmluconv.hxx>
30#include <xmloff/xmlimp.hxx>
31
32#include <tools/time.hxx>
33
34using namespace ::com::sun::star;
35
36// implementation of graphic property Stroke
37
38// implementation of presentation page property Change
39
40// implementation of an effect duration property handler
41
43{
44}
45
47 const OUString& rStrImpValue,
48 css::uno::Any& rValue,
49 const SvXMLUnitConverter& ) const
50{
51 util::Duration aDuration;
52
53 if (::sax::Converter::convertDuration(aDuration, rStrImpValue))
54 {
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;
60
61 return true;
62 }
63
64 SAL_WARN_IF(!rStrImpValue.isEmpty(), "xmloff", "Invalid duration: " << rStrImpValue);
65
66 return false;
67}
68
70 OUString& rStrExpValue,
71 const css::uno::Any& rValue,
72 const SvXMLUnitConverter& ) const
73{
74 double nVal = 0;
75
76 if(rValue >>= nVal)
77 {
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);
81
82 OUStringBuffer aOut;
83 ::sax::Converter::convertDuration(aOut, aDuration);
84 rStrExpValue = aOut.makeStringAndClear();
85 return true;
86 }
87
88 return false;
89}
90
91// implementation of an opacity property handler
92
94: mpImport( pImport )
95{
96}
97
99{
100}
101
103 const OUString& rStrImpValue,
104 css::uno::Any& rValue,
105 const SvXMLUnitConverter& ) const
106{
107 bool bRet = false;
108 sal_Int32 nValue = 0;
109
110 if( rStrImpValue.indexOf( '%' ) != -1 )
111 {
112 if (::sax::Converter::convertPercent( nValue, rStrImpValue ))
113 bRet = true;
114 }
115 else
116 {
117 nValue = sal_Int32( rStrImpValue.toDouble() * 100.0 );
118 bRet = true;
119 }
120
121 if( bRet )
122 {
123 // check ranges
124 if( nValue < 0 )
125 nValue = 0;
126 if( nValue > 100 )
127 nValue = 100;
128
129 // convert xml opacity to api transparency
130 nValue = 100 - nValue;
131
132 // #i42959#
133 if( mpImport )
134 {
135 sal_Int32 nUPD, nBuild;
136 if( mpImport->getBuildIds( nUPD, nBuild ) )
137 {
138 // correct import of documents written prior to StarOffice 8/OOO 2.0 final
139 if( (nUPD == 680) && (nBuild < 8951) )
140 nValue = 100 - nValue;
141 }
142 }
143
144 rValue <<= sal_uInt16(nValue);
145 }
146
147 return bRet;
148}
149
151 OUString& rStrExpValue,
152 const css::uno::Any& rValue,
153 const SvXMLUnitConverter& ) const
154{
155 bool bRet = false;
156 sal_uInt16 nVal = sal_uInt16();
157
158 if( rValue >>= nVal )
159 {
160 OUStringBuffer aOut;
161
162 nVal = 100 - nVal;
164 rStrExpValue = aOut.makeStringAndClear();
165 bRet = true;
166 }
167
168 return bRet;
169}
170
171// implementation of a text animation step amount
172
174{
175}
176
178 const OUString& rStrImpValue,
179 css::uno::Any& rValue,
180 const SvXMLUnitConverter& rUnitConverter ) const
181{
182 bool bRet = false;
183 sal_Int32 nValue = 0;
184
185 sal_Int32 nPos = rStrImpValue.indexOf( "px" );
186 if( nPos != -1 )
187 {
188 if (::sax::Converter::convertNumber(nValue, rStrImpValue.subView(0, nPos)))
189 {
190 rValue <<= sal_Int16( -nValue );
191 bRet = true;
192 }
193 }
194 else
195 {
196 if (rUnitConverter.convertMeasureToCore( nValue, rStrImpValue ))
197 {
198 rValue <<= sal_Int16( nValue );
199 bRet = true;
200 }
201 }
202
203 return bRet;
204}
205
207 OUString& rStrExpValue,
208 const css::uno::Any& rValue,
209 const SvXMLUnitConverter& rUnitConverter ) const
210{
211 bool bRet = false;
212 sal_Int16 nVal = sal_Int16();
213
214 if( rValue >>= nVal )
215 {
216 OUStringBuffer aOut;
217
218 if( nVal < 0 )
219 {
220 aOut.append( OUString::number(static_cast<sal_Int32>(-nVal) ) + "px" );
221 }
222 else
223 {
224 rUnitConverter.convertMeasureToXML( aOut, nVal );
225 }
226
227 rStrExpValue = aOut.makeStringAndClear();
228 bRet = true;
229 }
230
231 return bRet;
232}
233
235: mpExport( pExport )
236{
237}
238
240{
241}
242
243bool XMLDateTimeFormatHdl::importXML( const OUString& rStrImpValue, css::uno::Any& rValue, const SvXMLUnitConverter& ) const
244{
245 rValue <<= rStrImpValue;
246 return true;
247}
248
249bool XMLDateTimeFormatHdl::exportXML( OUString& rStrExpValue, const css::uno::Any& rValue, const SvXMLUnitConverter& ) const
250{
251 sal_Int32 nNumberFormat = 0;
252 if( mpExport && (rValue >>= nNumberFormat) )
253 {
254 mpExport->addDataStyle( nNumberFormat );
255 rStrExpValue = mpExport->getDataStyleName( nNumberFormat );
256 return true;
257 }
258
259 return false;
260}
261
262/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual OUString getDataStyleName(const sal_Int32 nNumberFormat, bool bTimeFormat=false) const
Definition: xmlexp.cxx:1820
virtual void addDataStyle(const sal_Int32 nNumberFormat, bool bTimeFormat=false)
Definition: xmlexp.cxx:1799
the SvXMLTypeConverter converts values of various types from their internal representation to the tex...
Definition: xmluconv.hxx:83
bool convertMeasureToCore(sal_Int32 &rValue, std::u16string_view rString, sal_Int32 nMin=SAL_MIN_INT32, sal_Int32 nMax=SAL_MAX_INT32) const
convert string to measure with meCoreMeasureUnit, using optional min and max values
Definition: xmluconv.cxx:188
void convertMeasureToXML(OUStringBuffer &rBuffer, sal_Int32 nMeasure) const
convert measure to string: from meCoreMeasureUnit to meXMLMeasureUnit
Definition: xmluconv.cxx:208
SvXMLExport * mpExport
Definition: propimp0.hxx:58
XMLDateTimeFormatHdl(SvXMLExport *pExport)
Definition: propimp0.cxx:234
virtual bool importXML(const OUString &rStrImpValue, css::uno::Any &rValue, const SvXMLUnitConverter &rUnitConverter) const override
Imports the given value according to the XML-data-type corresponding to the derived class.
Definition: propimp0.cxx:243
virtual ~XMLDateTimeFormatHdl() override
Definition: propimp0.cxx:239
virtual bool exportXML(OUString &rStrExpValue, const css::uno::Any &rValue, const SvXMLUnitConverter &rUnitConverter) const override
Exports the given value according to the XML-data-type corresponding to the derived class.
Definition: propimp0.cxx:249
virtual bool importXML(const OUString &rStrImpValue, css::uno::Any &rValue, const SvXMLUnitConverter &rUnitConverter) const override
Imports the given value according to the XML-data-type corresponding to the derived class.
Definition: propimp0.cxx:46
virtual ~XMLDurationPropertyHdl() override
Definition: propimp0.cxx:42
virtual bool exportXML(OUString &rStrExpValue, const css::uno::Any &rValue, const SvXMLUnitConverter &rUnitConverter) const override
Exports the given value according to the XML-data-type corresponding to the derived class.
Definition: propimp0.cxx:69
XMLOpacityPropertyHdl(SvXMLImport *pImport)
Definition: propimp0.cxx:93
virtual bool exportXML(OUString &rStrExpValue, const css::uno::Any &rValue, const SvXMLUnitConverter &rUnitConverter) const override
Exports the given value according to the XML-data-type corresponding to the derived class.
Definition: propimp0.cxx:150
virtual bool importXML(const OUString &rStrImpValue, css::uno::Any &rValue, const SvXMLUnitConverter &rUnitConverter) const override
Imports the given value according to the XML-data-type corresponding to the derived class.
Definition: propimp0.cxx:102
virtual ~XMLOpacityPropertyHdl() override
Definition: propimp0.cxx:98
SvXMLImport * mpImport
Definition: propimp0.hxx:38
virtual ~XMLTextAnimationStepPropertyHdl() override
Definition: propimp0.cxx:173
virtual bool importXML(const OUString &rStrImpValue, css::uno::Any &rValue, const SvXMLUnitConverter &rUnitConverter) const override
Imports the given value according to the XML-data-type corresponding to the derived class.
Definition: propimp0.cxx:177
virtual bool exportXML(OUString &rStrExpValue, const css::uno::Any &rValue, const SvXMLUnitConverter &rUnitConverter) const override
Exports the given value according to the XML-data-type corresponding to the derived class.
Definition: propimp0.cxx:206
static bool convertPercent(sal_Int32 &rValue, std::u16string_view rString)
static void convertDuration(OUStringBuffer &rBuffer, const double fTime)
static bool convertNumber(sal_Int32 &rValue, std::u16string_view aString, sal_Int32 nMin=SAL_MIN_INT32, sal_Int32 nMax=SAL_MAX_INT32)
static const sal_Int64 nanoSecPerSec
sal_Int16 nValue
sal_uInt16 nPos
#define SAL_WARN_IF(condition, area, stream)