summaryrefslogtreecommitdiff
path: root/svtools
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2018-03-12 13:04:41 +0900
committerTomaž Vajngerl <quikee@gmail.com>2018-03-12 12:56:02 +0100
commitafea2bbcd5cb879d18cda6eae3dfe893f6044be4 (patch)
treeb4e635b61f748a5397fd3e503496650b71dd721f /svtools
parentab9eff78f05e71d4d853fe72c03823287b49c93b (diff)
svtools: cleanup GraphicAccess
Change-Id: I1eb2b5dd6859653594771d950992dfca38161446 Reviewed-on: https://gerrit.libreoffice.org/51104 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'svtools')
-rw-r--r--svtools/source/misc/imageresourceaccess.cxx241
1 files changed, 109 insertions, 132 deletions
diff --git a/svtools/source/misc/imageresourceaccess.cxx b/svtools/source/misc/imageresourceaccess.cxx
index 5c7ff0ec86ca..8cfabbc51c73 100644
--- a/svtools/source/misc/imageresourceaccess.cxx
+++ b/svtools/source/misc/imageresourceaccess.cxx
@@ -32,159 +32,136 @@
#include <cppuhelper/implbase.hxx>
#include <comphelper/processfactory.hxx>
-
namespace svt
{
+namespace GraphicAccess
+{
+using namespace ::utl;
+using namespace css;
- using namespace ::utl;
- using namespace ::com::sun::star::io;
- using namespace ::com::sun::star::uno;
- using namespace ::com::sun::star::lang;
- using namespace ::com::sun::star::beans;
- using namespace ::com::sun::star::graphic;
-
-
- //= StreamSupplier
-
- typedef ::cppu::WeakImplHelper < XStream
- , XSeekable
- > StreamSupplier_Base;
- class StreamSupplier : public StreamSupplier_Base
- {
- private:
- Reference< XInputStream > m_xInput;
- Reference< XOutputStream > m_xOutput;
- Reference< XSeekable > m_xSeekable;
-
- public:
- StreamSupplier( const Reference< XInputStream >& _rxInput, const Reference< XOutputStream >& _rxOutput );
-
- protected:
- // XStream
- virtual Reference< XInputStream > SAL_CALL getInputStream( ) override;
- virtual Reference< XOutputStream > SAL_CALL getOutputStream( ) override;
-
- // XSeekable
- virtual void SAL_CALL seek( ::sal_Int64 location ) override;
- virtual ::sal_Int64 SAL_CALL getPosition( ) override;
- virtual ::sal_Int64 SAL_CALL getLength( ) override;
- };
-
-
- StreamSupplier::StreamSupplier( const Reference< XInputStream >& _rxInput, const Reference< XOutputStream >& _rxOutput )
- :m_xInput( _rxInput )
- ,m_xOutput( _rxOutput )
- {
- m_xSeekable.set(m_xInput, css::uno::UNO_QUERY);
- if ( !m_xSeekable.is() )
- m_xSeekable.set(m_xOutput, css::uno::UNO_QUERY);
- OSL_ENSURE( m_xSeekable.is(), "StreamSupplier::StreamSupplier: at least one of both must be seekable!" );
- }
-
-
- Reference< XInputStream > SAL_CALL StreamSupplier::getInputStream( )
- {
- return m_xInput;
- }
-
-
- Reference< XOutputStream > SAL_CALL StreamSupplier::getOutputStream( )
- {
- return m_xOutput;
- }
-
-
- void SAL_CALL StreamSupplier::seek( ::sal_Int64 location )
- {
- if ( !m_xSeekable.is() )
- throw NotConnectedException();
-
- m_xSeekable->seek( location );
- }
+typedef ::cppu::WeakImplHelper<io::XStream, io::XSeekable> StreamSupplier_Base;
+class StreamSupplier : public StreamSupplier_Base
+{
+private:
+ uno::Reference<io::XInputStream> m_xInput;
+ uno::Reference<io::XOutputStream> m_xOutput;
+ uno::Reference<io::XSeekable> m_xSeekable;
+
+public:
+ StreamSupplier(uno::Reference<io::XInputStream> const & rxInput, uno::Reference<io::XOutputStream> const & rxOutput);
+
+protected:
+ // XStream
+ virtual uno::Reference<io::XInputStream> SAL_CALL getInputStream() override;
+ virtual uno::Reference<io::XOutputStream> SAL_CALL getOutputStream() override;
+
+ // XSeekable
+ virtual void SAL_CALL seek(sal_Int64 location) override;
+ virtual sal_Int64 SAL_CALL getPosition() override;
+ virtual sal_Int64 SAL_CALL getLength() override;
+};
+
+StreamSupplier::StreamSupplier(uno::Reference<io::XInputStream> const & rxInput, uno::Reference<io::XOutputStream> const & rxOutput)
+ : m_xInput(rxInput)
+ , m_xOutput(rxOutput)
+{
+ m_xSeekable.set(m_xInput, uno::UNO_QUERY);
+ if (!m_xSeekable.is())
+ m_xSeekable.set(m_xOutput, uno::UNO_QUERY);
+ OSL_ENSURE(m_xSeekable.is(), "StreamSupplier::StreamSupplier: at least one of both must be seekable!");
+}
- ::sal_Int64 SAL_CALL StreamSupplier::getPosition( )
- {
- if ( !m_xSeekable.is() )
- throw NotConnectedException();
+uno::Reference<io::XInputStream> SAL_CALL StreamSupplier::getInputStream()
+{
+ return m_xInput;
+}
- return m_xSeekable->getPosition();
- }
+uno::Reference<io::XOutputStream> SAL_CALL StreamSupplier::getOutputStream()
+{
+ return m_xOutput;
+}
+void SAL_CALL StreamSupplier::seek(sal_Int64 nLocation)
+{
+ if (!m_xSeekable.is())
+ throw io::NotConnectedException();
+ m_xSeekable->seek(nLocation);
+}
- ::sal_Int64 SAL_CALL StreamSupplier::getLength( )
- {
- if ( !m_xSeekable.is() )
- throw NotConnectedException();
+sal_Int64 SAL_CALL StreamSupplier::getPosition()
+{
+ if (!m_xSeekable.is())
+ throw io::NotConnectedException();
+ return m_xSeekable->getPosition();
+}
- return m_xSeekable->getLength();
- }
+sal_Int64 SAL_CALL StreamSupplier::getLength()
+{
+ if (!m_xSeekable.is())
+ throw io::NotConnectedException();
+ return m_xSeekable->getLength();
+}
- //= GraphicAccess
+bool isSupportedURL(OUString const & rURL)
+{
+ return rURL.startsWith("private:resource/")
+ || rURL.startsWith("private:graphicrepository/")
+ || rURL.startsWith("private:standardimage/")
+ || rURL.startsWith("vnd.sun.star.extension://");
+}
+SvStream* getImageStream(uno::Reference<uno::XComponentContext> const & rxContext, OUString const & rImageResourceURL)
+{
+ SvStream* pReturn = nullptr;
- bool GraphicAccess::isSupportedURL( const OUString& _rURL )
+ try
{
- return _rURL.startsWith( "private:resource/" )
- || _rURL.startsWith( "private:graphicrepository/" )
- || _rURL.startsWith( "private:standardimage/" )
- || _rURL.startsWith( "vnd.sun.star.extension://" );
+ // get a GraphicProvider
+ uno::Reference<graphic::XGraphicProvider> xProvider = css::graphic::GraphicProvider::create(rxContext);
+
+ // let it create a graphic from the given URL
+ uno::Sequence<beans::PropertyValue> aMediaProperties(1);
+ aMediaProperties[0].Name = "URL";
+ aMediaProperties[0].Value <<= rImageResourceURL;
+ uno::Reference<graphic::XGraphic> xGraphic(xProvider->queryGraphic(aMediaProperties));
+
+ OSL_ENSURE(xGraphic.is(), "GraphicAccess::getImageStream: the provider did not give us a graphic object!");
+ if (!xGraphic.is())
+ return pReturn;
+
+ // copy the graphic to a in-memory buffer
+ SvMemoryStream* pMemBuffer = new SvMemoryStream;
+ uno::Reference<io::XStream> xBufferAccess = new StreamSupplier(
+ new OSeekableInputStreamWrapper(*pMemBuffer),
+ new OSeekableOutputStreamWrapper(*pMemBuffer));
+
+ aMediaProperties.realloc(2);
+ aMediaProperties[0].Name = "OutputStream";
+ aMediaProperties[0].Value <<= xBufferAccess;
+ aMediaProperties[1].Name = "MimeType";
+ aMediaProperties[1].Value <<= OUString("image/png");
+ xProvider->storeGraphic(xGraphic, aMediaProperties);
+
+ pMemBuffer->Seek(0);
+ pReturn = pMemBuffer;
}
-
-
- SvStream* GraphicAccess::getImageStream( const Reference< XComponentContext >& _rxContext, const OUString& _rImageResourceURL )
+ catch (const uno::Exception&)
{
- SvStream* pReturn = nullptr;
-
- try
- {
- // get a GraphicProvider
- Reference< XGraphicProvider > xProvider = css::graphic::GraphicProvider::create(_rxContext);
-
- // let it create a graphic from the given URL
- Sequence< PropertyValue > aMediaProperties( 1 );
- aMediaProperties[0].Name = "URL";
- aMediaProperties[0].Value <<= _rImageResourceURL;
- Reference< XGraphic > xGraphic( xProvider->queryGraphic( aMediaProperties ) );
- OSL_ENSURE( xGraphic.is(), "GraphicAccess::getImageStream: the provider did not give us a graphic object!" );
- if ( !xGraphic.is() )
- return pReturn;
-
- // copy the graphic to a in-memory buffer
- SvMemoryStream* pMemBuffer = new SvMemoryStream;
- Reference< XStream > xBufferAccess = new StreamSupplier(
- new OSeekableInputStreamWrapper( *pMemBuffer ),
- new OSeekableOutputStreamWrapper( *pMemBuffer )
- );
-
- aMediaProperties.realloc( 2 );
- aMediaProperties[0].Name = "OutputStream";
- aMediaProperties[0].Value <<= xBufferAccess;
- aMediaProperties[1].Name = "MimeType";
- aMediaProperties[1].Value <<= OUString( "image/png" );
- xProvider->storeGraphic( xGraphic, aMediaProperties );
-
- pMemBuffer->Seek( 0 );
- pReturn = pMemBuffer;
- }
- catch( const Exception& )
- {
- OSL_FAIL( "GraphicAccess::getImageStream: caught an exception!" );
- }
-
- return pReturn;
+ OSL_FAIL("GraphicAccess::getImageStream: caught an exception!");
}
+ return pReturn;
+}
- Reference< XInputStream > GraphicAccess::getImageXStream( const Reference< XComponentContext >& _rxContext, const OUString& _rImageResourceURL )
- {
- return new OSeekableInputStreamWrapper( getImageStream( _rxContext, _rImageResourceURL ), true ); // take ownership
- }
-
+uno::Reference<io::XInputStream> getImageXStream(uno::Reference<uno::XComponentContext> const & rxContext, OUString const & rImageResourceURL)
+{
+ return new OSeekableInputStreamWrapper(getImageStream(rxContext, rImageResourceURL), true); // take ownership
+}
+} // namespace GraphicAccess
} // namespace svt
-
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */