tdf#125893 DOCX import: fix "half" contextual paragraph spacing
Always ignore own top margin setting of the actual paragraph
with contextual spacing, if the previous paragraph is identical.
I.e. in that case, too, when the previous paragraph has no
contextual spacing, like MSO does.
Note: PARA_SPACE_MAX mode hasn't included this modification,
yet, so only ODT documents converted from DOCX use it at the
default setting.
See also commit ba18832ceeda21f047a664b71a4333a54737e6c8
(tdf#75221: make margin collapsing implementation conform OASIS
proposal)
Change-Id: Ida9d12b2c511fcd5e38ade7eb5f4650387c65813
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/97081
Tested-by: Jenkins
Reviewed-by: László Németh <nemeth@numbertext.org>
(cherry picked from commit e318d5d8146d18e2c76e23f2e3c39527f2af9f36)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/97065
Reviewed-by: Adolfo Jayme Barrientos <fitojb@ubuntu.com>
diff --git a/sw/qa/extras/layout/data/tdf125893.docx b/sw/qa/extras/layout/data/tdf125893.docx
new file mode 100644
index 0000000..f46f9af
--- /dev/null
+++ b/sw/qa/extras/layout/data/tdf125893.docx
Binary files differ
diff --git a/sw/qa/extras/layout/layout.cxx b/sw/qa/extras/layout/layout.cxx
index efd3616..7fe63d3 100644
--- a/sw/qa/extras/layout/layout.cxx
+++ b/sw/qa/extras/layout/layout.cxx
@@ -3018,6 +3018,14 @@
assertXPath(pXmlDoc, "//tab/row/cell[1]/txt/Text", "Portion", "Abcd efghijkl");
}
CPPUNIT_TEST_FIXTURE(SwLayoutWriter, testTdf125893)
{
createDoc("tdf125893.docx");
xmlDocUniquePtr pXmlDoc = parseLayoutDump();
// This was 400. The paragraph must have zero top border.
assertXPath(pXmlDoc, "/root/page/body/txt[4]/infos/prtBounds", "top", "0");
}
CPPUNIT_TEST_FIXTURE(SwLayoutWriter, testTdf117188)
{
createDoc("tdf117188.docx");
diff --git a/sw/source/core/layout/flowfrm.cxx b/sw/source/core/layout/flowfrm.cxx
index 480d605..3833920 100644
--- a/sw/source/core/layout/flowfrm.cxx
+++ b/sw/source/core/layout/flowfrm.cxx
@@ -1423,6 +1423,14 @@
&& lcl_getContextualSpacing(pPrevFrame)
&& lcl_IdenticalStyles(pPrevFrame, &m_rThis);
// tdf#125893 always ignore own top margin setting of the actual paragraph
// with contextual spacing, if the previous paragraph is identical
const bool bHalfContextualSpacing = !bContextualSpacing
&& pAttrs->GetULSpace().GetContext()
&& !lcl_getContextualSpacing(pPrevFrame)
&& lcl_getContextualSpacing(&m_rThis)
&& lcl_IdenticalStyles(pPrevFrame, &m_rThis);
// i#11860 - use new method to determine needed spacing
// values of found previous frame and use these values.
SwTwips nPrevLowerSpace = 0;
@@ -1434,6 +1442,7 @@
bPrevLineSpacingPorportional );
if( rIDSA.get(DocumentSettingId::PARA_SPACE_MAX) )
{
// FIXME: apply bHalfContextualSpacing for better portability?
nUpper = bContextualSpacing ? 0 : nPrevLowerSpace + pAttrs->GetULSpace().GetUpper();
SwTwips nAdd = nPrevLineSpacing;
// i#11859 - consideration of the line spacing
@@ -1477,8 +1486,9 @@
}
else
{
nUpper = bContextualSpacing ? 0 : std::max(static_cast<long>(nPrevLowerSpace),
static_cast<long>(pAttrs->GetULSpace().GetUpper()) );
nUpper = bContextualSpacing ? 0 : std::max(static_cast<long>(nPrevLowerSpace), bHalfContextualSpacing
? 0 : static_cast<long>(pAttrs->GetULSpace().GetUpper()) );
// i#11859 - consideration of the line spacing
// for the upper spacing of a text frame
if ( bUseFormerLineSpacing )