sw/qa/core/layout/calcmove.cxx | 18 ++++++++++ sw/qa/core/layout/data/ignore-top-margin-page-style-change.docx |binary sw/source/core/layout/calcmove.cxx | 10 +++++ 3 files changed, 28 insertions(+)
New commits: commit 6c7c0d0fb749470e71f12a98e5fde88bef4a92af Author: Miklos Vajna <vmik...@collabora.com> AuthorDate: Fri Dec 6 14:09:28 2024 +0100 Commit: Caolán McNamara <caolan.mcnam...@collabora.com> CommitDate: Mon Dec 9 09:31:42 2024 +0100 tdf#164095 sw: fix missing top margin on paragraph after changing page style Open the bugdoc, go to the page after the section break, there is a top margin for the first paragraph there in Word, but not in Writer. This went wrong in commit abd90828cf101581a07b9d1c371a8c3156521e9f (tdf#160952 sw: ignore top margin of para on non-first pages with newer DOCX, 2024-05-14), where it seemed that all implicit and explicit page breaks want to ignore that top margin for the first paragraph. Turns out this is more complex: implicit breaks and page breaks should be followed by an ignore, but not paragraphs after "section break (next page)". So restore the margins for the RES_PAGEDESC, but continue to have them for RES_BREAK & implicit breaks. (cherry picked from commit ae7900dd42a65aaf60df6b21b9ad511496b209d9) Change-Id: If1fcf3077b81a705d3587bdae422dcfa16f1c17c Reviewed-on: https://gerrit.libreoffice.org/c/core/+/177982 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com> Reviewed-by: Caolán McNamara <caolan.mcnam...@collabora.com> diff --git a/sw/qa/core/layout/calcmove.cxx b/sw/qa/core/layout/calcmove.cxx index ad53df9bd0f4..2a14e4cf90dd 100644 --- a/sw/qa/core/layout/calcmove.cxx +++ b/sw/qa/core/layout/calcmove.cxx @@ -82,6 +82,24 @@ CPPUNIT_TEST_FIXTURE(Test, testIgnoreTopMarginFly) // is a Writer feature. CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(4000), nParaTopMargin); } + +CPPUNIT_TEST_FIXTURE(Test, testIgnoreTopMarginPageStyleChange) +{ + // Given a DOCX (>= Word 2013), section break (next page) between pages 2 and 3: + createSwDoc("ignore-top-margin-page-style-change.docx"); + + // When laying out that document: + xmlDocUniquePtr pXmlDoc = parseLayoutDump(); + + // Then make sure that the top margin is not ignored on page 3: + sal_Int32 nParaTopMargin + = getXPath(pXmlDoc, "/root/page[3]/body/txt/infos/prtBounds"_ostr, "top"_ostr).toInt32(); + // Without the accompanying fix in place, this test would have failed with: + // - Expected: 2000 + // - Actual : 0 + // i.e. the top margin was ignored, which is incorrect. + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(2000), nParaTopMargin); +} } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/qa/core/layout/data/ignore-top-margin-page-style-change.docx b/sw/qa/core/layout/data/ignore-top-margin-page-style-change.docx new file mode 100644 index 000000000000..ea7d16d8851f Binary files /dev/null and b/sw/qa/core/layout/data/ignore-top-margin-page-style-change.docx differ diff --git a/sw/source/core/layout/calcmove.cxx b/sw/source/core/layout/calcmove.cxx index 0aac409e155b..89a133bd2393 100644 --- a/sw/source/core/layout/calcmove.cxx +++ b/sw/source/core/layout/calcmove.cxx @@ -1114,6 +1114,16 @@ bool SwFrame::IsCollapseUpper() const return false; } + // Avoid the ignore after applying a new page style (but do it after page breaks). + const SwTextNode* pTextNode = pTextFrame->GetTextNodeForParaProps(); + if (pTextNode) + { + if (pTextNode->HasSwAttrSet() && pTextNode->GetSwAttrSet().HasItem(RES_PAGEDESC)) + { + return false; + } + } + return true; }