summaryrefslogtreecommitdiff
path: root/sw
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.com>2023-06-15 08:24:23 +0200
committerMiklos Vajna <vmiklos@collabora.com>2023-06-15 09:28:56 +0200
commit737d90b7b7cb03bb6128b74a32906b0391868830 (patch)
tree7917fbac6e3f43db354aee0442dd212d3accc75b /sw
parent977878814a3573627026e31edb8a51c8f30c8a0c (diff)
sw floattable: fix handling of upper margin of anchor for fly intersect
The bugdoc has 2 paragraphs and a shape between them. Word has a small amount of space between the shape and the 2nd paragraph, Writer has a large amount of space between the shape and the 2nd paragraph. It seems what happens is that Writer puts both the text node's own upper spacing and the previous text node's lower spacing into the upper spacing of the text frame, so the check added in commit d07fc485d46f431405a3f6a002f951a08c559677 (tdf#116486 Consider upper margin in paragraph positioning with flys, 2018-04-10) is not entirely correct, as it deal with both upper and lower margins, but its intention was just the upper margins. Fix the problem by (indirectly) using GetUpperSpaceAmountConsideredForPrevFrame(), which allows doing the intersection for the original text node upper spacing but not for the text node lower spacing. This keeps the original bugdoc working, but fixes the unexpected vertical space for the new bugdoc. This is part of the effort so that the original bnc#816603 bugdoc's DOCX version moves an overlapping floating table from page 4 back to page 3, like Word does. testTdf122878 is modified to just make sure no overlap happens, manual testing of the bugdoc shows that our layout still matches Word. Change-Id: I4622fb77dc8a52493766e50688ec92065eac65bc Reviewed-on: https://gerrit.libreoffice.org/c/core/+/153101 Reviewed-by: Miklos Vajna <vmiklos@collabora.com> Tested-by: Jenkins
Diffstat (limited to 'sw')
-rw-r--r--sw/qa/core/text/data/para-upper-margin-fly-intersect.docxbin0 -> 14872 bytes
-rw-r--r--sw/qa/core/text/text.cxx30
-rw-r--r--sw/qa/extras/layout/layout3.cxx20
-rw-r--r--sw/source/core/text/itrform2.cxx6
4 files changed, 45 insertions, 11 deletions
diff --git a/sw/qa/core/text/data/para-upper-margin-fly-intersect.docx b/sw/qa/core/text/data/para-upper-margin-fly-intersect.docx
new file mode 100644
index 000000000000..e8e767fb3897
--- /dev/null
+++ b/sw/qa/core/text/data/para-upper-margin-fly-intersect.docx
Binary files differ
diff --git a/sw/qa/core/text/text.cxx b/sw/qa/core/text/text.cxx
index 6d71cadcf9ea..dff758985c37 100644
--- a/sw/qa/core/text/text.cxx
+++ b/sw/qa/core/text/text.cxx
@@ -1371,6 +1371,36 @@ CPPUNIT_TEST_FIXTURE(SwCoreTextTest, testTdf139863)
assertXPath(pXmlDoc, "//body/txt[2]/SwParaPortion/SwLineLayout/child::*", 1);
}
+CPPUNIT_TEST_FIXTURE(SwCoreTextTest, testParaUpperMarginFlyIntersect)
+{
+ // Given a document with 2 paragraphs, the paragraphs have both upper and lower spacing of 567
+ // twips:
+ createSwDoc("para-upper-margin-fly-intersect.docx");
+
+ // When laying out that document:
+ calcLayout();
+
+ // Then make sure that we shift down the text in the second paragraph only based on the 2nd para
+ // upper margin, not based on the 1st para lower margin:
+ xmlDocUniquePtr pXmlDoc = parseLayoutDump();
+ int nFlyCount
+ = getXPathContent(pXmlDoc,
+ "count(//SwParaPortion/SwLineLayout/child::*[@type='PortionType::Fly'])")
+ .toInt32();
+ int nHeight = 0;
+ for (int i = 1; i <= nFlyCount; ++i)
+ {
+ OString xPath = "(//SwParaPortion/SwLineLayout/child::*[@type='PortionType::Fly'])["
+ + OString::number(i) + "]";
+ nHeight += getXPath(pXmlDoc, xPath, "height").toInt32();
+ }
+ // Without the accompanying fix in place, this test would have failed with:
+ // - Expected: 521 (~500)
+ // - Actual : 857 (~1000)
+ // I.e. both upper and lower margin was taken into account.
+ CPPUNIT_ASSERT_EQUAL(521, nHeight);
+}
+
CPPUNIT_PLUGIN_IMPLEMENT();
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/qa/extras/layout/layout3.cxx b/sw/qa/extras/layout/layout3.cxx
index 9d4d53be5d39..784a295fa2e8 100644
--- a/sw/qa/extras/layout/layout3.cxx
+++ b/sw/qa/extras/layout/layout3.cxx
@@ -193,21 +193,21 @@ CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, testTdf122878)
{
createSwDoc("tdf122878.docx");
xmlDocUniquePtr pXmlDoc = parseLayoutDump();
- // FIXME: the XPath should be adjusted when the proper floating table would be imported
const sal_Int32 nTblTop
= getXPath(pXmlDoc, "/root/page[1]/footer/txt/anchored/fly/tab/infos/bounds", "top")
.toInt32();
- const sal_Int32 nFirstPageParaCount
- = getXPathContent(pXmlDoc, "count(/root/page[1]/body/txt)").toInt32();
- CPPUNIT_ASSERT_EQUAL(sal_Int32(30), nFirstPageParaCount);
- for (sal_Int32 i = 1; i <= nFirstPageParaCount; ++i)
+ SwDoc* pDoc = getSwDoc();
+ SwRootFrame* pLayout = pDoc->getIDocumentLayoutAccess().GetCurrentLayout();
+ auto pPage1 = dynamic_cast<SwPageFrame*>(pLayout->Lower());
+ CPPUNIT_ASSERT(pPage1);
+ SwFrame* pBody = pPage1->FindBodyCont();
+ for (SwFrame* pFrame = pBody->GetLower(); pFrame; pFrame = pFrame->GetNext())
{
- const OString xPath = "/root/page[1]/body/txt[" + OString::number(i) + "]/infos/bounds";
- const sal_Int32 nTxtBottom = getXPath(pXmlDoc, xPath, "top").toInt32()
- + getXPath(pXmlDoc, xPath, "height").toInt32();
+ const sal_Int32 nTxtBottom = pFrame->getFrameArea().Bottom();
// No body paragraphs should overlap the table in the footer
- CPPUNIT_ASSERT_MESSAGE(OString("testing paragraph #" + OString::number(i)).getStr(),
- nTxtBottom <= nTblTop);
+ CPPUNIT_ASSERT_MESSAGE(
+ OString("testing paragraph #" + OString::number(pFrame->GetFrameId())).getStr(),
+ nTxtBottom <= nTblTop);
}
}
diff --git a/sw/source/core/text/itrform2.cxx b/sw/source/core/text/itrform2.cxx
index d3fa1b71318f..51c3a49f2062 100644
--- a/sw/source/core/text/itrform2.cxx
+++ b/sw/source/core/text/itrform2.cxx
@@ -2720,7 +2720,11 @@ void SwTextFormatter::CalcFlyWidth( SwTextFormatInfo &rInf )
if (GetTextFrame()->GetDoc().getIDocumentSettingAccess().get(DocumentSettingId::ADD_VERTICAL_FLY_OFFSETS)
&& IsFirstTextLine())
{
- const tools::Long nUpper = m_pFrame->getFramePrintArea().Top();
+ tools::Long nUpper = m_pFrame->getFramePrintArea().Top();
+ // Make sure that increase only happens in case the upper spacing comes from the upper
+ // margin of the current text frame, not because of a lower spacing of the previous text
+ // frame.
+ nUpper -= m_pFrame->GetUpperSpaceAmountConsideredForPrevFrameAndPageGrid();
// Increase the rectangle
if( nUpper > 0 && nTop >= nUpper )
aLine.SubTop( nUpper );