diff options
author | Miklos Vajna <vmiklos@collabora.com> | 2024-05-17 08:07:23 +0200 |
---|---|---|
committer | Andras Timar <andras.timar@collabora.com> | 2024-05-17 19:57:46 +0200 |
commit | c2308ee58a21624574d8eb4f8c4182be768b0b75 (patch) | |
tree | 68c379c1c0a9f128273df87b90d51bba70cfc5f1 | |
parent | 39b9041a1e2a4850df33bf1ae36416341fed2e7e (diff) |
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 <vmiklos@collabora.com>
Tested-by: Jenkins
(cherry picked from commit b969e692000f50aafacc2eb577f545b8836dcc26)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/167683
Reviewed-by: Michael Stahl <michael.stahl@allotropia.de>
-rw-r--r-- | sw/qa/core/layout/calcmove.cxx | 24 | ||||
-rw-r--r-- | sw/qa/core/layout/data/ignore-top-margin-fly.odt | bin | 0 -> 11395 bytes | |||
-rw-r--r-- | sw/source/core/layout/calcmove.cxx | 6 |
3 files changed, 30 insertions, 0 deletions
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 Binary files differnew file mode 100644 index 000000000000..51bda8fe40a9 --- /dev/null +++ b/sw/qa/core/layout/data/ignore-top-margin-fly.odt 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()) |