sc/source/core/data/dociter.cxx                                          |    
6 +-
 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 -
 9 files changed, 65 insertions(+), 43 deletions(-)

New commits:
commit d785d26a5599d3d546b96958b0f1c6d5ed777a0d
Author:     Miklos Vajna <vmik...@collabora.com>
AuthorDate: Tue May 30 08:21:33 2023 +0200
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Tue May 30 12:49:52 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).
    
    Change-Id: I3c458cbe1f4b0947a94651cc205f2a7660d2ec2c
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/152377
    Reviewed-by: Miklos Vajna <vmik...@collabora.com>
    Tested-by: Jenkins

diff --git a/sw/qa/extras/rtfexport/rtfexport3.cxx 
b/sw/qa/extras/rtfexport/rtfexport3.cxx
index 2b45ca61f33e..8b5e2489a001 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 1bfc2ebc5740..96f0f628f6a9 100644
--- a/sw/source/filter/ww8/rtfexport.cxx
+++ b/sw/source/filter/ww8/rtfexport.cxx
@@ -829,7 +829,8 @@ ErrCode RtfExport::ExportDocument_Impl()
         Strm().WriteOString(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().WriteOString(LO_STRING_SVTOOLS_RTF_GUTTERPRL);
     }
@@ -858,7 +859,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 c1e3ec166fa5..69157a97829f 100644
--- a/writerfilter/source/rtftok/rtfdispatchvalue.cxx
+++ b/writerfilter/source/rtftok/rtfdispatchvalue.cxx
@@ -1844,66 +1844,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
 
commit 5655cc201e5a80997fe21bc2a0c7abcbe4fb488f
Author:     Xisco Fauli <xiscofa...@libreoffice.org>
AuthorDate: Fri May 19 12:17:13 2023 +0200
Commit:     Eike Rathke <er...@redhat.com>
CommitDate: Tue May 30 12:49:42 2023 +0200

    sc: avoid crash in ScHorizontalCellIterator
    
    At least do not crash with release builds as seen in
    
https://crashreport.libreoffice.org/stats/signature/ScHorizontalCellIterator::ScHorizontalCellIterator(ScDocument%20&,short,short,long,short,long)
    
    Change-Id: If253e950bbb709b585dc9398beddd1303dcb1b57
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/152000
    Tested-by: Jenkins
    Reviewed-by: Eike Rathke <er...@redhat.com>

diff --git a/sc/source/core/data/dociter.cxx b/sc/source/core/data/dociter.cxx
index 123d96d91b8c..fd4fa7afe42f 100644
--- a/sc/source/core/data/dociter.cxx
+++ b/sc/source/core/data/dociter.cxx
@@ -1039,7 +1039,11 @@ 
ScHorizontalCellIterator::ScHorizontalCellIterator(ScDocument& rDocument, SCTAB
 {
     assert(mnTab < rDoc.GetTableCount() && "index out of bounds, FIX IT");
 
-    nEndCol = rDoc.maTabs[mnTab]->ClampToAllocatedColumns(nEndCol);
+    const ScTable* pTab = rDoc.FetchTable(mnTab);
+    if (!pTab)
+        return;
+
+    nEndCol = pTab->ClampToAllocatedColumns(nEndCol);
     if (nEndCol < nStartCol) // E.g., somewhere completely outside allocated 
area
         nEndCol = nStartCol - 1; // Empty
 

Reply via email to