From 7364b3a2d820e028d30237cf13f562674759dc4f Mon Sep 17 00:00:00 2001 From: Marco Cecchetti Date: Sun, 8 Sep 2024 12:19:46 +0200 Subject: [PATCH] lok: slideshow rework: check that requested slide is the expected one MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I225dfea9981d43fb90888f5025792e9d24d9a789 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/173061 Tested-by: Jenkins CollaboraOffice Reviewed-by: Szymon Kłos Reviewed-on: https://gerrit.libreoffice.org/c/core/+/178129 Reviewed-by: Miklos Vajna Tested-by: Jenkins --- desktop/source/lib/init.cxx | 4 +++ include/LibreOfficeKit/LibreOfficeKit.h | 1 + include/LibreOfficeKit/LibreOfficeKit.hxx | 3 ++- include/vcl/ITiledRenderable.hxx | 1 + sd/qa/unit/tiledrendering/tiledrendering.cxx | 15 ++++++++--- sd/source/ui/inc/unomodel.hxx | 1 + sd/source/ui/unoidl/unomodel.cxx | 26 ++++++++++++++++++++ 7 files changed, 46 insertions(+), 5 deletions(-) diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx index d5ac74a2d14e..0a1a2a620150 100644 --- a/desktop/source/lib/init.cxx +++ b/desktop/source/lib/init.cxx @@ -1331,6 +1331,7 @@ static char* doc_getPresentationInfo(LibreOfficeKitDocument* pThis); static bool doc_createSlideRenderer( LibreOfficeKitDocument* pThis, + const char* pSlideHash, int nSlideNumber, unsigned* nViewWidth, unsigned* nViewHeight, bool bRenderBackground, bool bRenderMasterPage); @@ -5724,6 +5725,7 @@ static char* doc_getPresentationInfo(LibreOfficeKitDocument* pThis) static bool doc_createSlideRenderer( LibreOfficeKitDocument* pThis, + const char* pSlideHash, int nSlideNumber, unsigned* pViewWidth, unsigned* pViewHeight, bool bRenderBackground, bool bRenderMasterPage) { @@ -5737,9 +5739,11 @@ static bool doc_createSlideRenderer( return false; } + OString sSlideHash(pSlideHash); sal_Int32 nViewWidth = *pViewWidth; sal_Int32 nViewHeight = *pViewHeight; bool bReturn = pDoc->createSlideRenderer( + sSlideHash, nSlideNumber, nViewWidth, nViewHeight, bRenderBackground, bRenderMasterPage); diff --git a/include/LibreOfficeKit/LibreOfficeKit.h b/include/LibreOfficeKit/LibreOfficeKit.h index 757fb75821f7..b06b978db16c 100644 --- a/include/LibreOfficeKit/LibreOfficeKit.h +++ b/include/LibreOfficeKit/LibreOfficeKit.h @@ -541,6 +541,7 @@ struct _LibreOfficeKitDocumentClass /// @see lok::Document::createSlideRenderer bool (*createSlideRenderer) ( LibreOfficeKitDocument* pThis, + const char* pSlideHash, int nSlideNumber, unsigned* nViewWidth, unsigned* nViewHeight, bool bRenderBackground, bool bRenderMasterPage); diff --git a/include/LibreOfficeKit/LibreOfficeKit.hxx b/include/LibreOfficeKit/LibreOfficeKit.hxx index edd62dd59aff..b311fa03d1a9 100644 --- a/include/LibreOfficeKit/LibreOfficeKit.hxx +++ b/include/LibreOfficeKit/LibreOfficeKit.hxx @@ -917,11 +917,12 @@ public: /// Create a slide renderer in core for the input slide. bool createSlideRenderer( + const char* pSlideHash, int nSlideNumber, unsigned* nViewWidth, unsigned* nViewHeight, bool bRenderBackground, bool bRenderMasterPage) { return mpDoc->pClass->createSlideRenderer( - mpDoc, nSlideNumber, nViewWidth, nViewHeight, bRenderBackground, bRenderMasterPage); + mpDoc, pSlideHash, nSlideNumber, nViewWidth, nViewHeight, bRenderBackground, bRenderMasterPage); } /// Clean-up the slideshow (slide renderer) diff --git a/include/vcl/ITiledRenderable.hxx b/include/vcl/ITiledRenderable.hxx index 05db0bad6db0..9e57fc53b0a0 100644 --- a/include/vcl/ITiledRenderable.hxx +++ b/include/vcl/ITiledRenderable.hxx @@ -392,6 +392,7 @@ public: } /** Creates a slide show renderer (Impress only function) */ virtual bool createSlideRenderer( + const OString& /*rSlideHash*/, sal_Int32 /*nSlideNumber*/, sal_Int32& /*nViewWidth*/, sal_Int32& /*nViewHeight*/, bool /*bRenderBackground*/, bool /*bRenderMasterPage*/) { diff --git a/sd/qa/unit/tiledrendering/tiledrendering.cxx b/sd/qa/unit/tiledrendering/tiledrendering.cxx index 18b213e99abf..5f0a3b747a64 100644 --- a/sd/qa/unit/tiledrendering/tiledrendering.cxx +++ b/sd/qa/unit/tiledrendering/tiledrendering.cxx @@ -30,6 +30,7 @@ #include #include #include +#include #include #include #include @@ -41,6 +42,7 @@ #include #include #include + #include #include #include @@ -2791,9 +2793,10 @@ CPPUNIT_TEST_FIXTURE(SdTiledRenderingTest, testSlideshowLayeredRendering) CPPUNIT_ASSERT(pViewShell); SdPage* pPage = pViewShell->GetActualPage(); CPPUNIT_ASSERT(pPage); + std::string sHash = GetInterfaceHash(GetXDrawPageForSdrPage(pPage)); sal_Int32 nViewWidth = 2000; sal_Int32 nViewHeight = 2000; - CPPUNIT_ASSERT(pXImpressDocument->createSlideRenderer(0, nViewWidth, nViewHeight, true, true)); + CPPUNIT_ASSERT(pXImpressDocument->createSlideRenderer(sHash.c_str(), 0, nViewWidth, nViewHeight, true, true)); CPPUNIT_ASSERT_EQUAL(2000, nViewWidth); CPPUNIT_ASSERT_EQUAL(1125, nViewHeight); @@ -2869,10 +2872,12 @@ CPPUNIT_TEST_FIXTURE(SdTiledRenderingTest, testSlideshowLayeredRendering_WithFie sd::ViewShell* pViewShell = pXImpressDocument->GetDocShell()->GetViewShell(); CPPUNIT_ASSERT(pViewShell); SdPage* pPage = pViewShell->GetActualPage(); + CPPUNIT_ASSERT(pPage); + std::string sHash = GetInterfaceHash(GetXDrawPageForSdrPage(pPage)); sal_Int32 nViewWidth = 2000; sal_Int32 nViewHeight = 2000; - CPPUNIT_ASSERT(pXImpressDocument->createSlideRenderer(0, nViewWidth, nViewHeight, true, true)); + CPPUNIT_ASSERT(pXImpressDocument->createSlideRenderer(sHash.c_str(), 0, nViewWidth, nViewHeight, true, true)); CPPUNIT_ASSERT_EQUAL(2000, nViewWidth); CPPUNIT_ASSERT_EQUAL(1125, nViewHeight); @@ -2967,9 +2972,10 @@ CPPUNIT_TEST_FIXTURE(SdTiledRenderingTest, testSlideshowLayeredRendering_Animati CPPUNIT_ASSERT(pViewShell); SdPage* pPage = pViewShell->GetActualPage(); CPPUNIT_ASSERT(pPage); + std::string sHash = GetInterfaceHash(GetXDrawPageForSdrPage(pPage)); sal_Int32 nViewWidth = 2000; sal_Int32 nViewHeight = 2000; - CPPUNIT_ASSERT(pXImpressDocument->createSlideRenderer(0, nViewWidth, nViewHeight, true, true)); + CPPUNIT_ASSERT(pXImpressDocument->createSlideRenderer(sHash.c_str(), 0, nViewWidth, nViewHeight, true, true)); CPPUNIT_ASSERT_EQUAL(2000, nViewWidth); CPPUNIT_ASSERT_EQUAL(1125, nViewHeight); @@ -3078,7 +3084,8 @@ CPPUNIT_TEST_FIXTURE(SdTiledRenderingTest, testSlideshowLayeredRendering_Animati CPPUNIT_ASSERT(pPage); sal_Int32 nViewWidth = 2000; sal_Int32 nViewHeight = 2000; - CPPUNIT_ASSERT(pXImpressDocument->createSlideRenderer(0, nViewWidth, nViewHeight, true, true)); + std::string sHash = GetInterfaceHash(GetXDrawPageForSdrPage(pPage)); + CPPUNIT_ASSERT(pXImpressDocument->createSlideRenderer(sHash.c_str(), 0, nViewWidth, nViewHeight, true, true)); CPPUNIT_ASSERT_EQUAL(2000, nViewWidth); CPPUNIT_ASSERT_EQUAL(1125, nViewHeight); diff --git a/sd/source/ui/inc/unomodel.hxx b/sd/source/ui/inc/unomodel.hxx index 13a2635c781a..4e4019db3147 100644 --- a/sd/source/ui/inc/unomodel.hxx +++ b/sd/source/ui/inc/unomodel.hxx @@ -302,6 +302,7 @@ public: SD_DLLPUBLIC OString getPresentationInfo() const override; /// @see vcl::ITiledRenderable::createSlideRenderer(). SD_DLLPUBLIC bool createSlideRenderer( + const OString& rSlideHash, sal_Int32 nSlideNumber, sal_Int32& nViewWidth, sal_Int32& nViewHeight, bool bRenderBackground, bool bRenderMasterPage) override; /// @see vcl::ITiledRenderable::postSlideshowCleanup(). diff --git a/sd/source/ui/unoidl/unomodel.cxx b/sd/source/ui/unoidl/unomodel.cxx index 98cf5fcc3ce0..7f099a2b1b30 100644 --- a/sd/source/ui/unoidl/unomodel.cxx +++ b/sd/source/ui/unoidl/unomodel.cxx @@ -4525,12 +4525,38 @@ namespace { // use VCL slideshow renderer or not - leave the old one in for now, so it is possible to compare output constexpr const bool bVCLSlideShowRenderer = true; + +bool isRequestedSlideValid(SdDrawDocument* mpDoc, sal_Int32 nSlideNumber, const std::string& slideHash) +{ + try + { + uno::Reference xDrawPages(getXWeak(mpDoc->getUnoModel()), + uno::UNO_QUERY_THROW); + uno::Reference xSlides(xDrawPages->getDrawPages(), + uno::UNO_QUERY_THROW); + uno::Reference xSlide(xSlides->getByIndex(nSlideNumber), + uno::UNO_QUERY_THROW); + if (xSlide.is()) { + return slideHash == GetInterfaceHash(xSlide); + } + } + catch (uno::Exception&) + { + TOOLS_WARN_EXCEPTION( "sd", "SdXImpressDocument::createLOKSlideRenderer: failed" ); + } + return false; +} } bool SdXImpressDocument::createSlideRenderer( + const OString& rSlideHash, sal_Int32 nSlideNumber, sal_Int32& nViewWidth, sal_Int32& nViewHeight, bool bRenderBackground, bool bRenderMasterPage) { + std::string sSlideHash(rSlideHash); + if (!isRequestedSlideValid(mpDoc, nSlideNumber, sSlideHash)) + return false; + if (bVCLSlideShowRenderer) { SdPage* pPage = mpDoc->GetSdPage(sal_uInt16(nSlideNumber), PageKind::Standard);