sw/qa/extras/ooxmlexport/data/tdf153613_sdtAfterPgBreak.docx |binary
 sw/qa/extras/ooxmlexport/ooxmlexport18.cxx                   |    5 +
 writerfilter/source/dmapper/DomainMapper.cxx                 |   31 +++++++++++
 3 files changed, 36 insertions(+)

New commits:
commit af8fd3cfc71d404ae570c04b8e6540bcf6089009
Author:     Justin Luth <justin.l...@collabora.com>
AuthorDate: Thu Mar 2 19:32:27 2023 -0500
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Mon Mar 6 08:33:54 2023 +0000

    tdf#153613 writerfilter: handle defered break before SDT start
    
    If there are deferred column or page breaks before an SDT,
    then before starting the SDT we need to determine if the
    existing run needs to split - same as everywhere else.
    
    There was only one existing unit test that had any defered
    page or column breaks, so only two example documents to work from.
    That was tdf125778_lostPageBreakTOX.docx.
    
    Change-Id: I02d71577af13399d8aaf3ba0ce40fc6bed5e6e3c
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/148148
    Tested-by: Jenkins
    Reviewed-by: Justin Luth <jl...@mail.com>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/148195
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>
    Reviewed-by: Miklos Vajna <vmik...@collabora.com>

diff --git a/sw/qa/extras/ooxmlexport/data/tdf153613_sdtAfterPgBreak.docx 
b/sw/qa/extras/ooxmlexport/data/tdf153613_sdtAfterPgBreak.docx
new file mode 100644
index 000000000000..fa62b475cfaa
Binary files /dev/null and 
b/sw/qa/extras/ooxmlexport/data/tdf153613_sdtAfterPgBreak.docx differ
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport18.cxx 
b/sw/qa/extras/ooxmlexport/ooxmlexport18.cxx
index 129e42325640..7ab327f7e007 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport18.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport18.cxx
@@ -63,6 +63,11 @@ CPPUNIT_TEST_FIXTURE(Test, testInlineSdtHeader)
     loadAndSave("inline-sdt-header.docx");
 }
 
+DECLARE_OOXMLEXPORT_TEST(testTdf153613_sdtAfterPgBreak, 
"tdf153613_sdtAfterPgBreak.docx")
+{
+    CPPUNIT_ASSERT_EQUAL(2, getPages());
+}
+
 CPPUNIT_TEST_FIXTURE(Test, testTdf152636_lostPageBreak2)
 {
     loadAndReload("tdf152636_lostPageBreak2.docx");
diff --git a/writerfilter/source/dmapper/DomainMapper.cxx 
b/writerfilter/source/dmapper/DomainMapper.cxx
index c3a371fe6ec3..a3e50d8ea87d 100644
--- a/writerfilter/source/dmapper/DomainMapper.cxx
+++ b/writerfilter/source/dmapper/DomainMapper.cxx
@@ -1058,7 +1058,9 @@ void DomainMapper::lcl_attribute(Id nName, Value & val)
         break;
         case NS_ooxml::LN_CT_SdtBlock_sdtContent:
         case NS_ooxml::LN_CT_SdtRun_sdtContent:
+        {
             m_pImpl->m_pSdtHelper->SetSdtType(nName);
+
             if (m_pImpl->m_pSdtHelper->getControlType() == 
SdtControlType::unknown)
             {
                 // Still not determined content type? and it is even not 
unsupported? Then it is plain text field
@@ -1076,11 +1078,40 @@ void DomainMapper::lcl_attribute(Id nName, Value & val)
                     }
                 }
 
+                PropertyMapPtr pContext = 
m_pImpl->GetTopContextOfType(CONTEXT_PARAGRAPH);
+                if (pContext && m_pImpl->isBreakDeferred(PAGE_BREAK))
+                {
+                    if (!m_pImpl->GetFootnoteContext() && !m_pImpl->IsInShape()
+                        && !m_pImpl->IsInComments())
+                    {
+                        if (m_pImpl->GetIsFirstParagraphInSection() || 
!m_pImpl->IsFirstRun())
+                        {
+                            m_pImpl->m_bIsSplitPara = true;
+                            finishParagraph();
+                            lcl_startParagraphGroup();
+                        }
+                        pContext->Insert(PROP_BREAK_TYPE, 
uno::Any(style::BreakType_PAGE_BEFORE));
+                        m_pImpl->clearDeferredBreaks();
+                    }
+                }
+                else if (pContext && m_pImpl->isBreakDeferred(COLUMN_BREAK))
+                {
+                    if (m_pImpl->GetIsFirstParagraphInSection() || 
!m_pImpl->IsFirstRun())
+                    {
+                        mbIsSplitPara = true;
+                        finishParagraph();
+                        lcl_startParagraphGroup();
+                    }
+                    pContext->Insert(PROP_BREAK_TYPE, 
uno::Any(style::BreakType_COLUMN_BEFORE));
+                    m_pImpl->clearDeferredBreaks();
+                }
+
                 
m_pImpl->m_pSdtHelper->setControlType(SdtControlType::richText);
                 m_pImpl->PushSdt();
                 break;
             }
             m_pImpl->SetSdt(true);
+        }
         break;
         case NS_ooxml::LN_CT_SdtBlock_sdtEndContent:
         case NS_ooxml::LN_CT_SdtRun_sdtEndContent:

Reply via email to