writerfilter/qa/cppunittests/dmapper/PropertyMap.cxx | 37 +++++++++++++++++++ writerfilter/source/dmapper/PropertyMap.cxx | 5 +- 2 files changed, 40 insertions(+), 2 deletions(-)
New commits: commit 82b9c13bc59b94ee5b42d0d7384d807d323aaf67 Author: Justin Luth <jl...@mail.com> AuthorDate: Wed Jul 10 19:26:20 2024 -0400 Commit: Xisco Fauli <xiscofa...@libreoffice.org> CommitDate: Mon Jul 15 00:05:03 2024 +0200 tdf#160139 sw RTF paste: don't empty headers/footers Regression from quikee's 24.2 commit 4b0fa253a4540f5461397815d290586f9ddabe61 tdf#136472 adjust ooxml import to handle first header/footer RTF paste is particularly nasty because it calls CloseSectionGroup, which is rather strange for just pasting some characters... Fix the problem by leaving the paste alone: we already omit a number of actions in this case, and was similarly done initially by quikee in copyHeaderFooter. setHeaderFooterProperties() was newly added by quikee, so relatively safe to start avoiding on paste. make CppunitTest_sw_writerfilter_dmapper \ CPPUNIT_TEST_NAME=testPasteHeaderEmptied Change-Id: Iad997481a75bb971f9e71373175134cbec9aa7d9 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/170328 Reviewed-by: Tomaž Vajngerl <qui...@gmail.com> Tested-by: Jenkins (cherry picked from commit aaf93cd9629acd476284a4933a656ddd188a80aa) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/170349 Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org> Signed-off-by: Xisco Fauli <xiscofa...@libreoffice.org> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/170386 Reviewed-by: Justin Luth <jl...@mail.com> diff --git a/writerfilter/qa/cppunittests/dmapper/PropertyMap.cxx b/writerfilter/qa/cppunittests/dmapper/PropertyMap.cxx index 2952f1f93302..e06ee5236e0d 100644 --- a/writerfilter/qa/cppunittests/dmapper/PropertyMap.cxx +++ b/writerfilter/qa/cppunittests/dmapper/PropertyMap.cxx @@ -175,6 +175,43 @@ CPPUNIT_TEST_FIXTURE(Test, testPasteHeaderDisable) // Then make sure the header stays on: CPPUNIT_ASSERT(xStyle->getPropertyValue("HeaderIsOn").get<bool>()); } + +CPPUNIT_TEST_FIXTURE(Test, testPasteHeaderEmptied) +{ + // Given an empty document with a turned on footer with content: + loadFromFile(u"page-break-footer-table.docx"); + uno::Reference<style::XStyleFamiliesSupplier> xStyleFamiliesSupplier(mxComponent, + uno::UNO_QUERY); + uno::Reference<container::XNameAccess> xStyleFamilies + = xStyleFamiliesSupplier->getStyleFamilies(); + uno::Reference<container::XNameAccess> xStyleFamily( + xStyleFamilies->getByName(u"PageStyles"_ustr), uno::UNO_QUERY); + uno::Reference<beans::XPropertySet> xStyle(xStyleFamily->getByName(u"Standard"_ustr), + uno::UNO_QUERY); + + // When pasting RTF content: + uno::Reference<text::XTextDocument> xTextDocument(mxComponent, uno::UNO_QUERY); + uno::Reference<text::XTextRange> xText = xTextDocument->getText(); + uno::Reference<text::XTextRange> xBodyEnd = xText->getEnd(); + uno::Reference<document::XFilter> xFilter( + m_xSFactory->createInstance(u"com.sun.star.comp.Writer.RtfFilter"_ustr), uno::UNO_QUERY); + uno::Reference<document::XImporter> xImporter(xFilter, uno::UNO_QUERY); + xImporter->setTargetDocument(mxComponent); + std::unique_ptr<SvStream> pStream(new SvMemoryStream); + pStream->WriteOString("{\rtf1 paste}"); + pStream->Seek(0); + uno::Reference<io::XStream> xStream(new utl::OStreamWrapper(std::move(pStream))); + uno::Sequence aDescriptor{ comphelper::makePropertyValue(u"InputStream"_ustr, xStream), + comphelper::makePropertyValue(u"InsertMode"_ustr, true), + comphelper::makePropertyValue(u"TextInsertModeRange"_ustr, + xBodyEnd) }; + CPPUNIT_ASSERT(xFilter->filter(aDescriptor)); + + // Then make sure the header retains its contents: + uno::Reference<text::XTextRange> xFooterText(xStyle->getPropertyValue(u"FooterText"_ustr), + uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(u"Odd page footer"_ustr, xFooterText->getString()); +} } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/source/dmapper/PropertyMap.cxx b/writerfilter/source/dmapper/PropertyMap.cxx index af07ba1cdd9e..8846b2b8e87c 100644 --- a/writerfilter/source/dmapper/PropertyMap.cxx +++ b/writerfilter/source/dmapper/PropertyMap.cxx @@ -519,7 +519,8 @@ void SectionPropertyMap::removeXTextContent(uno::Reference<text::XText> const& r */ void SectionPropertyMap::setHeaderFooterProperties(DomainMapper_Impl& rDM_Impl) { - if (!m_aPageStyle.is()) + // do not alter header/footer during copy/paste + if (!m_aPageStyle.is() || !rDM_Impl.IsNewDoc()) return; bool bHasHeader = false; @@ -570,7 +571,7 @@ void SectionPropertyMap::setHeaderFooterProperties(DomainMapper_Impl& rDM_Impl) 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 && rDM_Impl.IsNewDoc()) + if (bHasHeader && !bHadFirstHeader && !m_bHadLeftHeader && !m_bHadRightHeader) { m_aPageStyle->setPropertyValue(sHeaderIsOn, uno::Any(false)); }