sw/qa/extras/ooxmlexport/ooxmlexport10.cxx               |   53 ++++++++++---
 sw/qa/extras/ooxmlexport/ooxmlexport8.cxx                |   61 ++++++++-------
 sw/source/filter/ww8/docxtableexport.cxx                 |    2 
 writerfilter/source/dmapper/DomainMapperTableHandler.cxx |    4 
 4 files changed, 83 insertions(+), 37 deletions(-)

New commits:
commit 3777923b34eb72ee2034ea0dbf13d1d6ab122025
Author:     Miklos Vajna <vmik...@collabora.com>
AuthorDate: Mon Mar 20 12:14:53 2023 +0100
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Tue Mar 21 10:06:59 2023 +0000

    sw floattable: fix handling of nested non-floating tables at cell start
    
    CppunitTest_sw_ooxmlexport8's testN779642 failed in the
    SW_FORCE_FLY_SPLIT=1 case.
    
    The bugdoc has a floating table, then an inner, non-floating table. The
    conversion to floating tables was disabled by the
    c1eebcdac9f2b289fd363399130c485ca5ff444c (tdf#79329 DOCX import: fix
    missing outer table with floattable at cell start, 2016-11-08).
    
    Given that SwFormatFlySplit doesn't need the delayed text frame
    conversion, we can get rid of this workaround.
    
    Fix a similar problem on the export side as well, where the positioning
    properties of the outer table leaked into the inner table. Once both the
    import and export are fixed, the test passes.
    
    (cherry picked from commit 48818dd359fbf0f37e1b318de89ab2ea7d735f58)
    
    Change-Id: I884ad38cbc247c885991b0faf0d37221b70a6ba7
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/149193
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>
    Reviewed-by: Miklos Vajna <vmik...@collabora.com>

diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport8.cxx 
b/sw/qa/extras/ooxmlexport/ooxmlexport8.cxx
index 8cd6d4961f38..dbcd48aca0b6 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport8.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport8.cxx
@@ -720,34 +720,41 @@ DECLARE_OOXMLEXPORT_TEST(testN793998, "n793998.docx")
     CPPUNIT_ASSERT(nTextPortion + nTabPortion > nParagraph - nRightMargin);
 }
 
-DECLARE_OOXMLEXPORT_TEST(testN779642, "n779642.docx")
+CPPUNIT_TEST_FIXTURE(Test, testN779642)
 {
-    uno::Reference<text::XTextTablesSupplier> xTextTablesSupplier(mxComponent, 
uno::UNO_QUERY);
-
-    // First problem: check that we have 2 tables, nesting caused the
-    // creation of outer one to fail
-    uno::Reference<container::XIndexAccess> 
xTables(xTextTablesSupplier->getTextTables(), uno::UNO_QUERY);
-    CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong number of imported tables", 
sal_Int32(2), xTables->getCount());
-
-    // Second problem: check that the outer table is in a frame, at the bottom 
of the page
-    uno::Reference<text::XTextTable> 
xTextTable(xTextTablesSupplier->getTextTables()->getByName("Table2"), 
uno::UNO_QUERY);
-    uno::Reference<beans::XPropertySet> xAnchor(xTextTable->getAnchor(), 
uno::UNO_QUERY);
-    uno::Any aFrame = xAnchor->getPropertyValue("TextFrame");
-    uno::Reference<beans::XPropertySet> xFrame;
-    aFrame >>= xFrame;
-    sal_Int16 nValue;
-    xFrame->getPropertyValue("VertOrient") >>= nValue;
-    CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong vertical orientation", 
text::VertOrientation::BOTTOM, nValue);
-    xFrame->getPropertyValue("VertOrientRelation") >>= nValue;
-    CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong vertical orientation relation", 
text::RelOrientation::PAGE_PRINT_AREA, nValue);
-
-    // tdf#106572 - perhaps not the best test to hijack since this file
-    // produces an error in Word, but it nicely matches danger points,
-    // and has a different first footer, so nice visual confirmation.
-    discardDumpedLayout();
-    xmlDocUniquePtr pXmlDoc = parseLayoutDump();
-    // There is no footer text on the first page.
-    assertXPath(pXmlDoc, "/root/page[1]/footer/txt", 0);
+    SwModelTestBase::FlySplitGuard aGuard;
+    auto verify = [this]() {
+        uno::Reference<text::XTextTablesSupplier> 
xTextTablesSupplier(mxComponent, uno::UNO_QUERY);
+
+        // First problem: check that we have 2 tables, nesting caused the
+        // creation of outer one to fail
+        uno::Reference<container::XIndexAccess> 
xTables(xTextTablesSupplier->getTextTables(), uno::UNO_QUERY);
+        CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong number of imported tables", 
sal_Int32(2), xTables->getCount());
+
+        // Second problem: check that the outer table is in a frame, at the 
bottom of the page
+        uno::Reference<text::XTextTable> 
xTextTable(xTextTablesSupplier->getTextTables()->getByName("Table2"), 
uno::UNO_QUERY);
+        uno::Reference<beans::XPropertySet> xAnchor(xTextTable->getAnchor(), 
uno::UNO_QUERY);
+        uno::Any aFrame = xAnchor->getPropertyValue("TextFrame");
+        uno::Reference<beans::XPropertySet> xFrame;
+        aFrame >>= xFrame;
+        sal_Int16 nValue;
+        xFrame->getPropertyValue("VertOrient") >>= nValue;
+        CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong vertical orientation", 
text::VertOrientation::BOTTOM, nValue);
+        xFrame->getPropertyValue("VertOrientRelation") >>= nValue;
+        CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong vertical orientation relation", 
text::RelOrientation::PAGE_PRINT_AREA, nValue);
+
+        // tdf#106572 - perhaps not the best test to hijack since this file
+        // produces an error in Word, but it nicely matches danger points,
+        // and has a different first footer, so nice visual confirmation.
+        discardDumpedLayout();
+        xmlDocUniquePtr pXmlDoc = parseLayoutDump();
+        // There is no footer text on the first page.
+        assertXPath(pXmlDoc, "/root/page[1]/footer/txt", 0);
+    };
+    createSwDoc("n779642.docx");
+    verify();
+    reload(mpFilter, "n779642.docx");
+    verify();
 }
 
 DECLARE_OOXMLEXPORT_TEST(testTbLrHeight, "tblr-height.docx")
