summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.com>2024-05-17 08:07:23 +0200
committerMiklos Vajna <vmiklos@collabora.com>2024-05-17 09:21:37 +0200
commitb969e692000f50aafacc2eb577f545b8836dcc26 (patch)
tree83043b0b5bb0c0fa6fd4b8f6705200650dd96d70
parentfa4ceeb487f89671efc8bf533192bf237c35b51e (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
-rw-r--r--sw/qa/core/layout/calcmove.cxx24
-rw-r--r--sw/qa/core/layout/data/ignore-top-margin-fly.odtbin0 -> 11395 bytes
-rw-r--r--sw/source/core/layout/calcmove.cxx6
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
new file mode 100644
index 000000000000..51bda8fe40a9
--- /dev/null
+++ b/sw/qa/core/layout/data/ignore-top-margin-fly.odt
Binary files differ
diff --git a/sw/source/core/layout/calcmove.cxx b/sw/source/core/layout/calcmove.cxx
index ea27716aaeed..6e8112308002 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())