xref: /aoo42x/main/xmloff/source/draw/propimp0.cxx (revision 63bba73c)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_xmloff.hxx"
26 #include <tools/string.hxx>
27 #include <rtl/ustrbuf.hxx>
28 #include "propimp0.hxx"
29 #include <com/sun/star/drawing/LineDash.hpp>
30 #include <com/sun/star/util/DateTime.hpp>
31 #include <com/sun/star/uno/Any.hxx>
32 #include <xmloff/xmluconv.hxx>
33 #include <xmloff/xmlimp.hxx>
34 
35 using ::rtl::OUString;
36 using ::rtl::OUStringBuffer;
37 
38 using namespace ::com::sun::star;
39 
40 //////////////////////////////////////////////////////////////////////////////
41 // implementation of graphic property Stroke
42 
43 
44 //////////////////////////////////////////////////////////////////////////////
45 // implementation of presentation page property Change
46 
47 //////////////////////////////////////////////////////////////////////////////
48 // implementation of an effect duration property handler
49 
50 
~XMLDurationPropertyHdl()51 XMLDurationPropertyHdl::~XMLDurationPropertyHdl()
52 {
53 }
54 
importXML(const OUString & rStrImpValue,::com::sun::star::uno::Any & rValue,const SvXMLUnitConverter &) const55 sal_Bool XMLDurationPropertyHdl::importXML(
56 	const OUString& rStrImpValue,
57 	::com::sun::star::uno::Any& rValue,
58 	const SvXMLUnitConverter& ) const
59 {
60 	util::DateTime aTime;
61 	SvXMLUnitConverter::convertTime( aTime,  rStrImpValue );
62 
63 	const sal_Int32 nSeconds = ( aTime.Hours * 60 + aTime.Minutes ) * 60 + aTime.Seconds;
64 	rValue <<= nSeconds;
65 
66 	return sal_True;
67 }
68 
exportXML(OUString & rStrExpValue,const::com::sun::star::uno::Any & rValue,const SvXMLUnitConverter &) const69 sal_Bool XMLDurationPropertyHdl::exportXML(
70 	OUString& rStrExpValue,
71 	const ::com::sun::star::uno::Any& rValue,
72 	const SvXMLUnitConverter& ) const
73 {
74 	sal_Int32 nVal = 0;
75 
76 	if(rValue >>= nVal)
77 	{
78 		util::DateTime aTime( 0, (sal_uInt16)nVal, 0, 0, 0, 0, 0 );
79 
80 		OUStringBuffer aOut;
81 		SvXMLUnitConverter::convertTime( aOut, aTime );
82 		rStrExpValue = aOut.makeStringAndClear();
83 		return sal_True;
84 	}
85 
86 	return sal_False;
87 }
88 
89 //////////////////////////////////////////////////////////////////////////////
90 // implementation of an opacity property handler
91 
92 
XMLOpacityPropertyHdl(SvXMLImport * pImport)93 XMLOpacityPropertyHdl::XMLOpacityPropertyHdl( SvXMLImport* pImport )
94 : mpImport( pImport )
95 {
96 }
97 
~XMLOpacityPropertyHdl()98 XMLOpacityPropertyHdl::~XMLOpacityPropertyHdl()
99 {
100 }
101 
importXML(const OUString & rStrImpValue,::com::sun::star::uno::Any & rValue,const SvXMLUnitConverter &) const102 sal_Bool XMLOpacityPropertyHdl::importXML(
103 	const OUString& rStrImpValue,
104 	::com::sun::star::uno::Any& rValue,
105 	const SvXMLUnitConverter& ) const
106 {
107 	sal_Bool bRet = sal_False;
108 	sal_Int32 nValue = 0;
109 
110 	if( rStrImpValue.indexOf( sal_Unicode('%') ) != -1 )
111 	{
112 		if( SvXMLUnitConverter::convertPercent( nValue, rStrImpValue ) )
113 			bRet = sal_True;
114 	}
115 	else
116 	{
117 		nValue = sal_Int32( rStrImpValue.toDouble() * 100.0 );
118 		bRet = sal_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 
exportXML(OUString & rStrExpValue,const::com::sun::star::uno::Any & rValue,const SvXMLUnitConverter &) const150 sal_Bool XMLOpacityPropertyHdl::exportXML(
151 	OUString& rStrExpValue,
152 	const ::com::sun::star::uno::Any& rValue,
153 	const SvXMLUnitConverter& ) const
154 {
155 	sal_Bool bRet = sal_False;
156 	sal_uInt16 nVal = sal_uInt16();
157 
158 	if( rValue >>= nVal )
159 	{
160 		OUStringBuffer aOut;
161 
162 		nVal = 100 - nVal;
163 		SvXMLUnitConverter::convertPercent( aOut, nVal );
164 		rStrExpValue = aOut.makeStringAndClear();
165 		bRet = sal_True;
166 	}
167 
168 	return bRet;
169 }
170 
171 //////////////////////////////////////////////////////////////////////////////
172 // implementation of an text animation step amount
173 
~XMLTextAnimationStepPropertyHdl()174 XMLTextAnimationStepPropertyHdl::~XMLTextAnimationStepPropertyHdl()
175 {
176 }
177 
importXML(const OUString & rStrImpValue,::com::sun::star::uno::Any & rValue,const SvXMLUnitConverter & rUnitConverter) const178 sal_Bool XMLTextAnimationStepPropertyHdl::importXML(
179 	const OUString& rStrImpValue,
180 	::com::sun::star::uno::Any& rValue,
181 	const SvXMLUnitConverter& rUnitConverter ) const
182 {
183 	sal_Bool bRet = sal_False;
184 	sal_Int32 nValue = 0;
185 
186 	const OUString aPX( RTL_CONSTASCII_USTRINGPARAM( "px" ) );
187 	sal_Int32 nPos = rStrImpValue.indexOf( aPX );
188 	if( nPos != -1 )
189 	{
190 		if( rUnitConverter.convertNumber( nValue, rStrImpValue.copy( 0, nPos ) ) )
191 		{
192 			rValue <<= sal_Int16( -nValue );
193 			bRet = sal_True;
194 		}
195 	}
196 	else
197 	{
198 		if( rUnitConverter.convertMeasure( nValue, rStrImpValue ) )
199 		{
200 			rValue <<= sal_Int16( nValue );
201 			bRet = sal_True;
202 		}
203 	}
204 
205 	return bRet;
206 }
207 
exportXML(OUString & rStrExpValue,const::com::sun::star::uno::Any & rValue,const SvXMLUnitConverter & rUnitConverter) const208 sal_Bool XMLTextAnimationStepPropertyHdl::exportXML(
209 	OUString& rStrExpValue,
210 	const ::com::sun::star::uno::Any& rValue,
211 	const SvXMLUnitConverter& rUnitConverter ) const
212 {
213 	sal_Bool bRet = sal_False;
214 	sal_Int16 nVal = sal_Int16();
215 
216 	if( rValue >>= nVal )
217 	{
218 		OUStringBuffer aOut;
219 
220 		if( nVal < 0 )
221 		{
222 			const OUString aPX( RTL_CONSTASCII_USTRINGPARAM( "px" ) );
223 			rUnitConverter.convertNumber( aOut, (sal_Int32)-nVal );
224 			aOut.append( aPX );
225 		}
226 		else
227 		{
228 			rUnitConverter.convertMeasure( aOut, nVal );
229 		}
230 
231 		rStrExpValue = aOut.makeStringAndClear();
232 		bRet = sal_True;
233 	}
234 
235 	return bRet;
236 }
237 
238 //////////////////////////////////////////////////////////////////////////////
239 
240 #include "sdxmlexp_impl.hxx"
241 
XMLDateTimeFormatHdl(SvXMLExport * pExport)242 XMLDateTimeFormatHdl::XMLDateTimeFormatHdl( SvXMLExport* pExport )
243 : mpExport( pExport )
244 {
245 }
246 
~XMLDateTimeFormatHdl()247 XMLDateTimeFormatHdl::~XMLDateTimeFormatHdl()
248 {
249 }
250 
importXML(const rtl::OUString & rStrImpValue,::com::sun::star::uno::Any & rValue,const SvXMLUnitConverter &) const251 sal_Bool XMLDateTimeFormatHdl::importXML( const rtl::OUString& rStrImpValue, ::com::sun::star::uno::Any& rValue, const SvXMLUnitConverter& ) const
252 {
253 	rValue <<= rStrImpValue;
254 	return true;
255 }
256 
exportXML(rtl::OUString & rStrExpValue,const::com::sun::star::uno::Any & rValue,const SvXMLUnitConverter &) const257 sal_Bool XMLDateTimeFormatHdl::exportXML( rtl::OUString& rStrExpValue, const ::com::sun::star::uno::Any& rValue, const SvXMLUnitConverter& ) const
258 {
259 	sal_Int32 nNumberFormat = 0;
260 	if( mpExport && (rValue >>= nNumberFormat) )
261 	{
262 		mpExport->addDataStyle( nNumberFormat );
263 		rStrExpValue = mpExport->getDataStyleName( nNumberFormat );
264 		return sal_True;
265 	}
266 
267 	return sal_False;
268 }
269