summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.com>2023-06-01 08:31:34 +0200
committerMiklos Vajna <vmiklos@collabora.com>2023-06-01 09:18:44 +0200
commite2f90d1d0e51c68dd01c9968cdb7a3bbb5658613 (patch)
treec15e0c44f8dbbf3601ba2a64f8a24ba54c00ffd5
parent4ee0aa2ebda0ccd61ea4e0da3caa07d5f9a72eb9 (diff)
tdf#103869 sw floattable: fix lost table right before a section break from DOCX
The bugdoc has 2 pages and 2 tables, one table on each page. The table on the first page was missing in Writer. What happened is that the floating table is anchored in the next paragraph, but that is removed (since it's the last one in the section, so no need for a "next" paragraph), which shifted the table to the next section, which was already a wrong anchor point. Then that next section (next page) started with a (floating) table, so a dummy text node was inserted at the start, which means once it's disposed at the end of the 2nd section, we lost the first floating table with its bad anchor. Fixing the problem was a bit tricky, because DomainMapper_Impl::RemoveLastParagraph() is called before the text frame conversion would be invoked in DomainMapperTableHandler::endTable(), so we can't check if this last paragraph has something anchored in it, as it's too early. Instead, detect that a floating table will be created, and don't remove the last paragraph in this case, since we know that we're at the end of the section (that's why we remove the last paragraph). The export result looks OK, we keep the paragraph-table-paragraph-table-paragraph model correctly. Change-Id: I4612a15d0d1ad3fe527593a21a4120096790a33f (cherry picked from commit ba2f4ebc5343f3eca27baaaf27906be2e6486fcd) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/152472 Reviewed-by: Miklos Vajna <vmiklos@collabora.com> Tested-by: Jenkins
-rw-r--r--writerfilter/qa/cppunittests/dmapper/DomainMapper_Impl.cxx17
-rw-r--r--writerfilter/qa/cppunittests/dmapper/data/floattable-sectend.docxbin0 -> 16398 bytes
-rw-r--r--writerfilter/source/dmapper/DomainMapper_Impl.cxx8
3 files changed, 25 insertions, 0 deletions
diff --git a/writerfilter/qa/cppunittests/dmapper/DomainMapper_Impl.cxx b/writerfilter/qa/cppunittests/dmapper/DomainMapper_Impl.cxx
index 858faf709fd4..733fef6b1db6 100644
--- a/writerfilter/qa/cppunittests/dmapper/DomainMapper_Impl.cxx
+++ b/writerfilter/qa/cppunittests/dmapper/DomainMapper_Impl.cxx
@@ -348,6 +348,23 @@ CPPUNIT_TEST_FIXTURE(Test, testFloatingTableSectionBreak)
// i.e. the document was of 1 page, the section break was lost.
CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int16>(2), xCursor->getPage());
}
+
+CPPUNIT_TEST_FIXTURE(Test, testFloattableSectend)
+{
+ // Given a document with 2 tables, table 1 on page 1, table 2 on page 2:
+ loadFromURL(u"floattable-sectend.docx");
+
+ // When importing that document and listing the tables:
+ uno::Reference<text::XTextTablesSupplier> xTextDocument(mxComponent, uno::UNO_QUERY);
+ uno::Reference<container::XIndexAccess> xTables(xTextDocument->getTextTables(), uno::UNO_QUERY);
+
+ // Then make sure that we have two tables:
+ // Without the accompanying fix in place, this test would have failed with:
+ // - Expected: 2
+ // - Actual : 1
+ // i.e. the first table was lost.
+ CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(2), xTables->getCount());
+}
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/writerfilter/qa/cppunittests/dmapper/data/floattable-sectend.docx b/writerfilter/qa/cppunittests/dmapper/data/floattable-sectend.docx
new file mode 100644
index 000000000000..50a121412d10
--- /dev/null
+++ b/writerfilter/qa/cppunittests/dmapper/data/floattable-sectend.docx
Binary files differ
diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.cxx b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
index b4405517eab0..14cdc0a155ca 100644
--- a/writerfilter/source/dmapper/DomainMapper_Impl.cxx
+++ b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
@@ -754,6 +754,14 @@ void DomainMapper_Impl::RemoveLastParagraph( )
uno::Reference< text::XTextAppend > xTextAppend = m_aTextAppendStack.top().xTextAppend;
if (!xTextAppend.is())
return;
+
+ if (hasTableManager() && getTableManager().getCurrentTablePosition().getLength() != 0)
+ {
+ // If we have an open floating table, then don't remove this paragraph, since that'll be the
+ // anchor of the floating table. Otherwise we would lose the table.
+ return;
+ }
+
try
{
uno::Reference< text::XTextCursor > xCursor;