[Libreoffice-commits] .: svtools/source sw/source

Thorsten Behrens thorsten at kemper.freedesktop.org
Tue Oct 25 14:23:50 PDT 2011


 svtools/source/filter/filter.cxx |   28 ++++++++++++++++++++++++++--
 sw/source/core/graphic/ndgrf.cxx |   10 +++++-----
 2 files changed, 31 insertions(+), 7 deletions(-)

New commits:
commit c0913d78c258f7e49b52f45909b2cebbd9fb6103
Author: Thorsten Behrens <tbehrens at suse.com>
Date:   Tue Oct 25 21:02:03 2011 +0200

    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.

diff --git a/svtools/source/filter/filter.cxx b/svtools/source/filter/filter.cxx
index b10a4ab..ddab749 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 b407c9b..11d9555 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;
             }
         }


More information about the Libreoffice-commits mailing list