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