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 #include "oox/ppt/slidetransition.hxx"
25 
26 #include <com/sun/star/uno/Any.hxx>
27 #include <com/sun/star/beans/XPropertySet.hpp>
28 #include <com/sun/star/presentation/AnimationSpeed.hpp>
29 #include <com/sun/star/animations/TransitionType.hpp>
30 #include <com/sun/star/animations/TransitionSubType.hpp>
31 
32 #include "oox/helper/helper.hxx"
33 #include "oox/helper/propertymap.hxx"
34 #include "oox/token/namespaces.hxx"
35 #include "oox/token/tokens.hxx"
36 #include "pptfilterhelpers.hxx"
37 
38 using rtl::OUString;
39 using namespace ::com::sun::star::uno;
40 using namespace ::com::sun::star::beans;
41 using namespace ::com::sun::star::animations;
42 using namespace ::com::sun::star::presentation;
43 
44 namespace oox { namespace ppt {
45 
46 
SlideTransition()47 	SlideTransition::SlideTransition()
48 		: mnTransitionType( 0 )
49 		, mnTransitionSubType( 0 )
50 		, mbTransitionDirectionNormal( true )
51 		, mnAnimationSpeed( AnimationSpeed_FAST )
52 		, mnFadeColor( 0 )
53 		, mbMode( true )
54 	{
55 
56 	}
57 
58 
SlideTransition(const OUString & sFilterName)59 	SlideTransition::SlideTransition(const OUString & sFilterName)
60 		: mnTransitionType( 0 )
61 		, mnTransitionSubType( 0 )
62 		, mbTransitionDirectionNormal( true )
63 		, mnAnimationSpeed( AnimationSpeed_FAST )
64 		, mnFadeColor( 0 )
65 		, mbMode( true )
66 	{
67 		const transition *p = transition::find( sFilterName );
68 		if( p )
69 		{
70 			mnTransitionType = p->mnType;
71 			mnTransitionSubType = p->mnSubType;
72 			mbTransitionDirectionNormal = p->mbDirection;
73 		}
74 	}
75 
76 
setSlideProperties(PropertyMap & aProps)77     void SlideTransition::setSlideProperties( PropertyMap & aProps )
78 	{
79 		try
80 		{
81             aProps[ PROP_TransitionType ] <<= mnTransitionType;
82             aProps[ PROP_TransitionSubtype ] <<= mnTransitionSubType;
83             aProps[ PROP_TransitionDirection ] <<= mbTransitionDirectionNormal;
84             aProps[ PROP_Speed ] <<= mnAnimationSpeed;
85             aProps[ PROP_TransitionFadeColor ] <<= mnFadeColor;
86 		}
87 		catch( Exception& )
88 		{
89 			// should not happen
90 			OSL_ENSURE( false, "exception raised" );
91 		}
92 	}
93 
setTransitionFilterProperties(const Reference<XTransitionFilter> & xFilter)94 	void SlideTransition::setTransitionFilterProperties( const Reference< XTransitionFilter > & xFilter )
95 	{
96 		try
97 		{
98 			xFilter->setTransition( mnTransitionType );
99 			xFilter->setSubtype( mnTransitionSubType );
100 			xFilter->setDirection( mbTransitionDirectionNormal );
101 			xFilter->setFadeColor( mnFadeColor );
102 			xFilter->setMode( mbMode );
103 		}
104 		catch( Exception& )
105 		{
106 			// should not happen
107 			OSL_ENSURE( false, "exception raised" );
108 		}
109 	}
110 
111 
setOoxTransitionSpeed(sal_Int32 nToken)112 	void SlideTransition::setOoxTransitionSpeed( sal_Int32 nToken)
113 	{
114 		switch( nToken  )
115 		{
116 			/* In case you want to use time values in second,
117 			 * the speed values are located in the PPT97 importer
118 			 * sd/source/filter/ppt/ppt97animations.cxx:664
119 			 * (void Ppt97Animation::UpdateCacheData() const)
120 			 */
121 		case XML_fast:
122 			mnAnimationSpeed = AnimationSpeed_FAST;
123 			break;
124 		case XML_med:
125 			mnAnimationSpeed = AnimationSpeed_MEDIUM;
126 			break;
127 		case XML_slow:
128 			mnAnimationSpeed = AnimationSpeed_SLOW;
129 			break;
130 		default:
131 			// should not happen. just ignore
132 			break;
133 		}
134 	}
135 
136 
137 
ooxToOdpEightDirections(::sal_Int32 nOoxType)138 	sal_Int16 SlideTransition::ooxToOdpEightDirections( ::sal_Int32 nOoxType )
139 	{
140     sal_Int16 nOdpDirection;
141 		nOdpDirection = ooxToOdpBorderDirections( nOoxType );
142 		if( nOdpDirection == 0 )
143 		{
144 			nOdpDirection = ooxToOdpCornerDirections( nOoxType );
145 		}
146 		return nOdpDirection;
147 	}
148 
149 
ooxToOdpBorderDirections(::sal_Int32 nOoxType)150 	sal_Int16 SlideTransition::ooxToOdpBorderDirections( ::sal_Int32 nOoxType )
151 	{
152     sal_Int16 nOdpDirection;
153 		switch( nOoxType )
154 		{
155 		case XML_d:
156 			nOdpDirection = TransitionSubType::FROMTOP;
157 			break;
158 		case XML_l:
159 			nOdpDirection = TransitionSubType::FROMLEFT;
160 			break;
161 		case XML_r:
162 			nOdpDirection = TransitionSubType::FROMRIGHT;
163 			break;
164 		case XML_u:
165 			nOdpDirection = TransitionSubType::FROMBOTTOM;
166 			break;
167 		default:
168 			nOdpDirection= 0;
169 			break;
170 		}
171 		return nOdpDirection;
172 	}
173 
ooxToOdpSideDirections(::sal_Int32 nOoxType)174 	sal_Int16 SlideTransition::ooxToOdpSideDirections( ::sal_Int32 nOoxType )
175 	{
176     sal_Int16 nOdpDirection;
177 		switch( nOoxType )
178 		{
179 		case XML_d:
180 		case XML_u:
181 			nOdpDirection = TransitionSubType::TOPTOBOTTOM;
182 			break;
183 		case XML_l:
184 		case XML_r:
185 			nOdpDirection = TransitionSubType::LEFTTORIGHT;
186 			break;
187 		default:
188 			nOdpDirection= 0;
189 			break;
190 		}
191 		return nOdpDirection;
192 	}
193 
ooxToOdpSideDirectionsDirectionNormal(::sal_Int32 nOoxType)194 	sal_Bool SlideTransition::ooxToOdpSideDirectionsDirectionNormal( ::sal_Int32 nOoxType )
195 	{
196     sal_Bool nOdpDirection = true;
197 		switch( nOoxType )
198 		{
199 		case XML_u:
200 		case XML_l:
201 			nOdpDirection = false;
202 			break;
203 		}
204 		return nOdpDirection;
205 	}
206 
ooxToOdpCornerDirections(::sal_Int32 nOoxType)207 	sal_Int16 SlideTransition::ooxToOdpCornerDirections( ::sal_Int32 nOoxType )
208 	{
209     sal_Int16 nOdpDirection;
210 		switch( nOoxType )
211 		{
212 		case XML_lu:
213 			nOdpDirection = TransitionSubType::FROMBOTTOMRIGHT;
214 			break;
215 		case XML_ru:
216 			nOdpDirection = TransitionSubType::FROMBOTTOMLEFT;
217 			break;
218 		case XML_ld:
219 			nOdpDirection = TransitionSubType::FROMTOPRIGHT;
220 			break;
221 		case XML_rd:
222 			nOdpDirection = TransitionSubType::FROMTOPLEFT;
223 			break;
224 		default:
225 			nOdpDirection = 0;
226 			break;
227 		}
228 		return nOdpDirection;
229 	}
230 
231 
ooxToOdpDirection(::sal_Int32 nOoxType)232 	sal_Int16 SlideTransition::ooxToOdpDirection( ::sal_Int32 nOoxType )
233 	{
234     sal_Int16 nOdpDir;
235 		switch( nOoxType )
236 		{
237 		case XML_vert:
238 			nOdpDir = TransitionSubType::VERTICAL;
239 			break;
240 		case XML_horz:
241 			nOdpDir = TransitionSubType::HORIZONTAL;
242 			break;
243 		default:
244 			nOdpDir = 0;
245 			break;
246 		}
247 		return nOdpDir;
248 	}
249 
setOoxTransitionType(::sal_Int32 OoxType,::sal_Int32 param1,::sal_Int32 param2)250 	void SlideTransition::setOoxTransitionType( ::sal_Int32 OoxType, ::sal_Int32 param1, ::sal_Int32 param2 )
251 	{
252 		switch( OoxType )
253 		{
254 		case PPT_TOKEN( blinds ):
255 			mnTransitionType = TransitionType::BLINDSWIPE;
256 			mnTransitionSubType = ooxToOdpDirection( param1 );
257 			break;
258 		case PPT_TOKEN( checker ):
259 			mnTransitionType = TransitionType::CHECKERBOARDWIPE;
260 			switch ( param1 )
261 			{
262 			case XML_vert:
263 				mnTransitionSubType = TransitionSubType::DOWN;
264 				break;
265 			case XML_horz:
266 				mnTransitionSubType = TransitionSubType::ACROSS;
267 				break;
268 			default:
269 				break;
270 			}
271 			break;
272 		case PPT_TOKEN( comb ):
273 			mnTransitionType = TransitionType::PUSHWIPE;
274 			switch( param1 )
275 			{
276 			case XML_vert:
277 				mnTransitionSubType = TransitionSubType::COMBVERTICAL;
278 				break;
279 			case XML_horz:
280 				mnTransitionSubType = TransitionSubType::COMBHORIZONTAL;
281 				break;
282 			default:
283 				break;
284 			}
285 			break;
286 		case PPT_TOKEN( cover ):
287 			mnTransitionType = TransitionType::SLIDEWIPE;
288 			mnTransitionSubType = ooxToOdpEightDirections( param1 );
289 			break;
290 		case PPT_TOKEN( pull ): // uncover
291 			mnTransitionType = TransitionType::SLIDEWIPE;
292 			mnTransitionSubType = ooxToOdpEightDirections( param1 );
293 			mbTransitionDirectionNormal = false;
294 			break;
295 		case PPT_TOKEN( cut ):
296 			// The binfilter seems to ignore this transition.
297 			// Fade to black instead if thrBlk is true.
298 			if( param1 )
299 			{
300 				mnTransitionType = TransitionType::FADE;
301 				mnTransitionSubType = TransitionSubType::FADEOVERCOLOR;
302 			}
303 			OSL_TRACE( "OOX: cut transition fallback." );
304 			break;
305 		case PPT_TOKEN( fade ):
306 			mnTransitionType = TransitionType::FADE;
307 			if( param1 )
308 			{
309 				mnTransitionSubType = TransitionSubType::FADEOVERCOLOR;
310 			}
311 			else
312 			{
313 				mnTransitionSubType = TransitionSubType::CROSSFADE;
314 			}
315 			break;
316 		case PPT_TOKEN( push ):
317 			mnTransitionType = TransitionType::PUSHWIPE;
318 			mnTransitionSubType = ooxToOdpBorderDirections( param1 );
319 			break;
320 		case PPT_TOKEN( wipe ):
321 			mnTransitionType = TransitionType::BARWIPE;
322 			mnTransitionSubType = ooxToOdpSideDirections( param1 );
323 			mbTransitionDirectionNormal = ooxToOdpSideDirectionsDirectionNormal( param1 );
324 			break;
325 		case PPT_TOKEN( split ):
326 			mnTransitionType = TransitionType::BARNDOORWIPE;
327 			mnTransitionSubType = ooxToOdpDirection( param1 );
328 			if( param2 == XML_in )
329 			{
330 				// reverse
331 				mbTransitionDirectionNormal = false;
332 			}
333 			break;
334 		case PPT_TOKEN( wheel ):
335 			mnTransitionType = TransitionType::PINWHEELWIPE;
336 			switch( param1 )
337 			{
338 			case 1:
339 				mnTransitionSubType = TransitionSubType::ONEBLADE;
340 				break;
341 			case 2:
342 				mnTransitionSubType = TransitionSubType::TWOBLADEVERTICAL;
343 				break;
344 			case 3:
345 				mnTransitionSubType = TransitionSubType::THREEBLADE;
346 				break;
347 			case 4:
348 				mnTransitionSubType = TransitionSubType::FOURBLADE;
349 				break;
350 			case 8:
351 				mnTransitionSubType = TransitionSubType::EIGHTBLADE;
352 				break;
353 			default:
354 				OSL_TRACE( "OOX: strange number of blades for thw wheel-wipe %d", param1 );
355 				if( param1 > 8 )
356 				{
357 					mnTransitionSubType = TransitionSubType::EIGHTBLADE;
358 				}
359 				else if( param1 > 4 )
360 				{
361 					mnTransitionSubType = TransitionSubType::FOURBLADE;
362 				}
363 				else if( param1 == 0)
364 				{
365 					mnTransitionSubType = TransitionSubType::ONEBLADE;
366 				}
367 				break;
368 			}
369 			break;
370 		case PPT_TOKEN( randomBar ):
371 			mnTransitionType = TransitionType::RANDOMBARWIPE;
372 			mnTransitionSubType = ooxToOdpDirection( param1 );
373 			break;
374 		case PPT_TOKEN( circle ):
375 			mnTransitionType = TransitionType::ELLIPSEWIPE;
376 			mnTransitionSubType = TransitionSubType::CIRCLE;
377 			break;
378 		case PPT_TOKEN( diamond ):
379 			mnTransitionType = TransitionType::IRISWIPE;
380 			mnTransitionSubType = TransitionSubType::DIAMOND;
381 			break;
382 		case PPT_TOKEN( dissolve ):
383 			mnTransitionType = TransitionType::DISSOLVE;
384 			mnTransitionSubType = TransitionSubType::DEFAULT;
385 			break;
386 		case PPT_TOKEN( newsflash ):
387 			// this is what the PPT binary filter does.... not sure I agree.
388 			mnTransitionType = TransitionType::FOURBOXWIPE;
389 			mnTransitionSubType = TransitionSubType::CORNERSOUT;
390 			break;
391 		case PPT_TOKEN( plus ):
392 			mnTransitionType = TransitionType::FOURBOXWIPE;
393 			mnTransitionSubType = TransitionSubType::CORNERSOUT;
394 			break;
395 		case PPT_TOKEN( random ):
396 			mnTransitionType = TransitionType::RANDOM;
397 			mnTransitionSubType = TransitionSubType::DEFAULT;
398 			break;
399 		case PPT_TOKEN( wedge ):
400 			mnTransitionType = TransitionType::FANWIPE;
401 			mnTransitionSubType = TransitionSubType::CENTERTOP;
402 			break;
403 		case PPT_TOKEN( zoom ):
404 			mnTransitionType = TransitionType::ZOOM;
405 			mnTransitionSubType = TransitionSubType::DEFAULT;
406 			break;
407 		default:
408 			mnTransitionType = 0;
409 			break;
410 		}
411 	}
412 
413 
414 } }
415