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>
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/155120
Tested-by: Jenkins
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 c8dca64..62dc42d 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport18.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport18.cxx
@@ -856,6 +856,20 @@ DECLARE_OOXMLEXPORT_TEST(testTdf155903, "tdf155903.odt")
// because the exported file was corrupted.
}
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 308768c..1758f76 100644
--- a/writerfilter/source/dmapper/DomainMapper_Impl.cxx
+++ b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
@@ -2996,7 +2996,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")
@@ -3409,6 +3409,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())
@@ -7125,7 +7133,7 @@ void DomainMapper_Impl::CloseFieldCommand()
break;
}
}
if (m_bStartTOC && (aIt->second.eFieldId == FIELD_PAGEREF) )
if (IsInTOC() && (aIt->second.eFieldId == FIELD_PAGEREF))
{
bCreateField = false;
}
@@ -7541,7 +7549,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;
@@ -8223,9 +8231,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
@@ -8299,7 +8307,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 55f3b67..b2fca78 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();