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 /vcl/source/graphic/UnoGraphicMapper.cxx | |
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 'vcl/source/graphic/UnoGraphicMapper.cxx')
-rw-r--r-- | vcl/source/graphic/UnoGraphicMapper.cxx | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/vcl/source/graphic/UnoGraphicMapper.cxx b/vcl/source/graphic/UnoGraphicMapper.cxx new file mode 100644 index 000000000000..6bde78097681 --- /dev/null +++ b/vcl/source/graphic/UnoGraphicMapper.cxx @@ -0,0 +1,87 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include <com/sun/star/uno/XComponentContext.hpp> +#include <com/sun/star/lang/XServiceInfo.hpp> +#include <com/sun/star/graphic/XGraphicMapper.hpp> +#include <com/sun/star/graphic/XGraphic.hpp> +#include <cppuhelper/implbase.hxx> +#include <cppuhelper/supportsservice.hxx> +#include <comphelper/unique_disposing_ptr.hxx> + +#include <memory> +#include <unordered_map> + +using namespace css; + +namespace +{ +class GraphicMapper : public cppu::WeakImplHelper<graphic::XGraphicMapper, lang::XServiceInfo> +{ +private: + std::unordered_map<OUString, uno::Reference<graphic::XGraphic>> maGraphicMap; + +public: + GraphicMapper() = default; + +protected: + // XServiceInfo + OUString SAL_CALL getImplementationName() override + { + return "com.sun.star.comp.graphic.GraphicMapper"; + } + sal_Bool SAL_CALL supportsService(const OUString& ServiceName) override + { + return cppu::supportsService(this, ServiceName); + } + css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames() override + { + return { "com.sun.star.graphic.GraphicMapper" }; + } + + // XTypeProvider + css::uno::Sequence<css::uno::Type> SAL_CALL getTypes() override + { + static const uno::Sequence<uno::Type> aTypes{ + cppu::UnoType<lang::XServiceInfo>::get(), cppu::UnoType<lang::XTypeProvider>::get(), + cppu::UnoType<graphic::XGraphicMapper>::get() + }; + return aTypes; + } + css::uno::Sequence<sal_Int8> SAL_CALL getImplementationId() override + { + return css::uno::Sequence<sal_Int8>(); + } + + // XGraphicMapper + css::uno::Reference<css::graphic::XGraphic> SAL_CALL findGraphic(const OUString& rId) override + { + auto aIterator = maGraphicMap.find(rId); + + if (aIterator == maGraphicMap.end()) + return css::uno::Reference<css::graphic::XGraphic>(); + + return aIterator->second; + } + void SAL_CALL putGraphic(const OUString& rId, + css::uno::Reference<css::graphic::XGraphic> const& rGraphic) override + { + maGraphicMap.emplace(rId, rGraphic); + } +}; +} + +extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface* +com_sun_star_comp_graphic_GraphicMapper_get_implementation(css::uno::XComponentContext*, + css::uno::Sequence<css::uno::Any> const&) +{ + return cppu::acquire(new GraphicMapper); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |