sw/qa/extras/ooxmlexport/ooxmlexport8.cxx                                |    
7 +-
 writerfilter/qa/cppunittests/dmapper/DomainMapperTableHandler.cxx        |   
28 +++++++---
 writerfilter/qa/cppunittests/dmapper/data/floattable-nested-3tables.docx 
|binary
 writerfilter/source/dmapper/DomainMapperTableHandler.cxx                 |   
11 +--
 4 files changed, 27 insertions(+), 19 deletions(-)

New commits:
commit 1795d5183d5371a24e8dcb15f8671c78b2c94665
Author:     Miklos Vajna <vmik...@collabora.com>
AuthorDate: Fri Apr 28 08:28:22 2023 +0200
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Fri Apr 28 09:24:01 2023 +0200

    sw floattable, crashtesting: fix PDF export of tdf114111-3.docx
    
    Converting the bugdoc to PDF crashed Writer layout since commit
    ce3308a926f036b87515b8cd97d2b197063dc77a (tdf#61594 sw floattable:
    import floating tables as split flys by default, 2023-04-12).
    
    The stripped down document has 3 tables: a toplevel, a middle and an
    inner one. The middle one is floating. SwFrame::GetNextFlyLeaf() doesn't
    support nested tables, so we move an inner table frame to a next page,
    causing a frame to have the in-table flag, without a table frame parent,
    leading to a crash.
    
    Fix the problem by just disabling floating tables for nested tables for
    now.
    
    It can be enabled later, and not supporting inner floating tables was
    the intent of 8818dd359fbf0f37e1b318de89ab2ea7d735f58 (sw floattable:
    fix handling of nested non-floating tables at cell start, 2023-03-20)
    anyway.
    
    Change-Id: I75db01c6c0fdd803130fbb2a8f2f90c6180051ac
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/151155
    Reviewed-by: Miklos Vajna <vmik...@collabora.com>
    Tested-by: Jenkins

diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport8.cxx 
b/sw/qa/extras/ooxmlexport/ooxmlexport8.cxx
index 8f2cfae7e0ad..3e1bffa299e8 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport8.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport8.cxx
@@ -512,9 +512,10 @@ DECLARE_OOXMLEXPORT_TEST(testTDF91260, "tdf91260.docx")
 
 DECLARE_OOXMLEXPORT_TEST(testFdo74357, "fdo74357.docx")
 {
-    // Floating table wasn't converted to a textframe.
-    // This was 0.
-    CPPUNIT_ASSERT_EQUAL(1, getShapes());
+    // Normal outer table, floating inner table.
+    uno::Reference<text::XTextTablesSupplier> xTextTablesSupplier(mxComponent, 
uno::UNO_QUERY);
+    uno::Reference<container::XIndexAccess> 
xIndexAccess(xTextTablesSupplier->getTextTables(), uno::UNO_QUERY);
+    CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xIndexAccess->getCount());
 
     // Bottom margin of the first paragraph was too large, causing a layout 
problem.
     // This was 494.
diff --git a/writerfilter/qa/cppunittests/dmapper/DomainMapperTableHandler.cxx 
b/writerfilter/qa/cppunittests/dmapper/DomainMapperTableHandler.cxx
index 0650e48fe607..803f2cd938b6 100644
--- a/writerfilter/qa/cppunittests/dmapper/DomainMapperTableHandler.cxx
+++ b/writerfilter/qa/cppunittests/dmapper/DomainMapperTableHandler.cxx
@@ -50,14 +50,11 @@ CPPUNIT_TEST_FIXTURE(Test, test1cellInsidevRightborder)
 CPPUNIT_TEST_FIXTURE(Test, testNestedFloatingTable)
 {
     loadFromURL(u"nested-floating-table.docx");
-    uno::Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(mxComponent, 
uno::UNO_QUERY);
-    uno::Reference<container::XIndexAccess> xDrawPage = 
xDrawPageSupplier->getDrawPage();
-    uno::Reference<beans::XPropertySet> xFrame(xDrawPage->getByIndex(0), 
uno::UNO_QUERY);
-    bool bIsFollowingTextFlow = false;
-    xFrame->getPropertyValue("IsFollowingTextFlow") >>= bIsFollowingTextFlow;
-    // Without the accompanying fix in place, this test would have failed, the 
nested floating table
-    // was partly positioned outside the table cell, leading to overlapping 
text.
-    CPPUNIT_ASSERT(bIsFollowingTextFlow);
+    // Normal outer table, floating inner tables.
+    uno::Reference<text::XTextTablesSupplier> xTextTablesSupplier(mxComponent, 
uno::UNO_QUERY);
+    uno::Reference<container::XIndexAccess> 
xIndexAccess(xTextTablesSupplier->getTextTables(),
+                                                         uno::UNO_QUERY);
+    CPPUNIT_ASSERT_EQUAL(sal_Int32(3), xIndexAccess->getCount());
 }
 
 CPPUNIT_TEST_FIXTURE(Test, testFloatingTableBreakBefore)
