diff options
author | Thorsten Behrens <tbehrens@suse.com> | 2011-10-25 21:02:03 +0200 |
---|---|---|
committer | Thorsten Behrens <tbehrens@suse.com> | 2011-10-25 23:23:40 +0200 |
commit | c0913d78c258f7e49b52f45909b2cebbd9fb6103 (patch) | |
tree | 7c2a2bd67f5de927b25fdf9a6500ee4576a6dc6b /svtools | |
parent | 494c6b5524dad78f2eeb48a3b979a11bc8413984 (diff) |
Fix fdo#41995 fallout - recognize .svg in odf containers
More code paths that needed fixing - Writer sports its own Graphic
loading implementation, so that had the need for the stream name
fwd-ing, too. The svg deep type detection was necessary for e.g. the
flat odf - which has inline svg without any filename.
Diffstat (limited to 'svtools')
-rw-r--r-- | svtools/source/filter/filter.cxx | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/svtools/source/filter/filter.cxx b/svtools/source/filter/filter.cxx index b10a4ab54347..ddab749e9e82 100644 --- a/svtools/source/filter/filter.cxx +++ b/svtools/source/filter/filter.cxx @@ -667,6 +667,30 @@ static sal_Bool ImpPeekGraphicFormat( SvStream& rStream, String& rFormatExtensio // just a simple test for the extension if( rFormatExtension.CompareToAscii( "SVG", 3 ) == COMPARE_EQUAL ) return sal_True; + + sal_uLong nSize = ( nStreamLen > 1024 ) ? 1024 : nStreamLen; + std::vector<sal_uInt8> aBuf(nSize); + + rStream.Seek( nStreamPos ); + rStream.Read( &aBuf[0], nSize ); + + // read the first 1024 bytes & check a few magic string + // constants (heuristically) + sal_Int8 aMagic1[] = {'<', 's', 'v', 'g'}; + if( std::search(aBuf.begin(), aBuf.end(), + aMagic1, aMagic1+SAL_N_ELEMENTS(aMagic1)) != aBuf.end() ) + { + rFormatExtension = UniString::CreateFromAscii( "SVG", 3 ); + return sal_True; + } + + sal_Int8 aMagic2[] = {'D', 'O', 'C', 'T', 'Y', 'P', 'E', ' ', 's', 'v', 'g'}; + if( std::search(aBuf.begin(), aBuf.end(), + aMagic2, aMagic2+SAL_N_ELEMENTS(aMagic2)) != aBuf.end() ) + { + rFormatExtension = UniString::CreateFromAscii( "SVG", 3 ); + return sal_True; + } } //--------------------------- TGA ------------------------------------ @@ -743,7 +767,7 @@ sal_uInt16 GraphicFilter::ImpTestOrFindFormat( const String& rPath, SvStream& rS else { String aTmpStr( pConfig->GetImportFormatExtension( rFormat ) ); - if( !ImpPeekGraphicFormat( rStream, aTmpStr, sal_True ) ) + if( !ImpPeekGraphicFormat( rStream, aTmpStr.ToUpperAscii(), sal_True ) ) return GRFILTER_FORMATERROR; if ( pConfig->GetImportFormatExtension( rFormat ).EqualsIgnoreCaseAscii( "pcd" ) ) { @@ -2180,7 +2204,7 @@ IMPL_LINK( GraphicFilter, FilterCallback, ConvertData*, pData ) { // Import nFormat = GetImportFormatNumberForShortName( String( aShortName.GetBuffer(), RTL_TEXTENCODING_UTF8 ) ); - nRet = ImportGraphic( pData->maGraphic, String(), pData->mrStm ) == 0; + nRet = ImportGraphic( pData->maGraphic, String(), pData->mrStm, nFormat ) == 0; } else if( aShortName.Len() ) { |