summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThorsten Behrens <tbehrens@suse.com>2011-10-25 21:02:03 +0200
committerThorsten Behrens <tbehrens@suse.com>2011-10-25 23:23:40 +0200
commitc0913d78c258f7e49b52f45909b2cebbd9fb6103 (patch)
tree7c2a2bd67f5de927b25fdf9a6500ee4576a6dc6b
parent494c6b5524dad78f2eeb48a3b979a11bc8413984 (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.
-rw-r--r--svtools/source/filter/filter.cxx28
-rwxr-xr-xsw/source/core/graphic/ndgrf.cxx10
2 files changed, 31 insertions, 7 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() )
{
diff --git a/sw/source/core/graphic/ndgrf.cxx b/sw/source/core/graphic/ndgrf.cxx
index b407c9b5b385..11d9555bb2d9 100755
--- a/sw/source/core/graphic/ndgrf.cxx
+++ b/sw/source/core/graphic/ndgrf.cxx
@@ -386,12 +386,11 @@ Size SwGrfNode::GetTwipSize() const
sal_Bool SwGrfNode::ImportGraphic( SvStream& rStrm )
{
Graphic aGraphic;
- if( !GraphicFilter::GetGraphicFilter().ImportGraphic( aGraphic, String(), rStrm ) )
+ const String aGraphicURL( aGrfObj.GetUserData() );
+ if( !GraphicFilter::GetGraphicFilter().ImportGraphic( aGraphic, aGraphicURL, rStrm ) )
{
- const String aUserData( aGrfObj.GetUserData() );
-
aGrfObj.SetGraphic( aGraphic );
- aGrfObj.SetUserData( aUserData );
+ aGrfObj.SetUserData( aGraphicURL );
return sal_True;
}
@@ -879,7 +878,8 @@ SwCntntNode* SwGrfNode::MakeCopy( SwDoc* pDoc, const SwNodeIndex& rIdx ) const
SvStream* pStrm = _GetStreamForEmbedGrf( refPics, aStrmName );
if ( pStrm )
{
- GraphicFilter::GetGraphicFilter().ImportGraphic( aTmpGrf, String(), *pStrm );
+ const String aGraphicURL( aGrfObj.GetUserData() );
+ GraphicFilter::GetGraphicFilter().ImportGraphic( aTmpGrf, aGraphicURL, *pStrm );
delete pStrm;
}
}