sw/qa/core/layout/calcmove.cxx | 24 +++++++++++++++++++++++ sw/qa/core/layout/data/ignore-top-margin-fly.odt |binary sw/source/core/layout/calcmove.cxx | 6 +++++ 3 files changed, 30 insertions(+)
New commits: commit 9b508c45a7c30a5c1847b7d93f2a26a653102588 Author: Miklos Vajna <vmik...@collabora.com> AuthorDate: Fri May 17 08:07:23 2024 +0200 Commit: Miklos Vajna <vmik...@collabora.com> CommitDate: Fri May 17 11:00:10 2024 +0200 tdf#160952 sw: ignore top margin only at page top, not in fly See <https://gerrit.libreoffice.org/c/core/+/167671/2#message-8603b129dd8bd72608259571056ded950182ca96>, multi-column shape text can't appear in DOCX files, so collapsing upper spacing in that case is not correct, avoid it. Change-Id: Icf69c8d84fdd15d6e3289ff614b2f6ba7cee1e0e Reviewed-on: https://gerrit.libreoffice.org/c/core/+/167758 Reviewed-by: Miklos Vajna <vmik...@collabora.com> Tested-by: Jenkins (cherry picked from commit b969e692000f50aafacc2eb577f545b8836dcc26) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/167683 Reviewed-by: Michael Stahl <michael.st...@allotropia.de> diff --git a/sw/qa/core/layout/calcmove.cxx b/sw/qa/core/layout/calcmove.cxx index a44dc1256b83..ad53df9bd0f4 100644 --- a/sw/qa/core/layout/calcmove.cxx +++ b/sw/qa/core/layout/calcmove.cxx @@ -58,6 +58,30 @@ CPPUNIT_TEST_FIXTURE(Test, testIgnoreTopMarginTable) // i.e. the top margin in B1's first paragraph was ignored, but not in Word. CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(2000), nParaTopMargin); } + +CPPUNIT_TEST_FIXTURE(Test, testIgnoreTopMarginFly) +{ + // Given a document with compat flags like DOCX (>= Word 2013), 2 pages, multi-col fly frame on + // page 2: + createSwDoc("ignore-top-margin-fly.odt"); + + // When laying out that document: + xmlDocUniquePtr pXmlDoc = parseLayoutDump(); + + // Then make sure that the top margin is not ignored inside shape text: + sal_Int32 nParaTopMargin + = getXPath( + pXmlDoc, + "/root/page[2]/body/section/column[2]/body/txt/anchored/fly/column/body/txt/infos/prtBounds"_ostr, + "top"_ostr) + .toInt32(); + // Without the accompanying fix in place, this test would have failed with: + // - Expected: 4000 + // - Actual : 0 + // i.e. the top margin was ignored inside shape text for Word compat, while multi-col shape text + // is a Writer feature. + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(4000), nParaTopMargin); +} } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/qa/core/layout/data/ignore-top-margin-fly.odt b/sw/qa/core/layout/data/ignore-top-margin-fly.odt new file mode 100644 index 000000000000..51bda8fe40a9 Binary files /dev/null and b/sw/qa/core/layout/data/ignore-top-margin-fly.odt differ diff --git a/sw/source/core/layout/calcmove.cxx b/sw/source/core/layout/calcmove.cxx index 63c774c25cd6..f358d74af0bd 100644 --- a/sw/source/core/layout/calcmove.cxx +++ b/sw/source/core/layout/calcmove.cxx @@ -1092,6 +1092,12 @@ bool SwFrame::IsCollapseUpper() const return false; } + if (IsInFly()) + { + // Not in a page's body. + return false; + } + // Word >= 2013 style: when we're at the top of the page's body, but not on the first page, then // ignore the upper margin for paragraphs. if (GetPrev() || !GetUpper() || !GetUpper()->IsBodyFrame())