diff options
author | Miklos Vajna <vmiklos@collabora.com> | 2024-02-05 10:38:06 +0100 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.com> | 2024-02-05 12:36:44 +0100 |
commit | d918beda2ab42668014b0dd42996b6ccc97e8c3a (patch) | |
tree | caf41debedf8d50d3c90df7255222a13e406e702 | |
parent | 1ae7a81e542c9b072e519d0ea0d4773ed26ca251 (diff) |
tdf#158814 DOCX import: fix unwanted header with type="first" & no titlePg
The bugdoc had no header in Word, but had one in Writer, since commit
17e51f427b3f0cec74ac8e0a1b3f51189006ae6f (DOCX import: first page header
should always set default headers as well, 2014-11-21).
The code has changed a log in the meantime, today we import first page
headers and left/right page headers as a single page style, but still
code was missing to detect the case when <w:headerReference
w:type="first"> was not followed by <w:titlePg>, which is an indicator
that the first page header/footer should be used.
Fix the problem by new flags to SectionPropertyMap to track if we ever
seen a first/left/right header. This allows making an informed decision
in SectionPropertyMap::setHeaderFooterProperties(): if the header is on,
but we effectively don't have none of a first, left or right header,
then it's time to turn it off, similar to what the DOC import does.
Note that this only changes behavior for headers, but if there is a
practical need, then the same could be also done for footers as well.
Instead of adding a new test, notice that testTdf112694 in
CppunitTest_sw_core_header_footer explicitly tests this case: a first
header which is not a title page. So change that testcase to assert the
behavior now matches Word and drop the FIXME.
Change-Id: Ib604e786d7a5a197d4b562533326206697de882a
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/162992
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Tested-by: Jenkins
-rw-r--r-- | sw/qa/core/header_footer/HeaderFooterTest.cxx | 6 | ||||
-rw-r--r-- | writerfilter/source/dmapper/DomainMapper_Impl.cxx | 9 | ||||
-rw-r--r-- | writerfilter/source/dmapper/PropertyMap.cxx | 6 | ||||
-rw-r--r-- | writerfilter/source/dmapper/PropertyMap.hxx | 3 |
4 files changed, 20 insertions, 4 deletions
diff --git a/sw/qa/core/header_footer/HeaderFooterTest.cxx b/sw/qa/core/header_footer/HeaderFooterTest.cxx index 6bb5fd616710..4d2938ef28dc 100644 --- a/sw/qa/core/header_footer/HeaderFooterTest.cxx +++ b/sw/qa/core/header_footer/HeaderFooterTest.cxx @@ -467,10 +467,8 @@ CPPUNIT_TEST_FIXTURE(HeaderFooterTest, testTdf112694) auto verify = [this]() { uno::Any aPageStyle = getStyles("PageStyles")->getByName("Standard"); // Header was on when header for file was for explicit first pages only - // (marked via <w:titlePg>). - //CPPUNIT_ASSERT(!getProperty<bool>(aPageStyle, "HeaderIsOn")); - // TODO - can't disable headers/footers selectively (only fo first page) - CPPUNIT_ASSERT(getProperty<bool>(aPageStyle, "HeaderIsOn")); + // but <w:titlePg> was missing. + CPPUNIT_ASSERT(!getProperty<bool>(aPageStyle, "HeaderIsOn")); }; createSwDoc("tdf112694.docx"); diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.cxx b/writerfilter/source/dmapper/DomainMapper_Impl.cxx index c5f0b4ddcf16..af14dffa8cc5 100644 --- a/writerfilter/source/dmapper/DomainMapper_Impl.cxx +++ b/writerfilter/source/dmapper/DomainMapper_Impl.cxx @@ -3814,7 +3814,10 @@ void DomainMapper_Impl::PushPageHeaderFooter(PagePartType ePagePartType, PageTyp if (eType == PageType::LEFT) { if (bHeader) + { pSectionContext->m_bLeftHeader = true; + pSectionContext->m_bHadLeftHeader = true; + } else pSectionContext->m_bLeftFooter = true; @@ -3823,7 +3826,10 @@ void DomainMapper_Impl::PushPageHeaderFooter(PagePartType ePagePartType, PageTyp else if (eType == PageType::FIRST) { if (bHeader) + { pSectionContext->m_bFirstHeader = true; + pSectionContext->m_bHadFirstHeader = true; + } else pSectionContext->m_bFirstFooter = true; @@ -3832,7 +3838,10 @@ void DomainMapper_Impl::PushPageHeaderFooter(PagePartType ePagePartType, PageTyp else { if (bHeader) + { pSectionContext->m_bRightHeader = true; + pSectionContext->m_bHadRightHeader = true; + } else pSectionContext->m_bRightFooter = true; diff --git a/writerfilter/source/dmapper/PropertyMap.cxx b/writerfilter/source/dmapper/PropertyMap.cxx index c2f60054b065..114de3b6198e 100644 --- a/writerfilter/source/dmapper/PropertyMap.cxx +++ b/writerfilter/source/dmapper/PropertyMap.cxx @@ -571,6 +571,12 @@ void SectionPropertyMap::setHeaderFooterProperties(DomainMapper_Impl& rDM_Impl) m_aPageStyle->setPropertyValue(getPropertyName(PROP_HEADER_IS_SHARED), uno::Any(!bEvenAndOdd)); m_aPageStyle->setPropertyValue(getPropertyName(PROP_FOOTER_IS_SHARED), uno::Any(!bEvenAndOdd)); m_aPageStyle->setPropertyValue(getPropertyName(PROP_FIRST_IS_SHARED), uno::Any(!m_bTitlePage)); + + bool bHadFirstHeader = m_bHadFirstHeader && m_bTitlePage; + if (bHasHeader && !bHadFirstHeader && !m_bHadLeftHeader && !m_bHadRightHeader) + { + m_aPageStyle->setPropertyValue(sHeaderIsOn, uno::Any(false)); + } } void SectionPropertyMap::SetBorder( BorderPosition ePos, sal_Int32 nLineDistance, const table::BorderLine2& rBorderLine, bool bShadow ) diff --git a/writerfilter/source/dmapper/PropertyMap.hxx b/writerfilter/source/dmapper/PropertyMap.hxx index 3b1b55dede9c..711ef47195a0 100644 --- a/writerfilter/source/dmapper/PropertyMap.hxx +++ b/writerfilter/source/dmapper/PropertyMap.hxx @@ -433,6 +433,9 @@ public: bool m_bLeftFooter = false; bool m_bRightHeader = false; bool m_bRightFooter = false; + bool m_bHadFirstHeader = false; + bool m_bHadLeftHeader = false; + bool m_bHadRightHeader = false; static void removeXTextContent(css::uno::Reference<css::text::XText> const& rxText); }; |