sw/qa/extras/ooxmlexport/data/floattable-nested-cell-start.odt |binary
 sw/qa/extras/ooxmlexport/ooxmlexport10.cxx                     |   17 
++++++++++
 sw/source/filter/ww8/docxattributeoutput.cxx                   |   16 +++++----
 3 files changed, 26 insertions(+), 7 deletions(-)

New commits:
commit d50e5d6d53c94124f825758a74e186b934fc2a4e
Author:     Miklos Vajna <vmik...@collabora.com>
AuthorDate: Thu Sep 14 08:29:30 2023 +0200
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Thu Sep 14 09:15:33 2023 +0200

    Related: tdf#55160 sw floattable, nested DOCX exp: fix inner tbl at cell 
start
    
    A cut-down bugdoc had an inline table, and an inner floating table,
    anchored in the start of the C1 cell.
    
    Exporting to DOCX resulted in a layout that looks like the floating
    table is not anchored inside the outer table anymore. Checking the
    markup, the floating table was written between row 1 & row 2, which is
    not a valid position for a floating table. Probably the intention was to
    write the floating table before the first paragraph in C1.
    
    Fix the problem by still writing the floating table in
    DocxAttributeOutput::StartParagraph(), before opening <w:p>, but do this
    after opening table/row/cell, which is late enough to have a correct
    anchor but is early enough to be still outside the paragraph.
    
    The import side of this still needs fixing.
    
    Change-Id: I1827b2def1faaf53312522f5a8415fbe697fcb8b
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/156904
    Reviewed-by: Miklos Vajna <vmik...@collabora.com>
    Tested-by: Jenkins

diff --git a/sw/qa/extras/ooxmlexport/data/floattable-nested-cell-start.odt 
b/sw/qa/extras/ooxmlexport/data/floattable-nested-cell-start.odt
new file mode 100644
index 000000000000..3e2ed72eca8c
Binary files /dev/null and 
b/sw/qa/extras/ooxmlexport/data/floattable-nested-cell-start.odt differ
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport10.cxx 
b/sw/qa/extras/ooxmlexport/ooxmlexport10.cxx
index 6b9a61fe2c0d..fb01ab2b47ba 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport10.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport10.cxx
@@ -139,6 +139,23 @@ CPPUNIT_TEST_FIXTURE(Test, testFloattableNestedDOCXExport)
     assertXPath(pXmlDoc, "//w:tblpPr", 2);
 }
 
+CPPUNIT_TEST_FIXTURE(Test, testFloattableNestedCellStartDOCXExport)
+{
+    // Given a document with a nested floating table at cell start:
+    createSwDoc("floattable-nested-cell-start.odt");
+
+    // When exporting to DOCX:
+    save("Office Open XML Text");
+
+    // Then make sure both floating table is exported at the right position:
+    xmlDocUniquePtr pXmlDoc = parseExport("word/document.xml");
+    // Without the accompanying fix in place, this test would have failed with
+    // - Expected: 1
+    // - Actual  : 0
+    // i.e. the inner <w:tbl> was between the two <w:tr>, not inside the C1 
cell.
+    assertXPath(pXmlDoc, "//w:tc/w:tbl/w:tblPr/w:tblpPr", 1);
+}
+
 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 6d67081e932f..79b9df031924 100644
--- a/sw/source/filter/ww8/docxattributeoutput.cxx
+++ b/sw/source/filter/ww8/docxattributeoutput.cxx
@@ -503,13 +503,6 @@ sal_Int32 
DocxAttributeOutput::StartParagraph(ww8::WW8TableNodeInfo::Pointer_t p
     if ( !m_aFramesOfParagraph.size() || !m_nTextFrameLevel )
         m_aFramesOfParagraph.push(std::vector<ww8::Frame>());
 
-    // look ahead for floating tables that were put into a frame during import
-    // floating tables in shapes are not supported: exclude this case
-    if (!m_rExport.SdrExporter().IsDMLAndVMLDrawingOpen())
-    {
-        checkAndWriteFloatingTables(*this);
-    }
-
     if ( m_nColBreakStatus == COLBRK_POSTPONE )
         m_nColBreakStatus = COLBRK_WRITE;
 
@@ -557,6 +550,15 @@ 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 (!m_rExport.SdrExporter().IsDMLAndVMLDrawingOpen())
+    {
+        // Do this after opening table/row/cell, so floating tables anchored 
at cell start go inside
+        // the cell, not outside.
+        checkAndWriteFloatingTables(*this);
+    }
+
     // Look up the "sdt end before this paragraph" property early, when it
     // would normally arrive, it would be too late (would be after the
     // paragraph start has been written).

Reply via email to