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
This commit is contained in:
Miklos Vajna
2023-05-25 10:31:31 +02:00
parent 9747d9a6ea
commit f5dc52dc9a
6 changed files with 89 additions and 3 deletions
+22
View File
@@ -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();
+10 -3
View File
@@ -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()
@@ -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, \
@@ -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: */
@@ -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))