diff options
author | Henry Castro <hcastro@collabora.com> | 2023-09-28 14:23:55 -0400 |
---|---|---|
committer | Henry Castro <hcastro@collabora.com> | 2023-10-03 21:48:00 +0200 |
commit | 9fabd7c11989c2a89c5bb238e6cb52b0a6678851 (patch) | |
tree | 63d4e497144b36022fdf0d2b974fcb4ac5ed93d4 /oox | |
parent | e47c1737d6f1365aa640f1960fb0c9892fde6d77 (diff) |
tdf#155512: oox: ppt: abstraction "importMasterSlide"
Signed-off-by: Henry Castro <hcastro@collabora.com>
Change-Id: Icfe8e3abbada7f728b2ad1f8e300a688f51d8f75
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/157386
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Caolán McNamara <caolan.mcnamara@collabora.com>
(cherry picked from commit 84ac58c37fffa0c8b6d55c70009515d013ad65b4)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/157468
Tested-by: Jenkins
Diffstat (limited to 'oox')
-rw-r--r-- | oox/source/ppt/presentationfragmenthandler.cxx | 137 |
1 files changed, 74 insertions, 63 deletions
diff --git a/oox/source/ppt/presentationfragmenthandler.cxx b/oox/source/ppt/presentationfragmenthandler.cxx index 9b52b92d97d0..538d79df7f50 100644 --- a/oox/source/ppt/presentationfragmenthandler.cxx +++ b/oox/source/ppt/presentationfragmenthandler.cxx @@ -215,6 +215,79 @@ void PresentationFragmentHandler::importCustomSlideShow(std::vector<CustomShow>& } } +SlidePersistPtr PresentationFragmentHandler::importMasterSlide(const Reference<frame::XModel>& xModel, + PowerPointImport& rFilter, + const OUString& rLayoutFragmentPath, + const OUString& rMasterFragmentPath) +{ + SlidePersistPtr pMasterPersistPtr; + Reference< drawing::XDrawPage > xMasterPage; + Reference< drawing::XMasterPagesSupplier > xMPS( xModel, uno::UNO_QUERY_THROW ); + Reference< drawing::XDrawPages > xMasterPages( xMPS->getMasterPages(), uno::UNO_SET_THROW ); + + sal_Int32 nIndex; + if( rFilter.getMasterPages().empty() ) + { + nIndex = 0; + xMasterPages->getByIndex( nIndex ) >>= xMasterPage; + } + else + { + nIndex = xMasterPages->getCount(); + xMasterPage = xMasterPages->insertNewByIndex( nIndex ); + } + + 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() ) + { + 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, rLayoutFragmentPath, pMasterPersistPtr ) ); + pMasterPersistPtr->createBackground( rFilter ); + pMasterPersistPtr->createXShapes( rFilter ); + + oox::drawingml::ThemePtr pTheme = pMasterPersistPtr->getTheme(); + if (pTheme) + { + pTheme->addTheme(pMasterPersistPtr->getPage()); + } + + return pMasterPersistPtr; +} + void PresentationFragmentHandler::saveThemeToGrabBag(const oox::drawingml::ThemePtr& pThemePtr, sal_Int32 nThemeIdx) { @@ -332,69 +405,7 @@ void PresentationFragmentHandler::importSlide(sal_uInt32 nSlide, bool bFirstPage if ( !pMasterPersistPtr ) { // masterpersist not found, we have to load it - Reference< drawing::XDrawPage > xMasterPage; - Reference< drawing::XMasterPagesSupplier > xMPS( xModel, uno::UNO_QUERY_THROW ); - Reference< drawing::XDrawPages > xMasterPages( xMPS->getMasterPages(), uno::UNO_SET_THROW ); - - sal_Int32 nIndex; - if( rFilter.getMasterPages().empty() ) - { - nIndex = 0; - xMasterPages->getByIndex( nIndex ) >>= xMasterPage; - } - else - { - nIndex = xMasterPages->getCount(); - xMasterPage = xMasterPages->insertNewByIndex( nIndex ); - } - - 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()); - } + pMasterPersistPtr = importMasterSlide(xModel, rFilter, aLayoutFragmentPath, aMasterFragmentPath); } } } |