diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.com> | 2014-03-03 22:30:32 +0100 |
---|---|---|
committer | Tomaž Vajngerl <tomaz.vajngerl@collabora.com> | 2014-03-03 22:42:25 +0100 |
commit | 115ae1259564a51a14a3363a00717b09882d55bf (patch) | |
tree | a7849aeca737afac415f34ab63d023865a68295d /vcl | |
parent | 4e62ac053bf6cb094130f3ba914b6f4485d3e0a2 (diff) |
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
Diffstat (limited to 'vcl')
-rw-r--r-- | vcl/source/filter/graphicfilter.cxx | 64 |
1 files changed, 40 insertions, 24 deletions
diff --git a/vcl/source/filter/graphicfilter.cxx b/vcl/source/filter/graphicfilter.cxx index 813600f35377..71e55e02b53e 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(); } |