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>
59 using ::com::sun::star::beans::NamedValue;
89 css::uno::Any convertPointPercent(
const css::awt::Point& rPoint)
91 css::animations::ValuePair aPair;
93 aPair.First <<=
static_cast<double>(rPoint.X) / 100000.0;
94 aPair.Second <<=
static_cast<double>(rPoint.Y) / 100000.0;
105 AnimColor(sal_Int16 cs, sal_Int32 o, sal_Int32 t, sal_Int32 th )
117 case AnimationColorSpace::HSL:
118 aColor <<= Sequence< double >{
one / 100000.0,
two / 100000.0,
three / 100000.0 };
120 case AnimationColorSpace::RGB:
121 nColor = ( ( (
one * 128 ) / 1000 ) & 0xff ) << 16
122 | ( ( (
two * 128 ) / 1000 ) & 0xff ) << 8
123 | ( ( (
three * 128 ) / 1000 ) & 0xff );
142 class MediaNodeContext
143 :
public TimeNodeContext
146 MediaNodeContext( FragmentHandler2
const & rParent, sal_Int32 aElement,
147 const Reference< XFastAttributeList >& xAttribs,
149 : TimeNodeContext( rParent, aElement, pNode )
154 AttributeList attribs( xAttribs );
158 case PPT_TOKEN( audio ):
161 case PPT_TOKEN( video ):
162 mbFullScrn = attribs.getBool( XML_fullScrn,
false );
169 virtual void onEndElement()
override
171 sal_Int32 aElement = getCurrentElement();
172 if( aElement == PPT_TOKEN( audio ) )
176 else if( aElement == PPT_TOKEN( video ) )
180 else if (aElement == PPT_TOKEN(cMediaNode))
188 switch ( aElementToken )
190 case PPT_TOKEN( cTn ):
191 return new CommonTimeNodeContext( *this, aElementToken, rAttribs.getFastAttributeList(),
mpNode );
192 case PPT_TOKEN( tgtEl ):
193 return new TimeTargetElementContext( *this,
mpNode->getTarget() );
194 case PPT_TOKEN(cMediaNode):
212 class SetTimeNodeContext
213 :
public TimeNodeContext
216 SetTimeNodeContext( FragmentHandler2
const & rParent, sal_Int32 aElement,
218 : TimeNodeContext( rParent, aElement, pNode )
223 virtual ~SetTimeNodeContext() noexcept
override
227 convertAnimationValueWithTimeNode(
mpNode,
maTo);
235 switch ( aElementToken )
237 case PPT_TOKEN( cBhvr ):
238 return new CommonBehaviorContext ( *this,
mpNode );
239 case PPT_TOKEN( to ):
241 return new AnimVariantContext( *this, aElementToken,
maTo );
254 class CmdTimeNodeContext
255 :
public TimeNodeContext
258 CmdTimeNodeContext( FragmentHandler2
const & rParent, sal_Int32 aElement,
259 const Reference< XFastAttributeList >& xAttribs,
261 : TimeNodeContext( rParent, aElement, pNode )
266 case PPT_TOKEN( cmd ):
267 msCommand = xAttribs->getOptionalValue( XML_cmd );
275 virtual void onEndElement()
override
277 if( !isCurrentElement( PPT_TOKEN( cmd ) ) )
285 sal_Int16 nCommand = EffectCommands::CUSTOM;
286 NamedValue aParamValue;
291 aParamValue.Name =
"Verb";
293 aParamValue.Value <<=
msCommand.toInt32();
294 nCommand = EffectCommands::VERB;
300 nCommand = EffectCommands::STOPAUDIO;
304 nCommand = EffectCommands::PLAY;
306 else if (
msCommand.startsWith(
"playFrom"))
309 rtl_math_ConversionStatus eStatus;
310 double fMediaTime = ::rtl::math::stringToDouble( aMediaTime, u
'.', u
',', &eStatus );
311 if( eStatus == rtl_math_ConversionStatus_Ok )
313 aParamValue.Name =
"MediaTime";
314 aParamValue.Value <<= fMediaTime;
316 nCommand = EffectCommands::PLAY;
320 nCommand = EffectCommands::TOGGLEPAUSE;
324 nCommand = EffectCommands::STOP;
329 if( nCommand == EffectCommands::CUSTOM )
331 SAL_WARN(
"oox.ppt",
"OOX: CmdTimeNodeContext::endFastElement(), unknown command!");
332 aParamValue.Name =
"UserDefined";
335 if( aParamValue.Value.hasValue() )
337 Sequence< NamedValue > aParamSeq( &aParamValue, 1 );
349 switch ( aElementToken )
351 case PPT_TOKEN( cBhvr ):
352 return new CommonBehaviorContext ( *this,
mpNode );
367 class SequenceTimeNodeContext
368 :
public TimeNodeContext
371 SequenceTimeNodeContext( FragmentHandler2
const & rParent, sal_Int32 aElement,
372 const Reference< XFastAttributeList >& xAttribs,
374 : TimeNodeContext( rParent, aElement, pNode )
378 AttributeList attribs(xAttribs);
379 mbConcurrent = attribs.getBool( XML_concurrent,
false );
380 mnNextAc = xAttribs->getOptionalValueToken( XML_nextAc, 0 );
381 mnPrevAc = xAttribs->getOptionalValueToken( XML_prevAc, 0 );
386 switch ( aElementToken )
388 case PPT_TOKEN( cTn ):
389 return new CommonTimeNodeContext( *this, aElementToken, rAttribs.getFastAttributeList(),
mpNode );
390 case PPT_TOKEN( nextCondLst ):
391 return new CondListContext( *this, aElementToken,
mpNode,
mpNode->getNextCondition() );
392 case PPT_TOKEN( prevCondLst ):
393 return new CondListContext( *this, aElementToken,
mpNode,
mpNode->getPrevCondition() );
408 class ParallelExclTimeNodeContext
409 :
public TimeNodeContext
412 ParallelExclTimeNodeContext( FragmentHandler2
const & rParent, sal_Int32 aElement,
414 : TimeNodeContext( rParent, aElement, pNode )
420 switch ( aElementToken )
422 case PPT_TOKEN( cTn ):
423 return new CommonTimeNodeContext( *this, aElementToken, rAttribs.getFastAttributeList(),
mpNode );
436 class AnimColorContext
437 :
public TimeNodeContext
440 AnimColorContext( FragmentHandler2
const & rParent, sal_Int32 aElement,
441 const Reference< XFastAttributeList >& xAttribs,
443 : TimeNodeContext( rParent, aElement, pNode )
444 ,
mnColorSpace( xAttribs->getOptionalValueToken( XML_clrSpc, 0 ) )
445 ,
mnDir( xAttribs->getOptionalValueToken( XML_dir, 0 ) )
447 ,
m_byColor( AnimationColorSpace::RGB, 0, 0, 0)
451 virtual void onEndElement()
override
454 if( !isCurrentElement( mnElement ) )
460 const GraphicHelper& rGraphicHelper = getFilter().getGraphicHelper();
471 switch ( aElementToken )
473 case PPT_TOKEN( hsl ):
478 m_byColor.colorSpace = AnimationColorSpace::HSL;
479 m_byColor.one = rAttribs.getInteger( XML_h, 0 );
480 m_byColor.two = rAttribs.getInteger( XML_s, 0 );
481 m_byColor.three = rAttribs.getInteger( XML_l, 0 );
485 case PPT_TOKEN( rgb ):
490 m_byColor.colorSpace = AnimationColorSpace::RGB;
491 m_byColor.one = rAttribs.getInteger( XML_r, 0 );
492 m_byColor.two = rAttribs.getInteger( XML_g, 0 );
493 m_byColor.three = rAttribs.getInteger( XML_b, 0 );
497 case PPT_TOKEN( by ):
501 case PPT_TOKEN( cBhvr ):
502 return new CommonBehaviorContext ( *this,
mpNode );
503 case PPT_TOKEN( to ):
505 return new ColorContext( *this,
maToClr );
506 case PPT_TOKEN( from ):
508 return new ColorContext( *this,
maFromClr );
528 :
public TimeNodeContext
531 AnimContext( FragmentHandler2
const & rParent, sal_Int32 aElement,
532 const Reference< XFastAttributeList >& xAttribs,
534 : TimeNodeContext( rParent, aElement, pNode )
537 sal_Int32 nCalcMode = xAttribs->getOptionalValueToken( XML_calcmode, 0 );
544 nEnum = AnimationCalcMode::DISCRETE;
547 nEnum = AnimationCalcMode::LINEAR;
552 nEnum = AnimationCalcMode::DISCRETE;
558 msFrom = xAttribs->getOptionalValue(XML_from);
559 msTo = xAttribs->getOptionalValue(XML_to);
560 msBy = xAttribs->getOptionalValue(XML_by);
562 mnValueType = xAttribs->getOptionalValueToken( XML_valueType, 0 );
565 virtual ~AnimContext() noexcept
override
571 convertAnimationValueWithTimeNode(
mpNode, aAny);
579 convertAnimationValueWithTimeNode(
mpNode, aAny);
587 convertAnimationValueWithTimeNode(
mpNode, aAny);
596 Sequence< double > aKeyTimes( nKeyTimes );
597 auto pKeyTimes = aKeyTimes.getArray();
598 Sequence< Any > aValues( nKeyTimes );
599 auto pValues = aValues.getArray();
606 aTime >>= pKeyTimes[
i];
608 convertAnimationValueWithTimeNode(
mpNode, pValues[i]);
612 if (!tav.msFormula.isEmpty())
627 switch ( aElementToken )
629 case PPT_TOKEN( cBhvr ):
630 return new CommonBehaviorContext ( *this,
mpNode );
631 case PPT_TOKEN( tavLst ):
632 return new TimeAnimValueListContext ( *this, maTavList );
648 class AnimScaleContext
649 :
public TimeNodeContext
652 AnimScaleContext( FragmentHandler2
const & rParent, sal_Int32 aElement,
653 const Reference< XFastAttributeList >& xAttribs,
655 : TimeNodeContext( rParent, aElement, pNode )
658 AttributeList attribs( xAttribs );
662 <<= sal_Int16(AnimationTransformType::SCALE);
665 virtual void onEndElement()
override
667 if( !isCurrentElement( mnElement ) )
670 if(
maTo.hasValue() )
674 if(
maBy.hasValue() )
686 switch ( aElementToken )
688 case PPT_TOKEN( cBhvr ):
689 return new CommonBehaviorContext ( *this,
mpNode );
690 case PPT_TOKEN( to ):
696 case PPT_TOKEN( from ):
702 case PPT_TOKEN( by ):
705 css::awt::Point aPoint =
GetPointPercent(rAttribs.getFastAttributeList());
709 maBy = convertPointPercent(aPoint);
727 :
public TimeNodeContext
730 AnimRotContext( FragmentHandler2
const & rParent, sal_Int32 aElement,
731 const Reference< XFastAttributeList >& xAttribs,
733 : TimeNodeContext( rParent, aElement, pNode )
735 AttributeList attribs( xAttribs );
738 <<= sal_Int16(AnimationTransformType::ROTATE);
741 if(attribs.hasAttribute( XML_by ) )
743 double fBy = attribs.getDouble( XML_by, 0.0 ) /
PER_DEGREE;
744 pNode->setBy(
Any( fBy ) );
746 if(attribs.hasAttribute( XML_from ) )
748 double fFrom = attribs.getDouble( XML_from, 0.0 ) /
PER_DEGREE;
749 pNode->setFrom(
Any( fFrom ) );
751 if(attribs.hasAttribute( XML_to ) )
753 double fTo = attribs.getDouble( XML_to, 0.0 ) /
PER_DEGREE;
754 pNode->setTo(
Any( fTo ) );
760 switch ( aElementToken )
762 case PPT_TOKEN( cBhvr ):
763 return new CommonBehaviorContext ( *this,
mpNode );
773 class AnimMotionContext
774 :
public TimeNodeContext
777 AnimMotionContext( FragmentHandler2
const & rParent, sal_Int32 aElement,
778 const Reference< XFastAttributeList >& xAttribs,
780 : TimeNodeContext( rParent, aElement, pNode )
783 <<= sal_Int16(AnimationTransformType::TRANSLATE);
785 AttributeList attribs( xAttribs );
786 sal_Int32 nOrigin = xAttribs->getOptionalValueToken( XML_origin, 0 );
798 OUString
aStr = xAttribs->getOptionalValue( XML_path );
801 if (aStr.endsWith(
"E"))
802 aStr = aStr.copy(0, aStr.getLength() - 1);
804 pNode->getNodeProperties()[
NP_PATH ] <<= aStr;
805 mnPathEditMode = xAttribs->getOptionalValueToken( XML_pathEditMode, 0 );
806 msPtsTypes = xAttribs->getOptionalValue( XML_ptsTypes );
807 mnAngle = attribs.getInteger( XML_rAng, 0 );
813 switch ( aElementToken )
815 case PPT_TOKEN( cBhvr ):
816 return new CommonBehaviorContext ( *this,
mpNode );
817 case PPT_TOKEN( to ):
827 case PPT_TOKEN( from ):
837 case PPT_TOKEN( by ):
847 case PPT_TOKEN( rCtr ):
868 class AnimEffectContext
869 :
public TimeNodeContext
872 AnimEffectContext( FragmentHandler2
const & rParent, sal_Int32 aElement,
873 const Reference< XFastAttributeList >& xAttribs,
875 : TimeNodeContext( rParent, aElement, pNode )
877 sal_Int32 nDir = xAttribs->getOptionalValueToken( XML_transition, 0 );
878 OUString sFilter = xAttribs->getOptionalValue( XML_filter );
882 if( !sFilter.isEmpty() )
884 SlideTransition aFilter( sFilter );
885 aFilter.setMode( nDir != XML_out );
886 pNode->setTransitionFilter( aFilter );
892 switch ( aElementToken )
894 case PPT_TOKEN( cBhvr ):
895 return new CommonBehaviorContext ( *this,
mpNode );
896 case PPT_TOKEN( progress ):
897 return new AnimVariantContext( *this, aElementToken,
maProgress );
912 FragmentHandler2
const & rParent, sal_Int32 aElement,
913 const Reference< XFastAttributeList >& xAttribs,
919 case PPT_TOKEN( animClr ):
920 pCtx =
new AnimColorContext( rParent, aElement, xAttribs, pNode );
922 case PPT_TOKEN( par ):
923 pCtx =
new ParallelExclTimeNodeContext( rParent, aElement, pNode );
925 case PPT_TOKEN( seq ):
926 pCtx =
new SequenceTimeNodeContext( rParent, aElement, xAttribs, pNode );
928 case PPT_TOKEN( excl ):
929 pCtx =
new ParallelExclTimeNodeContext( rParent, aElement, pNode );
931 case PPT_TOKEN(
anim ):
932 pCtx =
new AnimContext ( rParent, aElement, xAttribs, pNode );
934 case PPT_TOKEN( animEffect ):
935 pCtx =
new AnimEffectContext( rParent, aElement, xAttribs, pNode );
937 case PPT_TOKEN( animMotion ):
938 pCtx =
new AnimMotionContext( rParent, aElement, xAttribs, pNode );
940 case PPT_TOKEN( animRot ):
941 pCtx =
new AnimRotContext( rParent, aElement, xAttribs, pNode );
943 case PPT_TOKEN( animScale ):
944 pCtx =
new AnimScaleContext( rParent, aElement, xAttribs, pNode );
946 case PPT_TOKEN( cmd ):
947 pCtx =
new CmdTimeNodeContext( rParent, aElement, xAttribs, pNode );
949 case PPT_TOKEN(
set ):
950 pCtx =
new SetTimeNodeContext( rParent, aElement, pNode );
952 case PPT_TOKEN( audio ):
953 case PPT_TOKEN( video ):
954 pCtx =
new MediaNodeContext( rParent, aElement, xAttribs, pNode );
964 : FragmentHandler2( rParent )
965 , mnElement( aElement )
977 : FragmentHandler2( rParent )
990 switch( aElementToken )
992 case PPT_TOKEN( par ):
993 nNodeType = AnimationNodeType::PAR;
995 case PPT_TOKEN( seq ):
996 nNodeType = AnimationNodeType::SEQ;
998 case PPT_TOKEN( excl ):
1001 nNodeType = AnimationNodeType::PAR;
1003 case PPT_TOKEN(
anim ):
1004 nNodeType = AnimationNodeType::ANIMATE;
1006 case PPT_TOKEN( animClr ):
1007 nNodeType = AnimationNodeType::ANIMATECOLOR;
1009 case PPT_TOKEN( animEffect ):
1010 nNodeType = AnimationNodeType::TRANSITIONFILTER;
1012 case PPT_TOKEN( animMotion ):
1013 nNodeType = AnimationNodeType::ANIMATEMOTION;
1015 case PPT_TOKEN( animRot ):
1016 case PPT_TOKEN( animScale ):
1017 nNodeType = AnimationNodeType::ANIMATETRANSFORM;
1019 case PPT_TOKEN( cmd ):
1020 nNodeType = AnimationNodeType::COMMAND;
1022 case PPT_TOKEN(
set ):
1023 nNodeType = AnimationNodeType::SET;
1025 case PPT_TOKEN( audio ):
1028 case PPT_TOKEN( video ):
1030 SAL_WARN(
"oox.ppt",
"OOX: video requested, gave Audio instead" );
1034 nNodeType = AnimationNodeType::CUSTOM;
1035 SAL_INFO(
"oox.ppt",
"unhandled token " << aElementToken);
1039 TimeNodePtr pNode = std::make_shared<TimeNode>(nNodeType);
1040 maList.push_back( pNode );
1043 return pContext ? pContext :
this;
bool convertMeasure(OUString &rString)
convert the measure string to LibreOffice format.
std::vector< TimeNodePtr > TimeNodePtrList
AnimationAttributeEnum meAttribute
const sal_Int32 PER_DEGREE
virtual ~TimeNodeListContext() noexcept override
oox::drawingml::Color maFromClr
std::basic_string_view< charT, traits > getToken(std::basic_string_view< charT, traits > sv, charT delimiter, std::size_t &position)
oox::drawingml::Color maToClr
bool convertAnimationValue(AnimationAttributeEnum eAttribute, css::uno::Any &rValue)
convert attribute values of the animation target so that LibreOffice understand.
bool equalsAscii(std::u16string_view s1, const char *s2)
const ImplAttributeNameConversion * getAttributeConversionList()
std::array< css::uno::Any, NP_SIZE_ > NodePropertyMap
TimeAnimationValueList maTavList
virtual ~TimeNodeContext() noexcept override
Any GetTimeAnimateValueTime(const OUString &val)
#define TOOLS_WARN_EXCEPTION(area, stream)
::Color getColor(const GraphicHelper &rGraphicHelper,::Color nPhClr=API_RGB_TRANSPARENT) const
Returns the final RGB color value.
::std::vector< TimeAnimationValue > TimeAnimationValueList
bool isUsed() const
Returns true, if the color is initialized.
virtual ::oox::core::ContextHandlerRef onCreateContext(sal_Int32 aElementToken, const AttributeList &rAttribs) override
Will be called to create a context handler for the passed element.
Provides access to attribute values of an element.
const PropertyValue * pValues
#define SAL_INFO(area, stream)
awt::Point GetPointPercent(const Reference< XFastAttributeList > &xAttribs)
converts the attributes from a CT_TLPoint into an awt Point with 1/1000%
::rtl::Reference< ContextHandler > ContextHandlerRef
const css::uno::Reference< css::xml::sax::XFastAttributeList > & getFastAttributeList() const
Returns the wrapped com.sun.star.xml.sax.XFastAttributeList object.
std::shared_ptr< TimeNode > TimeNodePtr
#define SAL_WARN(area, stream)
TimeNodeListContext(::oox::core::FragmentHandler2 const &rParent, TimeNodePtrList &aList) noexcept
TimeNodeContext(::oox::core::FragmentHandler2 const &rParent, sal_Int32 aElement, const 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)
void set(css::uno::UnoInterfaceReference const &value)