include/oox/ppt/presentationfragmenthandler.hxx | 1 oox/source/ppt/customshowlistcontext.cxx | 23 ++++++----- oox/source/ppt/presentationfragmenthandler.cxx | 49 ++++++++++++++++++++++++ sd/qa/unit/data/pptx/tdf131390.pptx |binary sd/qa/unit/import-tests.cxx | 19 +++++++++ 5 files changed, 82 insertions(+), 10 deletions(-)
New commits: commit ecf48b2d4f3e54dbb2c1e295120d73e7b7a11338 Author: Tibor Nagy <nagy.tib...@nisz.hu> AuthorDate: Wed May 12 12:14:26 2021 +0200 Commit: László Németh <nem...@numbertext.org> CommitDate: Tue May 25 15:44:40 2021 +0200 tdf#131390 PPTX: fix custom slide show is not imported. Change-Id: I62e1bfaae23d1b18e71a2c16651d01144a26907c Reviewed-on: https://gerrit.libreoffice.org/c/core/+/115475 Tested-by: Jenkins Tested-by: László Németh <nem...@numbertext.org> Reviewed-by: László Németh <nem...@numbertext.org> diff --git a/include/oox/ppt/presentationfragmenthandler.hxx b/include/oox/ppt/presentationfragmenthandler.hxx index bc68b738b5dd..a9bb5bb67a77 100644 --- a/include/oox/ppt/presentationfragmenthandler.hxx +++ b/include/oox/ppt/presentationfragmenthandler.hxx @@ -51,6 +51,7 @@ private: const oox::ppt::SlidePersistPtr& rPersist ); void importSlide(sal_uInt32 nSlide, bool bFirstSlide, bool bImportNotes); void saveThemeToGrabBag(const oox::drawingml::ThemePtr& pThemePtr, sal_Int32 nThemeIdx); + void importCustomSlideShow(std::vector<CustomShow>& rCustomShowList); std::vector< OUString > maSlideMasterVector; std::vector< OUString > maSlidesVector; diff --git a/oox/source/ppt/customshowlistcontext.cxx b/oox/source/ppt/customshowlistcontext.cxx index 174ca1bbe91a..1e6befd639ae 100644 --- a/oox/source/ppt/customshowlistcontext.cxx +++ b/oox/source/ppt/customshowlistcontext.cxx @@ -33,12 +33,12 @@ namespace { class CustomShowContext : public ::oox::core::FragmentHandler2 { - CustomShow mrCustomShow; + std::vector< CustomShow >& mrCustomShowList; public: CustomShowContext( ::oox::core::FragmentHandler2 const & rParent, const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttribs, - CustomShow const & rCustomShow ); + std::vector< CustomShow >& rCustomShowList ); virtual ::oox::core::ContextHandlerRef onCreateContext( sal_Int32 aElementToken, const AttributeList& rAttribs ) override; }; @@ -47,12 +47,14 @@ public: CustomShowContext::CustomShowContext( FragmentHandler2 const & rParent, const Reference< XFastAttributeList >& rxAttribs, - CustomShow const & rCustomShow ) + std::vector< CustomShow >& rCustomShowList ) : FragmentHandler2( rParent ) -, mrCustomShow( rCustomShow ) +, mrCustomShowList( rCustomShowList ) { - mrCustomShow.maCustomShowName = rxAttribs->getOptionalValue( XML_name ); - mrCustomShow.mnId = rxAttribs->getOptionalValue( XML_id ); + CustomShow aCustomShow; + aCustomShow.maCustomShowName = rxAttribs->getOptionalValue( XML_name ); + aCustomShow.mnId = rxAttribs->getOptionalValue( XML_id ); + mrCustomShowList.push_back(aCustomShow); } ::oox::core::ContextHandlerRef CustomShowContext::onCreateContext( sal_Int32 aElementToken, const AttributeList& rAttribs ) @@ -60,7 +62,10 @@ CustomShowContext::CustomShowContext( FragmentHandler2 const & rParent, switch( aElementToken ) { case PPT_TOKEN( sld ) : - mrCustomShow.maSldLst.push_back( rAttribs.getString( R_TOKEN( id ), OUString() ) ); + mrCustomShowList.back().maSldLst.push_back( + getRelations() + .getRelationFromRelId(rAttribs.getString(R_TOKEN(id), OUString())) + ->maTarget); return this; default: break; @@ -86,9 +91,7 @@ CustomShowListContext::~CustomShowListContext( ) { case PPT_TOKEN( custShow ) : { - CustomShow aCustomShow; - mrCustomShowList.push_back( aCustomShow ); - return new CustomShowContext( *this, rAttribs.getFastAttributeList(), mrCustomShowList.back() ); + return new CustomShowContext( *this, rAttribs.getFastAttributeList(), mrCustomShowList ); } default: break; diff --git a/oox/source/ppt/presentationfragmenthandler.cxx b/oox/source/ppt/presentationfragmenthandler.cxx index a00b825d8c00..9aabd45d18af 100644 --- a/oox/source/ppt/presentationfragmenthandler.cxx +++ b/oox/source/ppt/presentationfragmenthandler.cxx @@ -35,6 +35,10 @@ #include <com/sun/star/xml/sax/XFastSAXSerializable.hpp> #include <com/sun/star/presentation/XPresentationPage.hpp> #include <com/sun/star/task/XStatusIndicator.hpp> +#include <com/sun/star/presentation/XCustomPresentationSupplier.hpp> +#include <com/sun/star/container/XIndexContainer.hpp> +#include <com/sun/star/lang/XSingleServiceFactory.hpp> +#include <com/sun/star/container/XNameContainer.hpp> #include <oox/drawingml/theme.hxx> #include <oox/drawingml/drawingmltypes.hxx> @@ -158,6 +162,49 @@ static void ResolveTextFields( XmlFilterBase const & rFilter ) } } +void PresentationFragmentHandler::importCustomSlideShow(std::vector<CustomShow>& rCustomShowList) +{ + PowerPointImport& rFilter = dynamic_cast<PowerPointImport&>(getFilter()); + Reference<frame::XModel> xModel(rFilter.getModel()); + Reference<XDrawPagesSupplier> xDrawPagesSupplier(xModel, UNO_QUERY_THROW); + Reference<XDrawPages> xDrawPages(xDrawPagesSupplier->getDrawPages(), UNO_SET_THROW); + + Reference<css::lang::XSingleServiceFactory> mxShowFactory; + Reference<css::container::XNameContainer> mxShows; + Reference<XCustomPresentationSupplier> xShowsSupplier(xModel, UNO_QUERY); + if (xShowsSupplier.is()) + { + mxShows = xShowsSupplier->getCustomPresentations(); + mxShowFactory.set(mxShows, UNO_QUERY); + } + + for (size_t i = 0; i < rCustomShowList.size(); ++i) + { + Reference<com::sun::star::container::XIndexContainer> xShow(mxShowFactory->createInstance(), + UNO_QUERY); + if (xShow.is()) + { + static const OUStringLiteral sSlide = u"slides/slide"; + for (size_t j = 0; j < rCustomShowList[i].maSldLst.size(); ++j) + { + OUString sCustomSlide = rCustomShowList[i].maSldLst[j]; + sal_Int32 nPageNumber = 0; + if (sCustomSlide.match(sSlide)) + nPageNumber = sCustomSlide.copy(sSlide.getLength()).toInt32(); + + Reference<XDrawPage> xPage; + xDrawPages->getByIndex(nPageNumber - 1) >>= xPage; + if (xPage.is()) + xShow->insertByIndex(xShow->getCount(), Any(xPage)); + } + + Any aAny; + aAny <<= xShow; + mxShows->insertByName(rCustomShowList[i].maCustomShowName, aAny); + } + } +} + void PresentationFragmentHandler::saveThemeToGrabBag(const oox::drawingml::ThemePtr& pThemePtr, sal_Int32 nThemeIdx) { @@ -497,6 +544,8 @@ void PresentationFragmentHandler::finalizeImport() nPagesImported++; } ResolveTextFields( rFilter ); + if (!maCustomShowList.empty()) + importCustomSlideShow(maCustomShowList); } catch( uno::Exception& ) { diff --git a/sd/qa/unit/data/pptx/tdf131390.pptx b/sd/qa/unit/data/pptx/tdf131390.pptx new file mode 100644 index 000000000000..22069d816478 Binary files /dev/null and b/sd/qa/unit/data/pptx/tdf131390.pptx differ diff --git a/sd/qa/unit/import-tests.cxx b/sd/qa/unit/import-tests.cxx index bf539dfdd08d..862f7e80c001 100644 --- a/sd/qa/unit/import-tests.cxx +++ b/sd/qa/unit/import-tests.cxx @@ -86,6 +86,7 @@ #include <com/sun/star/text/XTextCursor.hpp> #include <com/sun/star/xml/dom/XDocument.hpp> #include <com/sun/star/container/XNamed.hpp> +#include <com/sun/star/presentation/XCustomPresentationSupplier.hpp> #include <stlpool.hxx> #include <comphelper/processfactory.hxx> @@ -120,6 +121,7 @@ public: virtual void setUp() override; void testDocumentLayout(); + void testCustomSlideShow(); void testInternalHyperlink(); void testHyperlinkColor(); void testSmoketest(); @@ -239,6 +241,7 @@ public: CPPUNIT_TEST_SUITE(SdImportTest); CPPUNIT_TEST(testDocumentLayout); + CPPUNIT_TEST(testCustomSlideShow); CPPUNIT_TEST(testInternalHyperlink); CPPUNIT_TEST(testHyperlinkColor); CPPUNIT_TEST(testSmoketest); @@ -434,6 +437,22 @@ void SdImportTest::testDocumentLayout() } } +void SdImportTest::testCustomSlideShow() +{ + ::sd::DrawDocShellRef xDocShRef + = loadURL(m_directories.getURLFromSrc(u"/sd/qa/unit/data/pptx/tdf131390.pptx"), PPTX); + + css::uno::Reference<css::presentation::XCustomPresentationSupplier> aXCPSup( + xDocShRef->GetModel(), css::uno::UNO_QUERY); + css::uno::Reference<css::container::XNameContainer> aXCont(aXCPSup->getCustomPresentations()); + const css::uno::Sequence< OUString> aNameSeq( aXCont->getElementNames() ); + + // In the document, there are two custom presentations. + CPPUNIT_ASSERT_EQUAL(sal_uInt32(2), aNameSeq.size()); + + xDocShRef->DoClose(); +} + void SdImportTest::testInternalHyperlink() { ::sd::DrawDocShellRef xDocShRef _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits