include/svtools/rtfkeywd.hxx                                        |    1 
 sw/qa/extras/rtfexport/rtfexport3.cxx                               |   50 
++++++++++
 sw/source/filter/ww8/rtfattributeoutput.cxx                         |    8 +
 writerfilter/qa/cppunittests/rtftok/data/floattable-tbl-overlap.rtf |   17 +++
 writerfilter/qa/cppunittests/rtftok/rtfdispatchflag.cxx             |   18 +++
 writerfilter/source/rtftok/rtfdispatchflag.cxx                      |    8 +
 6 files changed, 102 insertions(+)

New commits:
commit c906e4b19fcbe578a21950a7ecb2fd3b5cfbc2ef
Author:     Miklos Vajna <vmik...@collabora.com>
AuthorDate: Tue Aug 15 08:33:55 2023 +0200
Commit:     Caolán McNamara <caolan.mcnam...@collabora.com>
CommitDate: Thu Aug 17 10:01:30 2023 +0200

    sw floattable: handle AllowOverlap==false in the RTF filter
    
    Map \tabsnoovrlp to SwFormatWrapInfluenceOnObjPos::mbAllowOverlap on
    import and do the opposite on export.
    
    (cherry picked from commit 68c8466dd80e7a964e1377ee3e0308dc449fbf2d)
    
    Change-Id: I3d786041648d62e80f2ea9e3d726426e01a8d192
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/155752
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>
    Reviewed-by: Caolán McNamara <caolan.mcnam...@collabora.com>

diff --git a/include/svtools/rtfkeywd.hxx b/include/svtools/rtfkeywd.hxx
index b4bac2af34cf..fa6346922437 100644
--- a/include/svtools/rtfkeywd.hxx
+++ b/include/svtools/rtfkeywd.hxx
@@ -1240,5 +1240,6 @@
 #define LO_STRING_SVTOOLS_RTF_TDFRMTXTRIGHT "\\tdfrmtxtRight"
 #define LO_STRING_SVTOOLS_RTF_TDFRMTXTTOP "\\tdfrmtxtTop"
 #define LO_STRING_SVTOOLS_RTF_TDFRMTXTBOTTOM "\\tdfrmtxtBottom"
+#define LO_STRING_SVTOOLS_RTF_TABSNOOVRLP "\\tabsnoovrlp"
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/qa/extras/rtfexport/rtfexport3.cxx 
b/sw/qa/extras/rtfexport/rtfexport3.cxx
index e3b0906705df..8fd8aac6268d 100644
--- a/sw/qa/extras/rtfexport/rtfexport3.cxx
+++ b/sw/qa/extras/rtfexport/rtfexport3.cxx
@@ -29,6 +29,11 @@
 #include <fmtpdsc.hxx>
 #include <IDocumentContentOperations.hxx>
 #include <IDocumentSettingAccess.hxx>
+#include <itabenum.hxx>
+#include <frmmgr.hxx>
+#include <formatflysplit.hxx>
+#include <fmtwrapinfluenceonobjpos.hxx>
+#include <frameformats.hxx>
 
 using namespace css;
 
@@ -642,6 +647,51 @@ CPPUNIT_TEST_FIXTURE(Test, testFloatingTableExport)
     CPPUNIT_ASSERT_EQUAL(nExpected, nRightMargin);
 }
 
