diff options
author | Mike Kaganski <mike.kaganski@collabora.com> | 2023-12-25 15:32:41 +0600 |
---|---|---|
committer | Xisco Fauli <xiscofauli@libreoffice.org> | 2024-01-03 10:26:58 +0100 |
commit | 62e8b576b287111bd0dc79e71334f77dcf909938 (patch) | |
tree | d7bb39449932d306e90e5b9b6013901a66041b23 /sw | |
parent | 9826f6175bda0d5812ac1cdf22431973524ec0f6 (diff) |
tdf#158855: Make sure to not add extra paragraph after a table in a section
Simplify the condition for last paragraph removal in lcl_utext, and clean up
the complications piled after commit 2e8aad6d45c53d554ccaf26de998ede708cfc289
(fdo#39056 fdo#75431 Section Properties if section starts with table,
2014-04-24). This makes sure that the trailing extra paragraph gets properly
removed, even when there was a dummy paragraph added for a table in section.
Because of the removed check, import used to avoid the removal of the extra
paragraph immediately following a table (when the table needed to be the last
element in the section); hence, in DomainMapper_Impl::appendTextSectionAfter,
a last section's table was followed by two paragraphs (one that is expected
to stay after the created section, and one before that, that was not removed
after the table). xCursor had ininitally both paragraphs in the selection
after the forward goto* calls; and then, gotoLeft excluded only the last
paragraph from the selection. After the change, in such a case, there is only
one paragraph in the end: the one that should stay after the created section.
But calling gotoLeft then would have to put the end of selection to a text
node inside the table; since the selection that starts before the table can't
end inside the table, the call resulted in the whole table excluded from the
selection. This requires to add a paragraph here, to allow the previous
behavior of cursor; and then the last paragraph in section is destroyed. The
code makes sure that the trailing paragraph kept after the creation of the
section has all the properties applied to the old last paragraph.
testFdo53985 used to check for total 9 paragraphs in the document; while
3 of those were introduced exactly by the bug fixed here; they are absent
in Word. The test is fixed; its logic is unchanged, and it still correctly
tests that a round-trip doesn't increase number of paragraphs.
Change-Id: Ibf6349ba7906dac185c759eb3b58c1849ee5064a
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/161275
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Signed-off-by: Xisco Fauli <xiscofauli@libreoffice.org>
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/161300
Diffstat (limited to 'sw')
-rw-r--r-- | sw/qa/extras/ooxmlexport/data/section_break_after_table.docx | bin | 0 -> 12583 bytes | |||
-rw-r--r-- | sw/qa/extras/ooxmlexport/ooxmlexport20.cxx | 19 | ||||
-rw-r--r-- | sw/qa/extras/ooxmlexport/ooxmlexport8.cxx | 2 |
3 files changed, 20 insertions, 1 deletions
diff --git a/sw/qa/extras/ooxmlexport/data/section_break_after_table.docx b/sw/qa/extras/ooxmlexport/data/section_break_after_table.docx Binary files differnew file mode 100644 index 000000000000..9f8e4c687bbb --- /dev/null +++ b/sw/qa/extras/ooxmlexport/data/section_break_after_table.docx diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport20.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport20.cxx index 4a4e6e087b68..639aea237618 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport20.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport20.cxx @@ -1022,6 +1022,25 @@ CPPUNIT_TEST_FIXTURE(Test, testtdf158044) assertXPath(pXmlDoc, "/w:document/w:body/w:p[8]/w:r[4]/w:rPr[1]/w:shadow[1]"_ostr); } +CPPUNIT_TEST_FIXTURE(Test, testTdf158855) +{ + // Given a table immediately followed by a section break + load(createFileURL(u"section_break_after_table.docx")); + + // Check that the import doesn't produce an extra empty paragraph before a page break + CPPUNIT_ASSERT_EQUAL(2, getPages()); // was 3 + CPPUNIT_ASSERT_EQUAL(2, getParagraphs()); // was 3 + uno::Reference<text::XTextTable>(getParagraphOrTable(1), uno::UNO_QUERY_THROW); + getParagraph(2, u"Next page"_ustr); // was empty, with the 3rd being "Next page" + + saveAndReload(mpFilter); + + CPPUNIT_ASSERT_EQUAL(2, getPages()); + CPPUNIT_ASSERT_EQUAL(2, getParagraphs()); + uno::Reference<text::XTextTable>(getParagraphOrTable(1), uno::UNO_QUERY_THROW); + getParagraph(2, u"Next page"_ustr); +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport8.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport8.cxx index 158b8f61d873..10fd87ebec2c 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport8.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport8.cxx @@ -756,7 +756,7 @@ DECLARE_OOXMLEXPORT_TEST(testFdo53985, "fdo53985.docx") CPPUNIT_ASSERT_EQUAL_MESSAGE("Section3 is protected", false, getProperty<bool>(xSect, "IsProtected")); // This was increasing by 3 every round-trip - an extra paragraph after each table in sections - CPPUNIT_ASSERT_EQUAL(9, getParagraphs()); + CPPUNIT_ASSERT_EQUAL(6, getParagraphs()); } DECLARE_OOXMLEXPORT_TEST(testFdo59638, "fdo59638.docx") |