LCOV - code coverage report
Current view: top level - oox/source/ppt - slidetransition.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 56 194 28.9 %
Date: 2015-06-13 12:38:46 Functions: 8 12 66.7 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.11