sw/qa/extras/ooxmlexport/data/tdf145998_firstHeader.odt |binary
 sw/qa/extras/ooxmlexport/ooxmlexport15.cxx              |   13 +++++++++++++
 sw/source/filter/ww8/wrtw8sty.cxx                       |    7 +++++++
 sw/source/filter/ww8/wrtww8.cxx                         |    1 +
 sw/source/filter/ww8/wrtww8.hxx                         |    1 +
 5 files changed, 22 insertions(+)

New commits:
commit 28a947c8ceae8bb4b9306801ff4503970e9b1e76
Author:     Justin Luth <jl...@mail.com>
AuthorDate: Fri Jul 22 20:14:05 2022 -0400
Commit:     Justin Luth <jl...@mail.com>
CommitDate: Sat Jul 23 12:28:32 2022 +0200

    related tdf#145998 sw ms export: smarter first header
    
    Possibly I should only set m_pPreviousSectionPageDesc
    when nBreakType is 2. However, this is export
    and LO doesn't have continuous sections,
    so it should be fine.
    
    The need for this should be VERY minimal now
    that a simple page break is usually utilized
    in this situation. As this unit test shows,
    it can still be valuable if a page renumber occurs.
    
    To push this idea much farther would require
    analysis of the actual layout, since a page chain
    can't be known whether we have seen a follow or not.
    
    Change-Id: I7dc37779ffebbf6649a10b08d561a14b0588c5c1
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/137376
    Tested-by: Jenkins
    Reviewed-by: Justin Luth <jl...@mail.com>

diff --git a/sw/qa/extras/ooxmlexport/data/tdf145998_firstHeader.odt 
b/sw/qa/extras/ooxmlexport/data/tdf145998_firstHeader.odt
new file mode 100644
index 000000000000..ad5e4c3e0320
Binary files /dev/null and 
b/sw/qa/extras/ooxmlexport/data/tdf145998_firstHeader.odt differ
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport15.cxx 
b/sw/qa/extras/ooxmlexport/ooxmlexport15.cxx
index 5838f8dcb93e..b1cb59bff766 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport15.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport15.cxx
@@ -507,6 +507,19 @@ CPPUNIT_TEST_FIXTURE(Test, 
testTdf145998_unnecessaryPageStyles)
     CPPUNIT_ASSERT_EQUAL(OUString(), parseDump("/root/page[5]/footer/txt"));
 }
 
+CPPUNIT_TEST_FIXTURE(Test, testTdf145998_firstHeader)
+{
+    loadAndReload("tdf145998_firstHeader.odt");
+
+    // Sanity check - always good to test when dealing with page styles and 
breaks.
+    CPPUNIT_ASSERT_EQUAL(2, getPages());
+
+    CPPUNIT_ASSERT_EQUAL(OUString("Very first header"), 
parseDump("/root/page[1]/header/txt"));
+
+    // Page Style is already used in prior section - this can't be the 
first-header
+    CPPUNIT_ASSERT_EQUAL(OUString("Normal Header"), 
parseDump("/root/page[2]/header/txt"));
+}
+
 CPPUNIT_TEST_FIXTURE(Test, testTdf135216_evenOddFooter)
 {
     loadAndReload("tdf135216_evenOddFooter.odt");
diff --git a/sw/source/filter/ww8/wrtw8sty.cxx 
b/sw/source/filter/ww8/wrtw8sty.cxx
index 3175894c26a6..d166b5d885c9 100644
--- a/sw/source/filter/ww8/wrtw8sty.cxx
+++ b/sw/source/filter/ww8/wrtw8sty.cxx
@@ -1609,6 +1609,7 @@ void MSWordExportBase::SectionProperties( const 
WW8_SepInfo& rSepInfo, WW8_PdAtt
 
     bool bOldPg = m_bOutPageDescs;
     m_bOutPageDescs = true;
+    const SwPageDesc* pSavedPageDesc = pPd;
 
     AttrOutput().StartSection();
 
@@ -1746,6 +1747,11 @@ void MSWordExportBase::SectionProperties( const 
WW8_SepInfo& rSepInfo, WW8_PdAtt
                 titlePage = true;
             }
         }
+        else if (nBreakCode == 2 && pPd == m_pPreviousSectionPageDesc && 
pPd->GetFollow() == pPd)
+        {
+            // The first title page has already been displayed in the previous 
section. Drop it.
+            titlePage = false;
+        }
 
         const SfxItemSet* pOldI = m_pISet;
 
@@ -1958,6 +1964,7 @@ void MSWordExportBase::SectionProperties( const 
WW8_SepInfo& rSepInfo, WW8_PdAtt
 
     // outside of the section properties again
     m_bOutPageDescs = bOldPg;
+    m_pPreviousSectionPageDesc = pSavedPageDesc;
 }
 
 bool WW8_WrPlcSepx::WriteKFText( WW8Export& rWrt )
diff --git a/sw/source/filter/ww8/wrtww8.cxx b/sw/source/filter/ww8/wrtww8.cxx
index 33228cb93d08..a57ffb9fc093 100644
--- a/sw/source/filter/ww8/wrtww8.cxx
+++ b/sw/source/filter/ww8/wrtww8.cxx
@@ -3863,6 +3863,7 @@ MSWordExportBase::MSWordExportBase( SwDoc& rDocument, 
std::shared_ptr<SwUnoCurso
     , m_nOrigRedlineFlags(RedlineFlags::NONE)
     , m_bOrigShowChanges(true)
     , m_pCurrentPageDesc(nullptr)
+    , m_pPreviousSectionPageDesc(nullptr)
     , m_bFirstTOCNodeWithSection(false)
     , m_pChpIter(nullptr)
     , m_pParentFrame(nullptr)
diff --git a/sw/source/filter/ww8/wrtww8.hxx b/sw/source/filter/ww8/wrtww8.hxx
index 34d7eed5d818..0a4e8d93925c 100644
--- a/sw/source/filter/ww8/wrtww8.hxx
+++ b/sw/source/filter/ww8/wrtww8.hxx
@@ -495,6 +495,7 @@ public:
     std::unordered_map<SwTOXMark const*, OUString> m_TOXMarkBookmarksByTOXMark;
     ww8::Frames m_aFrames;             // The floating frames in this document
     const SwPageDesc *m_pCurrentPageDesc;
+    const SwPageDesc* m_pPreviousSectionPageDesc;
     bool m_bFirstTOCNodeWithSection;
     std::unique_ptr<WW8_WrPlcPn> m_pPapPlc;
     std::unique_ptr<WW8_WrPlcPn> m_pChpPlc;

Reply via email to