+CPPUNIT_TEST_FIXTURE(Test, testFloattableOverlapNeverRTFExport)
+{
+    // Given a document with a floating table, overlap is not allowed:
+    {
+        createSwDoc();
+        SwDoc* pDoc = getSwDoc();
+        SwWrtShell* pWrtShell = getSwDocShell()->GetWrtShell();
+        pWrtShell->Insert2("before table");
+        // Insert a table:
+        SwInsertTableOptions aTableOptions(SwInsertTableFlags::DefaultBorder, 
0);
+        pWrtShell->InsertTable(aTableOptions, /*nRows=*/1, /*nCols=*/1);
+        pWrtShell->MoveTable(GotoPrevTable, fnTableStart);
+        // Select table:
+        pWrtShell->SelAll();
+        // Wrap the table in a text frame:
+        SwFlyFrameAttrMgr aMgr(true, pWrtShell, Frmmgr_Type::TEXT, nullptr);
+        pWrtShell->StartAllAction();
+        aMgr.InsertFlyFrame(RndStdIds::FLY_AT_PARA, aMgr.GetPos(), 
aMgr.GetSize());
+        pWrtShell->EndAllAction();
+        // Allow the text frame to split:
+        pWrtShell->StartAllAction();
+        SwFrameFormats* pFlys = pDoc->GetSpzFrameFormats();
+        SwFrameFormat* pFly = (*pFlys)[0];
+        SwAttrSet aSet(pFly->GetAttrSet());
+        aSet.Put(SwFormatFlySplit(true));
+        // Don't allow overlap:
+        SwFormatWrapInfluenceOnObjPos aInfluence;
+        aInfluence.SetAllowOverlap(false);
+        aSet.Put(aInfluence);
+        pDoc->SetAttr(aSet, *pFly);
+        pWrtShell->EndAllAction();
+    }
+
+    // When saving to RTF:
+    saveAndReload("Rich Text Format");
+
+    // Then make sure that the overlap=never markup is written:
+    SwDoc* pDoc = getSwDoc();
+    SwFrameFormats* pFlys = pDoc->GetSpzFrameFormats();
+    SwFrameFormat* pFly = (*pFlys)[0];
+    // Without the accompanying fix in place, this test would have failed, 
i.e. \tabsnoovrlp was not
+    // written.
+    
CPPUNIT_ASSERT(!pFly->GetAttrSet().GetWrapInfluenceOnObjPos().GetAllowOverlap());
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/filter/ww8/rtfattributeoutput.cxx 
b/sw/source/filter/ww8/rtfattributeoutput.cxx
index 5f5de3af8694..07c9c58098f3 100644
--- a/sw/source/filter/ww8/rtfattributeoutput.cxx
+++ b/sw/source/filter/ww8/rtfattributeoutput.cxx
@@ -94,6 +94,7 @@
 #include <frmatr.hxx>
 #include <swtable.hxx>
 #include <formatflysplit.hxx>
+#include <fmtwrapinfluenceonobjpos.hxx>
 #include "rtfexport.hxx"
 
 using namespace ::com::sun::star;
@@ -784,6 +785,13 @@ void RtfAttributeOutput::TablePositioning(SwFrameFormat* 
pFlyFormat)
     sal_uInt16 nTdfrmtxtRight = pFlyFormat->GetLRSpace().GetRight();
     m_aRowDefs.append(LO_STRING_SVTOOLS_RTF_TDFRMTXTRIGHT);
     m_aRowDefs.append(static_cast<sal_Int32>(nTdfrmtxtRight));
+
+    if (!pFlyFormat->GetWrapInfluenceOnObjPos().GetAllowOverlap())
+    {
+        // Allowing overlap is the default in both Writer and in RTF.
+        m_aRowDefs.append(LO_STRING_SVTOOLS_RTF_TABSNOOVRLP);
+        m_aRowDefs.append(static_cast<sal_Int32>(1));
+    }
 }
 
 void RtfAttributeOutput::TableDefinition(
diff --git 
a/writerfilter/qa/cppunittests/rtftok/data/floattable-tbl-overlap.rtf 
b/writerfilter/qa/cppunittests/rtftok/data/floattable-tbl-overlap.rtf
new file mode 100644
index 000000000000..16b8ef7fd4a5
--- /dev/null
+++ b/writerfilter/qa/cppunittests/rtftok/data/floattable-tbl-overlap.rtf
@@ -0,0 +1,17 @@
+{\rtf1
+\paperw12240\paperh15840\margl1440\margr1440\margt1440\margb1440\nobrkwrptbl
+\pard\plain\intbl
+{Table1\cell \cell }
+{\trowd\tpvpara\tphpg\tposx5596\tposyin\cellx4680\cellx5670\row}
+\pard\plain\intbl
+{\cell \cell }
+{\trowd \tpvpara\tphpg\tposx5596\tposyin\cellx4680\cellx5670\row }
+\pard\plain After table1\par
+\pard\plain\intbl
+{Table2\cell \cell }
+{\trowd \tpvpara\tposy0\tabsnoovrlp1\cellx4680\cellx6379\row}
+\pard\plain\intbl
+{\cell \cell }
+{\trowd\tpvpara\tposy0\tabsnoovrlp1\cellx4680\cellx6379\row }
+\pard\plain After table2 \par
+}
diff --git a/writerfilter/qa/cppunittests/rtftok/rtfdispatchflag.cxx 
b/writerfilter/qa/cppunittests/rtftok/rtfdispatchflag.cxx
index 6d6b85be61c4..bca1d4aeb4fd 100644
--- a/writerfilter/qa/cppunittests/rtftok/rtfdispatchflag.cxx
+++ b/writerfilter/qa/cppunittests/rtftok/rtfdispatchflag.cxx
@@ -12,6 +12,7 @@
 #include <com/sun/star/beans/XPropertySet.hpp>
 #include <com/sun/star/drawing/XDrawPageSupplier.hpp>
 #include <com/sun/star/text/RelOrientation.hpp>
+#include <com/sun/star/text/XTextFramesSupplier.hpp>
 
 using namespace ::com::sun::star;
 
@@ -82,6 +83,23 @@ CPPUNIT_TEST_FIXTURE(Test, testDoNotBreakWrappedTables)
     // set.
     CPPUNIT_ASSERT(bDoNotBreakWrappedTables);
 }
