summaryrefslogtreecommitdiff
path: root/xmloff
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2020-03-09 14:08:41 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2020-03-09 20:29:33 +0100
commitc8dbdd691e8d08d16f421d471eb269804de262d5 (patch)
treebf8a9a5556f66420411a09ca7f506364c8a5b040 /xmloff
parentc63e40eabf6886a6e6584be8d5a1cb2b573b86ff (diff)
use FastParser in XMLAnimationsContext
Change-Id: Ib6c99e7aa9d2797a04b9590c69008f6895f13780 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/90217 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'xmloff')
-rw-r--r--xmloff/inc/animimp.hxx18
-rw-r--r--xmloff/source/draw/animimp.cxx240
-rw-r--r--xmloff/source/draw/ximppage.cxx8
3 files changed, 128 insertions, 138 deletions
diff --git a/xmloff/inc/animimp.hxx b/xmloff/inc/animimp.hxx
index 8e2ead46867b..1511994a89c2 100644
--- a/xmloff/inc/animimp.hxx
+++ b/xmloff/inc/animimp.hxx
@@ -23,24 +23,22 @@
#include <memory>
#include <xmloff/xmlictxt.hxx>
-
-class AnimImpImpl;
+#include <com/sun/star/beans/XPropertySet.hpp>
// presentations:animations
class XMLAnimationsContext final : public SvXMLImportContext
{
- std::shared_ptr<AnimImpImpl> mpImpl;
-
public:
+ css::uno::Reference< css::beans::XPropertySet > mxLastShape;
+ OUString maLastShapeId;
+
+ XMLAnimationsContext( SvXMLImport& rImport);
- XMLAnimationsContext( SvXMLImport& rImport,
- sal_uInt16 nPrfx,
- const OUString& rLocalName,
- const css::uno::Reference< css::xml::sax::XAttributeList>& xAttrList);
+ virtual void SAL_CALL startFastElement( sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ) override;
- virtual SvXMLImportContextRef CreateChildContext( sal_uInt16 nPrefix, const OUString& rLocalName,
- const css::uno::Reference< css::xml::sax::XAttributeList>& xAttrList ) override;
+ virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(
+ sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& AttrList ) override;
};
#endif // INCLUDED_XMLOFF_INC_ANIMIMP_HXX
diff --git a/xmloff/source/draw/animimp.cxx b/xmloff/source/draw/animimp.cxx
index f2178aeb8454..580491ae3eb2 100644
--- a/xmloff/source/draw/animimp.cxx
+++ b/xmloff/source/draw/animimp.cxx
@@ -27,6 +27,7 @@
#include <sax/tools/converter.hxx>
#include <osl/diagnose.h>
+#include <sal/log.hxx>
#include <xmloff/xmltoken.hxx>
#include <xmloff/xmlimp.hxx>
@@ -315,12 +316,8 @@ AnimationEffect ImplSdXMLgetEffect( XMLEffect eKind, XMLEffectDirection eDirecti
}
}
-class AnimImpImpl
+namespace
{
-public:
- Reference< XPropertySet > mxLastShape;
- OUString maLastShapeId;
-
static constexpr OUStringLiteral gsDimColor = "DimColor";
static constexpr OUStringLiteral gsDimHide = "DimHide";
static constexpr OUStringLiteral gsDimPrev = "DimPrevious";
@@ -348,7 +345,7 @@ enum XMLActionKind
class XMLAnimationsEffectContext : public SvXMLImportContext
{
public:
- std::shared_ptr<AnimImpImpl> mpImpl;
+ rtl::Reference<XMLAnimationsContext> mxAnimationsContext;
XMLActionKind meKind;
bool mbTextEffect;
@@ -367,152 +364,141 @@ public:
public:
XMLAnimationsEffectContext( SvXMLImport& rImport,
- sal_uInt16 nPrfx,
- const OUString& rLocalName,
- const Reference< XAttributeList >& xAttrList,
- const std::shared_ptr<AnimImpImpl>& pImpl);
+ sal_Int32 nElement,
+ const Reference< XFastAttributeList >& xAttrList,
+ XMLAnimationsContext& rAnimationsContext);
- virtual void EndElement() override;
+ virtual void SAL_CALL startFastElement( sal_Int32 /*nElement*/,
+ const css::uno::Reference< css::xml::sax::XFastAttributeList >& /*xAttrList*/ ) override {}
- virtual SvXMLImportContextRef CreateChildContext( sal_uInt16 nPrefix, const OUString& rLocalName,
- const Reference< XAttributeList >& xAttrList ) override;
+ virtual void SAL_CALL endFastElement(sal_Int32 nElement) override;
+
+ virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(
+ sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ) override;
};
class XMLAnimationsSoundContext : public SvXMLImportContext
{
public:
- XMLAnimationsSoundContext( SvXMLImport& rImport, sal_uInt16 nPrfx, const OUString& rLocalName, const Reference< XAttributeList >& xAttrList, XMLAnimationsEffectContext* pParent );
+ XMLAnimationsSoundContext( SvXMLImport& rImport, sal_Int32 nElement, const Reference< XFastAttributeList >& xAttrList, XMLAnimationsEffectContext* pParent );
+
+ virtual void SAL_CALL startFastElement( sal_Int32 /*nElement*/,
+ const css::uno::Reference< css::xml::sax::XFastAttributeList >& /*xAttrList*/ ) override {}
};
}
-XMLAnimationsSoundContext::XMLAnimationsSoundContext( SvXMLImport& rImport, sal_uInt16 nPrfx, const OUString& rLocalName, const Reference< XAttributeList >& xAttrList, XMLAnimationsEffectContext* pParent )
-: SvXMLImportContext( rImport, nPrfx, rLocalName )
+XMLAnimationsSoundContext::XMLAnimationsSoundContext( SvXMLImport& rImport, sal_Int32 nElement, const Reference< XFastAttributeList >& xAttrList, XMLAnimationsEffectContext* pParent )
+: SvXMLImportContext( rImport )
{
- if( pParent && nPrfx == XML_NAMESPACE_PRESENTATION && IsXMLToken( rLocalName, XML_SOUND ) )
+ if( !pParent || nElement != XML_ELEMENT(PRESENTATION, XML_SOUND) )
+ return;
+
+ sax_fastparser::FastAttributeList *pAttribList =
+ sax_fastparser::FastAttributeList::castToFastAttributeList( xAttrList );
+ for (auto &aIter : *pAttribList)
{
- const sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
- for(sal_Int16 i=0; i < nAttrCount; i++)
+ OUString sValue = aIter.toString();
+ switch( aIter.getToken() )
{
- OUString sAttrName = xAttrList->getNameByIndex( i );
- OUString aLocalName;
- sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName );
- OUString sValue = xAttrList->getValueByIndex( i );
-
- switch( nPrefix )
- {
- case XML_NAMESPACE_XLINK:
- if( IsXMLToken( aLocalName, XML_HREF ) )
- {
- pParent->maSoundURL = rImport.GetAbsoluteReference(sValue);
- }
+ case XML_ELEMENT(XLINK, XML_HREF):
+ pParent->maSoundURL = rImport.GetAbsoluteReference(sValue);
break;
- case XML_NAMESPACE_PRESENTATION:
- if( IsXMLToken( aLocalName, XML_PLAY_FULL ) )
- {
- pParent->mbPlayFull = IsXMLToken( sValue, XML_TRUE );
- }
- }
+ case XML_ELEMENT(PRESENTATION, XML_PLAY_FULL):
+ pParent->mbPlayFull = IsXMLToken( sValue, XML_TRUE );
+ break;
+ default:
+ SAL_WARN("xmloff", "unknown attribute " << SvXMLImport::getPrefixAndNameFromToken(aIter.getToken()) << "=" << sValue);
}
}
}
-XMLAnimationsEffectContext::XMLAnimationsEffectContext( SvXMLImport& rImport, sal_uInt16 nPrfx, const OUString& rLocalName, const Reference< XAttributeList >& xAttrList, const std::shared_ptr<AnimImpImpl>& pImpl )
-: SvXMLImportContext(rImport, nPrfx, rLocalName),
- mpImpl( pImpl ),
+XMLAnimationsEffectContext::XMLAnimationsEffectContext( SvXMLImport& rImport,
+ sal_Int32 nElement,
+ const Reference< XFastAttributeList >& xAttrList,
+ XMLAnimationsContext& rAnimationsContext )
+: SvXMLImportContext(rImport),
+ mxAnimationsContext( &rAnimationsContext ),
meKind( XMLE_SHOW ), mbTextEffect( false ),
meEffect( EK_none ), meDirection( ED_none ), mnStartScale( 100 ),
meSpeed( AnimationSpeed_MEDIUM ), maDimColor(0), mbPlayFull( false )
{
- if( IsXMLToken( rLocalName, XML_SHOW_SHAPE ) )
+ switch(nElement & TOKEN_MASK)
{
- meKind = XMLE_SHOW;
- }
- else if( IsXMLToken( rLocalName, XML_SHOW_TEXT ) )
- {
- meKind = XMLE_SHOW;
- mbTextEffect = true;
- }
- else if( IsXMLToken( rLocalName, XML_HIDE_SHAPE ) )
- {
- meKind = XMLE_HIDE;
- }
- else if( IsXMLToken( rLocalName, XML_HIDE_TEXT ) )
- {
- meKind = XMLE_HIDE;
- mbTextEffect = true;
- }
- else if( IsXMLToken( rLocalName, XML_DIM ) )
- {
- meKind = XMLE_DIM;
- }
- else if( IsXMLToken( rLocalName, XML_PLAY ) )
- {
- meKind = XMLE_PLAY;
- }
- else
- {
- // unknown action, overread
- return;
+ case XML_SHOW_SHAPE:
+ meKind = XMLE_SHOW;
+ break;
+ case XML_SHOW_TEXT:
+ meKind = XMLE_SHOW;
+ mbTextEffect = true;
+ break;
+ case XML_HIDE_SHAPE:
+ meKind = XMLE_HIDE;
+ break;
+ case XML_HIDE_TEXT:
+ meKind = XMLE_HIDE;
+ mbTextEffect = true;
+ break;
+ case XML_DIM:
+ meKind = XMLE_DIM;
+ break;
+ case XML_PLAY:
+ meKind = XMLE_PLAY;
+ break;
+ default:
+ SAL_WARN("xmloff", "unknown element " << SvXMLImport::getPrefixAndNameFromToken(nElement));
+ // unknown action, overread
+ return;
}
- // read attributes
- const sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
- for(sal_Int16 i=0; i < nAttrCount; i++)
+ sax_fastparser::FastAttributeList *pAttribList =
+ sax_fastparser::FastAttributeList::castToFastAttributeList( xAttrList );
+ for (auto &aIter : *pAttribList)
{
- OUString sAttrName = xAttrList->getNameByIndex( i );
- OUString aLocalName;
- sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName );
- OUString sValue = xAttrList->getValueByIndex( i );
-
- switch( nPrefix )
+ OUString sValue = aIter.toString();
+ switch( aIter.getToken() )
{
- case XML_NAMESPACE_DRAW:
- if( IsXMLToken( aLocalName, XML_SHAPE_ID ) )
- {
+ case XML_ELEMENT(DRAW, XML_SHAPE_ID):
maShapeId = sValue;
- }
- else if( IsXMLToken( aLocalName, XML_COLOR ) )
- {
+ break;
+ case XML_ELEMENT(DRAW, XML_COLOR):
::sax::Converter::convertColor(maDimColor, sValue);
- }
- break;
+ break;
- case XML_NAMESPACE_PRESENTATION:
- if( IsXMLToken( aLocalName, XML_EFFECT ) )
- {
+ case XML_ELEMENT(PRESENTATION, XML_EFFECT):
SvXMLUnitConverter::convertEnum( meEffect, sValue, aXML_AnimationEffect_EnumMap );
- }
- else if( IsXMLToken(aLocalName, XML_DIRECTION ) )
- {
+ break;
+ case XML_ELEMENT(PRESENTATION, XML_DIRECTION):
SvXMLUnitConverter::convertEnum( meDirection, sValue, aXML_AnimationDirection_EnumMap );
- }
- else if( IsXMLToken( aLocalName, XML_START_SCALE ) )
+ break;
+ case XML_ELEMENT(PRESENTATION, XML_START_SCALE):
{
sal_Int32 nScale;
if (::sax::Converter::convertPercent( nScale, sValue ))
mnStartScale = static_cast<sal_Int16>(nScale);
+ break;
}
- else if( IsXMLToken( aLocalName, XML_SPEED ) )
- {
+ case XML_ELEMENT(PRESENTATION, XML_SPEED):
SvXMLUnitConverter::convertEnum( meSpeed, sValue, aXML_AnimationSpeed_EnumMap );
- }
- else if( IsXMLToken( aLocalName, XML_PATH_ID ) )
- {
+ break;
+ case XML_ELEMENT(PRESENTATION, XML_PATH_ID):
maPathShapeId = sValue;
- }
- break;
+ break;
+ default:
+ SAL_WARN("xmloff", "unknown attribute " << SvXMLImport::getPrefixAndNameFromToken(aIter.getToken()) << "=" << sValue);
}
}
}
-SvXMLImportContextRef XMLAnimationsEffectContext::CreateChildContext( sal_uInt16 nPrefix, const OUString& rLocalName, const Reference< XAttributeList>& xAttrList )
+css::uno::Reference< css::xml::sax::XFastContextHandler > XMLAnimationsEffectContext::createFastChildContext(
+ sal_Int32 nElement,
+ const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
{
- return new XMLAnimationsSoundContext( GetImport(), nPrefix, rLocalName, xAttrList, this );
+ return new XMLAnimationsSoundContext( GetImport(), nElement, xAttrList, this );
}
-void XMLAnimationsEffectContext::EndElement()
+void XMLAnimationsEffectContext::endFastElement(sal_Int32 )
{
// set effect on shape
@@ -523,7 +509,7 @@ void XMLAnimationsEffectContext::EndElement()
if( !maShapeId.isEmpty() )
{
Reference< XPropertySet > xSet;
- if( mpImpl->maLastShapeId != maShapeId )
+ if( mxAnimationsContext->maLastShapeId != maShapeId )
{
xSet.set( GetImport().getInterfaceToIdentifierMapper().getReference( maShapeId ), UNO_QUERY );
if( xSet.is() )
@@ -531,30 +517,30 @@ void XMLAnimationsEffectContext::EndElement()
// check for presentation shape service
{
Reference< XServiceInfo > xServiceInfo( xSet, UNO_QUERY );
- if( !xServiceInfo.is() || !xServiceInfo->supportsService( AnimImpImpl::gsPresShapeService ) )
+ if( !xServiceInfo.is() || !xServiceInfo->supportsService( gsPresShapeService ) )
return;
}
- mpImpl->maLastShapeId = maShapeId;
- mpImpl->mxLastShape = xSet;
+ mxAnimationsContext->maLastShapeId = maShapeId;
+ mxAnimationsContext->mxLastShape = xSet;
}
}
else
{
- xSet = mpImpl->mxLastShape;
+ xSet = mxAnimationsContext->mxLastShape;
}
if( xSet.is() )
{
if( meKind == XMLE_DIM )
{
- xSet->setPropertyValue( AnimImpImpl::gsDimPrev, Any(true) );
+ xSet->setPropertyValue( gsDimPrev, Any(true) );
- xSet->setPropertyValue( AnimImpImpl::gsDimColor, Any(maDimColor) );
+ xSet->setPropertyValue( gsDimColor, Any(maDimColor) );
}
else if( meKind == XMLE_PLAY )
{
- xSet->setPropertyValue( AnimImpImpl::gsIsAnimation, Any(true) );
+ xSet->setPropertyValue( gsIsAnimation, Any(true) );
// #i42894# speed is not supported for the old group animation fallback, so no need to set it
// aAny <<= meSpeed;
@@ -564,21 +550,21 @@ void XMLAnimationsEffectContext::EndElement()
{
if( meKind == XMLE_HIDE && !mbTextEffect && meEffect == EK_none )
{
- xSet->setPropertyValue( AnimImpImpl::gsDimHide, Any(true) );
+ xSet->setPropertyValue( gsDimHide, Any(true) );
}
else
{
const AnimationEffect eEffect = ImplSdXMLgetEffect( meEffect, meDirection, mnStartScale, meKind == XMLE_SHOW );
- OUString s = mbTextEffect ? AnimImpImpl::gsTextEffect : AnimImpImpl::gsEffect;
+ OUString s = mbTextEffect ? gsTextEffect : gsEffect;
xSet->setPropertyValue( s, makeAny( eEffect ) );
- xSet->setPropertyValue( AnimImpImpl::gsSpeed, makeAny( meSpeed ) );
+ xSet->setPropertyValue( gsSpeed, makeAny( meSpeed ) );
if( eEffect == AnimationEffect_PATH && !maPathShapeId.isEmpty() )
{
Reference< XShape > xPath( GetImport().getInterfaceToIdentifierMapper().getReference( maPathShapeId ), UNO_QUERY );
if( xPath.is() )
- xSet->setPropertyValue( AnimImpImpl::gsAnimPath, makeAny( xPath ) );
+ xSet->setPropertyValue( gsAnimPath, makeAny( xPath ) );
}
}
}
@@ -587,9 +573,9 @@ void XMLAnimationsEffectContext::EndElement()
{
if( xSet.is() )
{
- xSet->setPropertyValue( AnimImpImpl::gsSound, Any(maSoundURL) );
- xSet->setPropertyValue( AnimImpImpl::gsPlayFull, Any(mbPlayFull) );
- xSet->setPropertyValue( AnimImpImpl::gsSoundOn, Any(true) );
+ xSet->setPropertyValue( gsSound, Any(maSoundURL) );
+ xSet->setPropertyValue( gsPlayFull, Any(mbPlayFull) );
+ xSet->setPropertyValue( gsSoundOn, Any(true) );
}
else
{
@@ -605,17 +591,19 @@ void XMLAnimationsEffectContext::EndElement()
}
-XMLAnimationsContext::XMLAnimationsContext( SvXMLImport& rImport, sal_uInt16 nPrfx, const OUString& rLocalName,
- const css::uno::Reference< css::xml::sax::XAttributeList>& )
-: SvXMLImportContext(rImport, nPrfx, rLocalName)
-, mpImpl(std::make_shared<AnimImpImpl>())
+XMLAnimationsContext::XMLAnimationsContext( SvXMLImport& rImport )
+: SvXMLImportContext(rImport)
{
}
-SvXMLImportContextRef XMLAnimationsContext::CreateChildContext( sal_uInt16 nPrefix, const OUString& rLocalName,
- const css::uno::Reference< css::xml::sax::XAttributeList>& xAttrList )
+void XMLAnimationsContext::startFastElement( sal_Int32 /*nElement*/,
+ const css::uno::Reference< css::xml::sax::XFastAttributeList >& /*xAttrList*/ )
+{}
+
+css::uno::Reference< css::xml::sax::XFastContextHandler > XMLAnimationsContext::createFastChildContext(
+ sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
{
- return new XMLAnimationsEffectContext( GetImport(), nPrefix, rLocalName, xAttrList, mpImpl );
+ return new XMLAnimationsEffectContext( GetImport(), nElement, xAttrList, *this );
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/xmloff/source/draw/ximppage.cxx b/xmloff/source/draw/ximppage.cxx
index 1c3c555b719d..5bc4c9a8cc83 100644
--- a/xmloff/source/draw/ximppage.cxx
+++ b/xmloff/source/draw/ximppage.cxx
@@ -240,9 +240,13 @@ void SdXMLGenericPageContext::startFastElement( sal_Int32 /*nElement*/, const Re
}
css::uno::Reference< css::xml::sax::XFastContextHandler > SdXMLGenericPageContext::createFastChildContext(
- sal_Int32 /*nElement*/,
+ sal_Int32 nElement,
const Reference< xml::sax::XFastAttributeList>& /*xAttrList*/ )
{
+ if( nElement == XML_ELEMENT(PRESENTATION, XML_ANIMATIONS) )
+ {
+ return new XMLAnimationsContext( GetImport() );
+ }
return nullptr;
}
@@ -254,7 +258,7 @@ SvXMLImportContextRef SdXMLGenericPageContext::CreateChildContext( sal_uInt16 nP
if( nPrefix == XML_NAMESPACE_PRESENTATION && IsXMLToken( rLocalName, XML_ANIMATIONS ) )
{
- xContext = new XMLAnimationsContext( GetImport(), nPrefix, rLocalName, xAttrList );
+ // handled in createFastChildContext
}
else if( nPrefix == XML_NAMESPACE_OFFICE && IsXMLToken( rLocalName, XML_FORMS ) )
{