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 <vmiklos@collabora.com>
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 0000000..945bd42
--- /dev/null
+++ b/sw/qa/writerfilter/rtftok/data/endnote-at-section-end.rtf
@@ -0,0 +1,15 @@
{\rtf1
\paperw11906\paperh16838\margl1134\margr1134\margt1134\margb1134
\aendnotes\fet1
\pard\plain
First
\sect\sectd\sbknone\endnhere
second
\chftn
{\footnote\ftnalt\pard\plain
\chftn Endnote body
}
\sect\sectd\sbknone\endnhere\pard\plain
third
\par
}
diff --git a/sw/qa/writerfilter/rtftok/rtfdispatchflag.cxx b/sw/qa/writerfilter/rtftok/rtfdispatchflag.cxx
index 8c66043..62fb089 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 dfc5be5..acd753f 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: