summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.com>2024-12-06 14:09:28 +0100
committerMichael Stahl <michael.stahl@allotropia.de>2024-12-18 10:27:18 +0100
commit222b0cf18578d7407d67ef52370313b64bb1d7d7 (patch)
tree3692f867ae418b70ce093e5c1ea8406d53f95c95
parent28f06aa70df227616b513c5675caefbedcdd049b (diff)
tdf#164095 sw: fix missing top margin on paragraph after changing page style
Open the bugdoc, go to the page after the section break, there is a top margin for the first paragraph there in Word, but not in Writer. This went wrong in commit abd90828cf101581a07b9d1c371a8c3156521e9f (tdf#160952 sw: ignore top margin of para on non-first pages with newer DOCX, 2024-05-14), where it seemed that all implicit and explicit page breaks want to ignore that top margin for the first paragraph. Turns out this is more complex: implicit breaks and page breaks should be followed by an ignore, but not paragraphs after "section break (next page)". So restore the margins for the RES_PAGEDESC, but continue to have them for RES_BREAK & implicit breaks. Change-Id: If1fcf3077b81a705d3587bdae422dcfa16f1c17c Reviewed-on: https://gerrit.libreoffice.org/c/core/+/177973 Tested-by: Jenkins Reviewed-by: Miklos Vajna <vmiklos@collabora.com> (cherry picked from commit ae7900dd42a65aaf60df6b21b9ad511496b209d9) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/178020 Signed-off-by: Xisco Fauli <xiscofauli@libreoffice.org> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/178567 Reviewed-by: Michael Stahl <michael.stahl@allotropia.de>
-rw-r--r--sw/qa/core/layout/calcmove.cxx18
-rw-r--r--sw/qa/core/layout/data/ignore-top-margin-page-style-change.docxbin0 -> 12243 bytes
-rw-r--r--sw/source/core/layout/calcmove.cxx10
3 files changed, 28 insertions, 0 deletions
diff --git a/sw/qa/core/layout/calcmove.cxx b/sw/qa/core/layout/calcmove.cxx
index 8098dc238fc0..01c6643ef6e4 100644
--- a/sw/qa/core/layout/calcmove.cxx
+++ b/sw/qa/core/layout/calcmove.cxx
@@ -82,6 +82,24 @@ CPPUNIT_TEST_FIXTURE(Test, testIgnoreTopMarginFly)
// is a Writer feature.
CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(4000), nParaTopMargin);
}
+
+CPPUNIT_TEST_FIXTURE(Test, testIgnoreTopMarginPageStyleChange)
+{
+ // Given a DOCX (>= Word 2013), section break (next page) between pages 2 and 3:
+ createSwDoc("ignore-top-margin-page-style-change.docx");
+
+ // When laying out that document:
+ xmlDocUniquePtr pXmlDoc = parseLayoutDump();
+
+ // Then make sure that the top margin is not ignored on page 3:
+ sal_Int32 nParaTopMargin
+ = getXPath(pXmlDoc, "/root/page[3]/body/txt/infos/prtBounds", "top").toInt32();
+ // Without the accompanying fix in place, this test would have failed with:
+ // - Expected: 2000
+ // - Actual : 0
+ // i.e. the top margin was ignored, which is incorrect.
+ 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-page-style-change.docx b/sw/qa/core/layout/data/ignore-top-margin-page-style-change.docx
new file mode 100644
index 000000000000..ea7d16d8851f
--- /dev/null
+++ b/sw/qa/core/layout/data/ignore-top-margin-page-style-change.docx
Binary files differ
diff --git a/sw/source/core/layout/calcmove.cxx b/sw/source/core/layout/calcmove.cxx
index bda48e851fac..e04edcddd5a9 100644
--- a/sw/source/core/layout/calcmove.cxx
+++ b/sw/source/core/layout/calcmove.cxx
@@ -1118,6 +1118,16 @@ bool SwFrame::IsCollapseUpper() const
return false;
}
+ // Avoid the ignore after applying a new page style (but do it after page breaks).
+ const SwTextNode* pTextNode = pTextFrame->GetTextNodeForParaProps();
+ if (pTextNode)
+ {
+ if (pTextNode->HasSwAttrSet() && pTextNode->GetSwAttrSet().HasItem(RES_PAGEDESC))
+ {
+ return false;
+ }
+ }
+
return true;
}