[Libreoffice-commits] core.git: include/vcl svtools/source vcl/source
Miklos Vajna
vmiklos at collabora.co.uk
Tue May 23 14:37:02 UTC 2017
include/vcl/graphicfilter.hxx | 5 ++++
svtools/source/graphic/provider.cxx | 42 ++++++++++++++++++++++++++++++++++--
vcl/source/filter/graphicfilter.cxx | 17 ++++++++++++++
3 files changed, 62 insertions(+), 2 deletions(-)
New commits:
commit 6a91ea82502c0b9e6632d625962bf9da006c4a2f
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date: Tue May 23 15:26:14 2017 +0200
vcl GraphicFilter: add ImportGraphics()
This is similar to ImportGraphic(), but can handle multiple streams with
one function call.
Change-Id: I8d5dc8de64321c3c1fb9e1037527b411fd68dca8
Reviewed-on: https://gerrit.libreoffice.org/37953
Reviewed-by: Miklos Vajna <vmiklos at collabora.co.uk>
Tested-by: Jenkins <ci at libreoffice.org>
diff --git a/include/vcl/graphicfilter.hxx b/include/vcl/graphicfilter.hxx
index 8b8a7cef3008..c4c6c4359ce9 100644
--- a/include/vcl/graphicfilter.hxx
+++ b/include/vcl/graphicfilter.hxx
@@ -283,6 +283,11 @@ public:
sal_uInt16 * pDeterminedFormat = nullptr, GraphicFilterImportFlags nImportFlags = GraphicFilterImportFlags::NONE,
WMF_EXTERNALHEADER *pExtHeader = nullptr );
+ /// Imports multiple graphics.
+ ///
+ /// The resulting graphic is added to rGraphics on success, nullptr is added on failure.
+ void ImportGraphics(std::vector< std::shared_ptr<Graphic> >& rGraphics, const std::vector< std::shared_ptr<SvStream> >& rStreams);
+
sal_uInt16 ImportGraphic( Graphic& rGraphic, const OUString& rPath,
SvStream& rStream,
sal_uInt16 nFormat,
diff --git a/svtools/source/graphic/provider.cxx b/svtools/source/graphic/provider.cxx
index faec3fcd4d9b..fa34c5c712d6 100644
--- a/svtools/source/graphic/provider.cxx
+++ b/svtools/source/graphic/provider.cxx
@@ -438,11 +438,49 @@ uno::Reference< ::graphic::XGraphic > SAL_CALL GraphicProvider::queryGraphic( co
uno::Sequence< uno::Reference<graphic::XGraphic> > SAL_CALL GraphicProvider::queryGraphics(const uno::Sequence< uno::Sequence<beans::PropertyValue> >& rMediaPropertiesSeq)
{
- std::vector< uno::Reference<graphic::XGraphic> > aRet;
+ SolarMutexGuard aGuard;
+ // Turn properties into streams.
+ std::vector< std::shared_ptr<SvStream> > aStreams;
for (const auto& rMediaProperties : rMediaPropertiesSeq)
{
- aRet.push_back(queryGraphic(rMediaProperties));
+ SvStream* pStream = nullptr;
+ uno::Reference<io::XInputStream> xStream;
+
+ for (sal_Int32 i = 0; rMediaProperties.getLength(); ++i)
+ {
+ if (rMediaProperties[i].Name == "InputStream")
+ {
+ rMediaProperties[i].Value >>= xStream;
+ if (xStream.is())
+ pStream = utl::UcbStreamHelper::CreateStream(xStream);
+ break;
+ }
+ }
+
+ aStreams.push_back(std::shared_ptr<SvStream>(pStream));
+
+ }
+
+ // Import: streams to graphics.
+ std::vector< std::shared_ptr<Graphic> > aGraphics;
+ GraphicFilter& rFilter = GraphicFilter::GetGraphicFilter();
+ rFilter.ImportGraphics(aGraphics, aStreams);
+
+ // Returning: graphics to UNO objects.
+ std::vector< uno::Reference<graphic::XGraphic> > aRet;
+ for (const auto& pGraphic : aGraphics)
+ {
+ uno::Reference<graphic::XGraphic> xGraphic;
+
+ if (pGraphic)
+ {
+ auto pUnoGraphic = new unographic::Graphic();
+ pUnoGraphic->init(*pGraphic);
+ xGraphic = pUnoGraphic;
+ }
+
+ aRet.push_back(xGraphic);
}
return comphelper::containerToSequence(aRet);
diff --git a/vcl/source/filter/graphicfilter.cxx b/vcl/source/filter/graphicfilter.cxx
index d17f77027d32..da1396aa31f3 100644
--- a/vcl/source/filter/graphicfilter.cxx
+++ b/vcl/source/filter/graphicfilter.cxx
@@ -1316,6 +1316,23 @@ sal_uInt16 GraphicFilter::ImportGraphic( Graphic& rGraphic, const OUString& rPat
return ImportGraphic( rGraphic, rPath, rIStream, nFormat, pDeterminedFormat, nImportFlags, nullptr, pExtHeader );
}
+void GraphicFilter::ImportGraphics(std::vector< std::shared_ptr<Graphic> >& rGraphics, const std::vector< std::shared_ptr<SvStream> >& rStreams)
+{
+ for (const auto& pStream : rStreams)
+ {
+ Graphic* pGraphic = nullptr;
+
+ if (pStream)
+ {
+ auto pG = o3tl::make_unique<Graphic>();
+ if (ImportGraphic(*pG, "", *pStream) == GRFILTER_OK)
+ pGraphic = pG.release();
+ }
+
+ rGraphics.push_back(std::shared_ptr<Graphic>(pGraphic));
+ }
+}
+
sal_uInt16 GraphicFilter::ImportGraphic( Graphic& rGraphic, const OUString& rPath, SvStream& rIStream,
sal_uInt16 nFormat, sal_uInt16* pDeterminedFormat, GraphicFilterImportFlags nImportFlags,
css::uno::Sequence< css::beans::PropertyValue >* pFilterData,
More information about the Libreoffice-commits
mailing list