include/oox/shape/ShapeContextHandler.hxx | 6 ++++-- oox/source/shape/ShapeContextHandler.cxx | 10 +++++----- writerfilter/source/ooxml/OOXMLDocumentImpl.cxx | 8 ++++++++ writerfilter/source/ooxml/OOXMLDocumentImpl.hxx | 12 ++++++++++++ writerfilter/source/ooxml/OOXMLFastContextHandler.cxx | 14 +++++++++++++- 5 files changed, 42 insertions(+), 8 deletions(-)
New commits: commit 97123add76b743013fc5c222387feb4b9c13daf2 Author: Noel Grandin <[email protected]> AuthorDate: Tue Jun 29 08:19:12 2021 +0200 Commit: Noel Grandin <[email protected]> CommitDate: Tue Jun 29 11:29:48 2021 +0200 tdf#135316 share themePtr and ShapeFilterBase across all shapes .. in a document. Shavves 20% off my load time. Change-Id: I8101b4d229485ebdef0c1f72f856e7cda43559d5 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/118045 Tested-by: Jenkins Reviewed-by: Noel Grandin <[email protected]> diff --git a/include/oox/shape/ShapeContextHandler.hxx b/include/oox/shape/ShapeContextHandler.hxx index 5655cc25acf2..39549c5d33af 100644 --- a/include/oox/shape/ShapeContextHandler.hxx +++ b/include/oox/shape/ShapeContextHandler.hxx @@ -50,8 +50,7 @@ class OOX_DLLPUBLIC ShapeContextHandler: public ::cppu::WeakImplHelper< css::xml::sax::XFastContextHandler > { public: - explicit ShapeContextHandler - (css::uno::Reference< css::uno::XComponentContext > const & context); + explicit ShapeContextHandler(const rtl::Reference<ShapeFilterBase>& xFilterBase); virtual ~ShapeContextHandler() override; @@ -108,6 +107,9 @@ public: void setGraphicMapper(css::uno::Reference<css::graphic::XGraphicMapper> 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 3a0ed5a3a306..0d03d322d011 100644 --- a/oox/source/shape/ShapeContextHandler.cxx +++ b/oox/source/shape/ShapeContextHandler.cxx @@ -37,6 +37,7 @@ #include <oox/drawingml/themefragmenthandler.hxx> #include <cppuhelper/supportsservice.hxx> #include <memory> +#include <sal/log.hxx> using namespace ::com::sun::star; @@ -44,9 +45,9 @@ namespace oox::shape { using namespace core; using namespace drawingml; -ShapeContextHandler::ShapeContextHandler(uno::Reference< uno::XComponentContext > const & context) : +ShapeContextHandler::ShapeContextHandler(const rtl::Reference<ShapeFilterBase>& xFilterBase) : mnStartToken(0), - mxShapeFilterBase( new ShapeFilterBase(context) ) + mxShapeFilterBase(xFilterBase) { } @@ -257,14 +258,13 @@ void SAL_CALL ShapeContextHandler::startFastElement { mxShapeFilterBase->filter(maMediaDescriptor); - mpThemePtr = std::make_shared<Theme>(); - 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()) { + mpThemePtr = std::make_shared<Theme>(); // 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.cxx b/writerfilter/source/ooxml/OOXMLDocumentImpl.cxx index e0eb6bc48119..be397048df0f 100644 --- a/writerfilter/source/ooxml/OOXMLDocumentImpl.cxx +++ b/writerfilter/source/ooxml/OOXMLDocumentImpl.cxx @@ -25,6 +25,7 @@ #include <com/sun/star/xml/dom/DocumentBuilder.hpp> #include <com/sun/star/graphic/GraphicMapper.hpp> #include <ooxml/resourceids.hxx> +#include <oox/shape/ShapeFilterBase.hxx> #include "OOXMLStreamImpl.hxx" #include "OOXMLDocumentImpl.hxx" #include "OOXMLBinaryObjectReference.hxx" @@ -879,6 +880,13 @@ uno::Sequence<beans::PropertyValue > OOXMLDocumentImpl::getEmbeddingsList( ) return mxEmbeddingsList; } +const rtl::Reference<oox::shape::ShapeFilterBase>& OOXMLDocumentImpl::getShapeFilterBase() +{ + if (!mxShapeFilterBase) + mxShapeFilterBase = new oox::shape::ShapeFilterBase(mpStream->getContext()); + return mxShapeFilterBase; +} + OOXMLDocument * OOXMLDocumentFactory::createDocument (const OOXMLStream::Pointer_t& pStream, diff --git a/writerfilter/source/ooxml/OOXMLDocumentImpl.hxx b/writerfilter/source/ooxml/OOXMLDocumentImpl.hxx index c97c208534cf..5572d0c77d7b 100644 --- a/writerfilter/source/ooxml/OOXMLDocumentImpl.hxx +++ b/writerfilter/source/ooxml/OOXMLDocumentImpl.hxx @@ -23,6 +23,8 @@ #include <com/sun/star/xml/dom/XDocument.hpp> #include <com/sun/star/graphic/XGraphicMapper.hpp> +#include <oox/drawingml/drawingmltypes.hxx> + #include "OOXMLPropertySet.hxx" #include <vector> @@ -66,6 +68,10 @@ class OOXMLDocumentImpl : public OOXMLDocument css::uno::Sequence<css::beans::PropertyValue> maMediaDescriptor; /// Graphic mapper css::uno::Reference<css::graphic::XGraphicMapper> 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; + rtl::Reference<oox::shape::ShapeFilterBase> mxShapeFilterBase; bool mbCommentsExtendedResolved = false; @@ -146,6 +152,12 @@ public: { return mxGraphicMapper; } + + const oox::drawingml::ThemePtr & getTheme() const { return mpTheme; } + void setTheme(const oox::drawingml::ThemePtr& pTheme) { mpTheme = pTheme; } + + const rtl::Reference<oox::shape::ShapeFilterBase> & getShapeFilterBase(); + }; } diff --git a/writerfilter/source/ooxml/OOXMLFastContextHandler.cxx b/writerfilter/source/ooxml/OOXMLFastContextHandler.cxx index 16abb4987d35..9e190389d938 100644 --- a/writerfilter/source/ooxml/OOXMLFastContextHandler.cxx +++ b/writerfilter/source/ooxml/OOXMLFastContextHandler.cxx @@ -1695,8 +1695,11 @@ void OOXMLFastContextHandlerShape::setToken(Token_t nToken) if (!mrShapeContext.is()) { // Define the shape context for the whole document - mrShapeContext = new oox::shape::ShapeContextHandler(getComponentContext()); + mrShapeContext = new oox::shape::ShapeContextHandler(getDocument()->getShapeFilterBase()); 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); _______________________________________________ Libreoffice-commits mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
