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 <oox/ppt/slidetransition.hxx>
22 #include <com/sun/star/animations/TransitionType.hpp>
23 #include <com/sun/star/animations/TransitionSubType.hpp>
24 #include <com/sun/star/animations/XTransitionFilter.hpp>
26 #include <sal/log.hxx>
27 #include <tools/color.hxx>
28 #include <comphelper/diagnose_ex.hxx>
30 #include <oox/helper/propertymap.hxx>
31 #include <oox/token/namespaces.hxx>
32 #include <oox/token/properties.hxx>
33 #include <oox/token/tokens.hxx>
34 #include <oox/ppt/pptfilterhelpers.hxx>
36 using namespace ::com::sun::star::uno
;
37 using namespace ::com::sun::star::animations
;
38 using namespace ::com::sun::star::presentation
;
42 SlideTransition::SlideTransition()
43 : mnTransitionType( 0 )
44 , mnTransitionSubType( 0 )
45 , mbTransitionDirectionNormal( true )
46 , mnAnimationSpeed( AnimationSpeed_FAST
)
47 , mfTransitionDurationInSeconds( -1.0 )
50 , mnTransitionFadeColor( 0 )
55 SlideTransition::SlideTransition(std::u16string_view sFilterName
)
56 : mnTransitionType( 0 )
57 , mnTransitionSubType( 0 )
58 , mbTransitionDirectionNormal( true )
59 , mnAnimationSpeed( AnimationSpeed_FAST
)
60 , mfTransitionDurationInSeconds( -1.0 )
63 , mnTransitionFadeColor( 0 )
65 const transition
*p
= transition::find( sFilterName
);
68 mnTransitionType
= p
->mnType
;
69 mnTransitionSubType
= p
->mnSubType
;
70 mbTransitionDirectionNormal
= p
->mbDirection
;
74 void SlideTransition::setSlideProperties( PropertyMap
& aProps
)
78 aProps
.setProperty( PROP_TransitionType
, mnTransitionType
);
79 aProps
.setProperty( PROP_TransitionSubtype
, mnTransitionSubType
);
80 aProps
.setProperty( PROP_TransitionDirection
, mbTransitionDirectionNormal
);
81 aProps
.setProperty( PROP_Speed
, mnAnimationSpeed
);
82 if( mfTransitionDurationInSeconds
>= 0.0 )
83 aProps
.setProperty( PROP_TransitionDuration
, mfTransitionDurationInSeconds
);
84 aProps
.setProperty( PROP_TransitionFadeColor
, mnTransitionFadeColor
);
85 if( mnAdvanceTime
!= -1 ) {
86 aProps
.setProperty( PROP_Duration
, mnAdvanceTime
/1000);
87 aProps
.setProperty( PROP_Change
, static_cast<sal_Int32
>(1));
93 TOOLS_WARN_EXCEPTION( "oox", "" );
97 void SlideTransition::setTransitionFilterProperties( const Reference
< XTransitionFilter
> & xFilter
)
101 xFilter
->setTransition( mnTransitionType
);
102 xFilter
->setSubtype( mnTransitionSubType
);
103 xFilter
->setDirection( mbTransitionDirectionNormal
);
104 xFilter
->setFadeColor( 0 );
105 xFilter
->setMode( mbMode
);
110 TOOLS_WARN_EXCEPTION( "oox", "" );
114 void SlideTransition::setOoxTransitionSpeed( sal_Int32 nToken
)
118 /* the speed values are located in the PPT97 importer
119 * sd/source/filter/ppt/pptin.cxx:1783
120 * (void ImplSdPPTImport::ImportPageEffect)
123 mnAnimationSpeed
= AnimationSpeed_FAST
;
124 mfTransitionDurationInSeconds
= 0.5;
127 mnAnimationSpeed
= AnimationSpeed_MEDIUM
;
128 mfTransitionDurationInSeconds
= 0.75;
131 mnAnimationSpeed
= AnimationSpeed_SLOW
;
132 mfTransitionDurationInSeconds
= 1.0;
135 // should not happen. just ignore
140 void SlideTransition::setOoxTransitionSpeed( double fDurationInSeconds
)
143 mnAnimationSpeed
= ( fDurationInSeconds
<= 0.5 ) ? AnimationSpeed_FAST
144 : ( fDurationInSeconds
>= 1.0 ) ? AnimationSpeed_SLOW
: AnimationSpeed_MEDIUM
;
145 mfTransitionDurationInSeconds
= fDurationInSeconds
;
148 sal_Int16
SlideTransition::ooxToOdpEightDirections( ::sal_Int32 nOoxType
)
150 sal_Int16 nOdpDirection
;
151 nOdpDirection
= ooxToOdpBorderDirections( nOoxType
);
152 if( nOdpDirection
== 0 )
154 nOdpDirection
= ooxToOdpCornerDirections( nOoxType
);
156 return nOdpDirection
;
159 sal_Int16
SlideTransition::ooxToOdpBorderDirections( ::sal_Int32 nOoxType
)
161 sal_Int16 nOdpDirection
;
165 nOdpDirection
= TransitionSubType::FROMTOP
;
168 nOdpDirection
= TransitionSubType::FROMLEFT
;
171 nOdpDirection
= TransitionSubType::FROMRIGHT
;
174 nOdpDirection
= TransitionSubType::FROMBOTTOM
;
180 return nOdpDirection
;
183 sal_Int16
SlideTransition::ooxToOdpSideDirections( ::sal_Int32 nOoxType
)
185 sal_Int16 nOdpDirection
;
190 nOdpDirection
= TransitionSubType::TOPTOBOTTOM
;
194 nOdpDirection
= TransitionSubType::LEFTTORIGHT
;
200 return nOdpDirection
;
203 bool SlideTransition::ooxToOdpSideDirectionsDirectionNormal( ::sal_Int32 nOoxType
)
205 bool bOdpDirection
= true;
210 bOdpDirection
= false;
213 return bOdpDirection
;
216 sal_Int16
SlideTransition::ooxToOdpCornerDirections( ::sal_Int32 nOoxType
)
218 sal_Int16 nOdpDirection
;
222 nOdpDirection
= TransitionSubType::FROMBOTTOMRIGHT
;
225 nOdpDirection
= TransitionSubType::FROMBOTTOMLEFT
;
228 nOdpDirection
= TransitionSubType::FROMTOPRIGHT
;
231 nOdpDirection
= TransitionSubType::FROMTOPLEFT
;
237 return nOdpDirection
;
240 sal_Int16
SlideTransition::ooxToOdpDirection( ::sal_Int32 nOoxType
)
246 nOdpDir
= TransitionSubType::VERTICAL
;
249 nOdpDir
= TransitionSubType::HORIZONTAL
;
258 void SlideTransition::setOoxTransitionType( ::sal_Int32 OoxType
, ::sal_Int32 param1
, ::sal_Int32 param2
)
262 case PPT_TOKEN( blinds
):
263 mnTransitionType
= TransitionType::BLINDSWIPE
;
264 mnTransitionSubType
= ooxToOdpDirection( param1
);
266 case PPT_TOKEN( checker
):
267 mnTransitionType
= TransitionType::CHECKERBOARDWIPE
;
271 mnTransitionSubType
= TransitionSubType::DOWN
;
274 mnTransitionSubType
= TransitionSubType::ACROSS
;
280 case PPT_TOKEN( comb
):
281 mnTransitionType
= TransitionType::PUSHWIPE
;
285 mnTransitionSubType
= TransitionSubType::COMBVERTICAL
;
288 mnTransitionSubType
= TransitionSubType::COMBHORIZONTAL
;
294 case PPT_TOKEN( cover
):
295 mnTransitionType
= TransitionType::SLIDEWIPE
;
296 mnTransitionSubType
= ooxToOdpEightDirections( param1
);
298 case PPT_TOKEN( pull
): // uncover
299 mnTransitionType
= TransitionType::SLIDEWIPE
;
300 mnTransitionSubType
= ooxToOdpEightDirections( param1
);
301 mbTransitionDirectionNormal
= false;
303 case PPT_TOKEN( cut
):
306 mnTransitionType
= TransitionType::BARWIPE
;
307 mnTransitionSubType
= TransitionSubType::FADEOVERCOLOR
;
309 SAL_WARN("oox.ppt", "OOX: cut transition fallback." );
311 case PPT_TOKEN( fade
):
312 mnTransitionType
= TransitionType::FADE
;
315 mnTransitionSubType
= TransitionSubType::FADEOVERCOLOR
;
319 mnTransitionSubType
= TransitionSubType::CROSSFADE
;
322 case PPT_TOKEN( push
):
323 mnTransitionType
= TransitionType::PUSHWIPE
;
324 mnTransitionSubType
= ooxToOdpBorderDirections( param1
);
326 case PPT_TOKEN( wipe
):
327 mnTransitionType
= TransitionType::BARWIPE
;
328 mnTransitionSubType
= ooxToOdpSideDirections( param1
);
329 mbTransitionDirectionNormal
= ooxToOdpSideDirectionsDirectionNormal( param1
);
331 case PPT_TOKEN( split
):
332 mnTransitionType
= TransitionType::BARNDOORWIPE
;
333 mnTransitionSubType
= ooxToOdpDirection( param1
);
334 if( param2
== XML_in
)
337 mbTransitionDirectionNormal
= false;
340 case PPT_TOKEN( wheel
):
341 mnTransitionType
= TransitionType::PINWHEELWIPE
;
345 mnTransitionSubType
= TransitionSubType::ONEBLADE
;
348 mnTransitionSubType
= TransitionSubType::TWOBLADEVERTICAL
;
351 mnTransitionSubType
= TransitionSubType::THREEBLADE
;
354 mnTransitionSubType
= TransitionSubType::FOURBLADE
;
357 mnTransitionSubType
= TransitionSubType::EIGHTBLADE
;
362 "strange number of blades for the wheel-wipe " << param1
);
365 mnTransitionSubType
= TransitionSubType::EIGHTBLADE
;
367 else if( param1
> 4 )
369 mnTransitionSubType
= TransitionSubType::FOURBLADE
;
371 else if( param1
== 0)
373 mnTransitionSubType
= TransitionSubType::ONEBLADE
;
378 case PPT_TOKEN( randomBar
):
379 mnTransitionType
= TransitionType::RANDOMBARWIPE
;
380 mnTransitionSubType
= ooxToOdpDirection( param1
);
382 case PPT_TOKEN( circle
):
383 mnTransitionType
= TransitionType::ELLIPSEWIPE
;
384 mnTransitionSubType
= TransitionSubType::CIRCLE
;
386 case PPT_TOKEN( diamond
):
387 mnTransitionType
= TransitionType::IRISWIPE
;
388 mnTransitionSubType
= TransitionSubType::DIAMOND
;
390 case PPT_TOKEN( dissolve
):
391 mnTransitionType
= TransitionType::DISSOLVE
;
392 mnTransitionSubType
= TransitionSubType::DEFAULT
;
394 case PPT_TOKEN( newsflash
):
395 mnTransitionType
= TransitionType::ZOOM
;
396 mnTransitionSubType
= TransitionSubType::ROTATEIN
;
398 case PPT_TOKEN( plus
):
399 mnTransitionType
= TransitionType::FOURBOXWIPE
;
400 mnTransitionSubType
= TransitionSubType::CORNERSOUT
;
402 case PPT_TOKEN( random
):
403 mnTransitionType
= TransitionType::RANDOM
;
404 mnTransitionSubType
= TransitionSubType::DEFAULT
;
406 case PPT_TOKEN( wedge
):
407 mnTransitionType
= TransitionType::FANWIPE
;
408 mnTransitionSubType
= TransitionSubType::CENTERTOP
;
410 case PPT_TOKEN( zoom
):
411 mnTransitionType
= TransitionType::ZOOM
;
412 mnTransitionSubType
= TransitionSubType::DEFAULT
;
414 case P14_TOKEN(prism
):
415 mnTransitionType
= TransitionType::MISCSHAPEWIPE
;
417 mnTransitionSubType
= TransitionSubType::CORNERSIN
;
419 mnTransitionSubType
= TransitionSubType::CORNERSOUT
;
421 case P14_TOKEN(vortex
):
422 mnTransitionType
= TransitionType::MISCSHAPEWIPE
;
423 mnTransitionSubType
= TransitionSubType::VERTICAL
;
425 case P14_TOKEN(ripple
):
426 mnTransitionType
= TransitionType::MISCSHAPEWIPE
;
427 mnTransitionSubType
= TransitionSubType::HORIZONTAL
;
429 case P14_TOKEN(glitter
):
430 mnTransitionType
= TransitionType::MISCSHAPEWIPE
;
431 mnTransitionSubType
= TransitionSubType::DIAMOND
;
433 case P14_TOKEN(honeycomb
):
434 mnTransitionType
= TransitionType::MISCSHAPEWIPE
;
435 mnTransitionSubType
= TransitionSubType::HEART
;
437 case P14_TOKEN(flash
):
438 mnTransitionType
= TransitionType::FADE
;
439 mnTransitionSubType
= TransitionSubType::FADEOVERCOLOR
;
440 mnTransitionFadeColor
= static_cast<sal_Int32
>(COL_WHITE
);
442 case PPT_TOKEN(strips
):
443 mnTransitionType
= TransitionType::SLIDEWIPE
;
444 mnTransitionSubType
= ooxToOdpCornerDirections( param1
);
447 mnTransitionType
= 0;
452 void SlideTransition::setPresetTransition(std::u16string_view sPresetTransition
)
454 if (sPresetTransition
== u
"fallOver")
456 mnTransitionType
= TransitionType::MISCSHAPEWIPE
;
457 mnTransitionSubType
= TransitionSubType::LEFTTORIGHT
;
461 mnTransitionType
= 0;
467 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */