From 8203f31040e8f99196872e97456674d2f4a2bf83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Szymon=20K=C5=82os?= Date: Thu, 12 Sep 2024 11:22:10 +0200 Subject: [PATCH] slideshow: use unified hash for animations and layers Change-Id: I98d048f933469a63295776f689e96ce84d0c4f49 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/177969 Tested-by: Jenkins Reviewed-by: Miklos Vajna --- include/animations/animationnodehelper.hxx | 59 +++++++++++++++++++ sd/source/ui/inc/SlideshowLayerRenderer.hxx | 1 + sd/source/ui/tools/SlideshowLayerRenderer.cxx | 10 +++- sd/source/ui/unoidl/unomodel.cxx | 59 ++----------------- 4 files changed, 74 insertions(+), 55 deletions(-) diff --git a/include/animations/animationnodehelper.hxx b/include/animations/animationnodehelper.hxx index c23ab25c140f..8c79342c789b 100644 --- a/include/animations/animationnodehelper.hxx +++ b/include/animations/animationnodehelper.hxx @@ -19,12 +19,18 @@ #pragma once +#include +#include +#include +#include + #include #include #include #include #include #include +#include #include @@ -108,6 +114,59 @@ namespace anim return false; } + + inline css::uno::Reference getParagraphTarget( + const css::presentation::ParagraphTarget& pTarget) + { + try + { + css::uno::Reference xParaEnumAccess( + pTarget.Shape, css::uno::UNO_QUERY_THROW); + + css::uno::Reference xEnumeration( + xParaEnumAccess->createEnumeration(), + css::uno::UNO_SET_THROW); + sal_Int32 nParagraph = pTarget.Paragraph; + + while (xEnumeration->hasMoreElements()) + { + css::uno::Reference xRef( + xEnumeration->nextElement(), css::uno::UNO_QUERY); + if (nParagraph-- == 0) + return xRef; + } + } + catch (const css::uno::RuntimeException&) + { + SAL_WARN("animations", "getParagraphTarget"); + } + + css::uno::Reference xRef; + return xRef; + } + + inline void convertTarget(OStringBuffer& sTmp, const css::uno::Any& rTarget) + { + if (!rTarget.hasValue()) + return; + + css::uno::Reference xRef; + if (!(rTarget >>= xRef)) + { + if (auto pt = o3tl::tryAccess(rTarget)) + { + xRef = getParagraphTarget(*pt); + } + } + + SAL_WARN_IF(!xRef.is(), "animations", "convertTarget(), invalid target type!"); + if (xRef.is()) + { + const std::string aIdentifier(GetInterfaceHash(xRef)); + if (!aIdentifier.empty()) + sTmp.append(aIdentifier); + } + } } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sd/source/ui/inc/SlideshowLayerRenderer.hxx b/sd/source/ui/inc/SlideshowLayerRenderer.hxx index b6397ddc9fb8..5cd590e920e7 100644 --- a/sd/source/ui/inc/SlideshowLayerRenderer.hxx +++ b/sd/source/ui/inc/SlideshowLayerRenderer.hxx @@ -48,6 +48,7 @@ struct RenderState std::unordered_set maObjectsDone; std::unordered_set maInAnimation; + std::map maAnimationTargetHash; std::map maInitiallyVisible; sal_Int32 mnIndex[static_cast(RenderStage::Count)] = { 0, 0, 0, 0 }; SdrObject* mpCurrentTarget = nullptr; diff --git a/sd/source/ui/tools/SlideshowLayerRenderer.cxx b/sd/source/ui/tools/SlideshowLayerRenderer.cxx index 96f9000e69ad..bf5e34a65a6a 100644 --- a/sd/source/ui/tools/SlideshowLayerRenderer.cxx +++ b/sd/source/ui/tools/SlideshowLayerRenderer.cxx @@ -290,6 +290,14 @@ void SlideshowLayerRenderer::setupAnimations() maRenderState.maInitiallyVisible[pObject] = bVisible; } + + if (aAny.hasValue()) + { + OStringBuffer sTmp; + anim::convertTarget(sTmp, aAny); + maRenderState.maAnimationTargetHash[pObject] + = static_cast(sTmp); + } } } } @@ -361,7 +369,7 @@ void SlideshowLayerRenderer::writeJSON(OString& rJsonMsg) aJsonWriter.put("type", "animated"); { auto aContentNode = aJsonWriter.startNode("content"); - aJsonWriter.put("hash", RenderState::getObjectHash(pObject)); + aJsonWriter.put("hash", maRenderState.maAnimationTargetHash.at(pObject)); aJsonWriter.put("initVisible", maRenderState.isObjectInitiallyVisible(pObject)); aJsonWriter.put("type", "bitmap"); writeContentNode(aJsonWriter); diff --git a/sd/source/ui/unoidl/unomodel.cxx b/sd/source/ui/unoidl/unomodel.cxx index 12953834614c..98cf5fcc3ce0 100644 --- a/sd/source/ui/unoidl/unomodel.cxx +++ b/sd/source/ui/unoidl/unomodel.cxx @@ -61,6 +61,8 @@ #include +#include + #include #include #include @@ -586,8 +588,6 @@ private: void exportAnimate(const Reference& xAnimate); void convertValue(XMLTokenEnum eAttributeName, OStringBuffer& sTmp, const Any& rValue) const; - static void convertTarget(OStringBuffer& sTmp, const Any& rTarget); - static Reference getParagraphTarget( const ParagraphTarget& pTarget ); void convertTiming(OStringBuffer& sTmp, const Any& rValue) const; private: @@ -965,55 +965,6 @@ void AnimationsExporter::exportNodeImpl(const Reference& xNode) } } -Reference AnimationsExporter::getParagraphTarget(const ParagraphTarget& pTarget) -{ - try - { - Reference xParaEnumAccess(pTarget.Shape, UNO_QUERY_THROW); - - Reference xEnumeration(xParaEnumAccess->createEnumeration(), - css::uno::UNO_SET_THROW); - sal_Int32 nParagraph = pTarget.Paragraph; - - while (xEnumeration->hasMoreElements()) - { - Reference xRef(xEnumeration->nextElement(), UNO_QUERY); - if (nParagraph-- == 0) - return xRef; - } - } - catch (const RuntimeException&) - { - TOOLS_WARN_EXCEPTION("sd", "AnimationsExporter::getParagraphTarget"); - } - - Reference xRef; - return xRef; -} - -void AnimationsExporter::convertTarget(OStringBuffer& sTmp, const Any& rTarget) -{ - if (!rTarget.hasValue()) - return; - - Reference xRef; - if (!(rTarget >>= xRef)) - { - if (auto pt = o3tl::tryAccess(rTarget)) - { - xRef = getParagraphTarget(*pt); - } - } - - SAL_WARN_IF(!xRef.is(), "sd", "AnimationsExporter::convertTarget(), invalid target type!"); - if (xRef.is()) - { - const std::string aIdentifier(GetInterfaceHash(xRef)); - if (!aIdentifier.empty()) - sTmp.append(aIdentifier); - } -} - void AnimationsExporter::convertTiming(OStringBuffer& sTmp, const Any& rValue) const { if (!rValue.hasValue()) @@ -1056,7 +1007,7 @@ void AnimationsExporter::convertTiming(OStringBuffer& sTmp, const Any& rValue) c { if (pEvent->Source.hasValue()) { - convertTarget(sTmp, pEvent->Source); + anim::convertTarget(sTmp, pEvent->Source); sTmp.append('.'); } @@ -1219,7 +1170,7 @@ void AnimationsExporter::exportContainer(const Reference& xConta Any aTemp(xIter->getTarget()); if (aTemp.hasValue()) { - convertTarget(sTmp, aTemp); + anim::convertTarget(sTmp, aTemp); mrWriter.put("targetElement", sTmp.makeStringAndClear()); } sal_Int16 nTemp = xIter->getSubItem(); @@ -1273,7 +1224,7 @@ void AnimationsExporter::exportAnimate(const Reference& xAnimate) Any aTemp(xAnimate->getTarget()); if (aTemp.hasValue()) { - convertTarget(sTmp, aTemp); + anim::convertTarget(sTmp, aTemp); mrWriter.put("targetElement", sTmp.makeStringAndClear()); } nTemp = xAnimate->getSubItem();