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.
This commit is contained in:
Thorsten Behrens
2011-10-25 21:02:03 +02:00
parent 494c6b5524
commit c0913d78c2
2 changed files with 31 additions and 7 deletions

View File

@@ -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() )
{

View File

@@ -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;
}
}