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 620d1dc63b652db97b05eb21685dad70e6b2ab0d
Author:     Justin Luth <justin.l...@collabora.com>
AuthorDate: Thu Mar 2 19:32:27 2023 -0500
Commit:     Justin Luth <jl...@mail.com>
CommitDate: Fri Mar 3 15:30: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>

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 2e71b5bcc7fe..67c15685d7a3 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport18.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport18.cxx
@@ -197,6 +197,11 @@ 
DECLARE_OOXMLEXPORT_TEST(testTdf153613_textboxAfterPgBreak2, "tdf153613_textboxA
     assertXPathContent(pLayout, "//page[2]/body/txt", "There should be no 
prior carriage return.");
 }
 
+DECLARE_OOXMLEXPORT_TEST(testTdf153613_sdtAfterPgBreak, 
"tdf153613_sdtAfterPgBreak.docx")
+{
+    CPPUNIT_ASSERT_EQUAL(2, getPages());
+}
+
 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 573a1b41f4a5..d816aad4a9af 100644
--- a/writerfilter/source/dmapper/DomainMapper.cxx
+++ b/writerfilter/source/dmapper/DomainMapper.cxx
@@ -1075,7 +1075,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
@@ -1093,11 +1095,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