tdf#160952 sw: ignore top margin only at page top, not e.g. table top
The bugdoc has a table at the top of the 2nd page and we ignored the top
margin inside the table cell (for the first paragraph), while this
doesn't happen in Word.
As mentioned at
<https://gerrit.libreoffice.org/c/core/+/167221/3#message-c03abf8e8e3cd20d49006058e6b3eb130585ff8f>,
the old code assumed "top of the page" for all frames not having a
previous frame, while that code was only tested with text frames
directly in the body frame of a page frame.
Fix the problem by limiting this "collapse upper spacing" behavior to
frames directly in body frames. This keeps the old bugdoc working, but
is meant to restore the old, wanted behavior in other cases like e.g. in
table cells.
If later it's discovered that upper spacing collapsing is wanted in
other contexts, those are best added on a case by case basis.
Change-Id: Ieb93facd8b2e7f6412fd20873c10ce6c8b775619
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/167631
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Tested-by: Jenkins
diff --git a/sw/qa/core/layout/calcmove.cxx b/sw/qa/core/layout/calcmove.cxx
index 3e4deec..a44dc12 100644
--- a/sw/qa/core/layout/calcmove.cxx
+++ b/sw/qa/core/layout/calcmove.cxx
@@ -39,6 +39,25 @@ CPPUNIT_TEST_FIXTURE(Test, testIgnoreTopMargin)
// i.e. the top margin in the first para of a non-first page wasn't ignored, like in Word.
CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(0), nParaTopMargin);
}
CPPUNIT_TEST_FIXTURE(Test, testIgnoreTopMarginTable)
{
// Given a DOCX (>= Word 2013) file, with 2 pages:
// When loading that document:
createSwDoc("ignore-top-margin-table.docx");
// Then make sure that the paragraph on the 2nd page in B1 has a top margin:
xmlDocUniquePtr pXmlDoc = parseLayoutDump();
sal_Int32 nParaTopMargin
= getXPath(pXmlDoc, "/root/page[2]/body/tab/row/cell[2]/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 in B1's first paragraph was ignored, but not in Word.
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-table.docx b/sw/qa/core/layout/data/ignore-top-margin-table.docx
new file mode 100644
index 0000000..c82f6d6
--- /dev/null
+++ b/sw/qa/core/layout/data/ignore-top-margin-table.docx
Binary files differ
diff --git a/sw/source/core/layout/calcmove.cxx b/sw/source/core/layout/calcmove.cxx
index 50dd455..ea27716 100644
--- a/sw/source/core/layout/calcmove.cxx
+++ b/sw/source/core/layout/calcmove.cxx
@@ -1092,9 +1092,9 @@ bool SwFrame::IsCollapseUpper() const
return false;
}
// Word >= 2013 style: when we're at the top of the page, but not on the first page, then ignore
// the upper margin for paragraphs.
if (GetPrev())
// 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())
{
return false;
}