tdf#153592 writerfilter: don't defer breaks into shapes/comments

When starting a pargraph, we already had a clause to avoid
deferring page and column breaks when we were in a shape
or a comment. These clauses are also necessary
in the other sections of the code where we defer these breaks.

The provided test proves the two shape cases in lcl_utext.
I just took IsInComments along for the ride,
as it certainly would apply in that case as well.

make CppunitTest_sw_ooxmlexport18 CPPUNIT_TEST_NAME=testTdf153592_columnBreaks

ooxmlexport4's testTdf81345_045Original proves that it is
also needed in lcl_text. However, it is such a complex document
that I wasn't confident that a unit test would be stable enough.

Change-Id: I2de15341d3e756bf47fcd85b868a849c8a2419cd
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/146939
Tested-by: Jenkins
Reviewed-by: Justin Luth <jluth@mail.com>
diff --git a/sw/qa/extras/ooxmlexport/data/tdf153592_columnBreaks.docx b/sw/qa/extras/ooxmlexport/data/tdf153592_columnBreaks.docx
new file mode 100644
index 0000000..ea6acac
--- /dev/null
+++ b/sw/qa/extras/ooxmlexport/data/tdf153592_columnBreaks.docx
Binary files differ
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport18.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport18.cxx
index 8de09d6..8c2aa0c 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport18.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport18.cxx
@@ -112,6 +112,15 @@ DECLARE_OOXMLEXPORT_TEST(testTdf153042_noTab, "tdf153042_noTab.docx")
    assertXPath(pLayout, "//SwFixPortion", "width", "10");
}

CPPUNIT_TEST_FIXTURE(Test, testTdf153592_columnBreaks)
{
    loadAndSave("tdf153592_columnBreaks.docx");

    xmlDocUniquePtr pXmlDoc = parseExport("word/document.xml");
    // The two column breaks were lost on import. (I wouldn't complain if they were at 3,5)
    assertXPath(pXmlDoc, "//w:br", 2);
}

CPPUNIT_TEST_FIXTURE(Test, testTdf149551_mongolianVert)
{
    // Given a docx document with a shape with vert="mongolianVert".
diff --git a/writerfilter/source/dmapper/DomainMapper.cxx b/writerfilter/source/dmapper/DomainMapper.cxx
index c2e84cf..c6fd96e 100644
--- a/writerfilter/source/dmapper/DomainMapper.cxx
+++ b/writerfilter/source/dmapper/DomainMapper.cxx
@@ -3739,7 +3739,7 @@ void DomainMapper::lcl_text(const sal_uInt8 * data_, size_t len)
            m_pImpl->appendTextPortion("\n", pContext);
        }

        if (!m_pImpl->GetFootnoteContext())
        if (!m_pImpl->GetFootnoteContext() && !m_pImpl->IsInShape() && !m_pImpl->IsInComments())
        {
            if (m_pImpl->isBreakDeferred(PAGE_BREAK))
                m_pImpl->GetTopContext()->Insert(PROP_BREAK_TYPE, uno::Any(style::BreakType_PAGE_BEFORE));
@@ -4061,7 +4061,7 @@ void DomainMapper::lcl_utext(const sal_uInt8 * data_, size_t len)
            const bool bSingleParagraphAfterRedline = m_pImpl->GetIsFirstParagraphInSection(/*bAfterRedline=*/true) &&
                    m_pImpl->GetIsLastParagraphInSection();
            PropertyMapPtr pContext = m_pImpl->GetTopContextOfType(CONTEXT_PARAGRAPH);
            if (!m_pImpl->GetFootnoteContext())
            if (!m_pImpl->GetFootnoteContext() && !m_pImpl->IsInShape() && !m_pImpl->IsInComments())
            {
                if (m_pImpl->isBreakDeferred(PAGE_BREAK))
                {
@@ -4137,7 +4137,7 @@ void DomainMapper::lcl_utext(const sal_uInt8 * data_, size_t len)
        {
            // GetTopContext() is changed by inserted breaks, but we want to keep the current context
            PropertyMapPtr pContext = m_pImpl->GetTopContext();
            if (!m_pImpl->GetFootnoteContext())
            if (!m_pImpl->GetFootnoteContext() && !m_pImpl->IsInShape() && !m_pImpl->IsInComments())
            {
                if (m_pImpl->isBreakDeferred(PAGE_BREAK))
                {