diff options
author | Miklos Vajna <vmiklos@collabora.com> | 2020-03-23 21:05:43 +0100 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.com> | 2020-03-24 09:07:21 +0100 |
commit | e68d961a361a784df1000a978bd02eca57e30565 (patch) | |
tree | 78f8a55e98bfbffc1db5d57c204823aeffcf23e9 | |
parent | cc76ac6b9e7de8d120e3b57ab4ab63a10d73825e (diff) |
tdf#131282 sw layout: fix shifted down table next to a fly frame
Regression from commit fd7749fddc5a767461dfced55369af48e5a6d561 (sw: fix
handling of table vs fly overlaps in the AddVerticalFlyOffsets case,
2020-02-14), the problem was that the rectangle of the fly frame
included spacing when overlapping was checked.
Given that this code was explicitly added for Word compat purposes,
change it to ignore spacing. You can see that Word doesn't care about
spacing: increase the left margin of e.g. the pie chart in the bugdoc to
some large value and the table is still not shifted down.
Writer shifted the table down as the small spacing was already enough to
detect an overlap:
debug:21457:21457: SwTabFrame::CalcFlyOffsets: aTabRange is 896 -> 3698
debug:21457:21457: SwTabFrame::CalcFlyOffsets: aFlyRange is 3650 -> 6290
If we don't include that ~3 px spacing, then we don't overlap, similar
to Word.
Change-Id: I154c211bb0700d132fd168f49c1bbfb29e8caeb7
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/90939
Tested-by: Jenkins
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
-rw-r--r-- | sw/qa/core/layout/data/table-fly-overlap-spacing.docx | bin | 0 -> 27719 bytes | |||
-rw-r--r-- | sw/qa/core/layout/layout.cxx | 17 | ||||
-rw-r--r-- | sw/source/core/layout/tabfrm.cxx | 9 |
3 files changed, 24 insertions, 2 deletions
diff --git a/sw/qa/core/layout/data/table-fly-overlap-spacing.docx b/sw/qa/core/layout/data/table-fly-overlap-spacing.docx Binary files differnew file mode 100644 index 000000000000..648c8b93df29 --- /dev/null +++ b/sw/qa/core/layout/data/table-fly-overlap-spacing.docx diff --git a/sw/qa/core/layout/layout.cxx b/sw/qa/core/layout/layout.cxx index cd71d9e2a99b..7f8d885301d7 100644 --- a/sw/qa/core/layout/layout.cxx +++ b/sw/qa/core/layout/layout.cxx @@ -75,6 +75,23 @@ CPPUNIT_TEST_FIXTURE(SwCoreLayoutTest, testBtlrTableRowSpan) assertXPathContent(pXmlDoc, "//textarray[1]/text", "USA"); } +CPPUNIT_TEST_FIXTURE(SwCoreLayoutTest, testTableFlyOverlapSpacing) +{ + // Load a document that has an image on the right of a table. The table wraps around the image. + load(DATA_DIRECTORY, "table-fly-overlap-spacing.docx"); + SwTwips nFlyTop = parseDump("//body/txt/anchored/fly/infos/bounds", "top").toInt32(); + SwTwips nFlyHeight = parseDump("//body/txt/anchored/fly/infos/bounds", "height").toInt32(); + SwTwips nFlyBottom = nFlyTop + nFlyHeight; + SwTwips nTableFrameTop = parseDump("//tab/infos/bounds", "top").toInt32(); + SwTwips nTablePrintTop = parseDump("//tab/infos/prtBounds", "top").toInt32(); + SwTwips nTableTop = nTableFrameTop + nTablePrintTop; + // Without the accompanying fix in place, this test would have failed with: + // - Expected greater or equal than: 3993 + // - Actual : 3993 + // i.e. the table was below the image, not on the left of the image. + CPPUNIT_ASSERT_LESS(nFlyBottom, nTableTop); +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/core/layout/tabfrm.cxx b/sw/source/core/layout/tabfrm.cxx index 9beef619ed4a..be9fb1aef224 100644 --- a/sw/source/core/layout/tabfrm.cxx +++ b/sw/source/core/layout/tabfrm.cxx @@ -2806,8 +2806,13 @@ bool SwTabFrame::CalcFlyOffsets( SwTwips& rUpper, aRectFnSet.GetLeft(aRect) + aRectFnSet.GetLeft(getFramePrintArea()), aRectFnSet.GetLeft(aRect) + aRectFnSet.GetLeft(getFramePrintArea()) + aRectFnSet.GetWidth(getFramePrintArea())); - basegfx::B1DRange aFlyRange(aRectFnSet.GetLeft(aFlyRect), - aRectFnSet.GetRight(aFlyRect)); + + // Ignore spacing when determining the left/right edge of the fly, like + // Word does. + const SwRect aFlyRectWithoutSpaces = pFly->GetObjRect(); + basegfx::B1DRange aFlyRange(aRectFnSet.GetLeft(aFlyRectWithoutSpaces), + aRectFnSet.GetRight(aFlyRectWithoutSpaces)); + // If it does, shift the table down. Do this only in the compat case, // normally an SwFlyPortion is created instead that increases the height // of the first table row. |