From c9a290c2a87e9af3b0cd4ccbdd751dddab3532da Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Mon, 7 Sep 2015 08:42:46 +0200 Subject: tdf#83227 oox: reuse RelId in DML/VML export for the same graphic MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit So that large images are written only once to the ZIP container when they are exported using both markups. This affects drawinglayer images, the Writer ones are handled directly in sw and were already deduplicated. (cherry picked from commit b484e9814c66d8d51cea974390963a6944bc9d73) Conflicts: oox/source/export/drawingml.cxx Change-Id: Iff7c769329b42939833056b727b070f6a60da5e3 Reviewed-on: https://gerrit.libreoffice.org/18581 Reviewed-by: Caolán McNamara Tested-by: Caolán McNamara --- oox/source/export/drawingml.cxx | 33 +++++++++++++++++++++++++++++---- oox/source/export/vmlexport.cxx | 9 ++++++++- 2 files changed, 37 insertions(+), 5 deletions(-) (limited to 'oox') diff --git a/oox/source/export/drawingml.cxx b/oox/source/export/drawingml.cxx index edff9b933dd1..66dfb1ffcbf4 100644 --- a/oox/source/export/drawingml.cxx +++ b/oox/source/export/drawingml.cxx @@ -762,7 +762,7 @@ void DrawingML::WriteOutline( Reference rXPropSet ) mpFS->endElementNS( XML_a, XML_ln ); } -OUString DrawingML::WriteImage( const OUString& rURL, bool bRelPathToMedia ) +bool lcl_URLToGraphic(const OUString& rURL, Graphic& rGraphic) { OString aURLBS(OUStringToOString(rURL, RTL_TEXTENCODING_UTF8)); @@ -771,9 +771,18 @@ OUString DrawingML::WriteImage( const OUString& rURL, bool bRelPathToMedia ) if ( index != -1 ) { - DBG(fprintf (stderr, "begin: %ld %s\n", long( sizeof( aURLBegin ) ), USS( rURL ) + RTL_CONSTASCII_LENGTH( aURLBegin ) )); - Graphic aGraphic = GraphicObject( aURLBS.copy(RTL_CONSTASCII_LENGTH(aURLBegin)) ).GetTransformedGraphic (); + rGraphic = GraphicObject(aURLBS.copy(RTL_CONSTASCII_LENGTH(aURLBegin))).GetTransformedGraphic(); + return true; + } + + return false; +} +OUString DrawingML::WriteImage( const OUString& rURL, bool bRelPathToMedia ) +{ + Graphic aGraphic; + if (lcl_URLToGraphic(rURL, aGraphic)) + { return WriteImage( aGraphic , bRelPathToMedia ); } else @@ -923,7 +932,23 @@ OUString DrawingML::WriteImage( const Graphic& rGraphic , bool bRelPathToMedia ) OUString DrawingML::WriteBlip( Reference< XPropertySet > rXPropSet, const OUString& rURL, bool bRelPathToMedia, const Graphic *pGraphic ) { - OUString sRelId = pGraphic ? WriteImage( *pGraphic, bRelPathToMedia ) : WriteImage( rURL, bRelPathToMedia ); + OUString sRelId; + sal_uInt32 nChecksum = 0; + if (!rURL.isEmpty() && mpTextExport) + { + Graphic aGraphic; + if (lcl_URLToGraphic(rURL, aGraphic)) + { + nChecksum = aGraphic.GetChecksum(); + sRelId = mpTextExport->FindRelId(nChecksum); + } + } + if (sRelId.isEmpty()) + { + sRelId = pGraphic ? WriteImage( *pGraphic, bRelPathToMedia ) : WriteImage( rURL, bRelPathToMedia ); + if (!rURL.isEmpty() && mpTextExport) + mpTextExport->CacheRelId(nChecksum, sRelId); + } sal_Int16 nBright = 0; sal_Int32 nContrast = 0; diff --git a/oox/source/export/vmlexport.cxx b/oox/source/export/vmlexport.cxx index a0a1ac7677db..557bb8c18d9e 100644 --- a/oox/source/export/vmlexport.cxx +++ b/oox/source/export/vmlexport.cxx @@ -605,7 +605,14 @@ void VMLExport::Commit( EscherPropertyContainer& rProps, const Rectangle& rRect aStream.Seek(0); Graphic aGraphic; GraphicConverter::Import(aStream, aGraphic); - OUString aImageId = m_pTextExport->GetDrawingML().WriteImage( aGraphic ); + + sal_uInt32 nChecksum = aGraphic.GetChecksum(); + OUString aImageId = m_pTextExport->FindRelId(nChecksum); + if (aImageId.isEmpty()) + { + aImageId = m_pTextExport->GetDrawingML().WriteImage( aGraphic ); + m_pTextExport->CacheRelId(nChecksum, aImageId); + } pAttrList->add(FSNS(XML_r, XML_id), OUStringToOString(aImageId, RTL_TEXTENCODING_UTF8)); imageData = true; } -- cgit