diff options
author | Noel Grandin <noelgrandin@gmail.com> | 2023-12-30 15:08:30 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2023-12-30 19:05:29 +0100 |
commit | 04c3ef3c7224644b7e54ff215343391cef77f7b5 (patch) | |
tree | 27ba62d84f9ac6792cf457bc42818bf23fe6a7d6 | |
parent | 46b06663ae767d3423f2135fa91800cfa304877b (diff) |
ImgProdLockBytes is unnecessary
we already have facilities for doing this kind of wrapping
(removes another instance of SvLockBytes)
Change-Id: Ie3546efe06580f9492d8f6ddbc1a2e904036465a
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/161443
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
-rw-r--r-- | forms/source/component/imgprod.cxx | 149 | ||||
-rw-r--r-- | forms/source/component/imgprod.hxx | 4 |
2 files changed, 17 insertions, 136 deletions
diff --git a/forms/source/component/imgprod.cxx b/forms/source/component/imgprod.cxx index 002ef0cc56e8..d53796fc1f3a 100644 --- a/forms/source/component/imgprod.cxx +++ b/forms/source/component/imgprod.cxx @@ -32,133 +32,9 @@ #include <com/sun/star/io/XInputStream.hpp> #include <svtools/imageresourceaccess.hxx> +#include <unotools/ucbstreamhelper.hxx> #include <comphelper/processfactory.hxx> -namespace { - -class ImgProdLockBytes : public SvLockBytes -{ - css::uno::Reference< css::io::XInputStream > xStmRef; - css::uno::Sequence<sal_Int8> maSeq; - -public: - - ImgProdLockBytes( SvStream* pStm, bool bOwner ); - explicit ImgProdLockBytes( css::uno::Reference< css::io::XInputStream > xStreamRef ); - - virtual ErrCode ReadAt( sal_uInt64 nPos, void* pBuffer, std::size_t nCount, std::size_t * pRead ) const override; - virtual ErrCode WriteAt( sal_uInt64 nPos, const void* pBuffer, std::size_t nCount, std::size_t * pWritten ) override; - virtual ErrCode Flush() const override; - virtual ErrCode SetSize( sal_uInt64 nSize ) override; - virtual ErrCode Stat( SvLockBytesStat* ) const override; -}; - -} - -ImgProdLockBytes::ImgProdLockBytes( SvStream* pStm, bool bOwner ) : - SvLockBytes( pStm, bOwner ) -{ -} - - -ImgProdLockBytes::ImgProdLockBytes( css::uno::Reference< css::io::XInputStream > _xStmRef ) : - xStmRef(std::move( _xStmRef )) -{ - if( !xStmRef.is() ) - return; - - const sal_uInt32 nBytesToRead = 65535; - sal_uInt32 nRead; - - do - { - css::uno::Sequence< sal_Int8 > aReadSeq; - - nRead = xStmRef->readSomeBytes( aReadSeq, nBytesToRead ); - - if( nRead ) - { - const sal_uInt32 nOldLength = maSeq.getLength(); - maSeq.realloc( nOldLength + nRead ); - memcpy( maSeq.getArray() + nOldLength, aReadSeq.getConstArray(), aReadSeq.getLength() ); - } - } - while( nBytesToRead == nRead ); -} - -ErrCode ImgProdLockBytes::ReadAt(sal_uInt64 const nPos, - void* pBuffer, std::size_t nCount, std::size_t * pRead) const -{ - if( GetStream() ) - { - const_cast<SvStream*>(GetStream())->ResetError(); - const ErrCode nErr = SvLockBytes::ReadAt( nPos, pBuffer, nCount, pRead ); - const_cast<SvStream*>(GetStream())->ResetError(); - return nErr; - } - else - { - const std::size_t nSeqLen = maSeq.getLength(); - - if( nPos < nSeqLen ) - { - if( ( nPos + nCount ) > nSeqLen ) - nCount = nSeqLen - nPos; - - memcpy( pBuffer, maSeq.getConstArray() + nPos, nCount ); - *pRead = nCount; - } - else - *pRead = 0; - - return ERRCODE_NONE; - } -} - - -ErrCode ImgProdLockBytes::WriteAt(sal_uInt64 const nPos, - const void* pBuffer, std::size_t nCount, std::size_t * pWritten) -{ - if( GetStream() ) - return SvLockBytes::WriteAt( nPos, pBuffer, nCount, pWritten ); - else - { - DBG_ASSERT( xStmRef.is(), "ImgProdLockBytes::WriteAt: xInputStream has no reference..." ); - return ERRCODE_IO_CANTWRITE; - } -} - - -ErrCode ImgProdLockBytes::Flush() const -{ - return ERRCODE_NONE; -} - - -ErrCode ImgProdLockBytes::SetSize(sal_uInt64 const nSize) -{ - if( GetStream() ) - return SvLockBytes::SetSize( nSize ); - else - { - OSL_FAIL( "ImgProdLockBytes::SetSize not supported for xInputStream..." ); - return ERRCODE_IO_CANTWRITE; - } -} - - -ErrCode ImgProdLockBytes::Stat( SvLockBytesStat* pStat ) const -{ - if( GetStream() ) - return SvLockBytes::Stat( pStat ); - else - { - DBG_ASSERT( xStmRef.is(), "ImgProdLockBytes::Stat: xInputStream has no reference..." ); - pStat->nSize = maSeq.getLength(); - return ERRCODE_NONE; - } -} - ImageProducer::ImageProducer() : mnTransIndex(0) @@ -205,17 +81,18 @@ void ImageProducer::SetImage( const OUString& rPath ) maURL = rPath; moGraphic->Clear(); mbConsInit = false; - mpStm.reset(); + mxOwnedStream.reset(); + mpStm = nullptr; if ( ::svt::GraphicAccess::isSupportedURL( maURL ) ) { - mpStm = ::svt::GraphicAccess::getImageStream( ::comphelper::getProcessComponentContext(), maURL ); + mxOwnedStream = ::svt::GraphicAccess::getImageStream( ::comphelper::getProcessComponentContext(), maURL ); + mpStm = mxOwnedStream.get(); } else if( !maURL.isEmpty() ) { - std::unique_ptr<SvStream> pIStm = ::utl::UcbStreamHelper::CreateStream( maURL, StreamMode::STD_READ ); - if (pIStm) - mpStm.reset( new SvStream( new ImgProdLockBytes( pIStm.release(), true ) ) ); + mxOwnedStream = ::utl::UcbStreamHelper::CreateStream( maURL, StreamMode::STD_READ ); + mpStm = mxOwnedStream.get(); } } @@ -225,8 +102,8 @@ void ImageProducer::SetImage( SvStream& rStm ) maURL.clear(); moGraphic->Clear(); mbConsInit = false; - - mpStm.reset( new SvStream( new ImgProdLockBytes( &rStm, false ) ) ); + mxOwnedStream.reset(); + mpStm = &rStm; } @@ -235,10 +112,14 @@ void ImageProducer::setImage( css::uno::Reference< css::io::XInputStream > const maURL.clear(); moGraphic->Clear(); mbConsInit = false; - mpStm.reset(); + mxOwnedStream.reset(); + mpStm = nullptr; if( rInputStmRef.is() ) - mpStm.reset( new SvStream( new ImgProdLockBytes( rInputStmRef ) ) ); + { + mxOwnedStream = utl::UcbStreamHelper::CreateStream( rInputStmRef ); + mpStm = mxOwnedStream.get(); + } } diff --git a/forms/source/component/imgprod.hxx b/forms/source/component/imgprod.hxx index bfcb2c66b0ee..d1562caebf9f 100644 --- a/forms/source/component/imgprod.hxx +++ b/forms/source/component/imgprod.hxx @@ -48,8 +48,8 @@ private: ConsumerList_t maConsList; std::optional<Graphic> moGraphic; - std::unique_ptr<SvStream> - mpStm; + SvStream* mpStm; + std::unique_ptr<SvStream> mxOwnedStream; sal_uInt32 mnTransIndex; bool mbConsInit; Link<Graphic*,void> maDoneHdl; |