diff options
author | Miklos Vajna <vmiklos@collabora.com> | 2023-04-28 08:28:22 +0200 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.com> | 2023-05-02 10:32:17 +0200 |
commit | d161c6693039bbddeab447834c4cba271d5426d9 (patch) | |
tree | cc3585cc666321c8c33e4b5faa0d54f32b6f9b3e /writerfilter | |
parent | a7a9575e10cc63646e8e854d96bc379b95ce091b (diff) |
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.
(cherry picked from commit 1795d5183d5371a24e8dcb15f8671c78b2c94665)
Change-Id: I75db01c6c0fdd803130fbb2a8f2f90c6180051ac
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/151253
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Diffstat (limited to 'writerfilter')
-rw-r--r-- | writerfilter/qa/cppunittests/dmapper/DomainMapperTableHandler.cxx | 28 | ||||
-rw-r--r-- | writerfilter/qa/cppunittests/dmapper/data/floattable-nested-3tables.docx | bin | 0 -> 131360 bytes | |||
-rw-r--r-- | writerfilter/source/dmapper/DomainMapperTableHandler.cxx | 11 |
3 files changed, 23 insertions, 16 deletions
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 Binary files differnew file mode 100644 index 000000000000..f171a1150695 --- /dev/null +++ b/writerfilter/qa/cppunittests/dmapper/data/floattable-nested-3tables.docx diff --git a/writerfilter/source/dmapper/DomainMapperTableHandler.cxx b/writerfilter/source/dmapper/DomainMapperTableHandler.cxx index e36404b8f68c..8c52f8269706 100644 --- a/writerfilter/source/dmapper/DomainMapperTableHandler.cxx +++ b/writerfilter/source/dmapper/DomainMapperTableHandler.cxx @@ -1330,7 +1330,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"); @@ -1577,14 +1577,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; |