+
+CPPUNIT_TEST_FIXTURE(Test, testTblOverlap)
+{
+    // Given a document with 2 floating tables, the second is not allowed to 
overlap:
+    // When importing that document:
+    loadFromURL(u"floattable-tbl-overlap.rtf");
+
+    // Then make sure the second table is marked as "can't overlap":
+    uno::Reference<text::XTextFramesSupplier> xTextDocument(mxComponent, 
uno::UNO_QUERY);
+    uno::Reference<container::XIndexAccess> 
xFrames(xTextDocument->getTextFrames(), uno::UNO_QUERY);
+    uno::Reference<beans::XPropertySet> xFrame(xFrames->getByIndex(1), 
uno::UNO_QUERY);
+    bool bAllowOverlap{};
+    CPPUNIT_ASSERT(xFrame->getPropertyValue("AllowOverlap") >>= bAllowOverlap);
+    // Without the accompanying fix in place, this test would have failed, the 
tables were marked as
+    // "can overlap".
+    CPPUNIT_ASSERT(!bAllowOverlap);
+}
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/writerfilter/source/rtftok/rtfdispatchflag.cxx 
b/writerfilter/source/rtftok/rtfdispatchflag.cxx
index 0ca4d20645f1..de7b91e26fae 100644
--- a/writerfilter/source/rtftok/rtfdispatchflag.cxx
+++ b/writerfilter/source/rtftok/rtfdispatchflag.cxx
@@ -111,6 +111,14 @@ bool RTFDocumentImpl::dispatchFloatingTableFlag(RTFKeyword 
nKeyword)
         return true;
     }
 
+    if (nKeyword == RTFKeyword::TABSNOOVRLP)
+    {
+        m_aStates.top().getTableRowSprms().set(
+            NS_ooxml::LN_CT_TblPrBase_tblOverlap,
+            new RTFValue(NS_ooxml::LN_Value_ST_TblOverlap_never));
+        return true;
+    }
+
     return false;
 }
 

Reply via email to