diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2020-09-23 23:28:30 +0200 |
---|---|---|
committer | Tomaž Vajngerl <quikee@gmail.com> | 2020-09-25 12:01:07 +0200 |
commit | d0efd878dc41e3913a2d91ff4b5c335c1d71a85c (patch) | |
tree | 11eec3a4e334cec5f8739e99f3bd991a1ea2f80d /writerfilter/source | |
parent | 40c731726b583cdb3a8884e90f17637f35aa3ef8 (diff) |
fix Graphic duplication in import and add GraphicMapper
When importing writerfilter, we change to oox when
importing images. This transition doesn't store any
previous contexts and all instances are reset. The
problem occurs when we have identical images because
the transition erases all caches we have to determine
if an image has already been imported or not, which
causes that we import the same image multiple times
which create unnecessary copies.
This introduces the XGraphicMapper, which can be used
to store the XGraphic for a key and can be transferred
between writerfilter to oox. With this we can remember
which images were already imported and don't create
unnecessary internal copies which decreases memory.
This also includes a test which checks that the import
and export doesn't produce unnecessary copies of
identical images. The test checks that for OOXML, ODF
and MS Binary formats.
Change-Id: I33dc19218c565937fab77e132b3a996c51358b6e
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/103283
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'writerfilter/source')
-rw-r--r-- | writerfilter/source/ooxml/OOXMLDocumentImpl.cxx | 2 | ||||
-rw-r--r-- | writerfilter/source/ooxml/OOXMLDocumentImpl.hxx | 9 | ||||
-rw-r--r-- | writerfilter/source/ooxml/OOXMLFastContextHandler.cxx | 5 |
3 files changed, 16 insertions, 0 deletions
diff --git a/writerfilter/source/ooxml/OOXMLDocumentImpl.cxx b/writerfilter/source/ooxml/OOXMLDocumentImpl.cxx index db4990cc6497..fba694b5b77b 100644 --- a/writerfilter/source/ooxml/OOXMLDocumentImpl.cxx +++ b/writerfilter/source/ooxml/OOXMLDocumentImpl.cxx @@ -23,6 +23,7 @@ #include <com/sun/star/document/XDocumentPropertiesSupplier.hpp> #include <com/sun/star/xml/sax/SAXException.hpp> #include <com/sun/star/xml/dom/DocumentBuilder.hpp> +#include <com/sun/star/graphic/GraphicMapper.hpp> #include <ooxml/resourceids.hxx> #include "OOXMLStreamImpl.hxx" #include "OOXMLDocumentImpl.hxx" @@ -60,6 +61,7 @@ OOXMLDocumentImpl::OOXMLDocumentImpl(OOXMLStream::Pointer_t const & pStream, con , mnProgressEndPos(0) , m_rBaseURL(utl::MediaDescriptor(rDescriptor).getUnpackedValueOrDefault("DocumentBaseURL", OUString())) , maMediaDescriptor(rDescriptor) + , mxGraphicMapper(graphic::GraphicMapper::create(mpStream->getContext())) { pushShapeContext(); } diff --git a/writerfilter/source/ooxml/OOXMLDocumentImpl.hxx b/writerfilter/source/ooxml/OOXMLDocumentImpl.hxx index efaefd5f7d2a..1848f8971766 100644 --- a/writerfilter/source/ooxml/OOXMLDocumentImpl.hxx +++ b/writerfilter/source/ooxml/OOXMLDocumentImpl.hxx @@ -22,6 +22,7 @@ #include <ooxml/OOXMLDocument.hxx> #include <com/sun/star/xml/dom/XDocument.hpp> +#include <com/sun/star/graphic/XGraphicMapper.hpp> #include "OOXMLPropertySet.hxx" @@ -63,6 +64,8 @@ class OOXMLDocumentImpl : public OOXMLDocument /// DocumentBaseURL OUString m_rBaseURL; css::uno::Sequence<css::beans::PropertyValue> maMediaDescriptor; + /// Graphic mapper + css::uno::Reference<css::graphic::XGraphicMapper> mxGraphicMapper; private: void resolveFastSubStream(Stream & rStream, @@ -134,7 +137,13 @@ public: bool IsSkipImages() const { return mbSkipImages; }; OUString const& GetDocumentBaseURL() const { return m_rBaseURL; }; const css::uno::Sequence<css::beans::PropertyValue>& getMediaDescriptor() const; + + const css::uno::Reference<css::graphic::XGraphicMapper>& getGraphicMapper() const + { + return mxGraphicMapper; + } }; + } #endif // OOXML_DOCUMENT_IMPL_HXX diff --git a/writerfilter/source/ooxml/OOXMLFastContextHandler.cxx b/writerfilter/source/ooxml/OOXMLFastContextHandler.cxx index 938cbdf88812..104d3ad6a660 100644 --- a/writerfilter/source/ooxml/OOXMLFastContextHandler.cxx +++ b/writerfilter/source/ooxml/OOXMLFastContextHandler.cxx @@ -1670,6 +1670,11 @@ void OOXMLFastContextHandlerShape::setToken(Token_t nToken) mrShapeContext->setRelationFragmentPath(mpParserState->getTarget()); + auto xGraphicMapper = getDocument()->getGraphicMapper(); + + if (xGraphicMapper.is()) + mrShapeContext->setGraphicMapper(xGraphicMapper); + OOXMLFastContextHandler::setToken(nToken); if (mrShapeContext.is()) |