tdf#132149 ww8export: always check for break at end of paragraph

Make sure to check if the next node has a page-break
at the end of a split paragraph.

Change-Id: Ib103d7b2f653f9ae5772ff536c041afb445903b4
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/101344
Tested-by: Jenkins
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Reviewed-by: Justin Luth <justin_luth@sil.org>
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport15.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport15.cxx
index 6606bef..09f847b 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport15.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport15.cxx
@@ -525,8 +525,8 @@ DECLARE_OOXMLEXPORT_TEST(testTdf132149_pgBreak, "tdf132149_pgBreak.odt")
    assertXPath(pDump, "//page[2]/header", 0);

    //Page break is not lost. This SHOULD be on page 4, but sadly it is not.
    //assertXPathContent(pDump, "//page[5]/header", "First Page Style");
    //CPPUNIT_ASSERT(getXPathContent(pDump, "//page[5]/body/txt").startsWith("Lorem ipsum"));
    assertXPathContent(pDump, "//page[5]/header/txt", "First Page Style");
    CPPUNIT_ASSERT(getXPathContent(pDump, "//page[5]/body/txt").startsWith("Lorem ipsum"));
}

DECLARE_OOXMLEXPORT_TEST(testTdf135949_anchoredBeforeBreak, "tdf135949_anchoredBeforeBreak.docx")
diff --git a/sw/source/filter/ww8/wrtw8nds.cxx b/sw/source/filter/ww8/wrtw8nds.cxx
index 87ff1d82..3e9b52d 100644
--- a/sw/source/filter/ww8/wrtw8nds.cxx
+++ b/sw/source/filter/ww8/wrtw8nds.cxx
@@ -2723,10 +2723,20 @@ void MSWordExportBase::OutputTextNode( SwTextNode& rNode )
                assert(pNextPageDesc);
                PrepareNewPageDesc( rNode.GetpSwAttrSet(), rNode, nullptr , pNextPageDesc);
        }
        else if (!bNeedParaSplit)
        else
        {
            // else check if section break needed after the paragraph
            AttrOutput().SectionBreaks(rNode);
            bool bCheckSectionBreak = true;
            // only try to sectionBreak after a split para if the next node specifies a break
            if ( bNeedParaSplit )
            {
                SwNodeIndex aNextIndex( rNode, 1 );
                const SwTextNode* pNextNode = aNextIndex.GetNode().GetTextNode();
                bCheckSectionBreak = pNextNode && !NoPageBreakSection( pNextNode->GetpSwAttrSet() );
            }

            if ( bCheckSectionBreak )
                AttrOutput().SectionBreaks(rNode);
        }

        AttrOutput().StartParagraphProperties();