DOCX export: make sure a graphic is only written once
Even if it's referenced multiple times, because of mc:AlternateContent. Change-Id: Ie4cb0ec088d12be5421bac43113c8ae4636028e0
This commit is contained in:
BIN
sw/qa/extras/ooxmlexport/data/dml-picture-in-textframe.docx
Executable file
BIN
sw/qa/extras/ooxmlexport/data/dml-picture-in-textframe.docx
Executable file
Binary file not shown.
@@ -2307,6 +2307,17 @@ DECLARE_OOXMLEXPORT_TEST(testDmlShapeRelsize, "dml-shape-relsize.docx")
|
|||||||
assertXPath(pXmlDoc, "/w:document/w:body/w:p/w:r/mc:AlternateContent/mc:Choice/w:drawing/wp:anchor/wp14:sizeRelH", "relativeFrom", "margin");
|
assertXPath(pXmlDoc, "/w:document/w:body/w:p/w:r/mc:AlternateContent/mc:Choice/w:drawing/wp:anchor/wp14:sizeRelH", "relativeFrom", "margin");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DECLARE_OOXMLEXPORT_TEST(testDmlPictureInTextframe, "dml-picture-in-textframe.docx")
|
||||||
|
{
|
||||||
|
if (!m_bExported)
|
||||||
|
return;
|
||||||
|
|
||||||
|
uno::Reference<packages::zip::XZipFileAccess2> xNameAccess = packages::zip::ZipFileAccess::createWithURL(comphelper::getComponentContext(m_xSFactory), m_aTempFile.GetURL());
|
||||||
|
CPPUNIT_ASSERT_EQUAL(true, bool(xNameAccess->hasByName("word/media/image1.gif")));
|
||||||
|
// This was also true, image was written twice.
|
||||||
|
CPPUNIT_ASSERT_EQUAL(false, bool(xNameAccess->hasByName("word/media/image2.gif")));
|
||||||
|
}
|
||||||
|
|
||||||
DECLARE_OOXMLEXPORT_TEST(testDmlGroupshapeRelsize, "dml-groupshape-relsize.docx")
|
DECLARE_OOXMLEXPORT_TEST(testDmlGroupshapeRelsize, "dml-groupshape-relsize.docx")
|
||||||
{
|
{
|
||||||
xmlDocPtr pXmlDoc = parseExport("word/document.xml");
|
xmlDocPtr pXmlDoc = parseExport("word/document.xml");
|
||||||
|
@@ -3020,10 +3020,18 @@ void DocxAttributeOutput::FlyFrameGraphic( const SwGrfNode* pGrfNode, const Size
|
|||||||
else
|
else
|
||||||
pGraphic = pOLENode->GetGraphic();
|
pGraphic = pOLENode->GetGraphic();
|
||||||
|
|
||||||
m_rDrawingML.SetFS( m_pSerializer ); // to be sure that we write to the right stream
|
if (m_aRelIdCache.find(pGraphic) != m_aRelIdCache.end())
|
||||||
OUString aImageId = m_rDrawingML.WriteImage( *pGraphic );
|
// We already have a RelId for this Graphic.
|
||||||
|
aRelId = m_aRelIdCache[pGraphic];
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// 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 );
|
||||||
|
|
||||||
aRelId = OUStringToOString( aImageId, RTL_TEXTENCODING_UTF8 );
|
aRelId = OUStringToOString( aImageId, RTL_TEXTENCODING_UTF8 );
|
||||||
|
m_aRelIdCache[pGraphic] = aRelId;
|
||||||
|
}
|
||||||
|
|
||||||
nImageType = XML_embed;
|
nImageType = XML_embed;
|
||||||
}
|
}
|
||||||
|
@@ -824,6 +824,9 @@ private:
|
|||||||
|
|
||||||
bool m_setFootnote;
|
bool m_setFootnote;
|
||||||
|
|
||||||
|
/// RelId <-> Graphic* cache, so that in case of alternate content, the same graphic only gets written once.
|
||||||
|
std::map<const Graphic*, OString> m_aRelIdCache;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
DocxAttributeOutput( DocxExport &rExport, ::sax_fastparser::FSHelperPtr pSerializer, oox::drawingml::DrawingML* pDrawingML );
|
DocxAttributeOutput( DocxExport &rExport, ::sax_fastparser::FSHelperPtr pSerializer, oox::drawingml::DrawingML* pDrawingML );
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user