From e956091ad8ebfa77294e130bf2b5cf0200578fdb Mon Sep 17 00:00:00 2001 From: offtkp Date: Fri, 12 Aug 2022 21:27:16 +0300 Subject: [PATCH] Remove code duplication in GraphicDescriptor for EPS MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit GraphicFormatDetector and GraphicDescriptor have duplicate format detection code so now GraphicDescriptor uses GraphicFormatDetector functions instead to detect the format for EPS files Change-Id: I108aefc56a0e9215eaeef3ae2a7b4d884f0a5373 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/138208 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl --- vcl/source/filter/graphicfilter2.cxx | 22 +++++----------------- 1 file changed, 5 insertions(+), 17 deletions(-) diff --git a/vcl/source/filter/graphicfilter2.cxx b/vcl/source/filter/graphicfilter2.cxx index 1d08776f0b83..01741afa7ec2 100644 --- a/vcl/source/filter/graphicfilter2.cxx +++ b/vcl/source/filter/graphicfilter2.cxx @@ -918,24 +918,12 @@ bool GraphicDescriptor::ImpDetectPSD( SvStream& rStm, bool bExtendedInfo ) bool GraphicDescriptor::ImpDetectEPS( SvStream& rStm, bool ) { - // check the EPS preview and the file extension - sal_uInt32 nFirstLong = 0; - sal_uInt8 nFirstBytes[20] = {}; - bool bRet = false; - sal_Int32 nStmPos = rStm.Tell(); - rStm.SetEndian( SvStreamEndian::BIG ); - rStm.ReadUInt32( nFirstLong ); - rStm.SeekRel( -4 ); - rStm.ReadBytes( &nFirstBytes, 20 ); - - if ( ( nFirstLong == 0xC5D0D3C6 ) || aPathExt.startsWith( "eps" ) || - ( ImplSearchEntry( nFirstBytes, reinterpret_cast("%!PS-Adobe"), 10, 10 ) - && ImplSearchEntry( &nFirstBytes[15], reinterpret_cast("EPS"), 3, 3 ) ) ) - { - aMetadata.mnFormat = GraphicFileFormat::EPS; - bRet = true; - } + vcl::GraphicFormatDetector aDetector( rStm, aPathExt, false /*bExtendedInfo*/ ); + bool bRet = aDetector.detect(); + bRet &= aDetector.checkEPS(); + if ( bRet ) + aMetadata = aDetector.getMetadata(); rStm.Seek( nStmPos ); return bRet; }