From afa3dff9c7b963f1d312ef8c2efcbc8ab7271e62 Mon Sep 17 00:00:00 2001 From: Luboš Luňák Date: Fri, 18 Dec 2020 11:17:53 +0100 Subject: do not preload all images in the pptx importer MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Now with my GraphicFilter::MakeGraphicsAvailableThreaded() patches for Impress images will be loaded in parallel as they are needed, which should usually be more efficient than loading all of them immediately. This basically reverts commits: b1319842a49cdf6512bbd9e81081e2a9edbd6089 04e27df3c162f1df02f061b94434a38d1eaa3a46 9eb8e2737d3a4d52ce1b0cc44091a3b7ecf59e3b Change-Id: I46bb0d6d93fb69f03f464308f6fce1603aafdfd8 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/107945 Tested-by: Luboš Luňák Reviewed-by: Luboš Luňák --- include/oox/helper/graphichelper.hxx | 7 ---- oox/source/helper/graphichelper.cxx | 67 ------------------------------------ oox/source/ppt/pptimport.cxx | 41 ---------------------- 3 files changed, 115 deletions(-) diff --git a/include/oox/helper/graphichelper.hxx b/include/oox/helper/graphichelper.hxx index 9a99647589b2..50c54175db93 100644 --- a/include/oox/helper/graphichelper.hxx +++ b/include/oox/helper/graphichelper.hxx @@ -113,10 +113,6 @@ public: const css::uno::Reference< css::io::XInputStream >& rxInStrm, const WmfExternal* pExtHeader = nullptr ) const; - /** Imports graphics from the passed input streams. */ - std::vector< css::uno::Reference > - importGraphics(const std::vector< css::uno::Reference >& rStreams) const; - /** Imports a graphic from the passed binary memory block. */ css::uno::Reference< css::graphic::XGraphic > importGraphic( const StreamDataSequence& rGraphicData ) const; @@ -127,9 +123,6 @@ public: const OUString& rStreamName, const WmfExternal* pExtHeader = nullptr ) const; - /** Imports graphics from the storage with the passed stream names. */ - void importEmbeddedGraphics(const std::vector& rStreamNames) const; - /** calculates the original size of a graphic which is necessary to be able to calculate cropping values @return The original Graphic size in 100thmm */ css::awt::Size getOriginalSize( const css::uno::Reference< css::graphic::XGraphic >& rxGraphic ) const; diff --git a/oox/source/helper/graphichelper.cxx b/oox/source/helper/graphichelper.cxx index e8a1c94326a7..82978a76451e 100644 --- a/oox/source/helper/graphichelper.cxx +++ b/oox/source/helper/graphichelper.cxx @@ -35,7 +35,6 @@ #include #include #include -#include #include #include #include @@ -277,27 +276,6 @@ Reference< XGraphic > GraphicHelper::importGraphic( const Reference< XInputStrea return xGraphic; } -std::vector< uno::Reference > GraphicHelper::importGraphics(const std::vector< uno::Reference >& rStreams) const -{ - std::vector< uno::Sequence > aArgsVec; - - for (const auto& rStream : rStreams) - { - uno::Sequence aArgs = comphelper::InitPropertySequence( - { - {"InputStream", uno::makeAny(rStream)} - }); - aArgsVec.push_back(aArgs); - } - - std::vector< uno::Reference > aRet; - - if (mxGraphicProvider.is()) - aRet = comphelper::sequenceToContainer< std::vector< uno::Reference > >(mxGraphicProvider->queryGraphics(comphelper::containerToSequence(aArgsVec))); - - return aRet; -} - Reference< XGraphic > GraphicHelper::importGraphic( const StreamDataSequence& rGraphicData ) const { Reference< XGraphic > xGraphic; @@ -309,51 +287,6 @@ Reference< XGraphic > GraphicHelper::importGraphic( const StreamDataSequence& rG return xGraphic; } -void GraphicHelper::importEmbeddedGraphics(const std::vector& rStreamNames) const -{ - // Don't actually return anything, just fill maEmbeddedGraphics. - - // Stream names and streams to be imported. - std::vector aMissingStreamNames; - std::vector< uno::Reference > aMissingStreams; - - initializeGraphicMapperIfNeeded(); - - SAL_WARN_IF(!mxGraphicMapper.is(), "oox", "GraphicHelper::importEmbeddedGraphic - graphic mapper not available"); - - for (const auto& rStreamName : rStreamNames) - { - - if (rStreamName.isEmpty()) - { - SAL_WARN("oox", "GraphicHelper::importEmbeddedGraphics - empty stream name"); - continue; - } - - Reference xGraphic; - - xGraphic = mxGraphicMapper->findGraphic(rStreamName); - - if (!xGraphic.is()) - { - aMissingStreamNames.push_back(rStreamName); - aMissingStreams.push_back(mxStorage->openInputStream(rStreamName)); - } - } - - std::vector< uno::Reference > aGraphics = importGraphics(aMissingStreams); - - - assert(aGraphics.size() == aMissingStreamNames.size()); - for (size_t i = 0; i < aGraphics.size(); ++i) - { - if (aGraphics[i].is()) - { - mxGraphicMapper->putGraphic(aMissingStreamNames[i], aGraphics[i]); - } - } -} - Reference< XGraphic > GraphicHelper::importEmbeddedGraphic( const OUString& rStreamName, const WmfExternal* pExtHeader ) const { Reference< XGraphic > xGraphic; diff --git a/oox/source/ppt/pptimport.cxx b/oox/source/ppt/pptimport.cxx index f7d00920705e..98a855c77fa4 100644 --- a/oox/source/ppt/pptimport.cxx +++ b/oox/source/ppt/pptimport.cxx @@ -73,37 +73,6 @@ PowerPointImport::~PowerPointImport() maPPTShapes.clear(); } -/// Visits the relations from pRelations which are of type rType. -static void visitRelations(PowerPointImport& rImport, const core::RelationsRef& pRelations, const OUString& rType, std::vector& rImageFragments) -{ - core::RelationsRef pRelationsOfType = pRelations->getRelationsFromTypeFromOfficeDoc(rType); - if (!pRelationsOfType) - return; - - for (const auto& rRelation : *pRelationsOfType) - { - OUString aFragment = pRelationsOfType->getFragmentPathFromRelation(rRelation.second); - if (core::RelationsRef pFragmentRelations = rImport.importRelations(aFragment)) - { - // See if the fragment has images. - if (core::RelationsRef pImages = pFragmentRelations->getRelationsFromTypeFromOfficeDoc("image")) - { - for (const auto& rImage : *pImages) - { - OUString aPath = pImages->getFragmentPathFromRelation(rImage.second); - // Safe subset: e.g. WMF may have an external header from the - // referencing fragment. - if (aPath.endsWith(".jpg") || aPath.endsWith(".jpeg")) - rImageFragments.push_back(aPath); - } - } - - // See if the fragment has a slide layout, and recurse. - visitRelations(rImport, pFragmentRelations, "slideLayout", rImageFragments); - } - } -} - bool PowerPointImport::importDocument() { /* to activate the PPTX dumper, define the environment variable @@ -132,16 +101,6 @@ bool PowerPointImport::importDocument() const OUString sPresPropsPath = xPresentationFragmentHandler->getFragmentPathFromFirstTypeFromOfficeDoc("presProps"); - // importRelations() is cheap, it will do an actual import for the first time only. - if (core::RelationsRef pFragmentRelations = importRelations(aFragmentPath)) - { - std::vector aImageFragments; - visitRelations(*this, pFragmentRelations, "slide", aImageFragments); - visitRelations(*this, pFragmentRelations, "slideMaster", aImageFragments); - - getGraphicHelper().importEmbeddedGraphics(aImageFragments); - } - bool bRet = importFragment(xPresentationFragmentHandler); if (bRet && !sPresPropsPath.isEmpty()) { -- cgit