writerfilter/qa/cppunittests/ooxml/data/floattable-leak.docx |binary writerfilter/qa/cppunittests/ooxml/ooxml.cxx | 21 +++++++++++ writerfilter/source/ooxml/OOXMLFastContextHandler.cxx | 4 +- 3 files changed, 24 insertions(+), 1 deletion(-)
New commits: commit bb08310014173c968345b2a28b215c8e5294f827 Author: Miklos Vajna <vmik...@collabora.com> AuthorDate: Mon Sep 18 08:35:48 2023 +0200 Commit: Caolán McNamara <caolan.mcnam...@collabora.com> CommitDate: Fri Sep 22 14:22:36 2023 +0200 tdf#55160 sw floattable, nested DOCX imp: fix inner tables at cell start The trouble was that in case two floating tables start at an (outer) cell start, then everything up to the end of the first inner table ended up in the body text, not in the outer table. This happens because the table depth of the inserted dummy character was incorrect. Fix the problem by comparing what model.xml does at <w:p> start and what OOXMLFastContextHandlerTextTable::lcl_startFastElement() did in the dummy paragraph case, and sending the table depth in the dummy case as well. With this the bugdoc has the expected 19 floating tables in Writer and is of 1 page, both matching Word. (cherry picked from commit a33316afa4a20499159b8c900e56658512deb74a) Change-Id: I604956f28fdc01943ab913c5aa30365376c4d2b0 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/157040 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com> Reviewed-by: Caolán McNamara <caolan.mcnam...@collabora.com> diff --git a/writerfilter/qa/cppunittests/ooxml/data/floattable-leak.docx b/writerfilter/qa/cppunittests/ooxml/data/floattable-leak.docx new file mode 100644 index 000000000000..249cad95b8f4 Binary files /dev/null and b/writerfilter/qa/cppunittests/ooxml/data/floattable-leak.docx differ diff --git a/writerfilter/qa/cppunittests/ooxml/ooxml.cxx b/writerfilter/qa/cppunittests/ooxml/ooxml.cxx index fb790252becb..8602ecd8e77d 100644 --- a/writerfilter/qa/cppunittests/ooxml/ooxml.cxx +++ b/writerfilter/qa/cppunittests/ooxml/ooxml.cxx @@ -10,6 +10,7 @@ #include <test/unoapi_test.hxx> #include <com/sun/star/text/XTextTablesSupplier.hpp> +#include <com/sun/star/text/XTextDocument.hpp> using namespace ::com::sun::star; @@ -41,6 +42,26 @@ CPPUNIT_TEST_FIXTURE(Test, testFloatingTablesLost) // i.e. only the inner table was imported, the 2 others were lost. CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(3), xTables->getCount()); } + +CPPUNIT_TEST_FIXTURE(Test, testFloatingTableLeak) +{ + // Given an outer table and 2 inner tables at B1 start: + // When importing that document: + loadFromURL(u"floattable-leak.docx"); + + // Then make sure the body text only contains a table and an empty final paragraph: + uno::Reference<text::XTextDocument> xTextDocument(mxComponent, uno::UNO_QUERY); + uno::Reference<container::XEnumerationAccess> xParaEnumAccess(xTextDocument->getText(), + uno::UNO_QUERY); + uno::Reference<container::XEnumeration> xParaEnum = xParaEnumAccess->createEnumeration(); + uno::Reference<lang::XServiceInfo> xTable(xParaEnum->nextElement(), uno::UNO_QUERY); + // Without the accompanying fix in place, this test would have failed, the document started with + // a paragraph instead of a table. + CPPUNIT_ASSERT(xTable->supportsService("com.sun.star.text.TextTable")); + uno::Reference<lang::XServiceInfo> xParagraph(xParaEnum->nextElement(), uno::UNO_QUERY); + CPPUNIT_ASSERT(xParagraph->supportsService("com.sun.star.text.Paragraph")); + CPPUNIT_ASSERT(!xParaEnum->hasMoreElements()); +} } CPPUNIT_PLUGIN_IMPLEMENT(); diff --git a/writerfilter/source/ooxml/OOXMLFastContextHandler.cxx b/writerfilter/source/ooxml/OOXMLFastContextHandler.cxx index 51eee79e81a3..9646c266f9c7 100644 --- a/writerfilter/source/ooxml/OOXMLFastContextHandler.cxx +++ b/writerfilter/source/ooxml/OOXMLFastContextHandler.cxx @@ -1621,8 +1621,10 @@ void OOXMLFastContextHandlerTextTable::lcl_startFastElement if (mpParserState->GetFloatingTableEnded()) { // We're starting a new table, but the previous table was floating. Insert a dummy paragraph - // to ensure that the floating table has a suitable anchor. + // to ensure that the floating table has a suitable anchor. The function calls here are a + // subset of '<resource name="CT_P" resource="Stream">' in model.xml: startParagraphGroup(); + sendTableDepth(); endOfParagraph(); }