sw/qa/extras/rtfexport/rtfexport3.cxx | 23 +++++++ sw/source/filter/ww8/rtfexport.cxx | 8 ++ writerfilter/qa/cppunittests/rtftok/data/do-not-break-wrapped-tables.rtf | 10 +++ writerfilter/qa/cppunittests/rtftok/rtfdispatchflag.cxx | 17 +++++ writerfilter/source/dmapper/SettingsTable.cxx | 3 - writerfilter/source/rtftok/rtfdispatchflag.cxx | 8 -- writerfilter/source/rtftok/rtfdispatchvalue.cxx | 30 ---------- writerfilter/source/rtftok/rtfdocumentimpl.hxx | 3 - 8 files changed, 60 insertions(+), 42 deletions(-)
New commits: commit 391cbd2b780b5fd9670f16b3cbd38ec1e3fb6339 Author: Miklos Vajna <vmik...@collabora.com> AuthorDate: Tue May 30 08:21:33 2023 +0200 Commit: Miklos Vajna <vmik...@collabora.com> CommitDate: Wed May 31 15:25:02 2023 +0200 sw floattable: handle \nobrkwrptbl in the RTF filter This is the RTF import/export for the functionality added in commit 08fa2903df1a7cf9a1647fcf967e4c8b57dad793 (sw floattable: add a DoNotBreakWrappedTables compat flag, 2023-05-24). (cherry picked from commit d785d26a5599d3d546b96958b0f1c6d5ed777a0d) Change-Id: I3c458cbe1f4b0947a94651cc205f2a7660d2ec2c Reviewed-on: https://gerrit.libreoffice.org/c/core/+/152412 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com> Reviewed-by: Miklos Vajna <vmik...@collabora.com> diff --git a/sw/qa/extras/rtfexport/rtfexport3.cxx b/sw/qa/extras/rtfexport/rtfexport3.cxx index 00f553a499b0..e3b0906705df 100644 --- a/sw/qa/extras/rtfexport/rtfexport3.cxx +++ b/sw/qa/extras/rtfexport/rtfexport3.cxx @@ -28,6 +28,7 @@ #include <wrtsh.hxx> #include <fmtpdsc.hxx> #include <IDocumentContentOperations.hxx> +#include <IDocumentSettingAccess.hxx> using namespace css; @@ -430,6 +431,28 @@ DECLARE_RTFEXPORT_TEST(testTdf128428_dntblnsbdb, "tdf128428_dntblnsbdb.rtf") CPPUNIT_ASSERT_EQUAL(1, getPages()); } +CPPUNIT_TEST_FIXTURE(Test, testDontBreakWrappedTables) +{ + // Given a document with no 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 rtf: + reload(mpFilter, "dont-break-wrapped-tables.rtf"); + + // Then make sure \nobrkwrptbl is not written: + SwDoc* pDoc = getSwDoc(); + IDocumentSettingAccess& rIDSA = pDoc->getIDocumentSettingAccess(); + bool bDontBreakWrappedTables = rIDSA.get(DocumentSettingId::DO_NOT_BREAK_WRAPPED_TABLES); + // Without the accompanying fix in place, this test would have failed, the compat flag was not + // set. + CPPUNIT_ASSERT(bDontBreakWrappedTables); +} + CPPUNIT_TEST_FIXTURE(Test, testRtlGutter) { auto verify = [this]() { diff --git a/sw/source/filter/ww8/rtfexport.cxx b/sw/source/filter/ww8/rtfexport.cxx index 15f8faa74f0e..81ca9e2d241c 100644 --- a/sw/source/filter/ww8/rtfexport.cxx +++ b/sw/source/filter/ww8/rtfexport.cxx @@ -831,7 +831,8 @@ ErrCode RtfExport::ExportDocument_Impl() Strm().WriteCharPtr(OOO_STRING_SVTOOLS_RTF_MARGMIRROR); // Gutter at top? - if (m_rDoc.getIDocumentSettingAccess().get(DocumentSettingId::GUTTER_AT_TOP)) + IDocumentSettingAccess& rIDSA = m_rDoc.getIDocumentSettingAccess(); + if (rIDSA.get(DocumentSettingId::GUTTER_AT_TOP)) { Strm().WriteCharPtr(LO_STRING_SVTOOLS_RTF_GUTTERPRL); } @@ -860,7 +861,10 @@ ErrCode RtfExport::ExportDocument_Impl() // Enable breaking wrapped tables across pages: the "no" in the control word's name is // confusing. - Strm().WriteOString(LO_STRING_SVTOOLS_RTF_NOBRKWRPTBL); + if (!rIDSA.get(DocumentSettingId::DO_NOT_BREAK_WRAPPED_TABLES)) + { + Strm().WriteOString(LO_STRING_SVTOOLS_RTF_NOBRKWRPTBL); + } // size and empty margins of the page if (m_rDoc.GetPageDescCnt()) diff --git a/writerfilter/qa/cppunittests/rtftok/data/do-not-break-wrapped-tables.rtf b/writerfilter/qa/cppunittests/rtftok/data/do-not-break-wrapped-tables.rtf new file mode 100644 index 000000000000..f6ec013cb1dc --- /dev/null +++ b/writerfilter/qa/cppunittests/rtftok/data/do-not-break-wrapped-tables.rtf @@ -0,0 +1,10 @@ +{\rtf1 +\paperw12240\paperh6203\margl1440\margr1440\margt1440\margb1440 +\pard\plain First paragraph\par +\pard\plain\intbl A1\cell +\pard\plain\trowd\trrh1812\tpvpara\tphcol\tposy10\tposx20\tdfrmtxtLeft30\tdfrmtxtRight40\cellx3828\row +\pard\plain\intbl A2\cell +\pard\plain\trowd\trrh1812\tpvpara\tphcol\tposy10\tposx20\tdfrmtxtLeft30\tdfrmtxtRight40\cellx3828\row +\pard\plain Second paragraph. +\par +} diff --git a/writerfilter/qa/cppunittests/rtftok/rtfdispatchflag.cxx b/writerfilter/qa/cppunittests/rtftok/rtfdispatchflag.cxx index 810dc750d7d7..6d6b85be61c4 100644 --- a/writerfilter/qa/cppunittests/rtftok/rtfdispatchflag.cxx +++ b/writerfilter/qa/cppunittests/rtftok/rtfdispatchflag.cxx @@ -65,6 +65,23 @@ CPPUNIT_TEST_FIXTURE(Test, testFloatingTable) nExpected = o3tl::convert(40, o3tl::Length::twip, o3tl::Length::mm100); CPPUNIT_ASSERT_EQUAL(nExpected, nRightMargin); } + +CPPUNIT_TEST_FIXTURE(Test, testDoNotBreakWrappedTables) +{ + // Given a document without \nobrkwrptbl: + // When importing that document: + loadFromURL(u"do-not-break-wrapped-tables.rtf"); + + // 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/source/dmapper/SettingsTable.cxx b/writerfilter/source/dmapper/SettingsTable.cxx index 6ebdccddbfe7..586d8b752ef9 100644 --- a/writerfilter/source/dmapper/SettingsTable.cxx +++ b/writerfilter/source/dmapper/SettingsTable.cxx @@ -153,6 +153,7 @@ SettingsTable::SettingsTable(const DomainMapper& rDomainMapper) m_pImpl->m_bDoNotUseHTMLParagraphAutoSpacing = true; // Longer space sequence is opt-in for RTF, and not in OOXML. m_pImpl->m_bLongerSpaceSequence = true; + m_pImpl->m_bDoNotBreakWrappedTables = true; } m_pImpl->m_pDocumentProtection = std::make_shared<DocumentProtection>(); m_pImpl->m_pWriteProtection = std::make_shared<WriteProtection>(); @@ -398,7 +399,7 @@ void SettingsTable::lcl_sprm(Sprm& rSprm) m_pImpl->m_bGutterAtTop = nIntValue != 0; break; case NS_ooxml::LN_CT_Compat_doNotBreakWrappedTables: - m_pImpl->m_bDoNotBreakWrappedTables = true; + m_pImpl->m_bDoNotBreakWrappedTables = nIntValue != 0; break; default: { diff --git a/writerfilter/source/rtftok/rtfdispatchflag.cxx b/writerfilter/source/rtftok/rtfdispatchflag.cxx index bc3c3037e16d..0ca4d20645f1 100644 --- a/writerfilter/source/rtftok/rtfdispatchflag.cxx +++ b/writerfilter/source/rtftok/rtfdispatchflag.cxx @@ -34,11 +34,6 @@ namespace writerfilter::rtftok { bool RTFDocumentImpl::dispatchFloatingTableFlag(RTFKeyword nKeyword) { - if (!m_bBreakWrappedTables) - { - return false; - } - // Positioned Wrapped Tables OUString aParam; switch (nKeyword) @@ -1337,7 +1332,8 @@ RTFError RTFDocumentImpl::dispatchFlag(RTFKeyword nKeyword) break; case RTFKeyword::NOBRKWRPTBL: { - m_bBreakWrappedTables = true; + m_aSettingsTableSprms.set(NS_ooxml::LN_CT_Compat_doNotBreakWrappedTables, + new RTFValue(0)); } break; default: diff --git a/writerfilter/source/rtftok/rtfdispatchvalue.cxx b/writerfilter/source/rtftok/rtfdispatchvalue.cxx index f580ec69c5e9..d68c9bc2f3dc 100644 --- a/writerfilter/source/rtftok/rtfdispatchvalue.cxx +++ b/writerfilter/source/rtftok/rtfdispatchvalue.cxx @@ -1825,66 +1825,36 @@ RTFError RTFDocumentImpl::dispatchValue(RTFKeyword nKeyword, int nParam) break; case RTFKeyword::TPOSY: { - if (!m_bBreakWrappedTables) - { - break; - } - putNestedAttribute(m_aStates.top().getTableRowSprms(), NS_ooxml::LN_CT_TblPrBase_tblpPr, NS_ooxml::LN_CT_TblPPr_tblpY, new RTFValue(nParam)); } break; case RTFKeyword::TPOSX: { - if (!m_bBreakWrappedTables) - { - break; - } - putNestedAttribute(m_aStates.top().getTableRowSprms(), NS_ooxml::LN_CT_TblPrBase_tblpPr, NS_ooxml::LN_CT_TblPPr_tblpX, new RTFValue(nParam)); } break; case RTFKeyword::TDFRMTXTLEFT: { - if (!m_bBreakWrappedTables) - { - break; - } - putNestedAttribute(m_aStates.top().getTableRowSprms(), NS_ooxml::LN_CT_TblPrBase_tblpPr, NS_ooxml::LN_CT_TblPPr_leftFromText, new RTFValue(nParam)); } break; case RTFKeyword::TDFRMTXTRIGHT: { - if (!m_bBreakWrappedTables) - { - break; - } - putNestedAttribute(m_aStates.top().getTableRowSprms(), NS_ooxml::LN_CT_TblPrBase_tblpPr, NS_ooxml::LN_CT_TblPPr_rightFromText, new RTFValue(nParam)); } break; case RTFKeyword::TDFRMTXTTOP: { - if (!m_bBreakWrappedTables) - { - break; - } - putNestedAttribute(m_aStates.top().getTableRowSprms(), NS_ooxml::LN_CT_TblPrBase_tblpPr, NS_ooxml::LN_CT_TblPPr_topFromText, new RTFValue(nParam)); } break; case RTFKeyword::TDFRMTXTBOTTOM: { - if (!m_bBreakWrappedTables) - { - break; - } - putNestedAttribute(m_aStates.top().getTableRowSprms(), NS_ooxml::LN_CT_TblPrBase_tblpPr, NS_ooxml::LN_CT_TblPPr_bottomFromText, new RTFValue(nParam)); } diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.hxx b/writerfilter/source/rtftok/rtfdocumentimpl.hxx index bf1ff2c30611..47fedc431bfb 100644 --- a/writerfilter/source/rtftok/rtfdocumentimpl.hxx +++ b/writerfilter/source/rtftok/rtfdocumentimpl.hxx @@ -991,9 +991,6 @@ private: /// Are we after a \cell, but before a \row? bool m_bAfterCellBeforeRow; - - /// Floating tables are single-page by default. - bool m_bBreakWrappedTables = false; }; } // namespace writerfilter::rtftok