sw/qa/extras/ooxmlexport/data/floattable-nested.odt |binary
 sw/qa/extras/ooxmlexport/ooxmlexport10.cxx          |   17 +++++++++++++++++
 sw/source/filter/ww8/docxattributeoutput.cxx        |    5 ++++-
 3 files changed, 21 insertions(+), 1 deletion(-)

New commits:
commit 2887e6b8edbb4fdb093515a3a68269ed40e42116
Author:     Miklos Vajna <vmik...@collabora.com>
AuthorDate: Tue Sep 12 08:42:31 2023 +0200
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Tue Sep 12 09:35:12 2023 +0200

    sw floattable, nesting: fix DOCX export
    
    There were two problems here:
    
    1) DocxAttributeOutput::StartParagraph() didn't try to export an inner
       floating table as a floating table, resulting in writing a shape that
       can't span over multiple pages.
    
       Dropping the !pTextNodeInfo check should be OK, we'll just now
       clear the m_aFloatingTablesOfParagraph list at the end of the outer
       table.
    
    2) Once we tried to export the inner fly, the actual table/row/cell
       start was missing, because m_tableReference.m_nTableDepth wasn't
       reset, so DocxAttributeOutput::StartParagraph() didn't know it has to
       emit a table definition before the first para of the table.
    
       Fix this by stashing away the table state before the inner fly's
       export and restoring it after the inner fly export, similar to how this
       is done in e.g. DocxExport::WriteHeaderFooter().
    
    This is related to tdf#55160.
    
    Change-Id: Ib860283d32e392e2906aa12bc9eb61b5af5ca8de
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/156833
    Reviewed-by: Miklos Vajna <vmik...@collabora.com>
    Tested-by: Jenkins

diff --git a/sw/qa/extras/ooxmlexport/data/floattable-nested.odt 
b/sw/qa/extras/ooxmlexport/data/floattable-nested.odt
new file mode 100644
index 000000000000..8644412f60b6
Binary files /dev/null and 
b/sw/qa/extras/ooxmlexport/data/floattable-nested.odt differ
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport10.cxx 
b/sw/qa/extras/ooxmlexport/ooxmlexport10.cxx
index 5ad22de67e62..6b9a61fe2c0d 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport10.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport10.cxx
@@ -122,6 +122,23 @@ DECLARE_OOXMLEXPORT_TEST(testWpsOnly, "wps-only.docx")
     CPPUNIT_ASSERT_EQUAL(false, getProperty<bool>(getShape(2), "Opaque"));
 }
 
+CPPUNIT_TEST_FIXTURE(Test, testFloattableNestedDOCXExport)
+{
+    // Given a document with nested floating tables:
+    createSwDoc("floattable-nested.odt");
+
+    // When exporting to DOCX:
+    save("Office Open XML Text");
+
+    // Then make sure both floating table is exported:
+    xmlDocUniquePtr pXmlDoc = parseExport("word/document.xml");
+    // Without the accompanying fix in place, this test would have failed with
+    // - Expected: 2
+    // - Actual  : 1
+    // i.e. the inner floating table was lost.
+    assertXPath(pXmlDoc, "//w:tblpPr", 2);
+}
+
 DECLARE_OOXMLEXPORT_TEST(testWpgOnly, "wpg-only.docx")
 {
     uno::Reference<drawing::XShape> xShape = getShape(1);
diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx 
b/sw/source/filter/ww8/docxattributeoutput.cxx
index c2a55ff8bfc7..4b51f52c6796 100644
--- a/sw/source/filter/ww8/docxattributeoutput.cxx
+++ b/sw/source/filter/ww8/docxattributeoutput.cxx
@@ -421,6 +421,9 @@ void DocxAttributeOutput::WriteFloatingTable(ww8::Frame 
const* pParentFrame)
     //Save data here and restore when out of scope
     ExportDataSaveRestore aDataGuard(GetExport(), nStt, nEnd, pParentFrame);
 
+    // Stash away info about the current table, so m_tableReference is clean.
+    DocxTableExportContext aTableExportContext(*this);
+
     // set a floatingTableFrame AND unset parent frame,
     // otherwise exporter thinks we are still in a frame
     m_rExport.SetFloatingTableFrame(pParentFrame);
@@ -502,7 +505,7 @@ sal_Int32 
DocxAttributeOutput::StartParagraph(ww8::WW8TableNodeInfo::Pointer_t p
 
     // look ahead for floating tables that were put into a frame during import
     // floating tables in shapes are not supported: exclude this case
-    if (!pTextNodeInfo && !m_rExport.SdrExporter().IsDMLAndVMLDrawingOpen())
+    if (!m_rExport.SdrExporter().IsDMLAndVMLDrawingOpen())
     {
         checkAndWriteFloatingTables(*this);
     }

Reply via email to