officecfg/registry/schema/org/openoffice/Office/Writer.xcs | 7 ++- sw/qa/core/layout/flycnt.cxx | 12 ----- sw/qa/extras/ooxmlexport/ooxmlexport12.cxx | 1 sw/qa/extras/ooxmlexport/ooxmlexport19.cxx | 2 sw/qa/extras/ooxmlexport/ooxmlexport8.cxx | 2 sw/qa/extras/ooxmlexport/ooxmlexport9.cxx | 3 - sw/qa/extras/ooxmlimport/ooxmlimport2.cxx | 1 sw/qa/extras/uiwriter/uiwriter2.cxx | 2 sw/qa/filter/ww8/data/floattable-compat14.doc |binary sw/qa/filter/ww8/ww8.cxx | 22 ++++++++++ sw/qa/uitest/writer_tests6/tdf124675.py | 27 ++++++------- sw/qa/unit/swmodeltestbase.cxx | 10 ++-- sw/source/filter/ww8/ww8par6.cxx | 25 ++++++++++++ 13 files changed, 71 insertions(+), 43 deletions(-)
New commits: commit b0067dee80e8c33e5be9ca8acaafe7dab6cfc085 Author: Miklos Vajna <vmik...@collabora.com> AuthorDate: Fri Apr 14 08:11:49 2023 +0200 Commit: Miklos Vajna <vmik...@collabora.com> CommitDate: Fri Apr 14 09:30:40 2023 +0200 sw floatable: teach the DOC import about SwFormatFlySplit - add a new DOC/ImportFloatingTableAsSplitFly setting, replacing the old (enabled by default DOCX/ImportFloatingTableAsSplitFly) one - clean up old uses of SwModelTestBase::FlySplitGuard - if SwWW8ImplReader::StartApo has a table position, then map that to SwFormatFlySplit=true in the ImportFloatingTableAsSplitFly case - testcase for this Change-Id: Ibd798ea7eb79d7ec00620dd8921797232f4732d5 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/150381 Reviewed-by: Miklos Vajna <vmik...@collabora.com> Tested-by: Jenkins diff --git a/officecfg/registry/schema/org/openoffice/Office/Writer.xcs b/officecfg/registry/schema/org/openoffice/Office/Writer.xcs index 200572a620f3..dcd5dc71e68f 100644 --- a/officecfg/registry/schema/org/openoffice/Office/Writer.xcs +++ b/officecfg/registry/schema/org/openoffice/Office/Writer.xcs @@ -5662,12 +5662,17 @@ </info> <value>true</value> </prop> + </group> + <group oor:name="DOC"> + <info> + <desc>Contains settings for importing DOC.</desc> + </info> <prop oor:name="ImportFloatingTableAsSplitFly" oor:type="xs:boolean" oor:nillable="false"> <info> <desc>Specifies whether a floating table should be imported as a split text frame.</desc> <label>Import floating table as split frame.</label> </info> - <value>true</value> + <value>false</value> </prop> </group> </group> diff --git a/sw/qa/core/layout/flycnt.cxx b/sw/qa/core/layout/flycnt.cxx index 72591730bfb2..74368f01a01c 100644 --- a/sw/qa/core/layout/flycnt.cxx +++ b/sw/qa/core/layout/flycnt.cxx @@ -140,7 +140,6 @@ CPPUNIT_TEST_FIXTURE(Test, testSplitFlyWithTable) CPPUNIT_TEST_FIXTURE(Test, testSplitFlyVertOffset) { // Given a document with a floattable, split on 2 pages and a positive vertical offset: - SwModelTestBase::FlySplitGuard aGuard; createSwDoc("floattable-vertoffset.docx"); // When laying out that document: @@ -184,7 +183,6 @@ CPPUNIT_TEST_FIXTURE(Test, testSplitFlyVertOffset) CPPUNIT_TEST_FIXTURE(Test, testSplitFly3Pages) { // Given a document with a floattable, split on 3 pages: - SwModelTestBase::FlySplitGuard aGuard; createSwDoc("floattable-3pages.docx"); // When laying out that document: @@ -240,7 +238,6 @@ CPPUNIT_TEST_FIXTURE(Test, testSplitFly3Pages) CPPUNIT_TEST_FIXTURE(Test, testSplitFlyRow) { // Given a document with a floattable, single row split on 2 pages: - SwModelTestBase::FlySplitGuard aGuard; createSwDoc("floattable-rowsplit.docx"); // When laying out that document: @@ -299,7 +296,6 @@ CPPUNIT_TEST_FIXTURE(Test, testSplitFlyEnable) CPPUNIT_TEST_FIXTURE(Test, testSplitFlyFooter) { // Given a document with a floattable, table split on 2 pages with headers/footers: - SwModelTestBase::FlySplitGuard aGuard; createSwDoc("floattable-footer.docx"); // When laying out that document: @@ -338,7 +334,6 @@ CPPUNIT_TEST_FIXTURE(Test, testSplitFlyFooter) CPPUNIT_TEST_FIXTURE(Test, testSplitFlyFooter2Rows) { // Given a document with a 2nd page that contains the second half of a split row + a last row: - SwModelTestBase::FlySplitGuard aGuard; createSwDoc("floattable-footer-2rows.docx"); // When laying out that document: @@ -359,7 +354,6 @@ CPPUNIT_TEST_FIXTURE(Test, testSplitFlyFooter2Rows) CPPUNIT_TEST_FIXTURE(Test, testSplitFly2Cols) { // Given a document with a 2nd page that contains the second half of a split row and 2 columns: - SwModelTestBase::FlySplitGuard aGuard; createSwDoc("floattable-2cols.docx"); // When laying out that document: @@ -380,7 +374,6 @@ CPPUNIT_TEST_FIXTURE(Test, testSplitFly2Cols) CPPUNIT_TEST_FIXTURE(Test, testSplitFlyWidow) { // Given a document with a 2nd page that contains 2 lines, due to widow control: - SwModelTestBase::FlySplitGuard aGuard; createSwDoc("floattable-widow.docx"); // When laying out that document: @@ -426,7 +419,6 @@ CPPUNIT_TEST_FIXTURE(Test, testSplitFlyWidow) CPPUNIT_TEST_FIXTURE(Test, testSplitFlyCompat14) { // Given a Word 2010 document with 2 pages, one table row each: - SwModelTestBase::FlySplitGuard aGuard; createSwDoc("floattable-compat14.docx"); // When laying out that document: @@ -465,7 +457,6 @@ CPPUNIT_TEST_FIXTURE(Test, testSplitFlyCompat14) CPPUNIT_TEST_FIXTURE(Test, testSplitFlyCompat14Nosplit) { // Given a Word 2010 document with 2 pages, 2 rows on page 1, 1 row on page 2: - SwModelTestBase::FlySplitGuard aGuard; createSwDoc("floattable-compat14-nosplit.docx"); // When laying out that document: @@ -498,7 +489,6 @@ CPPUNIT_TEST_FIXTURE(Test, testSplitFlyCompat14Nosplit) CPPUNIT_TEST_FIXTURE(Test, testSplitFlyCompat14Body) { // Given a Word 2010 document with 2 pages, 1 row on page 1, 1 row on page 2: - SwModelTestBase::FlySplitGuard aGuard; createSwDoc("floattable-compat14-body.docx"); // When laying out that document: @@ -535,7 +525,6 @@ CPPUNIT_TEST_FIXTURE(Test, testSplitFlyCompat14Body) CPPUNIT_TEST_FIXTURE(Test, testSplitFlyFollowHorizontalPosition) { // Given a document with 2 pages, master fly on page 1, follow fly on page 2: - SwModelTestBase::FlySplitGuard aGuard; createSwDoc("floattable-hori-pos.docx"); // When laying out that document: @@ -635,7 +624,6 @@ CPPUNIT_TEST_FIXTURE(Test, testSplitFly1stRowDelete) CPPUNIT_TEST_FIXTURE(Test, testSplitFly3rdRowDelete) { // Given a document with a floattable, split on 3 pages: - SwModelTestBase::FlySplitGuard aGuard; createSwDoc("floattable-3pages.docx"); // When deleting the row of A3: diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport12.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport12.cxx index d7b24692d2a7..c97a60677b3c 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport12.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport12.cxx @@ -1509,7 +1509,6 @@ CPPUNIT_TEST_FIXTURE(Test, testTdf149388) CPPUNIT_TEST_FIXTURE(Test, testTdf132271) { - SwModelTestBase::FlySplitGuard aGuard; // see also testTdf149388 loadAndSave("tdf149388.docx"); xmlDocUniquePtr pXmlDoc = parseExport("word/document.xml"); diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport19.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport19.cxx index 984d67c46b89..94a2c57c00ea 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport19.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport19.cxx @@ -262,7 +262,6 @@ DECLARE_OOXMLEXPORT_TEST(mathtype, "mathtype.docx") CPPUNIT_TEST_FIXTURE(Test, testTdf8255) { - SwModelTestBase::FlySplitGuard aGuard; auto verify = [this]() { // A full-page-wide multi-page floating table should be allowed to split: uno::Reference<text::XTextFramesSupplier> xDocument(mxComponent, uno::UNO_QUERY); @@ -598,7 +597,6 @@ DECLARE_OOXMLEXPORT_TEST(testTdf97371, "tdf97371.docx") CPPUNIT_TEST_FIXTURE(Test, testTdf99140) { - SwModelTestBase::FlySplitGuard aGuard; auto verify = [this]() { // A multi-page floating table appeared only on the first page. SwDoc* pDoc = getSwDoc(); diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport8.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport8.cxx index 5bfc8fa8be57..8f2cfae7e0ad 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport8.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport8.cxx @@ -721,7 +721,6 @@ DECLARE_OOXMLEXPORT_TEST(testN793998, "n793998.docx") CPPUNIT_TEST_FIXTURE(Test, testN779642) { - SwModelTestBase::FlySplitGuard aGuard; auto verify = [this]() { uno::Reference<text::XTextTablesSupplier> xTextTablesSupplier(mxComponent, uno::UNO_QUERY); @@ -996,7 +995,6 @@ DECLARE_OOXMLEXPORT_TEST(testPageBorderShadow, "page-border-shadow.docx") DECLARE_OOXMLEXPORT_TEST(testN816593, "n816593.docx") { - SwModelTestBase::FlySplitGuard aGuard; // Two consecutive <w:tbl> without any paragraph in between, but with different tblpPr. In this // case we need to have 2 different tables instead of 1 uno::Reference<text::XTextTablesSupplier> xTablesSupplier(mxComponent, uno::UNO_QUERY); diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport9.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport9.cxx index 50c07f693c25..fc4a1c9f1445 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport9.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport9.cxx @@ -125,7 +125,6 @@ DECLARE_SW_ROUNDTRIP_TEST(testBadDocm, "bad.docm", nullptr, DocmTest) CPPUNIT_TEST_FIXTURE(Test, testTdf109063) { - SwModelTestBase::FlySplitGuard aGuard; auto verify = [this]() { // A near-page-width table should be allowed to split: uno::Reference<text::XTextFramesSupplier> xDocument(mxComponent, uno::UNO_QUERY); @@ -850,7 +849,6 @@ DECLARE_OOXMLEXPORT_TEST(testBnc519228OddBreaks, "bnc519228_odd-breaksB.docx") CPPUNIT_TEST_FIXTURE(Test, testTdf79329) { - SwModelTestBase::FlySplitGuard aGuard; auto verify = [this]() { uno::Reference<text::XTextTablesSupplier> xTablesSupplier(mxComponent, uno::UNO_QUERY); uno::Reference<container::XIndexAccess> xTables(xTablesSupplier->getTextTables(), uno::UNO_QUERY); @@ -1177,7 +1175,6 @@ DECLARE_OOXMLEXPORT_TEST(testTdf107033, "tdf107033.docx") #if HAVE_MORE_FONTS CPPUNIT_TEST_FIXTURE(Test, testTdf107889) { - SwModelTestBase::FlySplitGuard aGuard; auto verify = [this]() { // This was 1, multi-page table was imported as a non-split fly. xmlDocUniquePtr pXmlDoc = parseLayoutDump(); diff --git a/sw/qa/extras/ooxmlimport/ooxmlimport2.cxx b/sw/qa/extras/ooxmlimport/ooxmlimport2.cxx index caaa4b6842de..c3e834823c02 100644 --- a/sw/qa/extras/ooxmlimport/ooxmlimport2.cxx +++ b/sw/qa/extras/ooxmlimport/ooxmlimport2.cxx @@ -671,7 +671,6 @@ CPPUNIT_TEST_FIXTURE(Test, testTdf121804) CPPUNIT_TEST_FIXTURE(Test, testTdf114217) { - SwModelTestBase::FlySplitGuard aGuard; // The floating table was not split between page 1 and page 2. createSwDoc("tdf114217.docx"); SwDoc* pDoc = getSwDoc(); diff --git a/sw/qa/extras/uiwriter/uiwriter2.cxx b/sw/qa/extras/uiwriter/uiwriter2.cxx index 9a38e572b8b5..ccfe95910f5e 100644 --- a/sw/qa/extras/uiwriter/uiwriter2.cxx +++ b/sw/qa/extras/uiwriter/uiwriter2.cxx @@ -2445,7 +2445,6 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testUnfloatButtonSmallTable) CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testUnfloatButton) { - SwModelTestBase::FlySplitGuard aGuard; // Different use cases where unfloat button should be visible const std::vector<OUString> aTestFiles = { "unfloatable_floating_table.odt", // Typical use case of multipage floating table @@ -2509,7 +2508,6 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testUnfloatButtonReadOnlyMode) CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testUnfloating) { - SwModelTestBase::FlySplitGuard aGuard; // Test unfloating with tables imported from different file formats const std::vector<OUString> aTestFiles = { "unfloatable_floating_table.odt", diff --git a/sw/qa/filter/ww8/data/floattable-compat14.doc b/sw/qa/filter/ww8/data/floattable-compat14.doc new file mode 100644 index 000000000000..020aa2deb376 Binary files /dev/null and b/sw/qa/filter/ww8/data/floattable-compat14.doc differ diff --git a/sw/qa/filter/ww8/ww8.cxx b/sw/qa/filter/ww8/ww8.cxx index e5121d5612d6..f4db23ac6f8b 100644 --- a/sw/qa/filter/ww8/ww8.cxx +++ b/sw/qa/filter/ww8/ww8.cxx @@ -19,6 +19,9 @@ #include <frmmgr.hxx> #include <frameformats.hxx> #include <formatflysplit.hxx> +#include <IDocumentLayoutAccess.hxx> +#include <rootfrm.hxx> +#include <pagefrm.hxx> namespace { @@ -226,6 +229,25 @@ CPPUNIT_TEST_FIXTURE(Test, testDocxFloatingTableExport) // i.e. no floating table was exported. assertXPath(pXmlDoc, "//w:tbl/w:tblPr/w:tblpPr", 1); } + +CPPUNIT_TEST_FIXTURE(Test, testDocFloatingTableImport) +{ + SwModelTestBase::FlySplitGuard aGuard; + // Given a document with 2 pages: + createSwDoc("floattable-compat14.doc"); + + // When laying out that document: + calcLayout(); + + // Make sure that the table is split between page 1 and page 2: + SwDoc* pDoc = getSwDoc(); + SwRootFrame* pLayout = pDoc->getIDocumentLayoutAccess().GetCurrentLayout(); + auto pPage1 = dynamic_cast<SwPageFrame*>(pLayout->Lower()); + CPPUNIT_ASSERT(pPage1); + // Without the accompanying fix in place, this test would have failed, the fly frame was not + // split between page 1 and page 2. + CPPUNIT_ASSERT(pPage1->GetNext()); +} } CPPUNIT_PLUGIN_IMPLEMENT(); diff --git a/sw/qa/uitest/writer_tests6/tdf124675.py b/sw/qa/uitest/writer_tests6/tdf124675.py index 93bae8ea9284..83bddd42b108 100644 --- a/sw/qa/uitest/writer_tests6/tdf124675.py +++ b/sw/qa/uitest/writer_tests6/tdf124675.py @@ -14,24 +14,23 @@ from uitest.uihelper.common import get_state_as_dict, get_url_for_data_file class tdf124675(UITestCase): def test_tdf124675_crash_moving_SwTextFrame_previous_page(self): - with self.ui_test.set_config('/org.openoffice.Office.Writer/Filter/Import/DOCX/ImportFloatingTableAsSplitFly', True): - with self.ui_test.load_file(get_url_for_data_file("tdf124675.docx")) as writer_doc: - xWriterDoc = self.xUITest.getTopFocusWindow() - xWriterEdit = xWriterDoc.getChild("writer_edit") + with self.ui_test.load_file(get_url_for_data_file("tdf124675.docx")) as writer_doc: + xWriterDoc = self.xUITest.getTopFocusWindow() + xWriterEdit = xWriterDoc.getChild("writer_edit") - self.assertEqual(writer_doc.CurrentController.PageCount, 2) - self.assertEqual(get_state_as_dict(xWriterEdit)["CurrentPage"], "1") + self.assertEqual(writer_doc.CurrentController.PageCount, 2) + self.assertEqual(get_state_as_dict(xWriterEdit)["CurrentPage"], "1") - for i in range(52): - xWriterEdit.executeAction("TYPE", mkPropertyValues({"KEYCODE": "RETURN"})) + for i in range(52): + xWriterEdit.executeAction("TYPE", mkPropertyValues({"KEYCODE": "RETURN"})) - self.assertEqual(writer_doc.CurrentController.PageCount, 4) - self.assertEqual(get_state_as_dict(xWriterEdit)["CurrentPage"], "3") + self.assertEqual(writer_doc.CurrentController.PageCount, 4) + self.assertEqual(get_state_as_dict(xWriterEdit)["CurrentPage"], "3") - for i in range(52): - self.xUITest.executeCommand(".uno:Undo") + for i in range(52): + self.xUITest.executeCommand(".uno:Undo") - self.assertEqual(writer_doc.CurrentController.PageCount, 2) - self.assertEqual(get_state_as_dict(xWriterEdit)["CurrentPage"], "1") + self.assertEqual(writer_doc.CurrentController.PageCount, 2) + self.assertEqual(get_state_as_dict(xWriterEdit)["CurrentPage"], "1") # vim: set shiftwidth=4 softtabstop=4 expandtab: diff --git a/sw/qa/unit/swmodeltestbase.cxx b/sw/qa/unit/swmodeltestbase.cxx index 5f48985c86fe..446c290597b0 100644 --- a/sw/qa/unit/swmodeltestbase.cxx +++ b/sw/qa/unit/swmodeltestbase.cxx @@ -39,11 +39,11 @@ using namespace css; SwModelTestBase::FlySplitGuard::FlySplitGuard() { m_bOldValue - = officecfg::Office::Writer::Filter::Import::DOCX::ImportFloatingTableAsSplitFly::get(); + = officecfg::Office::Writer::Filter::Import::DOC::ImportFloatingTableAsSplitFly::get(); std::shared_ptr<comphelper::ConfigurationChanges> pChanges( comphelper::ConfigurationChanges::create()); - officecfg::Office::Writer::Filter::Import::DOCX::ImportFloatingTableAsSplitFly::set(true, - pChanges); + officecfg::Office::Writer::Filter::Import::DOC::ImportFloatingTableAsSplitFly::set(true, + pChanges); pChanges->commit(); } @@ -51,8 +51,8 @@ SwModelTestBase::FlySplitGuard::~FlySplitGuard() { std::shared_ptr<comphelper::ConfigurationChanges> pChanges( comphelper::ConfigurationChanges::create()); - officecfg::Office::Writer::Filter::Import::DOCX::ImportFloatingTableAsSplitFly::set(m_bOldValue, - pChanges); + officecfg::Office::Writer::Filter::Import::DOC::ImportFloatingTableAsSplitFly::set(m_bOldValue, + pChanges); pChanges->commit(); } diff --git a/sw/source/filter/ww8/ww8par6.cxx b/sw/source/filter/ww8/ww8par6.cxx index 78bd8b8a2dba..ba4e3ef6b9b8 100644 --- a/sw/source/filter/ww8/ww8par6.cxx +++ b/sw/source/filter/ww8/ww8par6.cxx @@ -68,6 +68,7 @@ #include <i18nlangtag/mslangid.hxx> #include <svx/xfillit0.hxx> #include <svx/xflclit.hxx> +#include <officecfg/Office/Writer.hxx> #include "sortedarray.hxx" #include "sprmids.hxx" #include <node.hxx> @@ -99,6 +100,7 @@ #include "ww8graf.hxx" #include <fmtwrapinfluenceonobjpos.hxx> +#include <formatflysplit.hxx> using namespace sw::util; using namespace sw::types; @@ -2457,6 +2459,22 @@ bool SwWW8ImplReader::IsDropCap() const return false; } +namespace +{ +bool IsFlySplitAllowed() +{ + bool bRet + = officecfg::Office::Writer::Filter::Import::DOC::ImportFloatingTableAsSplitFly::get(); + + if (!bRet) + { + bRet = getenv("SW_FORCE_FLY_SPLIT") != nullptr; + } + + return bRet; +} +} + bool SwWW8ImplReader::StartApo(const ApoTestResults &rApo, const WW8_TablePos *pTabPos) { m_xWFlyPara = ConstructApo(rApo, pTabPos); @@ -2498,6 +2516,13 @@ bool SwWW8ImplReader::StartApo(const ApoTestResults &rApo, const WW8_TablePos *p // ofz#34749 we shouldn't anchor anything into an 'extra' paragraph scheduled for // removal at end of import, but check if that scenario is happening m_aExtraneousParas.remove_if_present(m_pPaM->GetPointNode().GetTextNode()); + + if (pTabPos && IsFlySplitAllowed()) + { + // Map a positioned table to a split fly. + aFlySet.Put(SwFormatFlySplit(true)); + } + m_xSFlyPara->SetFlyFormat(m_rDoc.MakeFlySection(WW8SwFlyPara::eAnchor, m_pPaM->GetPoint(), &aFlySet)); OSL_ENSURE(m_xSFlyPara->GetFlyFormat()->GetAnchor().GetAnchorId() ==