sw/qa/extras/ooxmlexport/data/dml-picture-in-textframe.docx |binary
 sw/qa/extras/ooxmlexport/ooxmlexport.cxx                    |   11 +++++++++
 sw/source/filter/ww8/docxattributeoutput.cxx                |   14 +++++++++---
 sw/source/filter/ww8/docxattributeoutput.hxx                |    3 ++
 sw/source/filter/ww8/docxexport.cxx                         |    3 ++
 5 files changed, 28 insertions(+), 3 deletions(-)

New commits:
commit 32ada80a9f47b095d7b0c4d16e3422f6ef7f2ac2
Author: Miklos Vajna <vmik...@collabora.co.uk>
Date:   Fri Feb 21 12:57:57 2014 +0100

    DOCX export: make sure a graphic is only written once
    
    Even if it's referenced multiple times, because of mc:AlternateContent.
    
    Change-Id: Ie4cb0ec088d12be5421bac43113c8ae4636028e0

diff --git a/sw/qa/extras/ooxmlexport/data/dml-picture-in-textframe.docx 
b/sw/qa/extras/ooxmlexport/data/dml-picture-in-textframe.docx
new file mode 100755
index 0000000..7d58761
Binary files /dev/null and 
b/sw/qa/extras/ooxmlexport/data/dml-picture-in-textframe.docx differ
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport.cxx 
b/sw/qa/extras/ooxmlexport/ooxmlexport.cxx
index c68d3df..025b27e 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport.cxx
@@ -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");
 }
 
+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")
 {
     xmlDocPtr pXmlDoc = parseExport("word/document.xml");
diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx 
b/sw/source/filter/ww8/docxattributeoutput.cxx
index afeb057..ab71fd9 100644
--- a/sw/source/filter/ww8/docxattributeoutput.cxx
+++ b/sw/source/filter/ww8/docxattributeoutput.cxx
@@ -3020,10 +3020,18 @@ void DocxAttributeOutput::FlyFrameGraphic( const 
SwGrfNode* pGrfNode, const Size
         else
             pGraphic = pOLENode->GetGraphic();
 
-        m_rDrawingML.SetFS( m_pSerializer ); // to be sure that we write to 
the right stream
-        OUString aImageId = m_rDrawingML.WriteImage( *pGraphic );
+        if (m_aRelIdCache.find(pGraphic) != m_aRelIdCache.end())
+            // 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;
     }
diff --git a/sw/source/filter/ww8/docxattributeoutput.hxx 
b/sw/source/filter/ww8/docxattributeoutput.hxx
index e25606d..47ce782 100644
--- a/sw/source/filter/ww8/docxattributeoutput.hxx
+++ b/sw/source/filter/ww8/docxattributeoutput.hxx
@@ -824,6 +824,9 @@ private:
 
     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:
     DocxAttributeOutput( DocxExport &rExport, ::sax_fastparser::FSHelperPtr 
pSerializer, oox::drawingml::DrawingML* pDrawingML );
 
commit 3f6df3835fec71ea61894f9a3bbfe5e4a06a5495
Author: Miklos Vajna <vmik...@collabora.co.uk>
Date:   Fri Feb 21 12:56:59 2014 +0100

    DOCX export: fix image counters for multiple documents
    
    The next commit will have a testcase for this, too.
    
    Change-Id: Ia4ed1bb5095cc1ade78a404ec3328b7d1349dc3d

diff --git a/sw/source/filter/ww8/docxexport.cxx 
b/sw/source/filter/ww8/docxexport.cxx
index e004cc5..2f416e5 100644
--- a/sw/source/filter/ww8/docxexport.cxx
+++ b/sw/source/filter/ww8/docxexport.cxx
@@ -379,6 +379,9 @@ void DocxExport::ExportDocument_Impl()
     // init sections
     m_pSections = new MSWordSections( *this );
 
+    // Make sure images are counted from one, even when exporting multiple 
documents.
+    oox::drawingml::DrawingML::ResetCounters();
+
     WriteMainText();
 
     WriteFootnotesEndnotes();
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to