summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.com>2024-05-14 13:49:51 +0200
committerCaolán McNamara <caolan.mcnamara@collabora.com>2024-05-15 13:45:49 +0200
commit07c93a65d2c8579adb100b7ae0c312e1872a1f37 (patch)
treef8e916f068460f3a395e2f8e75daf024833c4b57
parent348d36dc80ccd5d911e1ff97aedb5a188d0177f7 (diff)
tdf#160952 sw: ignore top margin only at page top, not e.g. table topdistro/collabora/co-24.04
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. (cherry picked from commit 6025ac371bd5cd07c0af550d78db323ad394173b) Change-Id: Ieb93facd8b2e7f6412fd20873c10ce6c8b775619 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/167690 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com> Tested-by: Caolán McNamara <caolan.mcnamara@collabora.com> Reviewed-by: Caolán McNamara <caolan.mcnamara@collabora.com>
-rw-r--r--sw/qa/core/layout/calcmove.cxx19
-rw-r--r--sw/qa/core/layout/data/ignore-top-margin-table.docxbin0 -> 12465 bytes
-rw-r--r--sw/source/core/layout/calcmove.cxx6
3 files changed, 22 insertions, 3 deletions
diff --git a/sw/qa/core/layout/calcmove.cxx b/sw/qa/core/layout/calcmove.cxx
index 3e4deec52ae8..a44dc1256b83 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 000000000000..c82f6d63c13f
--- /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 081472b98ee3..63c774c25cd6 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;
}