sw/qa/writerfilter/dmapper/PropertyMap.cxx | 28 ++++++++++++++++-- sw/qa/writerfilter/dmapper/data/alt-chunk-header.docx |binary sw/source/writerfilter/dmapper/PropertyMap.cxx | 5 ++- 3 files changed, 29 insertions(+), 4 deletions(-)
New commits: commit 4607c8d67ec3583c5a3e017bf1fa6fc7514a1674 Author: Miklos Vajna <vmik...@collabora.com> AuthorDate: Fri Sep 5 21:10:56 2025 +0200 Commit: Miklos Vajna <vmik...@collabora.com> CommitDate: Fri Sep 5 22:54:28 2025 +0200 tdf#168221 DOCX import, altChunk: fix lost header/footer Open the bugdoc, first page should have a header, but it has no header. This went wrong in 32c322e9d037b29ded2297b400a2c596c042f1fa (DOCX import, altChunk: fix missing page break, 2020-10-26), the problem is that somewhat similar to copy&paste, the altChunk mechanism drops styles from the inner document: the section breaks in the middle of the document are wanted, but the final section break is not wanted. So fix the problem by restricting when SectionPropertyMap::CloseSectionGroup() sets the page style name: instead of always doing that for alt chunks, only do it for non-last section breaks. This keeps the old page break case working and fixes the new, lost header problem. Change-Id: I5fc2a3d0561795612d39e50d780c7f78757486e2 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/190625 Tested-by: Jenkins Reviewed-by: Miklos Vajna <vmik...@collabora.com> diff --git a/sw/qa/writerfilter/dmapper/PropertyMap.cxx b/sw/qa/writerfilter/dmapper/PropertyMap.cxx index be80c9d398bb..49648df7c991 100644 --- a/sw/qa/writerfilter/dmapper/PropertyMap.cxx +++ b/sw/qa/writerfilter/dmapper/PropertyMap.cxx @@ -7,7 +7,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include <test/unoapi_test.hxx> +#include <swmodeltestbase.hxx> #include <com/sun/star/text/XPageCursor.hpp> #include <com/sun/star/text/XTextViewCursorSupplier.hpp> @@ -22,16 +22,21 @@ #include <unotools/streamwrap.hxx> #include <comphelper/propertyvalue.hxx> +#include <docsh.hxx> +#include <IDocumentLayoutAccess.hxx> +#include <rootfrm.hxx> +#include <pagefrm.hxx> + using namespace ::com::sun::star; namespace { /// Tests for sw/source/writerfilter/dmapper/PropertyMap.cxx. -class Test : public UnoApiTest +class Test : public SwModelTestBase { public: Test() - : UnoApiTest(u"/sw/qa/writerfilter/dmapper/data/"_ustr) + : SwModelTestBase(u"/sw/qa/writerfilter/dmapper/data/"_ustr) { } }; @@ -217,6 +222,23 @@ CPPUNIT_TEST_FIXTURE(Test, testPasteHeaderEmptied) uno::UNO_QUERY); CPPUNIT_ASSERT_EQUAL(u"Odd page footer"_ustr, xFooterText->getString()); } + +CPPUNIT_TEST_FIXTURE(Test, testAltChunkHeader) +{ + // Given a document with an altChunk and a header: + // When loading that document: + createSwDoc("alt-chunk-header.docx"); + + // Then make sure the first page has a header: + SwDocShell* pDocShell = getSwDocShell(); + SwDoc* pDoc = pDocShell->GetDoc(); + SwRootFrame* pLayout = pDoc->getIDocumentLayoutAccess().GetCurrentLayout(); + auto pPage1 = pLayout->Lower()->DynCastPageFrame(); + SwFrame* pFrame = pPage1->GetLower(); + // Without the accompanying fix in place, this test would have failed, the first page had only a + // body frame, not a header-body-footer chain. + CPPUNIT_ASSERT(pFrame->IsHeaderFrame()); +} } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/qa/writerfilter/dmapper/data/alt-chunk-header.docx b/sw/qa/writerfilter/dmapper/data/alt-chunk-header.docx new file mode 100644 index 000000000000..c0db9df722c5 Binary files /dev/null and b/sw/qa/writerfilter/dmapper/data/alt-chunk-header.docx differ diff --git a/sw/source/writerfilter/dmapper/PropertyMap.cxx b/sw/source/writerfilter/dmapper/PropertyMap.cxx index 37802ac80a03..e54091ae22f4 100644 --- a/sw/source/writerfilter/dmapper/PropertyMap.cxx +++ b/sw/source/writerfilter/dmapper/PropertyMap.cxx @@ -1982,7 +1982,10 @@ void SectionPropertyMap::CloseSectionGroup( DomainMapper_Impl& rDM_Impl ) { xRangeProperties.set(rDM_Impl.m_xAltChunkStartingRange, uno::UNO_QUERY); } - if (xRangeProperties.is() && (rDM_Impl.IsNewDoc() || rDM_Impl.IsAltChunk())) + // Alt chunk: ignore last section break at the document end to avoid unwanted changes to + // the outer page style. + bool bNonLastInAltChunk = rDM_Impl.IsAltChunk() && !rDM_Impl.GetIsLastSectionGroup(); + if (xRangeProperties.is() && (rDM_Impl.IsNewDoc() || bNonLastInAltChunk)) { // Avoid setting page style in case of autotext: so inserting the autotext at the // end of the document does not introduce an unwanted page break.