@@ -82,6 +79,21 @@ CPPUNIT_TEST_FIXTURE(Test, testFloatingTableBreakBefore)
     // i.e. the page break was lost.
     CPPUNIT_ASSERT_EQUAL(style::BreakType_PAGE_BEFORE, eBreakType);
 }
+
+CPPUNIT_TEST_FIXTURE(Test, test3NestedFloatingTables)
+{
+    // Given a document with nested tables: outer and inner one is normal, 
middle one is floating:
+    // When laying out that document:
+    loadFromURL(u"floattable-nested-3tables.docx");
+
+    // Then make sure we don't crash and create the 3 tables:
+    // Without the accompanying fix in place, this would have crashed, layout 
can't handle nested
+    // floating tables currently.
+    uno::Reference<text::XTextTablesSupplier> xTextTablesSupplier(mxComponent, 
uno::UNO_QUERY);
+    uno::Reference<container::XIndexAccess> 
xIndexAccess(xTextTablesSupplier->getTextTables(),
+                                                         uno::UNO_QUERY);
+    CPPUNIT_ASSERT_EQUAL(sal_Int32(3), xIndexAccess->getCount());
+}
 }
 
 CPPUNIT_PLUGIN_IMPLEMENT();
diff --git 
a/writerfilter/qa/cppunittests/dmapper/data/floattable-nested-3tables.docx 
b/writerfilter/qa/cppunittests/dmapper/data/floattable-nested-3tables.docx
new file mode 100644
index 000000000000..f171a1150695
Binary files /dev/null and 
b/writerfilter/qa/cppunittests/dmapper/data/floattable-nested-3tables.docx 
differ
diff --git a/writerfilter/source/dmapper/DomainMapperTableHandler.cxx 
b/writerfilter/source/dmapper/DomainMapperTableHandler.cxx
index ac2f00a7d5a5..c70615a49a9f 100644
--- a/writerfilter/source/dmapper/DomainMapperTableHandler.cxx
+++ b/writerfilter/source/dmapper/DomainMapperTableHandler.cxx
@@ -1329,7 +1329,7 @@ static void lcl_convertFormulaRanges(const 
uno::Reference<text::XTextTable> & xT
     }
 }
 
-void DomainMapperTableHandler::endTable(unsigned int nestedTableLevel, bool 
bTableStartsAtCellStart)
+void DomainMapperTableHandler::endTable(unsigned int nestedTableLevel, bool 
/*bTableStartsAtCellStart*/)
 {
 #ifdef DBG_UTIL
     TagLogger::getInstance().startElement("tablehandler.endTable");
@@ -1576,14 +1576,9 @@ void DomainMapperTableHandler::endTable(unsigned int 
nestedTableLevel, bool bTab
             m_aTableProperties->getValue(TablePropertyMap::TABLE_WIDTH_TYPE, 
nTableWidthType);
             // m_xText points to the body text, get the current xText from 
m_rDMapper_Impl, in case e.g. we would be in a header.
             uno::Reference<text::XTextAppendAndConvert> 
xTextAppendAndConvert(m_rDMapper_Impl.GetTopTextAppend(), uno::UNO_QUERY);
-            // Only execute the conversion if the table is not anchored at
-            // the start of an outer table cell, that's not yet
-            // implemented.
-            // Multi-page floating tables works if an outer/toplevel table is 
floating, but not
-            // when an inner table would float.
-            bool bToplevelSplitFly = nestedTableLevel <= 1;
+            // Only execute the conversion for top-level tables.
             uno::Reference<beans::XPropertySet> xFrameAnchor;
-            if (xTextAppendAndConvert.is() && (!bTableStartsAtCellStart || 
bToplevelSplitFly))
+            if (xTextAppendAndConvert.is() && nestedTableLevel <= 1)
             {
                 std::deque<css::uno::Any> aFramedRedlines = 
m_rDMapper_Impl.m_aStoredRedlines[StoredRedlines::FRAME];
                 std::vector<sal_Int32> redPos, redLen;

Reply via email to