include/oox/ppt/presentationfragmenthandler.hxx | 4 oox/source/ppt/presentationfragmenthandler.cxx | 121 +++++++++++++----------- sd/qa/unit/export-tests-ooxml2.cxx | 4 3 files changed, 71 insertions(+), 58 deletions(-)
New commits: commit 1b871b635c7f368d46a0cff96c059a4d53b257d6 Author: Henry Castro <hcas...@collabora.com> AuthorDate: Thu Sep 28 15:01:43 2023 -0400 Commit: Henry Castro <hcas...@collabora.com> CommitDate: Thu Oct 5 12:59:42 2023 +0200 tdf#155512: oox: ppt: fix import master slides Import all master slides according to the relationship with slide layouts. Adjust unit test values: SdOOXMLExportTest2::testTdf106867 I do not know why those values change since importing embedded video source code was not touched SdOOXMLExportTest2::testAccentColor The accent6 is a constant value. Signed-off-by: Henry Castro <hcas...@collabora.com> Change-Id: Ic7c70d2c4ce30a7f2d2d1cf22604f1119a66f5f7 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/157387 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com> Tested-by: Caolán McNamara <caolan.mcnam...@collabora.com> Reviewed-by: Caolán McNamara <caolan.mcnam...@collabora.com> (cherry picked from commit 08ed103d734ebf65202dc097c7bb0990573f8fd1) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/157532 Tested-by: Jenkins (cherry picked from commit adcde78935fb8ca2b93322aa3a558d0b3ccdbfad) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/157546 diff --git a/include/oox/ppt/presentationfragmenthandler.hxx b/include/oox/ppt/presentationfragmenthandler.hxx index 4685ea2d8316..29204b282bdb 100644 --- a/include/oox/ppt/presentationfragmenthandler.hxx +++ b/include/oox/ppt/presentationfragmenthandler.hxx @@ -54,8 +54,8 @@ private: void importSlide(sal_uInt32 nSlide, bool bFirstSlide, bool bImportNotes); oox::ppt::SlidePersistPtr importMasterSlide(const ::com::sun::star::uno::Reference<::com::sun::star::frame::XModel>& xModel, ::oox::ppt::PowerPointImport& rFilter, - const OUString& rLayoutFragmentPath, - const OUString& rMasterFragmentPath); + std::u16string_view rLayoutFragmentPath, + std::u16string_view rMasterFragmentPath); void saveThemeToGrabBag(const oox::drawingml::ThemePtr& pThemePtr, sal_Int32 nThemeIdx); void importCustomSlideShow(std::vector<CustomShow>& rCustomShowList); static void importSlideNames(::oox::core::XmlFilterBase& rFilter, const std::vector<SlidePersistPtr>& rSlidePersist); diff --git a/oox/source/ppt/presentationfragmenthandler.cxx b/oox/source/ppt/presentationfragmenthandler.cxx index 8dd0af1345df..09c39902a66a 100644 --- a/oox/source/ppt/presentationfragmenthandler.cxx +++ b/oox/source/ppt/presentationfragmenthandler.cxx @@ -217,75 +217,88 @@ void PresentationFragmentHandler::importCustomSlideShow(std::vector<CustomShow>& SlidePersistPtr PresentationFragmentHandler::importMasterSlide(const Reference<frame::XModel>& xModel, PowerPointImport& rFilter, - const OUString& rLayoutFragmentPath, - const OUString& rMasterFragmentPath) + std::u16string_view rLayoutFragmentPath, + std::u16string_view rMasterFragmentPath) { - SlidePersistPtr pMasterPersistPtr; + OUString aLayoutFragmentPath; + OUString aMasterFragmentPath(rMasterFragmentPath); + SlidePersistPtr pMasterPersistPtr, pMasterPtr; Reference< drawing::XDrawPage > xMasterPage; Reference< drawing::XMasterPagesSupplier > xMPS( xModel, uno::UNO_QUERY_THROW ); Reference< drawing::XDrawPages > xMasterPages( xMPS->getMasterPages(), uno::UNO_SET_THROW ); + RelationsRef xMasterRelations = rFilter.importRelations( aMasterFragmentPath ); - sal_Int32 nIndex; - if( rFilter.getMasterPages().empty() ) + for (const auto& rEntry : *xMasterRelations) { - nIndex = 0; - xMasterPages->getByIndex( nIndex ) >>= xMasterPage; - } - else - { - nIndex = xMasterPages->getCount(); - xMasterPage = xMasterPages->insertNewByIndex( nIndex ); - } + aLayoutFragmentPath = xMasterRelations->getFragmentPathFromRelation(rEntry.second); - pMasterPersistPtr = std::make_shared<SlidePersist>( rFilter, true, false, xMasterPage, - std::make_shared<PPTShape>( Master, "com.sun.star.drawing.GroupShape" ), mpTextListStyle ); - pMasterPersistPtr->setLayoutPath( rLayoutFragmentPath ); - rFilter.getMasterPages().push_back( pMasterPersistPtr ); - rFilter.setActualSlidePersist( pMasterPersistPtr ); - FragmentHandlerRef xMasterFragmentHandler( new SlideFragmentHandler( rFilter, rMasterFragmentPath, pMasterPersistPtr, Master ) ); - - // set the correct theme - OUString aThemeFragmentPath = xMasterFragmentHandler->getFragmentPathFromFirstTypeFromOfficeDoc( u"theme" ); - if( !aThemeFragmentPath.isEmpty() ) - { - std::map< OUString, oox::drawingml::ThemePtr >& rThemes( rFilter.getThemes() ); - std::map< OUString, oox::drawingml::ThemePtr >::iterator aIter2( rThemes.find( aThemeFragmentPath ) ); - if( aIter2 == rThemes.end() ) + sal_Int32 nIndex; + if( rFilter.getMasterPages().empty() ) { - oox::drawingml::ThemePtr pThemePtr = std::make_shared<oox::drawingml::Theme>(); - pMasterPersistPtr->setTheme( pThemePtr ); - Reference<xml::dom::XDocument> xDoc= - rFilter.importFragment(aThemeFragmentPath); - - auto pTheme = std::make_shared<model::Theme>(); - pThemePtr->setTheme(pTheme); - - rFilter.importFragment( - new ThemeFragmentHandler(rFilter, aThemeFragmentPath, *pThemePtr, *pTheme), - Reference<xml::sax::XFastSAXSerializable>( - xDoc, - UNO_QUERY_THROW)); - rThemes[ aThemeFragmentPath ] = pThemePtr; - pThemePtr->setFragment(xDoc); - saveThemeToGrabBag(pThemePtr, nIndex + 1); + nIndex = 0; + xMasterPages->getByIndex( nIndex ) >>= xMasterPage; } else { - pMasterPersistPtr->setTheme( (*aIter2).second ); + nIndex = xMasterPages->getCount(); + xMasterPage = xMasterPages->insertNewByIndex( nIndex ); } - } - importSlide( xMasterFragmentHandler, pMasterPersistPtr ); - rFilter.importFragment( new LayoutFragmentHandler( rFilter, rLayoutFragmentPath, pMasterPersistPtr ) ); - pMasterPersistPtr->createBackground( rFilter ); - pMasterPersistPtr->createXShapes( rFilter ); - oox::drawingml::ThemePtr pTheme = pMasterPersistPtr->getTheme(); - if (pTheme) - { - pTheme->addTheme(pMasterPersistPtr->getPage()); + pMasterPersistPtr = std::make_shared<SlidePersist>( rFilter, true, false, xMasterPage, + std::make_shared<PPTShape>( Master, "com.sun.star.drawing.GroupShape" ), mpTextListStyle ); + pMasterPersistPtr->setLayoutPath( aLayoutFragmentPath ); + rFilter.getMasterPages().push_back( pMasterPersistPtr ); + rFilter.setActualSlidePersist( pMasterPersistPtr ); + FragmentHandlerRef xMasterFragmentHandler( new SlideFragmentHandler( rFilter, aMasterFragmentPath, pMasterPersistPtr, Master ) ); + + // set the correct theme + OUString aThemeFragmentPath = xMasterFragmentHandler->getFragmentPathFromFirstTypeFromOfficeDoc( u"theme" ); + if( !aThemeFragmentPath.isEmpty() ) + { + std::map< OUString, oox::drawingml::ThemePtr >& rThemes( rFilter.getThemes() ); + std::map< OUString, oox::drawingml::ThemePtr >::iterator aIter2( rThemes.find( aThemeFragmentPath ) ); + if( aIter2 == rThemes.end() ) + { + oox::drawingml::ThemePtr pThemePtr = std::make_shared<oox::drawingml::Theme>(); + pMasterPersistPtr->setTheme( pThemePtr ); + Reference<xml::dom::XDocument> xDoc= + rFilter.importFragment(aThemeFragmentPath); + + auto pTheme = std::make_shared<model::Theme>(); + pThemePtr->setTheme(pTheme); + + rFilter.importFragment( + new ThemeFragmentHandler(rFilter, aThemeFragmentPath, *pThemePtr, *pTheme), + Reference<xml::sax::XFastSAXSerializable>( + xDoc, + UNO_QUERY_THROW)); + rThemes[ aThemeFragmentPath ] = pThemePtr; + pThemePtr->setFragment(xDoc); + saveThemeToGrabBag(pThemePtr, nIndex + 1); + } + else + { + pMasterPersistPtr->setTheme( (*aIter2).second ); + } + } + importSlide( xMasterFragmentHandler, pMasterPersistPtr ); + rFilter.importFragment( new LayoutFragmentHandler( rFilter, aLayoutFragmentPath, pMasterPersistPtr ) ); + pMasterPersistPtr->createBackground( rFilter ); + pMasterPersistPtr->createXShapes( rFilter ); + + oox::drawingml::ThemePtr pTheme = pMasterPersistPtr->getTheme(); + if (pTheme) + { + pTheme->addTheme(pMasterPersistPtr->getPage()); + } + + if (pMasterPersistPtr->getLayoutPath() == rLayoutFragmentPath) + { + pMasterPtr = pMasterPersistPtr; + } } - return pMasterPersistPtr; + return pMasterPtr; } void PresentationFragmentHandler::saveThemeToGrabBag(const oox::drawingml::ThemePtr& pThemePtr, diff --git a/sd/qa/unit/export-tests-ooxml2.cxx b/sd/qa/unit/export-tests-ooxml2.cxx index aaf245f2e90d..754ee0d3035e 100644 --- a/sd/qa/unit/export-tests-ooxml2.cxx +++ b/sd/qa/unit/export-tests-ooxml2.cxx @@ -1313,7 +1313,7 @@ CPPUNIT_TEST_FIXTURE(SdOOXMLExportTest2, testTdf106867) "/p:sld/p:timing/p:tnLst/p:par/p:cTn/p:childTnLst/p:seq/p:cTn/p:childTnLst/p:par/" "p:cTn/p:childTnLst/p:par/p:cTn/p:childTnLst/p:par/p:cTn/p:childTnLst/p:cmd/" "p:cBhvr/p:tgtEl/p:spTgt", - "spid", "42"); + "spid", "491"); } CPPUNIT_TEST_FIXTURE(SdOOXMLExportTest2, testTdf112280) @@ -1694,7 +1694,7 @@ CPPUNIT_TEST_FIXTURE(SdOOXMLExportTest2, testAccentColor) "70ad47"); xmlDocUniquePtr pXmlDocTheme2 = parseExport("ppt/theme/theme2.xml"); assertXPath(pXmlDocTheme2, "/a:theme/a:themeElements/a:clrScheme/a:accent6/a:srgbClr", "val", - "deb340"); + "70ad47"); // Without the accompanying fix in place, this test would have failed with: // - Expected: Motyw pakietu Office