summaryrefslogtreecommitdiff
path: root/oox
diff options
context:
space:
mode:
authorDaniel Arato (NISZ) <arato.daniel@nisz.hu>2021-03-09 14:11:11 +0100
committerLászló Németh <nemeth@numbertext.org>2021-03-26 13:07:57 +0100
commit797fef38612fb2fd62d1f6591619b9361e526bca (patch)
treec4dcbc713091d8a9596b4d60d3c9228bd6b1281a /oox
parent2f2475bb5da7f9fcc30ed35f8946932d69b11294 (diff)
tdf#118535 DOCX export: save header image once
Writer used to dump the same image file as many times as it was featured in different headers or footers in the document, bloating the .docx file size. This is countered by making all "relationships" in the header*.xml.rels files point to the same image. Change-Id: I44d72630289c721d58d8f7e208517df2f1fe621c Reviewed-on: https://gerrit.libreoffice.org/c/core/+/112656 Tested-by: László Németh <nemeth@numbertext.org> Reviewed-by: László Németh <nemeth@numbertext.org>
Diffstat (limited to 'oox')
-rw-r--r--oox/source/export/drawingml.cxx31
-rw-r--r--oox/source/export/vmlexport.cxx10
2 files changed, 28 insertions, 13 deletions
diff --git a/oox/source/export/drawingml.cxx b/oox/source/export/drawingml.cxx
index 67f26e71daea..32780296ce89 100644
--- a/oox/source/export/drawingml.cxx
+++ b/oox/source/export/drawingml.cxx
@@ -1162,7 +1162,7 @@ const char* DrawingML::GetRelationCompPrefix() const
return "unknown";
}
-OUString DrawingML::WriteImage( const Graphic& rGraphic , bool bRelPathToMedia )
+OUString DrawingML::WriteImage( const Graphic& rGraphic , bool bRelPathToMedia, OUString* pFileName )
{
GfxLink aLink = rGraphic.GetGfxLink ();
OUString sMediaType;
@@ -1266,15 +1266,18 @@ OUString DrawingML::WriteImage( const Graphic& rGraphic , bool bRelPathToMedia )
sRelationCompPrefix = "../";
else
sRelationCompPrefix = GetRelationCompPrefix();
+ OUString sPath = OUStringBuffer()
+ .appendAscii( sRelationCompPrefix.getStr() )
+ .appendAscii( sRelPathToMedia.getStr() )
+ .append( static_cast<sal_Int32>(mnImageCounter ++) )
+ .appendAscii( pExtension )
+ .makeStringAndClear();
sRelId = mpFB->addRelation( mpFS->getOutputStream(),
oox::getRelationship(Relationship::IMAGE),
- OUStringBuffer()
- .appendAscii( sRelationCompPrefix.getStr() )
- .appendAscii( sRelPathToMedia.getStr() )
- .append( static_cast<sal_Int32>(mnImageCounter ++) )
- .appendAscii( pExtension )
- .makeStringAndClear() );
+ sPath );
+ if (pFileName)
+ *pFileName = sPath;
return sRelId;
}
@@ -1434,6 +1437,7 @@ OUString DrawingML::WriteXGraphicBlip(uno::Reference<beans::XPropertySet> const
bool bRelPathToMedia)
{
OUString sRelId;
+ OUString sFileName;
if (!rxGraphic.is())
return sRelId;
@@ -1443,16 +1447,25 @@ OUString DrawingML::WriteXGraphicBlip(uno::Reference<beans::XPropertySet> const
{
BitmapChecksum nChecksum = aGraphic.GetChecksum();
sRelId = mpTextExport->FindRelId(nChecksum);
+ sFileName = mpTextExport->FindFileName(nChecksum);
}
if (sRelId.isEmpty())
{
- sRelId = WriteImage(aGraphic, bRelPathToMedia);
+ sRelId = WriteImage(aGraphic, bRelPathToMedia, &sFileName);
if (mpTextExport)
{
BitmapChecksum nChecksum = aGraphic.GetChecksum();
- mpTextExport->CacheRelId(nChecksum, sRelId);
+ mpTextExport->CacheRelId(nChecksum, sRelId, sFileName);
}
}
+ else
+ {
+ // Include the same relation again. This makes it possible to
+ // reuse an image across different headers.
+ sRelId = mpFB->addRelation( mpFS->getOutputStream(),
+ oox::getRelationship(Relationship::IMAGE),
+ sFileName );
+ }
mpFS->startElementNS(XML_a, XML_blip, FSNS(XML_r, XML_embed), sRelId);
diff --git a/oox/source/export/vmlexport.cxx b/oox/source/export/vmlexport.cxx
index 9c6b89ef7dd7..9f8df2279611 100644
--- a/oox/source/export/vmlexport.cxx
+++ b/oox/source/export/vmlexport.cxx
@@ -741,8 +741,9 @@ void VMLExport::Commit( EscherPropertyContainer& rProps, const tools::Rectangle&
OUString aImageId = m_pTextExport->FindRelId(nChecksum);
if (aImageId.isEmpty())
{
- aImageId = m_pTextExport->GetDrawingML().WriteImage(aGraphic);
- m_pTextExport->CacheRelId(nChecksum, aImageId);
+ OUString aFileName;
+ aImageId = m_pTextExport->GetDrawingML().WriteImage(aGraphic, false, &aFileName);
+ m_pTextExport->CacheRelId(nChecksum, aImageId, aFileName);
}
pAttrList->add(FSNS(XML_r, XML_id),
OUStringToOString(aImageId, RTL_TEXTENCODING_UTF8));
@@ -763,8 +764,9 @@ void VMLExport::Commit( EscherPropertyContainer& rProps, const tools::Rectangle&
OUString aImageId = m_pTextExport->FindRelId(nChecksum);
if (aImageId.isEmpty())
{
- aImageId = m_pTextExport->GetDrawingML().WriteImage(aGraphic);
- m_pTextExport->CacheRelId(nChecksum, aImageId);
+ OUString aFileName;
+ aImageId = m_pTextExport->GetDrawingML().WriteImage(aGraphic, false, &aFileName);
+ m_pTextExport->CacheRelId(nChecksum, aImageId, aFileName);
}
pAttrList->add(FSNS(XML_r, XML_id),
OUStringToOString(aImageId, RTL_TEXTENCODING_UTF8));