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 
26 #include <sax/tools/converter.hxx>
27 
28 #include <xmloff/xmlexp.hxx>
29 #include <xmloff/xmluconv.hxx>
30 #include <xmloff/xmlimp.hxx>
31 
32 #include <tools/time.hxx>
33 
34 using 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;
163  ::sax::Converter::convertPercent( aOut, 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, std::u16string_view(rStrImpValue).substr(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( static_cast<sal_Int32>(-nVal) );
221  aOut.append( "px" );
222  }
223  else
224  {
225  rUnitConverter.convertMeasureToXML( aOut, nVal );
226  }
227 
228  rStrExpValue = aOut.makeStringAndClear();
229  bRet = true;
230  }
231 
232  return bRet;
233 }
234 
236 : mpExport( pExport )
237 {
238 }
239 
241 {
242 }
243 
244 bool XMLDateTimeFormatHdl::importXML( const OUString& rStrImpValue, css::uno::Any& rValue, const SvXMLUnitConverter& ) const
245 {
246  rValue <<= rStrImpValue;
247  return true;
248 }
249 
250 bool XMLDateTimeFormatHdl::exportXML( OUString& rStrExpValue, const css::uno::Any& rValue, const SvXMLUnitConverter& ) const
251 {
252  sal_Int32 nNumberFormat = 0;
253  if( mpExport && (rValue >>= nNumberFormat) )
254  {
255  mpExport->addDataStyle( nNumberFormat );
256  rStrExpValue = mpExport->getDataStyleName( nNumberFormat );
257  return true;
258  }
259 
260  return false;
261 }
262 
263 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
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:250
virtual ~XMLOpacityPropertyHdl() override
Definition: propimp0.cxx:98
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:69
static const sal_Int64 nanoSecPerSec
XMLDateTimeFormatHdl(SvXMLExport *pExport)
Definition: propimp0.cxx:235
the SvXMLTypeConverter converts values of various types from their internal representation to the tex...
Definition: xmluconv.hxx:77
virtual ~XMLDateTimeFormatHdl() override
Definition: propimp0.cxx:240
SvXMLImport * mpImport
Definition: propimp0.hxx:39
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:244
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 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
css::uno::Any const & rValue
Definition: ImageStyle.hxx:38
bool convertMeasureToCore(sal_Int32 &rValue, const OUString &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:171
virtual ~XMLDurationPropertyHdl() override
Definition: propimp0.cxx:42
virtual OUString getDataStyleName(const sal_Int32 nNumberFormat, bool bTimeFormat=false) const
Definition: xmlexp.cxx:1840
bool getBuildIds(sal_Int32 &rUPD, sal_Int32 &rBuild) const
returns the upd and build id (f.e.
Definition: xmlimp.cxx:1889
static void convertDuration(OUStringBuffer &rBuffer, const double fTime)
XMLOpacityPropertyHdl(SvXMLImport *pImport)
Definition: propimp0.cxx:93
SvXMLExport * mpExport
Definition: propimp0.hxx:59
virtual ~XMLTextAnimationStepPropertyHdl() override
Definition: propimp0.cxx:173
#define SAL_WARN_IF(condition, area, stream)
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 void addDataStyle(const sal_Int32 nNumberFormat, bool bTimeFormat=false)
Definition: xmlexp.cxx:1819
void convertMeasureToXML(OUStringBuffer &rBuffer, sal_Int32 nMeasure) const
convert measure to string: from meCoreMeasureUnit to meXMLMeasureUnit
Definition: xmluconv.cxx:181
sal_uInt16 nPos
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
sal_Int16 nValue
static bool convertPercent(sal_Int32 &rValue, const OUString &rString)
static bool convertNumber(sal_Int32 &rValue, std::u16string_view aString, sal_Int32 nMin=SAL_MIN_INT32, sal_Int32 nMax=SAL_MAX_INT32)