sw/qa/extras/ooxmlexport/data/tdf155736_PageNumbers_footer.docx |binary
 sw/qa/extras/ooxmlexport/ooxmlexport18.cxx                      |   14 ++++++
 writerfilter/source/dmapper/DomainMapper_Impl.cxx               |   21 
+++++++---
 writerfilter/source/dmapper/DomainMapper_Impl.hxx               |    2 
 4 files changed, 30 insertions(+), 7 deletions(-)

New commits:
commit 4c39b4c93c139ab804c96955149c463a2fb672a8
Author:     Satya <skompe...@opentext.com>
AuthorDate: Wed Jun 14 18:15:35 2023 +0530
Commit:     Skyler Grey <skyler.g...@collabora.com>
CommitDate: Wed Oct 11 21:57:28 2023 +0200

    tdf#155736 Modified IsInTOC() to handle IsInHeaderFooter() case.
    
    This fixes a problem of page numbers missing in the footer.
    The importer might start processing the footer before the
    TOC has finished - m_bStartTOC might be true.
    In this case we are not actually IsInTOC,and m_bStartTOC
    should be ignored and make use of IsInHeaderFooter() and 
m_bStartTOCHeaderFooter to confirm if the footer/header itself
    has TOC.
    
    Change-Id: Ieede9f8e2120556630ba57b9c748935788f3cc9a
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/153052
    Reviewed-by: Justin Luth <jl...@mail.com>
    Tested-by: Justin Luth <jl...@mail.com>
    (cherry picked from commit d7dd39e124f8a1fa199dd8322b642e8be04ed360)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/157789
    Reviewed-by: Skyler Grey <skyler.g...@collabora.com>
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>

diff --git a/sw/qa/extras/ooxmlexport/data/tdf155736_PageNumbers_footer.docx 
b/sw/qa/extras/ooxmlexport/data/tdf155736_PageNumbers_footer.docx
new file mode 100644
index 000000000000..58e36988002a
Binary files /dev/null and 
b/sw/qa/extras/ooxmlexport/data/tdf155736_PageNumbers_footer.docx differ
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport18.cxx 
b/sw/qa/extras/ooxmlexport/ooxmlexport18.cxx
index b2f02ce337bc..856efb375d11 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport18.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport18.cxx
@@ -715,6 +715,20 @@ CPPUNIT_TEST_FIXTURE(Test, testTdf157136)
     }
 }
 
