diff options
author | Noel Grandin <noelgrandin@gmail.com> | 2018-10-11 18:49:34 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2018-10-15 07:56:42 +0200 |
commit | 9ec8bf8f22fe74884185492ef2576ce79b41e4f1 (patch) | |
tree | 0b162c71c51a55125a2ce6055632d4f96180f431 /vcl | |
parent | a84e3df74eecc8778e3d5be5dd80ad4ddb511edf (diff) |
add SvStream::TellEnd
and simplify callsites to use it instead of the current
"seek to end, find pos, seek back to original pos"
pattern
Change-Id: Ib5828868f73c341891efc759af8bd4695ae2f33c
Reviewed-on: https://gerrit.libreoffice.org/61738
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'vcl')
-rw-r--r-- | vcl/source/edit/textview.cxx | 3 | ||||
-rw-r--r-- | vcl/source/filter/graphicfilter.cxx | 19 | ||||
-rw-r--r-- | vcl/source/filter/ipdf/pdfdocument.cxx | 3 | ||||
-rw-r--r-- | vcl/source/filter/ipdf/pdfread.cxx | 6 | ||||
-rw-r--r-- | vcl/source/filter/jpeg/Exif.cxx | 3 | ||||
-rw-r--r-- | vcl/source/filter/wmf/wmf.cxx | 3 | ||||
-rw-r--r-- | vcl/source/gdi/gdimetafiletools.cxx | 4 | ||||
-rw-r--r-- | vcl/source/gdi/pdfwriter_impl.cxx | 19 | ||||
-rw-r--r-- | vcl/source/gdi/pdfwriter_impl2.cxx | 3 | ||||
-rw-r--r-- | vcl/source/gdi/pngread.cxx | 5 | ||||
-rw-r--r-- | vcl/source/graphic/UnoGraphicProvider.cxx | 3 | ||||
-rw-r--r-- | vcl/unx/gtk/gtksalmenu.cxx | 2 | ||||
-rw-r--r-- | vcl/unx/gtk3/gtk3gtkinst.cxx | 2 |
13 files changed, 24 insertions, 51 deletions
diff --git a/vcl/source/edit/textview.cxx b/vcl/source/edit/textview.cxx index 5eb59e3eac9e..54757b008881 100644 --- a/vcl/source/edit/textview.cxx +++ b/vcl/source/edit/textview.cxx @@ -88,8 +88,7 @@ css::uno::Any TETextDataObject::getTransferData( const css::datatransfer::DataFl } else if ( nT == SotClipboardFormatId::HTML ) { - GetHTMLStream().Seek( STREAM_SEEK_TO_END ); - sal_uLong nLen = GetHTMLStream().Tell(); + sal_uLong nLen = GetHTMLStream().TellEnd(); GetHTMLStream().Seek(0); css::uno::Sequence< sal_Int8 > aSeq( nLen ); diff --git a/vcl/source/filter/graphicfilter.cxx b/vcl/source/filter/graphicfilter.cxx index 6cd6043dba9e..6eaccfbc37ee 100644 --- a/vcl/source/filter/graphicfilter.cxx +++ b/vcl/source/filter/graphicfilter.cxx @@ -244,10 +244,7 @@ static bool ImpPeekGraphicFormat( SvStream& rStream, OUString& rFormatExtension, sal_uInt8 sFirstBytes[ 256 ]; sal_uLong nFirstLong(0), nSecondLong(0); sal_uLong nStreamPos = rStream.Tell(); - - rStream.Seek( STREAM_SEEK_TO_END ); - sal_uLong nStreamLen = rStream.Tell() - nStreamPos; - rStream.Seek( nStreamPos ); + sal_uLong nStreamLen = rStream.remainingSize(); if ( !nStreamLen ) { @@ -255,9 +252,7 @@ static bool ImpPeekGraphicFormat( SvStream& rStream, OUString& rFormatExtension, if ( pLockBytes ) pLockBytes->SetSynchronMode(); - rStream.Seek( STREAM_SEEK_TO_END ); - nStreamLen = rStream.Tell() - nStreamPos; - rStream.Seek( nStreamPos ); + nStreamLen = rStream.remainingSize(); } if (!nStreamLen) @@ -1448,7 +1443,7 @@ Graphic GraphicFilter::ImportUnloadedGraphic(SvStream& rIStream) ErrCode nStatus = ImpTestOrFindFormat("", rIStream, nFormat); rIStream.Seek(nStreamBegin); - const sal_uInt32 nStreamLength(rIStream.Seek(STREAM_SEEK_TO_END) - nStreamBegin); + const sal_uInt32 nStreamLength(rIStream.remainingSize()); OUString aFilterName = pConfig->GetImportFilterName(nFormat); OUString aExternalFilterName = pConfig->GetExternalFilterName(nFormat, false); @@ -1849,14 +1844,13 @@ ErrCode GraphicFilter::ImportGraphic( Graphic& rGraphic, const OUString& rPath, else if( aFilterName.equalsIgnoreAsciiCase( IMP_SVG ) ) { const sal_uInt32 nStreamPosition(rIStream.Tell()); - const sal_uInt32 nStreamLength(rIStream.Seek(STREAM_SEEK_TO_END) - nStreamPosition); + const sal_uInt32 nStreamLength(rIStream.remainingSize()); bool bOkay(false); if(nStreamLength > 0) { std::vector<sal_uInt8> aTwoBytes(2); - rIStream.Seek(nStreamPosition); rIStream.ReadBytes(&aTwoBytes[0], 2); rIStream.Seek(nStreamPosition); @@ -1892,7 +1886,6 @@ ErrCode GraphicFilter::ImportGraphic( Graphic& rGraphic, const OUString& rPath, else { VectorGraphicDataArray aNewData(nStreamLength); - rIStream.Seek(nStreamPosition); rIStream.ReadBytes(aNewData.begin(), nStreamLength); if(!rIStream.GetError()) @@ -1957,12 +1950,10 @@ ErrCode GraphicFilter::ImportGraphic( Graphic& rGraphic, const OUString& rPath, // Graphic that contains the original data and decomposes to // primitives on demand - const sal_uInt32 nStreamPosition(rIStream.Tell()); - const sal_uInt32 nStreamLength(rIStream.Seek(STREAM_SEEK_TO_END) - nStreamPosition); + const sal_uInt32 nStreamLength(rIStream.remainingSize()); VectorGraphicDataArray aNewData(nStreamLength); bool bOkay(false); - rIStream.Seek(nStreamPosition); rIStream.ReadBytes(aNewData.begin(), nStreamLength); if (!rIStream.GetError()) diff --git a/vcl/source/filter/ipdf/pdfdocument.cxx b/vcl/source/filter/ipdf/pdfdocument.cxx index c74bcbbade84..09cafdea9f45 100644 --- a/vcl/source/filter/ipdf/pdfdocument.cxx +++ b/vcl/source/filter/ipdf/pdfdocument.cxx @@ -2638,8 +2638,7 @@ void PDFObjectElement::ParseStoredObjects() return; } - aStream.Seek(STREAM_SEEK_TO_END); - nLength = aStream.Tell(); + nLength = aStream.TellEnd(); aStream.Seek(0); std::vector<size_t> aObjNums; std::vector<size_t> aOffsets; diff --git a/vcl/source/filter/ipdf/pdfread.cxx b/vcl/source/filter/ipdf/pdfread.cxx index 0f14529eec5c..9815e89a1a2b 100644 --- a/vcl/source/filter/ipdf/pdfread.cxx +++ b/vcl/source/filter/ipdf/pdfread.cxx @@ -231,8 +231,7 @@ bool ImportPDF(SvStream& rStream, Bitmap& rBitmap, size_t nPageIndex, if (!getCompatibleStream(rStream, aMemoryStream, nPos, nSize)) return false; - aMemoryStream.Seek(STREAM_SEEK_TO_END); - rPdfData = css::uno::Sequence<sal_Int8>(aMemoryStream.Tell()); + rPdfData = css::uno::Sequence<sal_Int8>(aMemoryStream.TellEnd()); aMemoryStream.Seek(STREAM_SEEK_TO_BEGIN); aMemoryStream.ReadBytes(rPdfData.getArray(), rPdfData.getLength()); @@ -267,8 +266,7 @@ size_t ImportPDF(const OUString& rURL, std::vector<Bitmap>& rBitmaps, if (!getCompatibleStream(*xStream, aMemoryStream, STREAM_SEEK_TO_BEGIN, STREAM_SEEK_TO_END)) return 0; - aMemoryStream.Seek(STREAM_SEEK_TO_END); - rPdfData = css::uno::Sequence<sal_Int8>(aMemoryStream.Tell()); + rPdfData = css::uno::Sequence<sal_Int8>(aMemoryStream.TellEnd()); aMemoryStream.Seek(STREAM_SEEK_TO_BEGIN); aMemoryStream.ReadBytes(rPdfData.getArray(), rPdfData.getLength()); diff --git a/vcl/source/filter/jpeg/Exif.cxx b/vcl/source/filter/jpeg/Exif.cxx index c695a3a92983..725ebe1ae27e 100644 --- a/vcl/source/filter/jpeg/Exif.cxx +++ b/vcl/source/filter/jpeg/Exif.cxx @@ -87,8 +87,7 @@ bool Exif::processJpeg(SvStream& rStream, bool bSetValue) sal_uInt16 aMagic16; sal_uInt16 aLength; - rStream.Seek(STREAM_SEEK_TO_END); - sal_uInt32 aSize = rStream.Tell(); + sal_uInt32 aSize = rStream.TellEnd(); rStream.Seek(STREAM_SEEK_TO_BEGIN); rStream.SetEndian( SvStreamEndian::BIG ); diff --git a/vcl/source/filter/wmf/wmf.cxx b/vcl/source/filter/wmf/wmf.cxx index 4bc8d11a6a01..05939e734483 100644 --- a/vcl/source/filter/wmf/wmf.cxx +++ b/vcl/source/filter/wmf/wmf.cxx @@ -31,7 +31,7 @@ bool ReadWindowMetafile( SvStream& rStream, GDIMetaFile& rMTF ) // is nice enough to copy to an own MemStream to avoid that indirect // parameter passing...) const sal_uInt32 nStreamStart(rStream.Tell()); - const sal_uInt32 nStreamEnd(rStream.Seek(STREAM_SEEK_TO_END)); + const sal_uInt32 nStreamEnd(rStream.TellEnd()); if (nStreamStart >= nStreamEnd) { @@ -41,7 +41,6 @@ bool ReadWindowMetafile( SvStream& rStream, GDIMetaFile& rMTF ) // Read binary data to mem array const sal_uInt32 nStreamLength(nStreamEnd - nStreamStart); VectorGraphicDataArray aNewData(nStreamLength); - rStream.Seek(nStreamStart); rStream.ReadBytes(aNewData.begin(), nStreamLength); rStream.Seek(nStreamStart); diff --git a/vcl/source/gdi/gdimetafiletools.cxx b/vcl/source/gdi/gdimetafiletools.cxx index 7420e65bcdce..1f9f610f14ef 100644 --- a/vcl/source/gdi/gdimetafiletools.cxx +++ b/vcl/source/gdi/gdimetafiletools.cxx @@ -238,7 +238,7 @@ namespace "XPATHSTROKE_SEQ_BEGIN", 0, static_cast< const sal_uInt8* >(aMemStm.GetData()), - aMemStm.Seek(STREAM_SEEK_TO_END))); + aMemStm.TellEnd())); } void addSvtGraphicFill(const SvtGraphicFill &rFilling, GDIMetaFile& rTarget) @@ -251,7 +251,7 @@ namespace "XPATHFILL_SEQ_BEGIN", 0, static_cast< const sal_uInt8* >(aMemStm.GetData()), - aMemStm.Seek(STREAM_SEEK_TO_END))); + aMemStm.TellEnd())); } } // end of anonymous namespace diff --git a/vcl/source/gdi/pdfwriter_impl.cxx b/vcl/source/gdi/pdfwriter_impl.cxx index 0a25d2fd8120..150a85877809 100644 --- a/vcl/source/gdi/pdfwriter_impl.cxx +++ b/vcl/source/gdi/pdfwriter_impl.cxx @@ -2066,8 +2066,7 @@ bool PDFWriterImpl::compressStream( SvMemoryStream* pStream ) { if (!g_bDebugDisableCompression) { - pStream->Seek( STREAM_SEEK_TO_END ); - sal_uLong nEndPos = pStream->Tell(); + sal_uLong nEndPos = pStream->TellEnd(); pStream->Seek( STREAM_SEEK_TO_BEGIN ); ZCodec aCodec( 0x4000, 0x4000 ); SvMemoryStream aStream; @@ -2758,8 +2757,7 @@ bool PDFWriterImpl::emitTilings() tiling.m_aCellSize.setHeight( nH ); bool bDeflate = compressStream( tiling.m_pTilingStream.get() ); - tiling.m_pTilingStream->Seek( STREAM_SEEK_TO_END ); - sal_uInt64 const nTilingStreamSize = tiling.m_pTilingStream->Tell(); + sal_uInt64 const nTilingStreamSize = tiling.m_pTilingStream->TellEnd(); tiling.m_pTilingStream->Seek( STREAM_SEEK_TO_BEGIN ); // write pattern object @@ -4535,8 +4533,7 @@ bool PDFWriterImpl::emitAppearances( PDFWidget& rWidget, OStringBuffer& rAnnotDi bool bDeflate = compressStream( pApppearanceStream ); - pApppearanceStream->Seek( STREAM_SEEK_TO_END ); - sal_Int64 nStreamLen = pApppearanceStream->Tell(); + sal_Int64 nStreamLen = pApppearanceStream->TellEnd(); pApppearanceStream->Seek( STREAM_SEEK_TO_BEGIN ); sal_Int32 nObject = createObject(); CHECK_RETURN( updateObject( nObject ) ); @@ -8524,8 +8521,7 @@ void PDFWriterImpl::writeTransparentObject( TransparencyEmit& rObject ) CHECK_RETURN2( updateObject( rObject.m_nObject ) ); bool bFlateFilter = compressStream( rObject.m_pContentStream.get() ); - rObject.m_pContentStream->Seek( STREAM_SEEK_TO_END ); - sal_uLong nSize = rObject.m_pContentStream->Tell(); + sal_uLong nSize = rObject.m_pContentStream->TellEnd(); rObject.m_pContentStream->Seek( STREAM_SEEK_TO_BEGIN ); if (g_bDebugDisableCompression) { @@ -8609,8 +8605,7 @@ void PDFWriterImpl::writeTransparentObject( TransparencyEmit& rObject ) } else { - rObject.m_pSoftMaskStream->Seek( STREAM_SEEK_TO_END ); - sal_Int32 nMaskSize = static_cast<sal_Int32>(rObject.m_pSoftMaskStream->Tell()); + sal_Int32 nMaskSize = static_cast<sal_Int32>(rObject.m_pSoftMaskStream->TellEnd()); rObject.m_pSoftMaskStream->Seek( STREAM_SEEK_TO_BEGIN ); sal_Int32 nMaskObject = createObject(); aLine.append( "/SMask<</Type/Mask/S/Luminosity/G " ); @@ -8882,9 +8877,7 @@ void PDFWriterImpl::writeJPG( JPGEmit& rObject ) CHECK_RETURN2( rObject.m_pStream ); CHECK_RETURN2( updateObject( rObject.m_nObject ) ); - sal_Int32 nLength = 0; - rObject.m_pStream->Seek( STREAM_SEEK_TO_END ); - nLength = rObject.m_pStream->Tell(); + sal_Int32 nLength = rObject.m_pStream->TellEnd(); rObject.m_pStream->Seek( STREAM_SEEK_TO_BEGIN ); sal_Int32 nMaskObject = 0; diff --git a/vcl/source/gdi/pdfwriter_impl2.cxx b/vcl/source/gdi/pdfwriter_impl2.cxx index a4ce58af0e20..7636569fd8fb 100644 --- a/vcl/source/gdi/pdfwriter_impl2.cxx +++ b/vcl/source/gdi/pdfwriter_impl2.cxx @@ -181,8 +181,7 @@ void PDFWriterImpl::implWriteBitmapEx( const Point& i_rPoint, const Size& i_rSiz aTemp.SetCompressMode( aTemp.GetCompressMode() | SvStreamCompressFlags::ZBITMAP ); aTemp.SetVersion( SOFFICE_FILEFORMAT_40 ); // sj: up from version 40 our bitmap stream operator WriteDIBBitmapEx(aBitmapEx, aTemp); // is capable of zlib stream compression - aTemp.Seek( STREAM_SEEK_TO_END ); - nZippedFileSize = aTemp.Tell(); + nZippedFileSize = aTemp.TellEnd(); } if ( aBitmapEx.IsTransparent() ) { diff --git a/vcl/source/gdi/pngread.cxx b/vcl/source/gdi/pngread.cxx index b1c1e28b8384..78e3a19c7381 100644 --- a/vcl/source/gdi/pngread.cxx +++ b/vcl/source/gdi/pngread.cxx @@ -229,10 +229,7 @@ PNGReaderImpl::PNGReaderImpl( SvStream& rPNGStream ) maChunkIter = maChunkSeq.begin(); // estimate PNG file size (to allow sanity checks) - const std::size_t nStreamPos = mrPNGStream.Tell(); - mrPNGStream.Seek( STREAM_SEEK_TO_END ); - mnStreamSize = mrPNGStream.Tell(); - mrPNGStream.Seek( nStreamPos ); + mnStreamSize = mrPNGStream.TellEnd(); // check the PNG header magic sal_uInt32 nDummy = 0; diff --git a/vcl/source/graphic/UnoGraphicProvider.cxx b/vcl/source/graphic/UnoGraphicProvider.cxx index 82823b8152b1..ef0fd14c0149 100644 --- a/vcl/source/graphic/UnoGraphicProvider.cxx +++ b/vcl/source/graphic/UnoGraphicProvider.cxx @@ -818,8 +818,7 @@ void SAL_CALL GraphicProvider::storeGraphic( const uno::Reference< ::graphic::XG rFilter.GetExportFormatNumberForShortName( OUString::createFromAscii( pFilterShortName ) ), ( aFilterDataSeq.getLength() ? &aFilterDataSeq : nullptr ) ); } - aMemStrm.Seek( STREAM_SEEK_TO_END ); - pOStm->WriteBytes( aMemStrm.GetData(), aMemStrm.Tell() ); + pOStm->WriteBytes( aMemStrm.GetData(), aMemStrm.TellEnd() ); } } } diff --git a/vcl/unx/gtk/gtksalmenu.cxx b/vcl/unx/gtk/gtksalmenu.cxx index aa2f0eeab396..e504e5d7aef0 100644 --- a/vcl/unx/gtk/gtksalmenu.cxx +++ b/vcl/unx/gtk/gtksalmenu.cxx @@ -988,7 +988,7 @@ void GtkSalMenu::NativeSetItemIcon( unsigned nSection, unsigned nItemPos, const aWriter.Write(*pMemStm); GBytes *pBytes = g_bytes_new_with_free_func(pMemStm->GetData(), - pMemStm->Seek(STREAM_SEEK_TO_END), + pMemStm->TellEnd(), DestroyMemoryStream, pMemStm); diff --git a/vcl/unx/gtk3/gtk3gtkinst.cxx b/vcl/unx/gtk3/gtk3gtkinst.cxx index dd69aad8ad98..4fa46987cb68 100644 --- a/vcl/unx/gtk3/gtk3gtkinst.cxx +++ b/vcl/unx/gtk3/gtk3gtkinst.cxx @@ -1611,7 +1611,7 @@ namespace { GdkPixbufLoader *pixbuf_loader = gdk_pixbuf_loader_new(); gdk_pixbuf_loader_write(pixbuf_loader, static_cast<const guchar*>(xMemStm->GetData()), - xMemStm->Seek(STREAM_SEEK_TO_END), nullptr); + xMemStm->TellEnd(), nullptr); gdk_pixbuf_loader_close(pixbuf_loader, nullptr); pixbuf = gdk_pixbuf_loader_get_pixbuf(pixbuf_loader); if (pixbuf) |