oox/source/ppt/presentationfragmenthandler.cxx | 116 +++++++++++++------------ sd/qa/unit/export-tests-ooxml2.cxx | 4 2 files changed, 66 insertions(+), 54 deletions(-)
New commits: commit 08ed103d734ebf65202dc097c7bb0990573f8fd1 Author: Henry Castro <hcas...@collabora.com> AuthorDate: Thu Sep 28 15:01:43 2023 -0400 Commit: Caolán McNamara <caolan.mcnam...@collabora.com> CommitDate: Tue Oct 3 11:32:22 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> diff --git a/oox/source/ppt/presentationfragmenthandler.cxx b/oox/source/ppt/presentationfragmenthandler.cxx index a0f13c83ae05..0ab32be82a21 100644 --- a/oox/source/ppt/presentationfragmenthandler.cxx +++ b/oox/source/ppt/presentationfragmenthandler.cxx @@ -204,72 +204,84 @@ SlidePersistPtr PresentationFragmentHandler::importMasterSlide(const Reference<f const OUString& rLayoutFragmentPath, const OUString& rMasterFragmentPath) { - SlidePersistPtr pMasterPersistPtr; + OUString aLayoutFragmentPath; + 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( rMasterFragmentPath ); - 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, 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() ) + { + 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 a777de2b385c..1996210bc6c2 100644 --- a/sd/qa/unit/export-tests-ooxml2.cxx +++ b/sd/qa/unit/export-tests-ooxml2.cxx @@ -1462,7 +1462,7 @@ void 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"); } void SdOOXMLExportTest2::testTdf112280() @@ -1843,7 +1843,7 @@ void 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