include/oox/helper/graphichelper.hxx | 3 +++ oox/source/helper/graphichelper.cxx | 28 ++++++++++++++++++++++++++++ oox/source/ppt/pptimport.cxx | 16 ++++++++-------- 3 files changed, 39 insertions(+), 8 deletions(-)
New commits: commit 04e27df3c162f1df02f061b94434a38d1eaa3a46 Author: Miklos Vajna <[email protected]> Date: Tue May 23 09:25:37 2017 +0200 oox: add GraphicHelper::importEmbeddedGraphics() Similar to GraphicHelper::importEmbeddedGraphic(), but it takes a list of image paths to import. Change-Id: I11b670a0b2c693540054c78be2cee3835477b7e6 Reviewed-on: https://gerrit.libreoffice.org/37938 Reviewed-by: Miklos Vajna <[email protected]> Tested-by: Jenkins <[email protected]> diff --git a/include/oox/helper/graphichelper.hxx b/include/oox/helper/graphichelper.hxx index 41a1ed76aac1..3102585ed881 100644 --- a/include/oox/helper/graphichelper.hxx +++ b/include/oox/helper/graphichelper.hxx @@ -124,6 +124,9 @@ public: const OUString& rStreamName, const WMF_EXTERNALHEADER* pExtHeader = nullptr ) const; + /** Imports graphics from the storage with the passed stream names. */ + void importEmbeddedGraphics(const std::vector<OUString>& rStreamNames) const; + /** Creates a persistent graphic object from the passed graphic. @return The URL of the created and internally cached graphic object. */ OUString createGraphicObject( diff --git a/oox/source/helper/graphichelper.cxx b/oox/source/helper/graphichelper.cxx index f4ac89353b57..abe062cc82f4 100644 --- a/oox/source/helper/graphichelper.cxx +++ b/oox/source/helper/graphichelper.cxx @@ -274,6 +274,34 @@ Reference< XGraphic > GraphicHelper::importGraphic( const StreamDataSequence& rG return xGraphic; } +void GraphicHelper::importEmbeddedGraphics(const std::vector<OUString>& rStreamNames) const +{ + // Don't actually return anything, just fill maEmbeddedGraphics. + + // Input stream -> stream name map. + std::map< uno::Reference<io::XInputStream>, OUString > aStreamNames; + + for (const auto& rStreamName : rStreamNames) + { + if(rStreamName.isEmpty()) + { + SAL_WARN("oox", "GraphicHelper::importEmbeddedGraphics - empty stream name"); + continue; + } + + EmbeddedGraphicMap::const_iterator aIt = maEmbeddedGraphics.find(rStreamName); + if (aIt == maEmbeddedGraphics.end()) + aStreamNames[mxStorage->openInputStream(rStreamName)] = rStreamName; + } + + for (const auto& rStream : aStreamNames) + { + uno::Reference<graphic::XGraphic> xGraphic = importGraphic(rStream.first); + if (xGraphic.is()) + maEmbeddedGraphics[rStream.second] = xGraphic; + } +} + Reference< XGraphic > GraphicHelper::importEmbeddedGraphic( const OUString& rStreamName, const WMF_EXTERNALHEADER* pExtHeader ) const { Reference< XGraphic > xGraphic; diff --git a/oox/source/ppt/pptimport.cxx b/oox/source/ppt/pptimport.cxx index 74285e7dbe97..474abb6278e2 100644 --- a/oox/source/ppt/pptimport.cxx +++ b/oox/source/ppt/pptimport.cxx @@ -100,7 +100,13 @@ static void visitRelations(PowerPointImport& rImport, core::RelationsRef pRelati if (core::RelationsRef pImages = pFragmentRelations->getRelationsFromTypeFromOfficeDoc("image")) { for (const auto& rImage : *pImages) - rImageFragments.push_back(pImages->getFragmentPathFromRelation(rImage.second)); + { + 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. @@ -130,13 +136,7 @@ bool PowerPointImport::importDocument() visitRelations(*this, pFragmentRelations, "slide", aImageFragments); visitRelations(*this, pFragmentRelations, "slideMaster", aImageFragments); - for (const auto& rImage : aImageFragments) - { - // Safe subset: e.g. WMF may have an external header from the - // referencing fragment. - if (rImage.endsWith(".jpg") || rImage.endsWith(".jpeg")) - getGraphicHelper().importEmbeddedGraphic(rImage); - } + getGraphicHelper().importEmbeddedGraphics(aImageFragments); } bool bRet = importFragment(xPresentationFragmentHandler); _______________________________________________ Libreoffice-commits mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
