diff options
author | Miklos Vajna <vmiklos@collabora.com> | 2023-06-08 08:09:12 +0200 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.com> | 2023-06-08 12:55:01 +0200 |
commit | 81a108770233825557c2dae5776d7417be017fb8 (patch) | |
tree | 628c7580f01797cd33004a0da7a858db9d3d638e /sw/qa/core/text/text.cxx | |
parent | ac2838a9cd5577f92dbece130fa6fb8b8e26e6cd (diff) |
sw floattable, compat mode: handle lower margin of anchor for fly intersect
The bugdoc has 2 floating tables and they were overlapping in Writer,
but not in Word.
What seems to happen is that the document has a floating table, followed
by an empty paragraph, and in case that empty paragraph goes above the
floating table, then we overlap, but if it goes below the floating
table, then the next paragraph will start below the empty paragraph, so
no overlap will happen. This is possible in Word, because in "Word 2010"
compat mode it has 327 twips vertical space above the first floating
table (set by its positioning attribute), and in case the empty
paragraph has a font size of 11pt (220 twips) + 200 twips of lower
margin (inherited from the default paragraph style), then this 420 twips
of space doesn't fit. Note that for new documents Word ("Word 2013"
mode) does the same as Writer and ignores the lower spacing when
intersecting lines with flys.
Fix the problem by introducing a new
SwTextFrame::GetLowerMarginForFlyIntersect() that gives us the lower
spacing if 1) this is Word 2010 compat mode 2) this text frame has no
fly portions / multiple lines yet and 3) this paragraph is empty. Then
use this function at 3 places where we used to intersect with the
absolute print area of the frame, and extend these places with the lower
spacing.
This could be extended in the future for non-empty paragraphs as well,
but the bugdoc works without that, and the change is invasive enough, so
better to limit the scope.
Change-Id: I6e9693847beaec5d9bbf9f8a5699795579c3ff71
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/152726
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Tested-by: Jenkins
Diffstat (limited to 'sw/qa/core/text/text.cxx')
-rw-r--r-- | sw/qa/core/text/text.cxx | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/sw/qa/core/text/text.cxx b/sw/qa/core/text/text.cxx index f321a01c3aa5..30a12adc7af7 100644 --- a/sw/qa/core/text/text.cxx +++ b/sw/qa/core/text/text.cxx @@ -42,6 +42,7 @@ #include <ndtxt.hxx> #include <txatbase.hxx> #include <textcontentcontrol.hxx> +#include <pagefrm.hxx> /// Covers sw/source/core/text/ fixes. class SwCoreTextTest : public SwModelTestBase @@ -1281,6 +1282,33 @@ CPPUNIT_TEST_FIXTURE(SwCoreTextTest, testTdf41652NBSPWidth) nSectionAfterNBSPX_optionEnabled_justified); } +CPPUNIT_TEST_FIXTURE(SwCoreTextTest, testFloattableOverlap) +{ + // Given a document with 2 floating tables, not overlapping in Word's "Word 2010" compat mode, + // because the first empty paragraph is below the first floating table: + createSwDoc("floattable-overlap.docx"); + + // When laying out that document: + calcLayout(); + + // Then make sure they don't overlap in Writer, either: + SwDoc* pDoc = getSwDoc(); + SwRootFrame* pLayout = pDoc->getIDocumentLayoutAccess().GetCurrentLayout(); + auto pPage1 = dynamic_cast<SwPageFrame*>(pLayout->Lower()); + CPPUNIT_ASSERT(pPage1); + CPPUNIT_ASSERT(pPage1->GetSortedObjs()); + const SwSortedObjs& rPage1Objs = *pPage1->GetSortedObjs(); + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), rPage1Objs.size()); + SwAnchoredObject* pPage1Obj1 = rPage1Objs[0]; + const SwRect& rRect1 = pPage1Obj1->GetObjRectWithSpaces(); + SwAnchoredObject* pPage1Obj2 = rPage1Objs[1]; + const SwRect& rRect2 = pPage1Obj2->GetObjRectWithSpaces(); + // Without the accompanying fix in place, this test would have failed, the empty paragraph, + // which is after the floating table in the document model went above the floating table in the + // layout, which resulted in an overlap. + CPPUNIT_ASSERT(!rRect1.Overlaps(rRect2)); +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |