summaryrefslogtreecommitdiff
path: root/sw
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2020-09-22 07:29:34 +0200
committerTomaž Vajngerl <quikee@gmail.com>2020-09-25 18:57:25 +0200
commit0120fecc22b36a55a2a25573a7a9632319b2b0ff (patch)
treec62245d9d90f5cbb6e96c82fca319b090a420977 /sw
parent16aec96177f83fc94a68350b72533479b577e438 (diff)
docx export: Use checksum as key to cache graphic, not Graphic*
The problem is when we have multiple identical images in the document and try to export. Without this change, the images will be duplicated because the cache is using Graphic*, for which the instance changes all the time (is not unique). Using the checksum will make sure that all the images with the same content will be saved as one image into the document. Reviewed-on: https://gerrit.libreoffice.org/c/core/+/103132 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <quikee@gmail.com> (cherry picked from commit 8679bf3ec608aec277fd677082aa5c38e63a65ce) Change-Id: I980af2dba51060ce4320571aca14d21e26ed8976 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/103406 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com> Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'sw')
-rw-r--r--sw/source/filter/ww8/docxattributeoutput.cxx46
-rw-r--r--sw/source/filter/ww8/docxattributeoutput.hxx8
2 files changed, 40 insertions, 14 deletions
diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx b/sw/source/filter/ww8/docxattributeoutput.cxx
index 90a427ce30ed..eefa7b25fd51 100644
--- a/sw/source/filter/ww8/docxattributeoutput.cxx
+++ b/sw/source/filter/ww8/docxattributeoutput.cxx
@@ -4819,8 +4819,8 @@ void DocxAttributeOutput::PopRelIdCache()
void DocxAttributeOutput::PushRelIdCache()
{
- m_aRelIdCache.push(std::map<const Graphic*, OString>());
- m_aSdrRelIdCache.push(std::map<BitmapChecksum, OUString>());
+ m_aRelIdCache.emplace();
+ m_aSdrRelIdCache.emplace();
}
OUString DocxAttributeOutput::FindRelId(BitmapChecksum nChecksum)
@@ -4839,6 +4839,29 @@ void DocxAttributeOutput::CacheRelId(BitmapChecksum nChecksum, const OUString& r
m_aSdrRelIdCache.top()[nChecksum] = rRelId;
}
+OString DocxAttributeOutput::getExistingGraphicRelId(BitmapChecksum nChecksum)
+{
+ OString aResult;
+
+ if (m_aRelIdCache.empty())
+ return aResult;
+
+ auto pIterator = m_aRelIdCache.top().find(nChecksum);
+
+ if (pIterator != m_aRelIdCache.top().end())
+ {
+ aResult = pIterator->second;
+ }
+
+ return aResult;
+}
+
+void DocxAttributeOutput::cacheGraphicRelId(BitmapChecksum nChecksum, OString const & rRelId)
+{
+ if (!m_aRelIdCache.empty())
+ m_aRelIdCache.top().emplace(nChecksum, rRelId);
+}
+
void DocxAttributeOutput::FlyFrameGraphic( const SwGrfNode* pGrfNode, const Size& rSize, const SwFlyFrameFormat* pOLEFrameFormat, SwOLENode* pOLENode, const SdrObject* pSdrObj )
{
SAL_INFO("sw.ww8", "TODO DocxAttributeOutput::FlyFrameGraphic( const SwGrfNode* pGrfNode, const Size& rSize, const SwFlyFrameFormat* pOLEFrameFormat, SwOLENode* pOLENode, const SdrObject* pSdrObj ) - some stuff still missing" );
@@ -4878,25 +4901,24 @@ void DocxAttributeOutput::FlyFrameGraphic( const SwGrfNode* pGrfNode, const Size
else
{
// inline, we also have to write the image itself
- const Graphic* pGraphic = nullptr;
+ Graphic aGraphic;
if (pGrfNode)
- pGraphic = &pGrfNode->GetGrf();
+ aGraphic = pGrfNode->GetGrf();
else
- pGraphic = pOLENode->GetGraphic();
+ aGraphic = *pOLENode->GetGraphic();
- if (!m_aRelIdCache.empty() && m_aRelIdCache.top().find(pGraphic) != m_aRelIdCache.top().end())
- // We already have a RelId for this Graphic.
- aRelId = m_aRelIdCache.top()[pGraphic];
- else
+ BitmapChecksum aChecksum = aGraphic.GetChecksum();
+ aRelId = getExistingGraphicRelId(aChecksum);
+
+ if (aRelId.isEmpty())
{
// Not in cache, then need to write it.
m_rDrawingML.SetFS( m_pSerializer ); // to be sure that we write to the right stream
- OUString aImageId = m_rDrawingML.WriteImage( *pGraphic );
+ OUString aImageId = m_rDrawingML.WriteImage(aGraphic);
aRelId = OUStringToOString( aImageId, RTL_TEXTENCODING_UTF8 );
- if (!m_aRelIdCache.empty())
- m_aRelIdCache.top()[pGraphic] = aRelId;
+ cacheGraphicRelId(aChecksum, aRelId);
}
nImageType = XML_embed;
diff --git a/sw/source/filter/ww8/docxattributeoutput.hxx b/sw/source/filter/ww8/docxattributeoutput.hxx
index b87d5e4efd9e..a6d5d1e88d62 100644
--- a/sw/source/filter/ww8/docxattributeoutput.hxx
+++ b/sw/source/filter/ww8/docxattributeoutput.hxx
@@ -950,8 +950,12 @@ private:
bool m_setFootnote;
- /// RelId <-> Graphic* cache, so that in case of alternate content, the same graphic only gets written once.
- std::stack< std::map<const Graphic*, OString> > m_aRelIdCache;
+ OString getExistingGraphicRelId(BitmapChecksum aChecksum);
+ void cacheGraphicRelId(BitmapChecksum nChecksum, OString const & rRelId);
+
+ /// RelId <-> BitmapChecksum cache, so that in case of alternate content, the same graphic only gets written once.
+ std::stack< std::map<BitmapChecksum, OString> > m_aRelIdCache;
+
/// RelId <-> BitmapChecksum cache, similar to m_aRelIdCache, but used for non-Writer graphics, handled in oox.
std::stack< std::map<BitmapChecksum, OUString> > m_aSdrRelIdCache;