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

New commits:
commit beae0eaf6a7534181a0fbd11d071aaef8617d05f
Author:     Justin Luth <justin.l...@collabora.com>
AuthorDate: Thu Mar 2 19:32:27 2023 -0500
Commit:     Justin Luth <jl...@mail.com>
CommitDate: Tue Mar 7 14:03:44 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/+/148362
    Tested-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 47992f819bf6..06dc588a37c7 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport18.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport18.cxx
@@ -87,6 +87,12 @@ DECLARE_OOXMLEXPORT_TEST(testTdf153526_commentInNumbering, 
"tdf153526_commentInN
     CPPUNIT_ASSERT_EQUAL(13, getParagraphs());
 }
 
+DECLARE_OOXMLEXPORT_TEST(testTdf153613_sdtAfterPgBreak, 
"tdf153613_sdtAfterPgBreak.docx")
+{
+    // the page break was missing. Before the fix this was 1 page
+    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 61b4d6d114d4..46060b2d9950 100644
--- a/writerfilter/source/dmapper/DomainMapper.cxx
+++ b/writerfilter/source/dmapper/DomainMapper.cxx
@@ -1074,7 +1074,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
@@ -1092,11 +1094,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