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 <jluth@mail.com>
Tested-by: Justin Luth <jluth@mail.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 0000000..58e3698
--- /dev/null
+++ b/sw/qa/extras/ooxmlexport/data/tdf155736_PageNumbers_footer.docx
Binary files differ
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport18.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport18.cxx
index fbb8791..9183863 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport18.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport18.cxx
@@ -850,6 +850,20 @@ DECLARE_OOXMLEXPORT_TEST(testTdf135786, "tdf135786.docx")
CPPUNIT_ASSERT_EQUAL(2, getParagraphs());
}
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 f75fbf5..8b5cf8b 100644
--- a/writerfilter/source/dmapper/DomainMapper_Impl.cxx
+++ b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
@@ -2959,7 +2959,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")
@@ -3372,6 +3372,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())
@@ -7063,7 +7071,7 @@ void DomainMapper_Impl::CloseFieldCommand()
break;
}
}
if (m_bStartTOC && (aIt->second.eFieldId == FIELD_PAGEREF) )
if (IsInTOC() && (aIt->second.eFieldId == FIELD_PAGEREF))
{
bCreateField = false;
}
@@ -7451,7 +7459,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;
@@ -8133,9 +8141,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
@@ -8209,7 +8217,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 4668ebc..c6b38d6 100644
--- a/writerfilter/source/dmapper/DomainMapper_Impl.hxx
+++ b/writerfilter/source/dmapper/DomainMapper_Impl.hxx
@@ -858,7 +858,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();