sw/qa/writerfilter/rtftok/data/endnote-at-section-end.rtf |   15 +++++++++
 sw/qa/writerfilter/rtftok/rtfdispatchflag.cxx             |   23 ++++++++++++++
 sw/source/writerfilter/rtftok/rtfdispatchflag.cxx         |    7 +++-
 3 files changed, 44 insertions(+), 1 deletion(-)

New commits:
commit ad8fa1b5912a04f4cc016965175315e4784fa229
Author:     Miklos Vajna <[email protected]>
AuthorDate: Wed Jun 5 09:34:14 2024 +0200
Commit:     Miklos Vajna <[email protected]>
CommitDate: Wed Jun 5 10:38:18 2024 +0200

    tdf#161417 RTF import: handle endnotes at section ends
    
    This is similar to commit 2d2dd56e0b2dc708f1f758d7fc9a1263ff09b83c
    (tdf#160984 sw continuous endnotes: DOCX: import <w:endnotePr> pos ==
    sectEnd, 2024-05-28), but that was for DOCX import, this is for RTF
    import.
    
    Change-Id: I6772f78360f681d18559556e71526eb76670bec2
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/168424
    Reviewed-by: Miklos Vajna <[email protected]>
    Tested-by: Jenkins

diff --git a/sw/qa/writerfilter/rtftok/data/endnote-at-section-end.rtf 
b/sw/qa/writerfilter/rtftok/data/endnote-at-section-end.rtf
new file mode 100644
index 000000000000..945bd42c24c9
--- /dev/null
+++ b/sw/qa/writerfilter/rtftok/data/endnote-at-section-end.rtf
@@ -0,0 +1,15 @@
+{ tf1
+\paperw11906\paperh16838\margl1134\margr1134\margt1134\margb1134
+endnoteset1
+\pard\plain
+First
+\sect\sectd\sbknonendnhere
+second
++{ootnotetnalt\pard\plain
++}
+\sect\sectd\sbknonendnhere\pard\plain
+third
+\par
+}
diff --git a/sw/qa/writerfilter/rtftok/rtfdispatchflag.cxx 
b/sw/qa/writerfilter/rtftok/rtfdispatchflag.cxx
index 8c660435a3a6..62fb089e29d3 100644
--- a/sw/qa/writerfilter/rtftok/rtfdispatchflag.cxx
+++ b/sw/qa/writerfilter/rtftok/rtfdispatchflag.cxx
@@ -13,6 +13,7 @@
 #include <com/sun/star/drawing/XDrawPageSupplier.hpp>
 #include <com/sun/star/text/RelOrientation.hpp>
 #include <com/sun/star/text/XTextFramesSupplier.hpp>
+#include <com/sun/star/text/XTextDocument.hpp>
 
 using namespace ::com::sun::star;
 
@@ -100,6 +101,28 @@ CPPUNIT_TEST_FIXTURE(Test, testTblOverlap)
     // "can overlap".
     CPPUNIT_ASSERT(!bAllowOverlap);
 }
+
+CPPUNIT_TEST_FIXTURE(Test, testEndnoteAtSectionEndRTFImport)
+{
+    // Given a document with at-section-end endnotes enabled:
+    // When loading that document:
+    loadFromFile(u"endnote-at-section-end.rtf");
+
+    // Go to the second paragraph, which is inside Word's second section:
+    uno::Reference<text::XTextDocument> xTextDocument(mxComponent, 
uno::UNO_QUERY);
+    uno::Reference<container::XEnumerationAccess> 
xParaEnumAccess(xTextDocument->getText(),
+                                                                  
uno::UNO_QUERY);
+    uno::Reference<container::XEnumeration> xParaEnum = 
xParaEnumAccess->createEnumeration();
+    xParaEnum->nextElement();
+    uno::Reference<beans::XPropertySet> xPara(xParaEnum->nextElement(), 
uno::UNO_QUERY);
+    uno::Reference<beans::XPropertySet> xSection;
+    xPara->getPropertyValue("TextSection") >>= xSection;
+    bool bEndnoteIsCollectAtTextEnd = false;
+    xSection->getPropertyValue("EndnoteIsCollectAtTextEnd") >>= 
bEndnoteIsCollectAtTextEnd;
+    // Without the accompanying fix in place, this test would have failed, 
endnotes were always at
+    // document end.
+    CPPUNIT_ASSERT(bEndnoteIsCollectAtTextEnd);
+}
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/writerfilter/rtftok/rtfdispatchflag.cxx 
b/sw/source/writerfilter/rtftok/rtfdispatchflag.cxx
index dfc5be5b1e05..acd753fe6eb3 100644
--- a/sw/source/writerfilter/rtftok/rtfdispatchflag.cxx
+++ b/sw/source/writerfilter/rtftok/rtfdispatchflag.cxx
@@ -925,8 +925,13 @@ RTFError RTFDocumentImpl::dispatchFlag(RTFKeyword nKeyword)
         break;
         case RTFKeyword::AENDDOC:
             // Noop, this is the default in Writer.
+            break;
         case RTFKeyword::AENDNOTES:
-            // Noop
+        {
+            auto pValue = new RTFValue(NS_ooxml::LN_Value_ST_EdnPos_sectEnd);
+            m_aSettingsTableSprms.set(NS_ooxml::LN_CT_EdnProps_pos, pValue);
+        }
+        break;
         case RTFKeyword::AFTNRSTCONT:
             // Noop, this is the default in Writer.
         case RTFKeyword::AFTNRESTART:

Reply via email to