sw/qa/core/header_footer/HeaderFooterTest.cxx | 5 +++ sw/qa/extras/rtfexport/rtfexport8.cxx | 12 ++++++++ writerfilter/source/dmapper/PropertyMap.cxx | 39 +++++++++++++++----------- 3 files changed, 40 insertions(+), 16 deletions(-)
New commits: commit 63922566a8bde0977ae644b3b6752fb453a197fc Author: Justin Luth <justin.l...@collabora.com> AuthorDate: Thu Jan 16 20:25:22 2025 -0500 Commit: Miklos Vajna <vmik...@collabora.com> CommitDate: Mon Jan 20 10:54:09 2025 +0100 tdf#164748 writerfilter: fix missing even/odd header properties Lots of header/footer page style properties are ignored if the header/footer is not first enabled. So copying propertyList MUST follow completeCopyHeaderFooter() [which is where all those settings are turned on]. However, copying properties AFTER turning on the header/footer was Exception'ing when trying to copy BottomMarginComplexColor as void(). So ignore any property-copy errors, and then everything should work in theory... ...and it seems to. make CppunitTest_sw_core_header_footer \ CPPUNIT_TEST_NAME=testBnc519228OddBreaks make CppunitTest_sw_rtfexport8 \ CPPUNIT_TEST_NAME=testTdf160976_headerFooter Change-Id: Iecf0a070e77525c04b44c4fc38efa0f9d558eca5 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/180417 Tested-by: Jenkins Reviewed-by: Justin Luth <jl...@mail.com> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/180428 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com> Reviewed-by: Miklos Vajna <vmik...@collabora.com> diff --git a/sw/qa/core/header_footer/HeaderFooterTest.cxx b/sw/qa/core/header_footer/HeaderFooterTest.cxx index 4d2938ef28dc..b7d932894910 100644 --- a/sw/qa/core/header_footer/HeaderFooterTest.cxx +++ b/sw/qa/core/header_footer/HeaderFooterTest.cxx @@ -683,6 +683,8 @@ CPPUNIT_TEST_FIXTURE(HeaderFooterTest, testFirstPageFooterEnabled) CPPUNIT_TEST_FIXTURE(HeaderFooterTest, testBnc519228OddBreaks) { auto verify = [this]() { + CPPUNIT_ASSERT_EQUAL(5, getPages()); // logical pages - "blank page" 4 usually not displayed + // Check that all the normal styles are not set as right-only, those should be only those used after odd page breaks. auto xStyles = getStyles("PageStyles"); uno::Reference<beans::XPropertySet> xStyle; @@ -735,6 +737,9 @@ CPPUNIT_TEST_FIXTURE(HeaderFooterTest, testBnc519228OddBreaks) CPPUNIT_ASSERT_EQUAL(getProperty<sal_Int32>(page1Style, "TopMargin"), getProperty<sal_Int32>(page2Style, "TopMargin")); + //tdf164748 + CPPUNIT_ASSERT_EQUAL(getProperty<bool>(page1Style, u"HeaderDynamicSpacing"_ustr), + getProperty<bool>(page2Style, u"HeaderDynamicSpacing"_ustr)); } // Page 5 diff --git a/sw/qa/extras/rtfexport/rtfexport8.cxx b/sw/qa/extras/rtfexport/rtfexport8.cxx index 743d652ce31c..5557837f83da 100644 --- a/sw/qa/extras/rtfexport/rtfexport8.cxx +++ b/sw/qa/extras/rtfexport/rtfexport8.cxx @@ -366,6 +366,18 @@ CPPUNIT_TEST_FIXTURE(Test, testTdf160976_headerFooter) verify(); saveAndReload(mpFilter); verify(/*IsExported*/ true); + + //tdf#164748: export must have the all same footer settings as the first page + auto xStyles = getStyles(u"PageStyles"_ustr); + auto xPara = getParagraph(2, "2"); + OUString page2StyleName = getProperty<OUString>(xPara, u"PageDescName"_ustr); + uno::Reference<beans::XPropertySet> page2Style; + page2Style.set(xStyles->getByName(page2StyleName), uno::UNO_QUERY); + CPPUNIT_ASSERT(getProperty<bool>(page2Style, u"FooterDynamicSpacing"_ustr)); + CPPUNIT_ASSERT_EQUAL(sal_Int32(915), + getProperty<sal_Int32>(page2Style, u"FooterBodyDistance"_ustr)); + CPPUNIT_ASSERT_EQUAL(sal_Int32(1016), getProperty<sal_Int32>(page2Style, u"FooterHeight"_ustr)); + // note: an unexpected header surfaces on page 3. } diff --git a/writerfilter/source/dmapper/PropertyMap.cxx b/writerfilter/source/dmapper/PropertyMap.cxx index 568560172156..d1ca10a117e5 100644 --- a/writerfilter/source/dmapper/PropertyMap.cxx +++ b/writerfilter/source/dmapper/PropertyMap.cxx @@ -1500,11 +1500,22 @@ void SectionPropertyMap::CreateEvenOddPageStyleCopy(DomainMapper_Impl& rDM_Impl, uno::Reference<beans::XPropertySet> evenOddStyle( rDM_Impl.GetTextFactory()->createInstance("com.sun.star.style.PageStyle"), uno::UNO_QUERY); - // Unfortunately using setParent() does not work for page styles, so make a deep copy of the page style. + rDM_Impl.GetPageStyles()->insertByName(evenOddStyleName, uno::Any(evenOddStyle)); + uno::Reference<beans::XPropertySet> pageProperties(m_aPageStyle); uno::Reference<beans::XPropertySetInfo> pagePropertiesInfo(pageProperties->getPropertySetInfo()); const uno::Sequence<beans::Property> propertyList(pagePropertiesInfo->getProperties()); + if (rDM_Impl.IsNewDoc()) + { + bool const bEvenAndOdd(rDM_Impl.GetSettingsTable()->GetEvenAndOddHeaders()); + completeCopyHeaderFooter(pageProperties, evenOddStyle, + !rDM_Impl.SeenHeaderFooter(PagePartType::Header, PageType::RIGHT) + && (!bEvenAndOdd || !rDM_Impl.SeenHeaderFooter(PagePartType::Header, PageType::LEFT)), + !rDM_Impl.SeenHeaderFooter(PagePartType::Footer, PageType::RIGHT) + && (!bEvenAndOdd || !rDM_Impl.SeenHeaderFooter(PagePartType::Footer, PageType::LEFT))); + } + // Ignore write-only properties. static const std::unordered_set<OUString> staticDenylist = { "FooterBackGraphicURL", "BackGraphicURL", "HeaderBackGraphicURL", @@ -1513,6 +1524,7 @@ void SectionPropertyMap::CreateEvenOddPageStyleCopy(DomainMapper_Impl& rDM_Impl, "HeaderText", "HeaderTextLeft", "HeaderTextFirst", "FooterText", "FooterTextLeft", "FooterTextFirst" }; + // Unfortunately page styles can't inherit from a parent, so make a deep copy of the page style. bool isMirrorMargins = PageBreakType::Even == eBreakType && rDM_Impl.GetSettingsTable()->GetMirrorMarginSettings(); for (const auto& rProperty : propertyList) { @@ -1528,26 +1540,21 @@ void SectionPropertyMap::CreateEvenOddPageStyleCopy(DomainMapper_Impl& rDM_Impl, else if (rProperty.Name == u"RightMargin"_ustr) sSetName = u"LeftMargin"_ustr; } - evenOddStyle->setPropertyValue( - sSetName, - pageProperties->getPropertyValue(rProperty.Name)); + try + { + evenOddStyle->setPropertyValue( + sSetName, + pageProperties->getPropertyValue(rProperty.Name)); + } + catch (uno::Exception&) + { + DBG_UNHANDLED_EXCEPTION("writerfilter", "failed to copy page style property"); + } } } } evenOddStyle->setPropertyValue("FollowStyle", uno::Any(m_sPageStyleName)); - rDM_Impl.GetPageStyles()->insertByName(evenOddStyleName, uno::Any(evenOddStyle)); - - if (rDM_Impl.IsNewDoc()) - { - bool const bEvenAndOdd(rDM_Impl.GetSettingsTable()->GetEvenAndOddHeaders()); - completeCopyHeaderFooter(pageProperties, evenOddStyle, - !rDM_Impl.SeenHeaderFooter(PagePartType::Header, PageType::RIGHT) - && (!bEvenAndOdd || !rDM_Impl.SeenHeaderFooter(PagePartType::Header, PageType::LEFT)), - !rDM_Impl.SeenHeaderFooter(PagePartType::Footer, PageType::RIGHT) - && (!bEvenAndOdd || !rDM_Impl.SeenHeaderFooter(PagePartType::Footer, PageType::LEFT))); - } - if (eBreakType == PageBreakType::Even) evenOddStyle->setPropertyValue(getPropertyName(PROP_PAGE_STYLE_LAYOUT), uno::Any(style::PageStyleLayout_LEFT)); else if (eBreakType == PageBreakType::Odd)