diff --git a/include/oox/shape/ShapeContextHandler.hxx b/include/oox/shape/ShapeContextHandler.hxx index 5655cc25acf2..77ae18f8eb75 100644 --- a/include/oox/shape/ShapeContextHandler.hxx +++ b/include/oox/shape/ShapeContextHandler.hxx @@ -108,6 +108,9 @@ public: void setGraphicMapper(css::uno::Reference const & rGraphicMapper); + void setTheme(const oox::drawingml::ThemePtr& pTheme) { mpThemePtr = pTheme; } + const oox::drawingml::ThemePtr& getTheme() { return mpThemePtr; } + private: ShapeContextHandler(ShapeContextHandler const &) = delete; void operator =(ShapeContextHandler const &) = delete; diff --git a/oox/source/shape/ShapeContextHandler.cxx b/oox/source/shape/ShapeContextHandler.cxx index 4eb20ad36cda..a4cd8db133ce 100644 --- a/oox/source/shape/ShapeContextHandler.cxx +++ b/oox/source/shape/ShapeContextHandler.cxx @@ -37,6 +37,7 @@ #include #include #include +#include using namespace ::com::sun::star; @@ -263,14 +264,14 @@ void SAL_CALL ShapeContextHandler::startFastElement { mxShapeFilterBase->filter(maMediaDescriptor); - mpThemePtr = std::make_shared(); - if (Element == DGM_TOKEN(relIds) || Element == LC_TOKEN(lockedCanvas) || Element == C_TOKEN(chart) || Element == WPS_TOKEN(wsp) || Element == WPG_TOKEN(wgp) || Element == OOX_TOKEN(dmlPicture, pic)) { // Parse the theme relation, if available; the diagram won't have colors without it. - if (!msRelationFragmentPath.isEmpty()) + if (!mpThemePtr && !msRelationFragmentPath.isEmpty()) { + SAL_DEBUG("theme theme theme"); + mpThemePtr = std::make_shared(); // Get Target for Type = "officeDocument" from _rels/.rels file // aOfficeDocumentFragmentPath is pointing to "word/document.xml" for docx & to "ppt/presentation.xml" for pptx FragmentHandlerRef rFragmentHandlerRef(new ShapeFragmentHandler(*mxShapeFilterBase, "/")); diff --git a/writerfilter/source/ooxml/OOXMLDocumentImpl.hxx b/writerfilter/source/ooxml/OOXMLDocumentImpl.hxx index c97c208534cf..ec079fa86de0 100644 --- a/writerfilter/source/ooxml/OOXMLDocumentImpl.hxx +++ b/writerfilter/source/ooxml/OOXMLDocumentImpl.hxx @@ -23,6 +23,8 @@ #include #include +#include + #include "OOXMLPropertySet.hxx" #include @@ -66,6 +68,9 @@ class OOXMLDocumentImpl : public OOXMLDocument css::uno::Sequence maMediaDescriptor; /// Graphic mapper css::uno::Reference mxGraphicMapper; + // For a document there is a single theme in document.xml.rels + // and the same is used by header and footer as well. + oox::drawingml::ThemePtr mpTheme; bool mbCommentsExtendedResolved = false; @@ -146,6 +151,10 @@ public: { return mxGraphicMapper; } + + const oox::drawingml::ThemePtr & getTheme() const { return mpTheme; } + void setTheme(const oox::drawingml::ThemePtr& pTheme) { mpTheme = pTheme; } + }; } diff --git a/writerfilter/source/ooxml/OOXMLFastContextHandler.cxx b/writerfilter/source/ooxml/OOXMLFastContextHandler.cxx index 16abb4987d35..24b2661ba593 100644 --- a/writerfilter/source/ooxml/OOXMLFastContextHandler.cxx +++ b/writerfilter/source/ooxml/OOXMLFastContextHandler.cxx @@ -1697,6 +1697,9 @@ void OOXMLFastContextHandlerShape::setToken(Token_t nToken) // Define the shape context for the whole document mrShapeContext = new oox::shape::ShapeContextHandler(getComponentContext()); getDocument()->setShapeContext(mrShapeContext); + auto pThemePtr = getDocument()->getTheme(); + if (pThemePtr) + mrShapeContext->setTheme(pThemePtr); } mrShapeContext->setModel(getDocument()->getModel()); @@ -1786,6 +1789,15 @@ OOXMLFastContextHandlerShape::lcl_createFastChildContext (Token_t Element, const uno::Reference< xml::sax::XFastAttributeList > & Attribs) { + // we need to share a single theme across all the shapes, but we parse it + // in ShapeContextHandler. So if it has been parsed there, propogate it to + // the document. + if (mrShapeContext && mrShapeContext->getTheme() && !getDocument()->getTheme()) + { + auto pThemePtr = mrShapeContext->getTheme(); + getDocument()->setTheme(pThemePtr); + } + uno::Reference< xml::sax::XFastContextHandler > xContextHandler; bool bGroupShape = Element == Token_t(NMSP_vml | XML_group);