22#include <rtl/math.hxx>
26#include <com/sun/star/animations/AnimationTransformType.hpp>
27#include <com/sun/star/animations/AnimationCalcMode.hpp>
28#include <com/sun/star/animations/AnimationColorSpace.hpp>
29#include <com/sun/star/animations/AnimationNodeType.hpp>
30#include <com/sun/star/animations/ValuePair.hpp>
31#include <com/sun/star/presentation/EffectCommands.hpp>
32#include <com/sun/star/beans/NamedValue.hpp>
39#include <oox/token/namespaces.hxx>
40#include <oox/token/tokens.hxx>
60using ::com::sun::star::beans::NamedValue;
90 css::uno::Any convertPointPercent(
const css::awt::Point& rPoint)
92 css::animations::ValuePair aPair;
94 aPair.First <<=
static_cast<double>(rPoint.X) / 100000.0;
95 aPair.Second <<=
static_cast<double>(rPoint.Y) / 100000.0;
106 AnimColor(sal_Int16 cs, sal_Int32 o, sal_Int32 t, sal_Int32 th )
118 case AnimationColorSpace::HSL:
119 aColor <<= Sequence< double >{
one / 100000.0,
two / 100000.0,
three / 100000.0 };
121 case AnimationColorSpace::RGB:
122 nColor = ( ( (
one * 128 ) / 1000 ) & 0xff ) << 16
123 | ( ( (
two * 128 ) / 1000 ) & 0xff ) << 8
124 | ( ( (
three * 128 ) / 1000 ) & 0xff );
143 class MediaNodeContext
144 :
public TimeNodeContext
147 MediaNodeContext( FragmentHandler2
const & rParent, sal_Int32 aElement,
148 const Reference< XFastAttributeList >& xAttribs,
150 : TimeNodeContext( rParent, aElement, pNode )
155 AttributeList attribs( xAttribs );
159 case PPT_TOKEN( audio ):
162 case PPT_TOKEN( video ):
163 mbFullScrn = attribs.getBool( XML_fullScrn,
false );
170 virtual void onEndElement()
override
172 sal_Int32 aElement = getCurrentElement();
173 if( aElement == PPT_TOKEN( audio ) )
177 else if( aElement == PPT_TOKEN( video ) )
181 else if (aElement == PPT_TOKEN(cMediaNode))
189 switch ( aElementToken )
191 case PPT_TOKEN( cTn ):
192 return new CommonTimeNodeContext( *this, aElementToken, rAttribs.getFastAttributeList(),
mpNode );
193 case PPT_TOKEN( tgtEl ):
194 return new TimeTargetElementContext( *this,
mpNode->getTarget() );
195 case PPT_TOKEN(cMediaNode):
213 class SetTimeNodeContext
214 :
public TimeNodeContext
217 SetTimeNodeContext( FragmentHandler2
const & rParent, sal_Int32 aElement,
219 : TimeNodeContext( rParent, aElement, pNode )
224 virtual ~SetTimeNodeContext() noexcept
override
228 convertAnimationValueWithTimeNode(
mpNode,
maTo);
236 switch ( aElementToken )
238 case PPT_TOKEN( cBhvr ):
239 return new CommonBehaviorContext ( *this,
mpNode );
240 case PPT_TOKEN( to ):
242 return new AnimVariantContext( *this, aElementToken,
maTo );
255 class CmdTimeNodeContext
256 :
public TimeNodeContext
259 CmdTimeNodeContext( FragmentHandler2
const & rParent, sal_Int32 aElement,
260 const Reference< XFastAttributeList >& xAttribs,
262 : TimeNodeContext( rParent, aElement, pNode )
267 case PPT_TOKEN( cmd ):
268 msCommand = xAttribs->getOptionalValue( XML_cmd );
276 virtual void onEndElement()
override
278 if( !isCurrentElement( PPT_TOKEN( cmd ) ) )
286 sal_Int16 nCommand = EffectCommands::CUSTOM;
287 NamedValue aParamValue;
292 aParamValue.Name =
"Verb";
294 aParamValue.Value <<=
msCommand.toInt32();
295 nCommand = EffectCommands::VERB;
301 nCommand = EffectCommands::STOPAUDIO;
305 nCommand = EffectCommands::PLAY;
307 else if (
msCommand.startsWith(
"playFrom"))
310 rtl_math_ConversionStatus eStatus;
311 double fMediaTime = ::rtl::math::stringToDouble( aMediaTime, u
'.', u
',', &eStatus );
312 if( eStatus == rtl_math_ConversionStatus_Ok )
314 aParamValue.Name =
"MediaTime";
315 aParamValue.Value <<= fMediaTime;
317 nCommand = EffectCommands::PLAY;
321 nCommand = EffectCommands::TOGGLEPAUSE;
325 nCommand = EffectCommands::STOP;
330 if( nCommand == EffectCommands::CUSTOM )
332 SAL_WARN(
"oox.ppt",
"OOX: CmdTimeNodeContext::endFastElement(), unknown command!");
333 aParamValue.Name =
"UserDefined";
336 if( aParamValue.Value.hasValue() )
338 Sequence< NamedValue > aParamSeq( &aParamValue, 1 );
350 switch ( aElementToken )
352 case PPT_TOKEN( cBhvr ):
353 return new CommonBehaviorContext ( *this,
mpNode );
368 class SequenceTimeNodeContext
369 :
public TimeNodeContext
372 SequenceTimeNodeContext( FragmentHandler2
const & rParent, sal_Int32 aElement,
373 const Reference< XFastAttributeList >& xAttribs,
375 : TimeNodeContext( rParent, aElement, pNode )
379 AttributeList attribs(xAttribs);
380 mbConcurrent = attribs.getBool( XML_concurrent,
false );
381 mnNextAc = xAttribs->getOptionalValueToken( XML_nextAc, 0 );
382 mnPrevAc = xAttribs->getOptionalValueToken( XML_prevAc, 0 );
387 switch ( aElementToken )
389 case PPT_TOKEN( cTn ):
390 return new CommonTimeNodeContext( *this, aElementToken, rAttribs.getFastAttributeList(),
mpNode );
391 case PPT_TOKEN( nextCondLst ):
392 return new CondListContext( *this, aElementToken,
mpNode,
mpNode->getNextCondition() );
393 case PPT_TOKEN( prevCondLst ):
394 return new CondListContext( *this, aElementToken,
mpNode,
mpNode->getPrevCondition() );
409 class ParallelExclTimeNodeContext
410 :
public TimeNodeContext
413 ParallelExclTimeNodeContext( FragmentHandler2
const & rParent, sal_Int32 aElement,
415 : TimeNodeContext( rParent, aElement, pNode )
421 switch ( aElementToken )
423 case PPT_TOKEN( cTn ):
424 return new CommonTimeNodeContext( *this, aElementToken, rAttribs.getFastAttributeList(),
mpNode );
437 class AnimColorContext
438 :
public TimeNodeContext
441 AnimColorContext( FragmentHandler2
const & rParent, sal_Int32 aElement,
442 const Reference< XFastAttributeList >& xAttribs,
444 : TimeNodeContext( rParent, aElement, pNode )
445 ,
mnColorSpace( xAttribs->getOptionalValueToken( XML_clrSpc, 0 ) )
446 ,
mnDir( xAttribs->getOptionalValueToken( XML_dir, 0 ) )
448 ,
m_byColor( AnimationColorSpace::RGB, 0, 0, 0)
452 virtual void onEndElement()
override
455 if( !isCurrentElement( mnElement ) )
461 const GraphicHelper& rGraphicHelper = getFilter().getGraphicHelper();
472 switch ( aElementToken )
474 case PPT_TOKEN( hsl ):
479 m_byColor.colorSpace = AnimationColorSpace::HSL;
480 m_byColor.one = rAttribs.getInteger( XML_h, 0 );
481 m_byColor.two = rAttribs.getInteger( XML_s, 0 );
482 m_byColor.three = rAttribs.getInteger( XML_l, 0 );
486 case PPT_TOKEN( rgb ):
491 m_byColor.colorSpace = AnimationColorSpace::RGB;
492 m_byColor.one = rAttribs.getInteger( XML_r, 0 );
493 m_byColor.two = rAttribs.getInteger( XML_g, 0 );
494 m_byColor.three = rAttribs.getInteger( XML_b, 0 );
498 case PPT_TOKEN( by ):
502 case PPT_TOKEN( cBhvr ):
503 return new CommonBehaviorContext ( *this,
mpNode );
504 case PPT_TOKEN( to ):
506 return new ColorContext( *this,
maToClr );
507 case PPT_TOKEN( from ):
509 return new ColorContext( *this,
maFromClr );
529 :
public TimeNodeContext
532 AnimContext( FragmentHandler2
const & rParent, sal_Int32 aElement,
533 const Reference< XFastAttributeList >& xAttribs,
535 : TimeNodeContext( rParent, aElement, pNode )
538 sal_Int32 nCalcMode = xAttribs->getOptionalValueToken( XML_calcmode, 0 );
545 nEnum = AnimationCalcMode::DISCRETE;
548 nEnum = AnimationCalcMode::LINEAR;
553 nEnum = AnimationCalcMode::DISCRETE;
559 msFrom = xAttribs->getOptionalValue(XML_from);
560 msTo = xAttribs->getOptionalValue(XML_to);
561 msBy = xAttribs->getOptionalValue(XML_by);
563 mnValueType = xAttribs->getOptionalValueToken( XML_valueType, 0 );
566 virtual ~AnimContext() noexcept
override
572 convertAnimationValueWithTimeNode(
mpNode, aAny);
580 convertAnimationValueWithTimeNode(
mpNode, aAny);
588 convertAnimationValueWithTimeNode(
mpNode, aAny);
597 Sequence< double > aKeyTimes( nKeyTimes );
598 auto pKeyTimes = aKeyTimes.getArray();
599 Sequence< Any > aValues( nKeyTimes );
600 auto pValues = aValues.getArray();
607 aTime >>= pKeyTimes[
i];
609 convertAnimationValueWithTimeNode(
mpNode, pValues[
i]);
613 if (!tav.msFormula.isEmpty())
628 switch ( aElementToken )
630 case PPT_TOKEN( cBhvr ):
631 return new CommonBehaviorContext ( *this,
mpNode );
632 case PPT_TOKEN( tavLst ):
633 return new TimeAnimValueListContext ( *this,
maTavList );
649 class AnimScaleContext
650 :
public TimeNodeContext
653 AnimScaleContext( FragmentHandler2
const & rParent, sal_Int32 aElement,
654 const Reference< XFastAttributeList >& xAttribs,
656 : TimeNodeContext( rParent, aElement, pNode )
659 AttributeList attribs( xAttribs );
663 <<= sal_Int16(AnimationTransformType::SCALE);
666 virtual void onEndElement()
override
668 if( !isCurrentElement( mnElement ) )
671 if(
maTo.hasValue() )
675 if(
maBy.hasValue() )
687 switch ( aElementToken )
689 case PPT_TOKEN( cBhvr ):
690 return new CommonBehaviorContext ( *this,
mpNode );
691 case PPT_TOKEN( to ):
697 case PPT_TOKEN( from ):
703 case PPT_TOKEN( by ):
706 css::awt::Point aPoint =
GetPointPercent(rAttribs.getFastAttributeList());
710 maBy = convertPointPercent(aPoint);
728 :
public TimeNodeContext
731 AnimRotContext( FragmentHandler2
const & rParent, sal_Int32 aElement,
732 const Reference< XFastAttributeList >& xAttribs,
734 : TimeNodeContext( rParent, aElement, pNode )
736 AttributeList attribs( xAttribs );
739 <<= sal_Int16(AnimationTransformType::ROTATE);
742 if(attribs.hasAttribute( XML_by ) )
744 double fBy = attribs.getDouble( XML_by, 0.0 ) /
PER_DEGREE;
745 pNode->setBy(
Any( fBy ) );
747 if(attribs.hasAttribute( XML_from ) )
749 double fFrom = attribs.getDouble( XML_from, 0.0 ) /
PER_DEGREE;
750 pNode->setFrom(
Any( fFrom ) );
752 if(attribs.hasAttribute( XML_to ) )
754 double fTo = attribs.getDouble( XML_to, 0.0 ) /
PER_DEGREE;
755 pNode->setTo(
Any( fTo ) );
761 switch ( aElementToken )
763 case PPT_TOKEN( cBhvr ):
764 return new CommonBehaviorContext ( *this,
mpNode );
774 class AnimMotionContext
775 :
public TimeNodeContext
778 AnimMotionContext( FragmentHandler2
const & rParent, sal_Int32 aElement,
779 const Reference< XFastAttributeList >& xAttribs,
781 : TimeNodeContext( rParent, aElement, pNode )
784 <<= sal_Int16(AnimationTransformType::TRANSLATE);
786 AttributeList attribs( xAttribs );
787 sal_Int32 nOrigin = xAttribs->getOptionalValueToken( XML_origin, 0 );
799 OUString
aStr = xAttribs->getOptionalValue( XML_path );
802 if (
aStr.endsWith(
"E"))
806 mnPathEditMode = xAttribs->getOptionalValueToken( XML_pathEditMode, 0 );
807 msPtsTypes = xAttribs->getOptionalValue( XML_ptsTypes );
808 mnAngle = attribs.getInteger( XML_rAng, 0 );
814 switch ( aElementToken )
816 case PPT_TOKEN( cBhvr ):
817 return new CommonBehaviorContext ( *this,
mpNode );
818 case PPT_TOKEN( to ):
828 case PPT_TOKEN( from ):
838 case PPT_TOKEN( by ):
848 case PPT_TOKEN( rCtr ):
869 class AnimEffectContext
870 :
public TimeNodeContext
873 AnimEffectContext( FragmentHandler2
const & rParent, sal_Int32 aElement,
874 const Reference< XFastAttributeList >& xAttribs,
876 : TimeNodeContext( rParent, aElement, pNode )
878 sal_Int32 nDir = xAttribs->getOptionalValueToken( XML_transition, 0 );
879 OUString sFilter = xAttribs->getOptionalValue( XML_filter );
883 if( !sFilter.isEmpty() )
885 SlideTransition aFilter( sFilter );
886 aFilter.setMode( nDir != XML_out );
887 pNode->setTransitionFilter( aFilter );
893 switch ( aElementToken )
895 case PPT_TOKEN( cBhvr ):
896 return new CommonBehaviorContext ( *this,
mpNode );
897 case PPT_TOKEN( progress ):
898 return new AnimVariantContext( *this, aElementToken,
maProgress );
913 FragmentHandler2
const & rParent, sal_Int32 aElement,
914 const Reference< XFastAttributeList >& xAttribs,
920 case PPT_TOKEN( animClr ):
921 pCtx =
new AnimColorContext( rParent, aElement, xAttribs, pNode );
923 case PPT_TOKEN( par ):
924 pCtx =
new ParallelExclTimeNodeContext( rParent, aElement, pNode );
926 case PPT_TOKEN( seq ):
927 pCtx =
new SequenceTimeNodeContext( rParent, aElement, xAttribs, pNode );
929 case PPT_TOKEN( excl ):
930 pCtx =
new ParallelExclTimeNodeContext( rParent, aElement, pNode );
932 case PPT_TOKEN(
anim ):
933 pCtx =
new AnimContext ( rParent, aElement, xAttribs, pNode );
935 case PPT_TOKEN( animEffect ):
936 pCtx =
new AnimEffectContext( rParent, aElement, xAttribs, pNode );
938 case PPT_TOKEN( animMotion ):
939 pCtx =
new AnimMotionContext( rParent, aElement, xAttribs, pNode );
941 case PPT_TOKEN( animRot ):
942 pCtx =
new AnimRotContext( rParent, aElement, xAttribs, pNode );
944 case PPT_TOKEN( animScale ):
945 pCtx =
new AnimScaleContext( rParent, aElement, xAttribs, pNode );
947 case PPT_TOKEN( cmd ):
948 pCtx =
new CmdTimeNodeContext( rParent, aElement, xAttribs, pNode );
950 case PPT_TOKEN(
set ):
951 pCtx =
new SetTimeNodeContext( rParent, aElement, pNode );
953 case PPT_TOKEN( audio ):
954 case PPT_TOKEN( video ):
955 pCtx =
new MediaNodeContext( rParent, aElement, xAttribs, pNode );
965 : FragmentHandler2( rParent )
966 , mnElement( aElement )
967 ,
mpNode(std::move( pNode ))
978 : FragmentHandler2( rParent )
991 switch( aElementToken )
993 case PPT_TOKEN( par ):
994 nNodeType = AnimationNodeType::PAR;
996 case PPT_TOKEN( seq ):
997 nNodeType = AnimationNodeType::SEQ;
999 case PPT_TOKEN( excl ):
1002 nNodeType = AnimationNodeType::PAR;
1004 case PPT_TOKEN(
anim ):
1005 nNodeType = AnimationNodeType::ANIMATE;
1007 case PPT_TOKEN( animClr ):
1008 nNodeType = AnimationNodeType::ANIMATECOLOR;
1010 case PPT_TOKEN( animEffect ):
1011 nNodeType = AnimationNodeType::TRANSITIONFILTER;
1013 case PPT_TOKEN( animMotion ):
1014 nNodeType = AnimationNodeType::ANIMATEMOTION;
1016 case PPT_TOKEN( animRot ):
1017 case PPT_TOKEN( animScale ):
1018 nNodeType = AnimationNodeType::ANIMATETRANSFORM;
1020 case PPT_TOKEN( cmd ):
1021 nNodeType = AnimationNodeType::COMMAND;
1023 case PPT_TOKEN(
set ):
1024 nNodeType = AnimationNodeType::SET;
1026 case PPT_TOKEN( audio ):
1027 nNodeType = AnimationNodeType::AUDIO;
1029 case PPT_TOKEN( video ):
1030 nNodeType = AnimationNodeType::AUDIO;
1031 SAL_WARN(
"oox.ppt",
"OOX: video requested, gave Audio instead" );
1035 nNodeType = AnimationNodeType::CUSTOM;
1036 SAL_INFO(
"oox.ppt",
"unhandled token " << aElementToken);
1040 TimeNodePtr pNode = std::make_shared<TimeNode>(nNodeType);
1041 maList.push_back( pNode );
1044 return pContext ? pContext :
this;
const PropertyValue * pValues
Provides access to attribute values of an element.
const css::uno::Reference< css::xml::sax::XFastAttributeList > & getFastAttributeList() const
Returns the wrapped com.sun.star.xml.sax.XFastAttributeList object.
bool isUsed() const
Returns true, if the color is initialized.
::Color getColor(const GraphicHelper &rGraphicHelper, ::Color nPhClr=API_RGB_TRANSPARENT) const
Returns the final RGB color value.
TimeNodeContext(::oox::core::FragmentHandler2 const &rParent, sal_Int32 aElement, TimeNodePtr pNode) noexcept
static rtl::Reference< TimeNodeContext > makeContext(::oox::core::FragmentHandler2 const &rParent, sal_Int32 aElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttribs, const TimeNodePtr &pNode)
virtual ~TimeNodeContext() noexcept override
virtual ::oox::core::ContextHandlerRef onCreateContext(sal_Int32 aElementToken, const AttributeList &rAttribs) override
TimeNodeListContext(::oox::core::FragmentHandler2 const &rParent, TimeNodePtrList &aList) noexcept
virtual ~TimeNodeListContext() noexcept override
#define TOOLS_WARN_EXCEPTION(area, stream)
#define SAL_WARN(area, stream)
#define SAL_INFO(area, stream)
void set(css::uno::UnoInterfaceReference const &value)
std::basic_string_view< charT, traits > getToken(std::basic_string_view< charT, traits > sv, charT delimiter, std::size_t &position)
bool equalsAscii(std::u16string_view s1, std::string_view s2)
::rtl::Reference< ContextHandler > ContextHandlerRef
awt::Point GetPointPercent(const Reference< XFastAttributeList > &xAttribs)
converts the attributes from a CT_TLPoint into an awt Point with 1/1000%
const sal_Int32 PER_DEGREE
std::shared_ptr< TimeNode > TimeNodePtr
bool convertMeasure(OUString &rString)
convert the measure string to LibreOffice format.
const ImplAttributeNameConversion * getAttributeConversionList()
::std::vector< TimeAnimationValue > TimeAnimationValueList
bool convertAnimationValue(AnimationAttributeEnum eAttribute, css::uno::Any &rValue)
convert attribute values of the animation target so that LibreOffice understand.
Any GetTimeAnimateValueTime(const OUString &val)
std::vector< TimeNodePtr > TimeNodePtrList
std::array< css::uno::Any, NP_SIZE_ > NodePropertyMap
css::uno::Reference< css::linguistic2::XProofreadingIterator > get(css::uno::Reference< css::uno::XComponentContext > const &context)
AnimationAttributeEnum meAttribute
oox::drawingml::Color maFromClr
oox::drawingml::Color maToClr
TimeAnimationValueList maTavList