diff options
author | Miklos Vajna <vmiklos@collabora.com> | 2023-05-25 08:18:02 +0200 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.com> | 2023-05-25 10:31:31 +0200 |
commit | f5dc52dc9a068fec3323c3089929a81675b0d1ba (patch) | |
tree | 7e64cf49e0d866f383ecd7bdf011e829761310e3 | |
parent | 9747d9a6ea954dfca4152d36fdb28a8b77fec84b (diff) |
sw floattable: handle <w:doNotBreakWrappedTables> in the DOCX filter
<w:doNotBreakWrappedTables> primarily appears in documents imported from
RTF, unless \nobrkwrptbl is specified there (which, confusingly, means
to do split floating tables).
Change-Id: I1891b89787719805e6c87045dee3c63c68ed2940
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/152255
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Tested-by: Jenkins
-rw-r--r-- | sw/qa/filter/ww8/ww8.cxx | 22 | ||||
-rw-r--r-- | sw/source/filter/ww8/docxexport.cxx | 13 | ||||
-rw-r--r-- | writerfilter/CppunitTest_writerfilter_dmapper.mk | 1 | ||||
-rw-r--r-- | writerfilter/qa/cppunittests/dmapper/SettingsTable.cxx | 46 | ||||
-rw-r--r-- | writerfilter/qa/cppunittests/dmapper/data/do-not-break-wrapped-tables.docx | bin | 0 -> 13150 bytes | |||
-rw-r--r-- | writerfilter/source/dmapper/SettingsTable.cxx | 10 |
6 files changed, 89 insertions, 3 deletions
diff --git a/sw/qa/filter/ww8/ww8.cxx b/sw/qa/filter/ww8/ww8.cxx index d9eaff9fd82e..8f6266a86426 100644 --- a/sw/qa/filter/ww8/ww8.cxx +++ b/sw/qa/filter/ww8/ww8.cxx @@ -25,6 +25,7 @@ #include <rootfrm.hxx> #include <pagefrm.hxx> #include <ftnfrm.hxx> +#include <IDocumentSettingAccess.hxx> namespace { @@ -305,6 +306,27 @@ CPPUNIT_TEST_FIXTURE(Test, test3Endnotes) // document, which is incorrect. CPPUNIT_ASSERT_EQUAL(3, nEndnotes); } + +CPPUNIT_TEST_FIXTURE(Test, testDoNotBreakWrappedTables) +{ + // Given a document with the DO_NOT_BREAK_WRAPPED_TABLES compat mode enabled: + createSwDoc(); + SwDoc* pDoc = getSwDoc(); + IDocumentSettingAccess& rIDSA = pDoc->getIDocumentSettingAccess(); + rIDSA.set(DocumentSettingId::DO_NOT_BREAK_WRAPPED_TABLES, true); + + // When saving to docx: + save("Office Open XML Text"); + + // Then make sure the compat flag is serialized: + xmlDocUniquePtr pXmlDoc = parseExport("word/settings.xml"); + // Without the accompanying fix in place, this test would have failed with: + // - Expected: 1 + // - Actual : 0 + // - XPath '/w:settings/w:compat/w:doNotBreakWrappedTables' number of nodes is incorrect + // i.e. <w:doNotBreakWrappedTables> was not written. + assertXPath(pXmlDoc, "/w:settings/w:compat/w:doNotBreakWrappedTables", 1); +} } CPPUNIT_PLUGIN_IMPLEMENT(); diff --git a/sw/source/filter/ww8/docxexport.cxx b/sw/source/filter/ww8/docxexport.cxx index 59b91603acc1..af9979a1d660 100644 --- a/sw/source/filter/ww8/docxexport.cxx +++ b/sw/source/filter/ww8/docxexport.cxx @@ -1001,7 +1001,8 @@ static auto WriteCompat(SwDoc const& rDoc, ::sax_fastparser::FSHelperPtr const& rpFS, sal_Int32 & rTargetCompatibilityMode) -> void { - if (!rDoc.getIDocumentSettingAccess().get(DocumentSettingId::ADD_EXT_LEADING)) + const IDocumentSettingAccess& rIDSA = rDoc.getIDocumentSettingAccess(); + if (!rIDSA.get(DocumentSettingId::ADD_EXT_LEADING)) { rpFS->singleElementNS(XML_w, XML_noLeading); if (rTargetCompatibilityMode > 14) @@ -1010,13 +1011,19 @@ WriteCompat(SwDoc const& rDoc, ::sax_fastparser::FSHelperPtr const& rpFS, } } // Do not justify lines with manual break - if (rDoc.getIDocumentSettingAccess().get(DocumentSettingId::DO_NOT_JUSTIFY_LINES_WITH_MANUAL_BREAK)) + if (rIDSA.get(DocumentSettingId::DO_NOT_JUSTIFY_LINES_WITH_MANUAL_BREAK)) { rpFS->singleElementNS(XML_w, XML_doNotExpandShiftReturn); } // tdf#146515 export "Use printer metrics for document formatting" - if (!rDoc.getIDocumentSettingAccess().get(DocumentSettingId::USE_VIRTUAL_DEVICE)) + if (!rIDSA.get(DocumentSettingId::USE_VIRTUAL_DEVICE)) rpFS->singleElementNS(XML_w, XML_usePrinterMetrics); + + if (rIDSA.get(DocumentSettingId::DO_NOT_BREAK_WRAPPED_TABLES)) + { + // Map the DoNotBreakWrappedTables compat flag to <w:doNotBreakWrappedTables>. + rpFS->singleElementNS(XML_w, XML_doNotBreakWrappedTables); + } } void DocxExport::WriteSettings() diff --git a/writerfilter/CppunitTest_writerfilter_dmapper.mk b/writerfilter/CppunitTest_writerfilter_dmapper.mk index 6dcfa52d6184..209a8e0d6bb8 100644 --- a/writerfilter/CppunitTest_writerfilter_dmapper.mk +++ b/writerfilter/CppunitTest_writerfilter_dmapper.mk @@ -24,6 +24,7 @@ $(eval $(call gb_CppunitTest_add_exception_objects,writerfilter_dmapper, \ writerfilter/qa/cppunittests/dmapper/TextEffectsHandler \ writerfilter/qa/cppunittests/dmapper/PropertyMap \ writerfilter/qa/cppunittests/dmapper/SdtHelper \ + writerfilter/qa/cppunittests/dmapper/SettingsTable \ )) $(eval $(call gb_CppunitTest_use_libraries,writerfilter_dmapper, \ diff --git a/writerfilter/qa/cppunittests/dmapper/SettingsTable.cxx b/writerfilter/qa/cppunittests/dmapper/SettingsTable.cxx new file mode 100644 index 000000000000..8b36a6170bb0 --- /dev/null +++ b/writerfilter/qa/cppunittests/dmapper/SettingsTable.cxx @@ -0,0 +1,46 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include <test/unoapi_test.hxx> + +#include <com/sun/star/beans/XPropertySet.hpp> + +using namespace com::sun::star; + +namespace +{ +/// Tests for writerfilter/source/dmapper/SettingsTable.cxx. +class Test : public UnoApiTest +{ +public: + Test() + : UnoApiTest("/writerfilter/qa/cppunittests/dmapper/data/") + { + } +}; + +CPPUNIT_TEST_FIXTURE(Test, testDoNotBreakWrappedTables) +{ + // Given a document with <w:doNotBreakWrappedTables>: + // When importing that document: + loadFromURL(u"do-not-break-wrapped-tables.docx"); + + // Then make sure that the matching compat flag is set: + uno::Reference<lang::XMultiServiceFactory> xDocument(mxComponent, uno::UNO_QUERY); + uno::Reference<beans::XPropertySet> xSettings( + xDocument->createInstance("com.sun.star.document.Settings"), uno::UNO_QUERY); + bool bDoNotBreakWrappedTables{}; + xSettings->getPropertyValue("DoNotBreakWrappedTables") >>= bDoNotBreakWrappedTables; + // Without the accompanying fix in place, this test would have failed, the compat flag was not + // set. + CPPUNIT_ASSERT(bDoNotBreakWrappedTables); +} +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/qa/cppunittests/dmapper/data/do-not-break-wrapped-tables.docx b/writerfilter/qa/cppunittests/dmapper/data/do-not-break-wrapped-tables.docx Binary files differnew file mode 100644 index 000000000000..088c056f3511 --- /dev/null +++ b/writerfilter/qa/cppunittests/dmapper/data/do-not-break-wrapped-tables.docx diff --git a/writerfilter/source/dmapper/SettingsTable.cxx b/writerfilter/source/dmapper/SettingsTable.cxx index d24dae617c01..6ebdccddbfe7 100644 --- a/writerfilter/source/dmapper/SettingsTable.cxx +++ b/writerfilter/source/dmapper/SettingsTable.cxx @@ -108,6 +108,7 @@ struct SettingsTable_Impl std::shared_ptr<DocumentProtection> m_pDocumentProtection; std::shared_ptr<WriteProtection> m_pWriteProtection; bool m_bGutterAtTop = false; + bool m_bDoNotBreakWrappedTables = false; SettingsTable_Impl() : m_nDefaultTabStop( 720 ) //default is 1/2 in @@ -396,6 +397,9 @@ void SettingsTable::lcl_sprm(Sprm& rSprm) case NS_ooxml::LN_CT_Settings_gutterAtTop: m_pImpl->m_bGutterAtTop = nIntValue != 0; break; + case NS_ooxml::LN_CT_Compat_doNotBreakWrappedTables: + m_pImpl->m_bDoNotBreakWrappedTables = true; + break; default: { #ifdef DBG_UTIL @@ -628,6 +632,12 @@ void SettingsTable::ApplyProperties(uno::Reference<text::XTextDocument> const& x } } + if (m_pImpl->m_bDoNotBreakWrappedTables) + { + // Map <w:doNotBreakWrappedTables> to the DoNotBreakWrappedTables compat flag. + xDocumentSettings->setPropertyValue("DoNotBreakWrappedTables", uno::Any(true)); + } + // Auto hyphenation: turns on hyphenation by default, <w:suppressAutoHyphens/> may still disable it at a paragraph level. // Situation is similar for RTF_WIDOWCTRL, which turns on widow / orphan control by default. if (!(m_pImpl->m_bAutoHyphenation || m_pImpl->m_bNoHyphenateCaps || m_pImpl->m_bWidowControl)) |