[Libreoffice-commits] core.git: include/oox oox/source
Miklos Vajna
vmiklos at collabora.co.uk
Tue May 23 10:06:29 UTC 2017
include/oox/helper/graphichelper.hxx | 4 ++
oox/source/helper/graphichelper.cxx | 49 ++++++++++++++++++++++++++++++-----
2 files changed, 46 insertions(+), 7 deletions(-)
New commits:
commit b1319842a49cdf6512bbd9e81081e2a9edbd6089
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date: Tue May 23 10:20:03 2017 +0200
oox: add GraphicHelper::importGraphics()
Similar to GraphicHelper::importGraphic(), but can import multiple
streams with one function call.
Change-Id: I5fd398bb6649259e86967f8db5cc1e212f50bc8e
Reviewed-on: https://gerrit.libreoffice.org/37942
Reviewed-by: Miklos Vajna <vmiklos at collabora.co.uk>
Tested-by: Jenkins <ci at libreoffice.org>
diff --git a/include/oox/helper/graphichelper.hxx b/include/oox/helper/graphichelper.hxx
index 3102585ed881..17f896683ab4 100644
--- a/include/oox/helper/graphichelper.hxx
+++ b/include/oox/helper/graphichelper.hxx
@@ -114,6 +114,10 @@ public:
const css::uno::Reference< css::io::XInputStream >& rxInStrm,
const WMF_EXTERNALHEADER* pExtHeader = nullptr ) const;
+ /** Imports graphics from the passed input streams. */
+ std::vector< css::uno::Reference<css::graphic::XGraphic> >
+ importGraphics(const std::vector< css::uno::Reference<css::io::XInputStream> >& rStreams) const;
+
/** Imports a graphic from the passed binary memory block. */
css::uno::Reference< css::graphic::XGraphic >
importGraphic( const StreamDataSequence& rGraphicData ) const;
diff --git a/oox/source/helper/graphichelper.cxx b/oox/source/helper/graphichelper.cxx
index abe062cc82f4..7927daedd39e 100644
--- a/oox/source/helper/graphichelper.cxx
+++ b/oox/source/helper/graphichelper.cxx
@@ -36,6 +36,7 @@
#include <vcl/wmf.hxx>
#include <vcl/svapp.hxx>
#include <tools/gen.hxx>
+#include <comphelper/propertysequence.hxx>
#include "oox/helper/containerhelper.hxx"
#include "oox/helper/propertyset.hxx"
#include "oox/token/properties.hxx"
@@ -263,6 +264,34 @@ Reference< XGraphic > GraphicHelper::importGraphic( const Reference< XInputStrea
return xGraphic;
}
+std::vector< uno::Reference<graphic::XGraphic> > GraphicHelper::importGraphics(const std::vector< uno::Reference<io::XInputStream> >& rStreams) const
+{
+ std::vector< uno::Reference<graphic::XGraphic> > aRet;
+
+ for (const auto& rStream : rStreams)
+ {
+ uno::Reference<graphic::XGraphic> xGraphic;
+ if (rStream.is() && mxGraphicProvider.is())
+ {
+ try
+ {
+ uno::Sequence<beans::PropertyValue > aArgs = comphelper::InitPropertySequence(
+ {
+ {"InputStream", uno::makeAny(rStream)}
+ });
+ xGraphic = mxGraphicProvider->queryGraphic(aArgs);
+ }
+ catch( const uno::Exception& rException)
+ {
+ SAL_WARN("oox", "GraphicHelper::importGraphic: queryGraphics() failed: " << rException.Message);
+ }
+ }
+ aRet.push_back(xGraphic);
+ }
+
+ return aRet;
+}
+
Reference< XGraphic > GraphicHelper::importGraphic( const StreamDataSequence& rGraphicData ) const
{
Reference< XGraphic > xGraphic;
@@ -278,8 +307,9 @@ void GraphicHelper::importEmbeddedGraphics(const std::vector<OUString>& rStreamN
{
// Don't actually return anything, just fill maEmbeddedGraphics.
- // Input stream -> stream name map.
- std::map< uno::Reference<io::XInputStream>, OUString > aStreamNames;
+ // Stream names and streams to be imported.
+ std::vector<OUString> aMissingStreamNames;
+ std::vector< uno::Reference<io::XInputStream> > aMissingStreams;
for (const auto& rStreamName : rStreamNames)
{
@@ -291,14 +321,19 @@ void GraphicHelper::importEmbeddedGraphics(const std::vector<OUString>& rStreamN
EmbeddedGraphicMap::const_iterator aIt = maEmbeddedGraphics.find(rStreamName);
if (aIt == maEmbeddedGraphics.end())
- aStreamNames[mxStorage->openInputStream(rStreamName)] = rStreamName;
+ {
+ aMissingStreamNames.push_back(rStreamName);
+ aMissingStreams.push_back(mxStorage->openInputStream(rStreamName));
+ }
}
- for (const auto& rStream : aStreamNames)
+ std::vector< uno::Reference<graphic::XGraphic> > aGraphics = importGraphics(aMissingStreams);
+
+ assert(aGraphics.size() == aMissingStreamNames.size());
+ for (size_t i = 0; i < aGraphics.size(); ++i)
{
- uno::Reference<graphic::XGraphic> xGraphic = importGraphic(rStream.first);
- if (xGraphic.is())
- maEmbeddedGraphics[rStream.second] = xGraphic;
+ if (aGraphics[i].is())
+ maEmbeddedGraphics[aMissingStreamNames[i]] = aGraphics[i];
}
}
More information about the Libreoffice-commits
mailing list