LibreOffice Module oox (master)  1
slidetransition.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 
21 
22 #include <com/sun/star/animations/TransitionType.hpp>
23 #include <com/sun/star/animations/TransitionSubType.hpp>
24 #include <com/sun/star/animations/XTransitionFilter.hpp>
25 
26 #include <osl/diagnose.h>
27 #include <sal/log.hxx>
28 #include <tools/color.hxx>
29 #include <tools/diagnose_ex.h>
30 
32 #include <oox/token/namespaces.hxx>
33 #include <oox/token/properties.hxx>
34 #include <oox/token/tokens.hxx>
36 
37 using namespace ::com::sun::star::uno;
38 using namespace ::com::sun::star::animations;
39 using namespace ::com::sun::star::presentation;
40 
41 namespace oox::ppt {
42 
44  : mnTransitionType( 0 )
45  , mnTransitionSubType( 0 )
46  , mbTransitionDirectionNormal( true )
47  , mnAnimationSpeed( AnimationSpeed_FAST )
48  , mfTransitionDurationInSeconds( -1.0 )
49  , mbMode( true )
50  , mnAdvanceTime( -1 )
52  {
53 
54  }
55 
56  SlideTransition::SlideTransition(const OUString & sFilterName)
57  : mnTransitionType( 0 )
58  , mnTransitionSubType( 0 )
59  , mbTransitionDirectionNormal( true )
60  , mnAnimationSpeed( AnimationSpeed_FAST )
61  , mfTransitionDurationInSeconds( -1.0 )
62  , mbMode( true )
63  , mnAdvanceTime( -1 )
65  {
66  const transition *p = transition::find( sFilterName );
67  if( p )
68  {
72  }
73  }
74 
76  {
77  try
78  {
79  aProps.setProperty( PROP_TransitionType, mnTransitionType);
80  aProps.setProperty( PROP_TransitionSubtype, mnTransitionSubType);
81  aProps.setProperty( PROP_TransitionDirection, mbTransitionDirectionNormal);
82  aProps.setProperty( PROP_Speed, mnAnimationSpeed);
84  aProps.setProperty( PROP_TransitionDuration, mfTransitionDurationInSeconds);
85  aProps.setProperty( PROP_TransitionFadeColor, mnTransitionFadeColor);
86  if( mnAdvanceTime != -1 ) {
87  aProps.setProperty( PROP_Duration, mnAdvanceTime/1000);
88  aProps.setProperty( PROP_Change, static_cast<sal_Int32>(1));
89  }
90  }
91  catch( Exception& )
92  {
93  // should not happen
94  TOOLS_WARN_EXCEPTION( "oox", "" );
95  }
96  }
97 
98  void SlideTransition::setTransitionFilterProperties( const Reference< XTransitionFilter > & xFilter )
99  {
100  try
101  {
102  xFilter->setTransition( mnTransitionType );
103  xFilter->setSubtype( mnTransitionSubType );
104  xFilter->setDirection( mbTransitionDirectionNormal );
105  xFilter->setFadeColor( 0 );
106  xFilter->setMode( mbMode );
107  }
108  catch( Exception& )
109  {
110  // should not happen
111  TOOLS_WARN_EXCEPTION( "oox", "" );
112  }
113  }
114 
116  {
117  switch( nToken )
118  {
119  /* the speed values are located in the PPT97 importer
120  * sd/source/filter/ppt/pptin.cxx:1783
121  * (void ImplSdPPTImport::ImportPageEffect)
122  */
123  case XML_fast:
124  mnAnimationSpeed = AnimationSpeed_FAST;
126  break;
127  case XML_med:
128  mnAnimationSpeed = AnimationSpeed_MEDIUM;
130  break;
131  case XML_slow:
132  mnAnimationSpeed = AnimationSpeed_SLOW;
134  break;
135  default:
136  // should not happen. just ignore
137  break;
138  }
139  }
140 
141  void SlideTransition::setOoxTransitionSpeed( double fDurationInSeconds )
142  {
143  // for compatibility
144  mnAnimationSpeed = ( fDurationInSeconds <= 0.5 ) ? AnimationSpeed_FAST
145  : ( fDurationInSeconds >= 1.0 ) ? AnimationSpeed_SLOW : AnimationSpeed_MEDIUM;
146  mfTransitionDurationInSeconds = fDurationInSeconds;
147  }
148 
149  sal_Int16 SlideTransition::ooxToOdpEightDirections( ::sal_Int32 nOoxType )
150  {
151  sal_Int16 nOdpDirection;
152  nOdpDirection = ooxToOdpBorderDirections( nOoxType );
153  if( nOdpDirection == 0 )
154  {
155  nOdpDirection = ooxToOdpCornerDirections( nOoxType );
156  }
157  return nOdpDirection;
158  }
159 
160  sal_Int16 SlideTransition::ooxToOdpBorderDirections( ::sal_Int32 nOoxType )
161  {
162  sal_Int16 nOdpDirection;
163  switch( nOoxType )
164  {
165  case XML_d:
166  nOdpDirection = TransitionSubType::FROMTOP;
167  break;
168  case XML_l:
169  nOdpDirection = TransitionSubType::FROMLEFT;
170  break;
171  case XML_r:
172  nOdpDirection = TransitionSubType::FROMRIGHT;
173  break;
174  case XML_u:
175  nOdpDirection = TransitionSubType::FROMBOTTOM;
176  break;
177  default:
178  nOdpDirection= 0;
179  break;
180  }
181  return nOdpDirection;
182  }
183 
184  sal_Int16 SlideTransition::ooxToOdpSideDirections( ::sal_Int32 nOoxType )
185  {
186  sal_Int16 nOdpDirection;
187  switch( nOoxType )
188  {
189  case XML_d:
190  case XML_u:
191  nOdpDirection = TransitionSubType::TOPTOBOTTOM;
192  break;
193  case XML_l:
194  case XML_r:
195  nOdpDirection = TransitionSubType::LEFTTORIGHT;
196  break;
197  default:
198  nOdpDirection= 0;
199  break;
200  }
201  return nOdpDirection;
202  }
203 
205  {
206  bool bOdpDirection = true;
207  switch( nOoxType )
208  {
209  case XML_u:
210  case XML_l:
211  bOdpDirection = false;
212  break;
213  }
214  return bOdpDirection;
215  }
216 
217  sal_Int16 SlideTransition::ooxToOdpCornerDirections( ::sal_Int32 nOoxType )
218  {
219  sal_Int16 nOdpDirection;
220  switch( nOoxType )
221  {
222  case XML_lu:
223  nOdpDirection = TransitionSubType::FROMBOTTOMRIGHT;
224  break;
225  case XML_ru:
226  nOdpDirection = TransitionSubType::FROMBOTTOMLEFT;
227  break;
228  case XML_ld:
229  nOdpDirection = TransitionSubType::FROMTOPRIGHT;
230  break;
231  case XML_rd:
232  nOdpDirection = TransitionSubType::FROMTOPLEFT;
233  break;
234  default:
235  nOdpDirection = 0;
236  break;
237  }
238  return nOdpDirection;
239  }
240 
241  sal_Int16 SlideTransition::ooxToOdpDirection( ::sal_Int32 nOoxType )
242  {
243  sal_Int16 nOdpDir;
244  switch( nOoxType )
245  {
246  case XML_vert:
247  nOdpDir = TransitionSubType::VERTICAL;
248  break;
249  case XML_horz:
250  nOdpDir = TransitionSubType::HORIZONTAL;
251  break;
252  default:
253  nOdpDir = 0;
254  break;
255  }
256  return nOdpDir;
257  }
258 
259  void SlideTransition::setOoxTransitionType( ::sal_Int32 OoxType, ::sal_Int32 param1, ::sal_Int32 param2 )
260  {
261  switch( OoxType )
262  {
263  case PPT_TOKEN( blinds ):
264  mnTransitionType = TransitionType::BLINDSWIPE;
266  break;
267  case PPT_TOKEN( checker ):
268  mnTransitionType = TransitionType::CHECKERBOARDWIPE;
269  switch ( param1 )
270  {
271  case XML_vert:
272  mnTransitionSubType = TransitionSubType::DOWN;
273  break;
274  case XML_horz:
275  mnTransitionSubType = TransitionSubType::ACROSS;
276  break;
277  default:
278  break;
279  }
280  break;
281  case PPT_TOKEN( comb ):
282  mnTransitionType = TransitionType::PUSHWIPE;
283  switch( param1 )
284  {
285  case XML_vert:
286  mnTransitionSubType = TransitionSubType::COMBVERTICAL;
287  break;
288  case XML_horz:
289  mnTransitionSubType = TransitionSubType::COMBHORIZONTAL;
290  break;
291  default:
292  break;
293  }
294  break;
295  case PPT_TOKEN( cover ):
296  mnTransitionType = TransitionType::SLIDEWIPE;
298  break;
299  case PPT_TOKEN( pull ): // uncover
300  mnTransitionType = TransitionType::SLIDEWIPE;
303  break;
304  case PPT_TOKEN( cut ):
305  if( param1 )
306  {
307  mnTransitionType = TransitionType::BARWIPE;
308  mnTransitionSubType = TransitionSubType::FADEOVERCOLOR;
309  }
310  SAL_WARN("oox.ppt", "OOX: cut transition fallback." );
311  break;
312  case PPT_TOKEN( fade ):
313  mnTransitionType = TransitionType::FADE;
314  if( param1 )
315  {
316  mnTransitionSubType = TransitionSubType::FADEOVERCOLOR;
317  }
318  else
319  {
320  mnTransitionSubType = TransitionSubType::CROSSFADE;
321  }
322  break;
323  case PPT_TOKEN( push ):
324  mnTransitionType = TransitionType::PUSHWIPE;
326  break;
327  case PPT_TOKEN( wipe ):
328  mnTransitionType = TransitionType::BARWIPE;
331  break;
332  case PPT_TOKEN( split ):
333  mnTransitionType = TransitionType::BARNDOORWIPE;
335  if( param2 == XML_in )
336  {
337  // reverse
339  }
340  break;
341  case PPT_TOKEN( wheel ):
342  mnTransitionType = TransitionType::PINWHEELWIPE;
343  switch( param1 )
344  {
345  case 1:
346  mnTransitionSubType = TransitionSubType::ONEBLADE;
347  break;
348  case 2:
349  mnTransitionSubType = TransitionSubType::TWOBLADEVERTICAL;
350  break;
351  case 3:
352  mnTransitionSubType = TransitionSubType::THREEBLADE;
353  break;
354  case 4:
355  mnTransitionSubType = TransitionSubType::FOURBLADE;
356  break;
357  case 8:
358  mnTransitionSubType = TransitionSubType::EIGHTBLADE;
359  break;
360  default:
361  SAL_INFO(
362  "oox.ppt",
363  "strange number of blades for the wheel-wipe " << param1);
364  if( param1 > 8 )
365  {
366  mnTransitionSubType = TransitionSubType::EIGHTBLADE;
367  }
368  else if( param1 > 4 )
369  {
370  mnTransitionSubType = TransitionSubType::FOURBLADE;
371  }
372  else if( param1 == 0)
373  {
374  mnTransitionSubType = TransitionSubType::ONEBLADE;
375  }
376  break;
377  }
378  break;
379  case PPT_TOKEN( randomBar ):
380  mnTransitionType = TransitionType::RANDOMBARWIPE;
382  break;
383  case PPT_TOKEN( circle ):
384  mnTransitionType = TransitionType::ELLIPSEWIPE;
385  mnTransitionSubType = TransitionSubType::CIRCLE;
386  break;
387  case PPT_TOKEN( diamond ):
388  mnTransitionType = TransitionType::IRISWIPE;
389  mnTransitionSubType = TransitionSubType::DIAMOND;
390  break;
391  case PPT_TOKEN( dissolve ):
392  mnTransitionType = TransitionType::DISSOLVE;
393  mnTransitionSubType = TransitionSubType::DEFAULT;
394  break;
395  case PPT_TOKEN( newsflash ):
396  mnTransitionType = TransitionType::ZOOM;
397  mnTransitionSubType = TransitionSubType::ROTATEIN;
398  break;
399  case PPT_TOKEN( plus ):
400  mnTransitionType = TransitionType::FOURBOXWIPE;
401  mnTransitionSubType = TransitionSubType::CORNERSOUT;
402  break;
403  case PPT_TOKEN( random ):
404  mnTransitionType = TransitionType::RANDOM;
405  mnTransitionSubType = TransitionSubType::DEFAULT;
406  break;
407  case PPT_TOKEN( wedge ):
408  mnTransitionType = TransitionType::FANWIPE;
409  mnTransitionSubType = TransitionSubType::CENTERTOP;
410  break;
411  case PPT_TOKEN( zoom ):
412  mnTransitionType = TransitionType::ZOOM;
413  mnTransitionSubType = TransitionSubType::DEFAULT;
414  break;
415  case P14_TOKEN(prism):
416  mnTransitionType = TransitionType::MISCSHAPEWIPE;
417  if (param1)
418  mnTransitionSubType = TransitionSubType::CORNERSIN;
419  else
420  mnTransitionSubType = TransitionSubType::CORNERSOUT;
421  break;
422  case P14_TOKEN(vortex):
423  mnTransitionType = TransitionType::MISCSHAPEWIPE;
424  mnTransitionSubType = TransitionSubType::VERTICAL;
425  break;
426  case P14_TOKEN(ripple):
427  mnTransitionType = TransitionType::MISCSHAPEWIPE;
428  mnTransitionSubType = TransitionSubType::HORIZONTAL;
429  break;
430  case P14_TOKEN(glitter):
431  mnTransitionType = TransitionType::MISCSHAPEWIPE;
432  mnTransitionSubType = TransitionSubType::DIAMOND;
433  break;
434  case P14_TOKEN(honeycomb):
435  mnTransitionType = TransitionType::MISCSHAPEWIPE;
436  mnTransitionSubType = TransitionSubType::HEART;
437  break;
438  case P14_TOKEN(flash):
439  mnTransitionType = TransitionType::FADE;
440  mnTransitionSubType = TransitionSubType::FADEOVERCOLOR;
441  mnTransitionFadeColor = static_cast<sal_Int32>(COL_WHITE);
442  break;
443  case PPT_TOKEN(strips):
444  mnTransitionType = TransitionType::SLIDEWIPE;
446  break;
447  default:
448  mnTransitionType = 0;
449  break;
450  }
451  }
452 
453  void SlideTransition::setPresetTransition(std::u16string_view sPresetTransition)
454  {
455  if (sPresetTransition == u"fallOver")
456  {
457  mnTransitionType = TransitionType::MISCSHAPEWIPE;
458  mnTransitionSubType = TransitionSubType::LEFTTORIGHT;
459  }
460  else
461  {
462  mnTransitionType = 0;
463  }
464  }
465 
466 }
467 
468 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
A helper that maps property identifiers to property values.
Definition: propertymap.hxx:52
static sal_Int16 ooxToOdpDirection(::sal_Int32 nOoxType)
void setSlideProperties(PropertyMap &props)
void setTransitionFilterProperties(const css::uno::Reference< css::animations::XTransitionFilter > &xFilter)
static sal_Int16 ooxToOdpSideDirections(::sal_Int32 nOoxType)
void setOoxTransitionType(::sal_Int32 OoxType,::sal_Int32 param1,::sal_Int32 param2)
sal_Int16 mnTransitionType
bool setProperty(sal_Int32 nPropId, Type &&rValue)
Sets the specified property to the passed value.
Definition: propertymap.hxx:70
static bool ooxToOdpSideDirectionsDirectionNormal(::sal_Int32 nOoxType)
std::vector< OUString > split(const OUString &rStr, sal_Unicode cSeparator)
bool mbMode
https://api.libreoffice.org/docs/common/ref/com/sun/star/animations/XTransitionFilter.html Mode property
static sal_Int16 ooxToOdpCornerDirections(::sal_Int32 nOoxType)
void setOoxTransitionSpeed(sal_Int32 nToken)
Set one of standard values for slide transition duration.
static sal_Int16 ooxToOdpEightDirections(::sal_Int32 nOoxType)
#define TOOLS_WARN_EXCEPTION(area, stream)
RGBColor mnTransitionFadeColor
float u
static const transition * find(const OUString &rName)
bool mbMode
sal_Int16 mnTransitionSubType
const ::std::vector< Color > ImpSvNumberformatScan::StandardColor COL_WHITE
#define SAL_INFO(area, stream)
void setPresetTransition(std::u16string_view sPresetTransition)
void * p
#define SAL_WARN(area, stream)
static sal_Int16 ooxToOdpBorderDirections(::sal_Int32 nOoxType)
css::presentation::AnimationSpeed mnAnimationSpeed