return unique_ptr from :svt::GraphicAccess::getImageStream

Change-Id: Ie63259ce826101e553c1cb03a85e7c0ba5f0f9f5
Reviewed-on: https://gerrit.libreoffice.org/78719
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
This commit is contained in:
Noel Grandin 2019-09-06 16:34:45 +02:00
parent 08e09136a6
commit f76a7bcc65
3 changed files with 9 additions and 9 deletions

View File

@ -206,7 +206,7 @@ void ImageProducer::SetImage( const OUString& rPath )
if ( ::svt::GraphicAccess::isSupportedURL( maURL ) ) if ( ::svt::GraphicAccess::isSupportedURL( maURL ) )
{ {
mpStm.reset( ::svt::GraphicAccess::getImageStream( ::comphelper::getProcessComponentContext(), maURL ) ); mpStm = ::svt::GraphicAccess::getImageStream( ::comphelper::getProcessComponentContext(), maURL );
} }
else if( !maURL.isEmpty() ) else if( !maURL.isEmpty() )
{ {

View File

@ -50,7 +50,7 @@ SVT_DLLPUBLIC bool isSupportedURL(OUString const & rURL);
the image must be copied), so you are strongly encouraged to only use it the image must be copied), so you are strongly encouraged to only use it
when you know that the image is small enough. when you know that the image is small enough.
*/ */
SVT_DLLPUBLIC SvStream* getImageStream( SVT_DLLPUBLIC std::unique_ptr<SvStream> getImageStream(
css::uno::Reference<css::uno::XComponentContext> const & rxContext, css::uno::Reference<css::uno::XComponentContext> const & rxContext,
OUString const & rImageResourceURL); OUString const & rImageResourceURL);

View File

@ -111,9 +111,9 @@ bool isSupportedURL(OUString const & rURL)
|| rURL.startsWith("vnd.sun.star.extension://"); || rURL.startsWith("vnd.sun.star.extension://");
} }
SvStream* getImageStream(uno::Reference<uno::XComponentContext> const & rxContext, OUString const & rImageResourceURL) std::unique_ptr<SvStream> getImageStream(uno::Reference<uno::XComponentContext> const & rxContext, OUString const & rImageResourceURL)
{ {
SvStream* pReturn = nullptr; std::unique_ptr<SvMemoryStream> pMemBuffer;
try try
{ {
@ -128,10 +128,10 @@ SvStream* getImageStream(uno::Reference<uno::XComponentContext> const & rxContex
OSL_ENSURE(xGraphic.is(), "GraphicAccess::getImageStream: the provider did not give us a graphic object!"); OSL_ENSURE(xGraphic.is(), "GraphicAccess::getImageStream: the provider did not give us a graphic object!");
if (!xGraphic.is()) if (!xGraphic.is())
return pReturn; return pMemBuffer;
// copy the graphic to an in-memory buffer // copy the graphic to an in-memory buffer
SvMemoryStream* pMemBuffer = new SvMemoryStream; pMemBuffer.reset(new SvMemoryStream);
uno::Reference<io::XStream> xBufferAccess = new StreamSupplier( uno::Reference<io::XStream> xBufferAccess = new StreamSupplier(
new OSeekableInputStreamWrapper(*pMemBuffer), new OSeekableInputStreamWrapper(*pMemBuffer),
new OSeekableOutputStreamWrapper(*pMemBuffer)); new OSeekableOutputStreamWrapper(*pMemBuffer));
@ -144,19 +144,19 @@ SvStream* getImageStream(uno::Reference<uno::XComponentContext> const & rxContex
xProvider->storeGraphic(xGraphic, aMediaProperties); xProvider->storeGraphic(xGraphic, aMediaProperties);
pMemBuffer->Seek(0); pMemBuffer->Seek(0);
pReturn = pMemBuffer;
} }
catch (const uno::Exception&) catch (const uno::Exception&)
{ {
OSL_FAIL("GraphicAccess::getImageStream: caught an exception!"); OSL_FAIL("GraphicAccess::getImageStream: caught an exception!");
pMemBuffer.reset();
} }
return pReturn; return pMemBuffer;
} }
uno::Reference<io::XInputStream> getImageXStream(uno::Reference<uno::XComponentContext> const & rxContext, OUString const & rImageResourceURL) uno::Reference<io::XInputStream> getImageXStream(uno::Reference<uno::XComponentContext> const & rxContext, OUString const & rImageResourceURL)
{ {
return new OSeekableInputStreamWrapper(getImageStream(rxContext, rImageResourceURL), true); // take ownership return new OSeekableInputStreamWrapper(getImageStream(rxContext, rImageResourceURL).release(), true); // take ownership
} }
} // namespace GraphicAccess } // namespace GraphicAccess