+DECLARE_OOXMLEXPORT_TEST(testTdf155736, "tdf155736_PageNumbers_footer.docx")
+{
+    CPPUNIT_ASSERT_EQUAL(2, getPages());
+
+    xmlDocUniquePtr pXmlDoc = parseLayoutDump();
+    assertXPath(pXmlDoc, "/root/page[1]/footer");
+    assertXPath(pXmlDoc, "/root/page[2]/footer");
+    //Without the fix in place, it would have failed with
+    //- Expected: Page * of *
+    //- Actual  : Page of
+    CPPUNIT_ASSERT_EQUAL(OUString("Page * of *"), 
parseDump("/root/page[1]/footer/txt/text()"));
+    CPPUNIT_ASSERT_EQUAL(OUString("Page * of *"), 
parseDump("/root/page[2]/footer/txt/text()"));
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.cxx 
b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
index 8f21f04e03ac..7c6c54182854 100644
--- a/writerfilter/source/dmapper/DomainMapper_Impl.cxx
+++ b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
@@ -2850,7 +2850,7 @@ void DomainMapper_Impl::appendTextPortion( const 
OUString& rString, const Proper
         // If we are in comments, then disable CharGrabBag, comment text 
doesn't support that.
         uno::Sequence< beans::PropertyValue > aValues = 
pPropertyMap->GetPropertyValues(/*bCharGrabBag=*/!m_bIsInComments);
 
-        if (m_bStartTOC || m_bStartIndex || m_bStartBibliography)
+        if (IsInTOC() || m_bStartIndex || m_bStartBibliography)
             for( auto& rValue : asNonConstRange(aValues) )
             {
                 if (rValue.Name == "CharHidden")
@@ -3263,6 +3263,14 @@ void 
DomainMapper_Impl::fillEmptyFrameProperties(std::vector<beans::PropertyValu
         
rFrameProperties.push_back(comphelper::makePropertyValue(getPropertyName(aMarginIds[i]),
 static_cast<sal_Int32>(0)));
 }
 
+bool DomainMapper_Impl::IsInTOC() const
+{
+    if (IsInHeaderFooter())
+        return m_bStartTOCHeaderFooter;
+    else
+        return m_bStartTOC;
+}
+
 void DomainMapper_Impl::ConvertHeaderFooterToTextFrame(bool bDynamicHeightTop, 
bool bDynamicHeightBottom)
 {
     while (!m_aHeaderFooterTextAppendStack.empty())
@@ -6977,7 +6985,7 @@ void DomainMapper_Impl::CloseFieldCommand()
                 break;
             }
             }
-            if (m_bStartTOC && (aIt->second.eFieldId == FIELD_PAGEREF) )
+            if (IsInTOC() && (aIt->second.eFieldId == FIELD_PAGEREF))
             {
                 bCreateField = false;
             }
@@ -7365,7 +7373,7 @@ void DomainMapper_Impl::CloseFieldCommand()
                 break;
                 case FIELD_PAGEREF:
                 case FIELD_REF:
-                if (xFieldProperties.is() && !m_bStartTOC)
+                if (xFieldProperties.is() && !IsInTOC())
                 {
                     bool bPageRef = aIt->second.eFieldId == FIELD_PAGEREF;
 
@@ -8047,9 +8055,9 @@ void DomainMapper_Impl::PopFieldContext()
                 else
                 {
                     xToInsert.set(pContext->GetTC(), uno::UNO_QUERY);
-                    if( !xToInsert.is() && !m_bStartTOC && !m_bStartIndex && 
!m_bStartBibliography )
+                    if (!xToInsert.is() && !IsInTOC() && !m_bStartIndex && 
!m_bStartBibliography)
                         xToInsert = pContext->GetTextField();
-                    if( xToInsert.is() && !m_bStartTOC && !m_bStartIndex && 
!m_bStartBibliography)
+                    if (xToInsert.is() && !IsInTOC() && !m_bStartIndex && 
!m_bStartBibliography)
                     {
                         PropertyMap aMap;
                         // Character properties of the field show up here the
@@ -8123,7 +8131,8 @@ void DomainMapper_Impl::PopFieldContext()
                                 if (!pContext->GetHyperlinkTarget().isEmpty())
                                     
xCrsrProperties->setPropertyValue("HyperLinkTarget", 
uno::Any(pContext->GetHyperlinkTarget()));
 
-                                if (m_bStartTOC) {
+                                if (IsInTOC())
+                                {
                                     OUString sDisplayName("Index Link");
                                     
xCrsrProperties->setPropertyValue("VisitedCharStyleName",uno::Any(sDisplayName));
                                     
xCrsrProperties->setPropertyValue("UnvisitedCharStyleName",uno::Any(sDisplayName));
diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.hxx 
b/writerfilter/source/dmapper/DomainMapper_Impl.hxx
index 71fc206564a8..c188ab828380 100644
--- a/writerfilter/source/dmapper/DomainMapper_Impl.hxx
+++ b/writerfilter/source/dmapper/DomainMapper_Impl.hxx
@@ -874,7 +874,7 @@ public:
     void ConvertHeaderFooterToTextFrame(bool, bool);
     static void 
fillEmptyFrameProperties(std::vector<css::beans::PropertyValue>& 
rFrameProperties, bool bSetAnchorToChar);
 
-    bool IsInTOC() const { return m_bStartTOC; }
+    bool IsInTOC() const;
 
     void PushFootOrEndnote( bool bIsFootnote );
     void PopFootOrEndnote();

Reply via email to