[Libreoffice-commits] core.git: vcl/source

Tomaž Vajngerl tomaz.vajngerl at collabora.com
Mon Mar 3 13:42:55 PST 2014


 vcl/source/filter/graphicfilter.cxx |   64 ++++++++++++++++++++++--------------
 1 file changed, 40 insertions(+), 24 deletions(-)

New commits:
commit 115ae1259564a51a14a3363a00717b09882d55bf
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.com>
Date:   Mon Mar 3 22:30:32 2014 +0100

    fdo#75487 Store svgz decompressed (as plain svg) in the document.
    
    Put decompressed svg in GfxLink so that when the document is
    saved, the graphics is stored as plain svg. This is done so
    because of backwards compatibility (older LO won't be able to
    read compressed svg data in the document) and because the document
    itself is already compressed.
    
    Change-Id: I125005dfba785701e756487092f25bb90bcd2bcb

diff --git a/vcl/source/filter/graphicfilter.cxx b/vcl/source/filter/graphicfilter.cxx
index 813600f..71e55e0 100644
--- a/vcl/source/filter/graphicfilter.cxx
+++ b/vcl/source/filter/graphicfilter.cxx
@@ -1343,7 +1343,7 @@ sal_uInt16 GraphicFilter::ImportGraphic( Graphic& rGraphic, const OUString& rPat
                                      WMF_EXTERNALHEADER *pExtHeader )
 {
     OUString                aFilterName;
-    sal_uLong               nStmBegin;
+    sal_uLong               nStreamBegin;
     sal_uInt16              nStatus;
     GraphicReader*          pContext = rGraphic.GetContext();
     GfxLinkType             eLinkType = GFX_LINK_TYPE_NONE;
@@ -1355,6 +1355,9 @@ sal_uInt16 GraphicFilter::ImportGraphic( Graphic& rGraphic, const OUString& rPat
     bool                bAllowPartialStreamRead = false;
     bool                bCreateNativeLink = true;
 
+    sal_uInt8* pGraphicContent = NULL;
+    sal_Int32  nGraphicContentSize = 0;
+
     ResetLastError();
 
     if ( pFilterData )
@@ -1394,10 +1397,10 @@ sal_uInt16 GraphicFilter::ImportGraphic( Graphic& rGraphic, const OUString& rPat
         if( bDummyContext )
         {
             rGraphic.SetContext( NULL );
-            nStmBegin = 0;
+            nStreamBegin = 0;
         }
         else
-            nStmBegin = rIStream.Tell();
+            nStreamBegin = rIStream.Tell();
 
         bAbort = false;
         nStatus = ImpTestOrFindFormat( rPath, rIStream, nFormat );
@@ -1406,11 +1409,11 @@ sal_uInt16 GraphicFilter::ImportGraphic( Graphic& rGraphic, const OUString& rPat
         {
             rGraphic.SetContext( (GraphicReader*) 1 );
             rIStream.ResetError();
-            rIStream.Seek( nStmBegin );
+            rIStream.Seek( nStreamBegin );
             return (sal_uInt16) ImplSetError( GRFILTER_OK );
         }
 
-        rIStream.Seek( nStmBegin );
+        rIStream.Seek( nStreamBegin );
 
         if( ( nStatus != GRFILTER_OK ) || rIStream.GetError() )
             return (sal_uInt16) ImplSetError( ( nStatus != GRFILTER_OK ) ? nStatus : GRFILTER_OPENERROR, &rIStream );
@@ -1425,7 +1428,7 @@ sal_uInt16 GraphicFilter::ImportGraphic( Graphic& rGraphic, const OUString& rPat
         if( pContext && !bDummyContext )
             aFilterName = pContext->GetUpperFilterName();
 
-        nStmBegin = 0;
+        nStreamBegin = 0;
         nStatus = GRFILTER_OK;
     }
 
@@ -1540,6 +1543,11 @@ sal_uInt16 GraphicFilter::ImportGraphic( Graphic& rGraphic, const OUString& rPat
                         aMemStream.Seek(STREAM_SEEK_TO_BEGIN);
                         aMemStream.Read(aNewData.get(), nMemoryLength);
 
+                        // Make a uncompressed copy for GfxLink
+                        nGraphicContentSize = nMemoryLength;
+                        pGraphicContent = new sal_uInt8[nGraphicContentSize];
+                        std::copy(aNewData.get(), aNewData.get() + nMemoryLength, pGraphicContent);
+
                         if(!aMemStream.GetError() )
                         {
                             SvgDataPtr aSvgDataPtr(new SvgData(aNewData, nMemoryLength, rPath));
@@ -1742,28 +1750,36 @@ sal_uInt16 GraphicFilter::ImportGraphic( Graphic& rGraphic, const OUString& rPat
 
     if( nStatus == GRFILTER_OK && bCreateNativeLink && ( eLinkType != GFX_LINK_TYPE_NONE ) && !rGraphic.GetContext() && !bLinkSet )
     {
-        const sal_uLong nStmEnd = rIStream.Tell();
-        const sal_uLong nBufSize = nStmEnd - nStmBegin;
-
-        if( nBufSize )
+        if (pGraphicContent == NULL)
         {
-            sal_uInt8*  pBuf=0;
-            try
-            {
-                pBuf = new sal_uInt8[ nBufSize ];
-            }
-            catch (const std::bad_alloc&)
-            {
-                nStatus = GRFILTER_TOOBIG;
-            }
+            const sal_uLong nStreamEnd = rIStream.Tell();
+            nGraphicContentSize = nStreamEnd - nStreamBegin;
 
-            if( nStatus == GRFILTER_OK )
+            if (nGraphicContentSize > 0)
             {
-                rIStream.Seek( nStmBegin );
-                rIStream.Read( pBuf, nBufSize );
-                rGraphic.SetLink( GfxLink( pBuf, nBufSize, eLinkType, true ) );
+                try
+                {
+                    pGraphicContent = new sal_uInt8[nGraphicContentSize];
+                }
+                catch (const std::bad_alloc&)
+                {
+                    nStatus = GRFILTER_TOOBIG;
+                }
+
+                if( nStatus == GRFILTER_OK )
+                {
+                    rIStream.Seek(nStreamBegin);
+                    rIStream.Read(pGraphicContent, nGraphicContentSize);
+                }
             }
         }
+        if( nStatus == GRFILTER_OK )
+            rGraphic.SetLink( GfxLink( pGraphicContent, nGraphicContentSize, eLinkType, true ) );
+    }
+    else
+    {
+        if(nGraphicContentSize > 0)
+            delete[] pGraphicContent;
     }
 
     // Set error code or try to set native buffer
@@ -1773,7 +1789,7 @@ sal_uInt16 GraphicFilter::ImportGraphic( Graphic& rGraphic, const OUString& rPat
             nStatus = GRFILTER_ABORT;
 
         ImplSetError( nStatus, &rIStream );
-        rIStream.Seek( nStmBegin );
+        rIStream.Seek( nStreamBegin );
         rGraphic.Clear();
     }
 


More information about the Libreoffice-commits mailing list