diff --git a/sw/source/filter/ww8/docxtableexport.cxx 
b/sw/source/filter/ww8/docxtableexport.cxx
index 2bed2576f738..8f036cf407f2 100644
--- a/sw/source/filter/ww8/docxtableexport.cxx
+++ b/sw/source/filter/ww8/docxtableexport.cxx
@@ -279,6 +279,8 @@ void DocxAttributeOutput::TableDefinition(
                                        pAttributes);
         m_pSerializer->singleElementNS(XML_w, XML_tblpPr, pAttributes);
         bFloatingTableWritten = true;
+        // The outer table was floating, make sure potential inner tables are 
not floating.
+        m_rExport.SetFloatingTableFrame(nullptr);
     }
 
     // Extract properties from grab bag
diff --git a/writerfilter/source/dmapper/DomainMapperTableHandler.cxx 
b/writerfilter/source/dmapper/DomainMapperTableHandler.cxx
index 500775c9f988..1c1682608962 100644
--- a/writerfilter/source/dmapper/DomainMapperTableHandler.cxx
+++ b/writerfilter/source/dmapper/DomainMapperTableHandler.cxx
@@ -1619,7 +1619,9 @@ void DomainMapperTableHandler::endTable(unsigned int 
nestedTableLevel, bool bTab
                 // Only execute the conversion if the table is not anchored at
                 // the start of an outer table cell, that's not yet
                 // implemented.
-                if (xTextAppendAndConvert.is() && !bTableStartsAtCellStart)
+                // Tables starting at cell start are not a problem if we don't 
delay via
+                // m_aPendingFloatingTables.
+                if (xTextAppendAndConvert.is() && (!bTableStartsAtCellStart || 
IsFlySplitAllowed()))
                 {
                     std::deque<css::uno::Any> aFramedRedlines = 
m_rDMapper_Impl.m_aStoredRedlines[StoredRedlines::FRAME];
                     std::vector<sal_Int32> redPos, redLen;
commit 28d8a10a5941779ab8902c95973ef771d576b6f1
Author:     Miklos Vajna <vmik...@collabora.com>
AuthorDate: Mon Mar 20 09:05:39 2023 +0100
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Tue Mar 21 10:06:45 2023 +0000

    sw floattable: fix CppunitTest_sw_ooxmlexport10's testTdf99140
    
    Assert this at a layout level, which still passes:
    
    - the table is split on two different pages
    
    - the width of the floating table is correct
    
    (cherry picked from commit 75249d502e83c10ec38ef8cc8ee58c6c877c6ee9)
    
    Change-Id: I580db33fc7c049d27c1b2c8da5aac4b37e989695
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/149192
    Tested-by: Miklos Vajna <vmik...@collabora.com>
    Reviewed-by: Miklos Vajna <vmik...@collabora.com>

diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport10.cxx 
b/sw/qa/extras/ooxmlexport/ooxmlexport10.cxx
index b4e3de2d74e9..95d29b40dec6 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport10.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport10.cxx
@@ -45,6 +45,12 @@
 #include <IDocumentDrawModelAccess.hxx>
 #include <unotxdoc.hxx>
 #include <docsh.hxx>
+#include <IDocumentLayoutAccess.hxx>
+#include <rootfrm.hxx>
+#include <pagefrm.hxx>
+#include <flyfrms.hxx>
+#include <sortedobjs.hxx>
+#include <txtfrm.hxx>
 
 class Test : public SwModelTestBase
 {
@@ -1217,16 +1223,45 @@ DECLARE_OOXMLEXPORT_TEST(testTdf97371, "tdf97371.docx")
     CPPUNIT_ASSERT(nDiff < 10);
 }
 
-DECLARE_OOXMLEXPORT_TEST(testTdf99140, "tdf99140.docx")
+CPPUNIT_TEST_FIXTURE(Test, testTdf99140)
 {
-    // This was 1: a multi-page floating table was imported as a TextFrame.
-    CPPUNIT_ASSERT_EQUAL(0, getShapes());
-
-    uno::Reference<text::XTextTablesSupplier> xTablesSupplier(mxComponent, 
uno::UNO_QUERY);
-    uno::Reference<container::XIndexAccess> 
xTables(xTablesSupplier->getTextTables(), uno::UNO_QUERY);
-    uno::Reference<beans::XPropertySet> 
xTableProperties(xTables->getByIndex(1), uno::UNO_QUERY);
-    // This was text::HoriOrientation::NONE, the second table was too wide due 
to this.
-    CPPUNIT_ASSERT_EQUAL(text::HoriOrientation::LEFT_AND_WIDTH, 
getProperty<sal_Int16>(xTableProperties, "HoriOrient"));
+    SwModelTestBase::FlySplitGuard aGuard;
+    auto verify = [this]() {
+        // A multi-page floating table appeared only on the first page.
+        SwDoc* pDoc = getSwDoc();
+        SwRootFrame* pLayout = 
pDoc->getIDocumentLayoutAccess().GetCurrentLayout();
+        auto pPage1 = dynamic_cast<SwPageFrame*>(pLayout->Lower());
+        CPPUNIT_ASSERT(pPage1);
+        const SwSortedObjs& rPage1Objs = *pPage1->GetSortedObjs();
+        CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), rPage1Objs.size());
+        auto pPage1Fly = dynamic_cast<SwFlyAtContentFrame*>(rPage1Objs[0]);
+        CPPUNIT_ASSERT(pPage1Fly);
+        SwFrame* pTab1 = pPage1Fly->GetLower();
+        // This was text::HoriOrientation::NONE, the second table was too wide 
due to this.
+        CPPUNIT_ASSERT_EQUAL(static_cast<tools::Long>(9622), 
pTab1->getFrameArea().Width());
+        SwFrame* pRow1 = pTab1->GetLower();
+        SwFrame* pCell1 = pRow1->GetLower();
+        auto pText1 = dynamic_cast<SwTextFrame*>(pCell1->GetLower());
+        CPPUNIT_ASSERT(pText1);
+        CPPUNIT_ASSERT_EQUAL(OUString("Table2:A1"), pText1->GetText());
+
+        auto pPage2 = dynamic_cast<SwPageFrame*>(pPage1->GetNext());
+        CPPUNIT_ASSERT(pPage2);
+        const SwSortedObjs& rPage2Objs = *pPage2->GetSortedObjs();
+        CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), rPage2Objs.size());
+        auto pPage2Fly = dynamic_cast<SwFlyAtContentFrame*>(rPage2Objs[0]);
+        CPPUNIT_ASSERT(pPage2Fly);
+        SwFrame* pTab2 = pPage2Fly->GetLower();
+        SwFrame* pRow2 = pTab2->GetLower();
+        SwFrame* pCell2 = pRow2->GetLower();
+        auto pText2 = dynamic_cast<SwTextFrame*>(pCell2->GetLower());
+        CPPUNIT_ASSERT(pText2);
+        CPPUNIT_ASSERT_EQUAL(OUString("Table2:A2"), pText2->GetText());
+    };
+    createSwDoc("tdf99140.docx");
+    verify();
+    reload(mpFilter, "tdf99140.docx");
+    verify();
 }
 
 CPPUNIT_TEST_FIXTURE(Test, testTableMarginAdjustment)

Reply via email to