sw/qa/core/layout/data/floattable-no-footer-overlap.docx |binary
 sw/qa/core/layout/flycnt.cxx                             |   22 +++++++++++++++
 sw/source/core/layout/fly.cxx                            |    8 ++++-
 3 files changed, 28 insertions(+), 2 deletions(-)

New commits:
commit 693ad3aadbf84afa750af73c330fe7e09b38a2e7
Author:     Miklos Vajna <vmik...@collabora.com>
AuthorDate: Tue Jul 18 08:30:04 2023 +0200
Commit:     Mike Kaganski <mike.kagan...@collabora.com>
CommitDate: Mon Jul 31 11:49:19 2023 +0200

    tdf#120262 sw floattable, legacy: go outside body only for page frame vert 
pos
    
    The bugdoc has to pages, the floating table from the top of page 2 is
    partially moved to page 1 and overlaps with the footer text.
    
    Part of the reason this happens is that in case the vertical position is
    relative to the page frame, then Word allows using the footer area for
    floating tables (see tdf#155118), but turns out that in case the
    position is relative to other places (e.g. paragraph), then this is not
    necessary.
    
    Fix the problem by making the "is legacy" condition in
    GetFlyAnchorBottom() more strict, which keeps tdf#155118 fixed, but
    improves this bugdoc.
    
    Leave the layout unchanged for cases where the floating table is not in
    the body text (e.g. footnotes). Now the overlap is fixed, but still a
    bug remains where the first row on this split table is not moved page 2.
    
    (cherry picked from commit 9a5d1c250cbaac855b3e63d8c5fa0882ba7d14a2)
    
    Change-Id: I96d6eb527d7f33dd65de8a66f815219c02625d93
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/154647
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com>

diff --git a/sw/qa/core/layout/data/floattable-no-footer-overlap.docx 
b/sw/qa/core/layout/data/floattable-no-footer-overlap.docx
new file mode 100644
index 000000000000..ca2f0d6d7244
Binary files /dev/null and 
b/sw/qa/core/layout/data/floattable-no-footer-overlap.docx differ
diff --git a/sw/qa/core/layout/flycnt.cxx b/sw/qa/core/layout/flycnt.cxx
index 7d89a34ac914..106be77ceac2 100644
--- a/sw/qa/core/layout/flycnt.cxx
+++ b/sw/qa/core/layout/flycnt.cxx
@@ -946,6 +946,28 @@ CPPUNIT_TEST_FIXTURE(Test, testSplitFlyAnchorKeepWithNext)
     const SwSortedObjs& rPage2Objs = *pPage2->GetSortedObjs();
     CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), rPage2Objs.size());
 }
+
+CPPUNIT_TEST_FIXTURE(Test, testSplitFlyNoFooterOverlap)
+{
+    // Given a document with 2 pages, a floating table on both pages:
+    createSwDoc("floattable-no-footer-overlap.docx");
+
+    // When calculating the layout:
+    calcLayout();
+
+    // Then make sure the second page has a floating table:
+    SwDoc* pDoc = getSwDoc();
+    SwRootFrame* pLayout = pDoc->getIDocumentLayoutAccess().GetCurrentLayout();
+    auto pPage1 = dynamic_cast<SwPageFrame*>(pLayout->Lower());
+    CPPUNIT_ASSERT(pPage1);
+    auto pPage2 = dynamic_cast<SwPageFrame*>(pPage1->GetNext());
+    // Without the accompanying fix in place, this test would have failed, 
there was no page 2, both
+    // floating tables were on page 1.
+    CPPUNIT_ASSERT(pPage2);
+    CPPUNIT_ASSERT(pPage2->GetSortedObjs());
+    const SwSortedObjs& rPage2Objs = *pPage2->GetSortedObjs();
+    CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), rPage2Objs.size());
+}
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/core/layout/fly.cxx b/sw/source/core/layout/fly.cxx
index d03e015f2c14..68184da48fd6 100644
--- a/sw/source/core/layout/fly.cxx
+++ b/sw/source/core/layout/fly.cxx
@@ -99,8 +99,12 @@ SwTwips GetFlyAnchorBottom(SwFlyFrame* pFly, const SwFrame& 
rAnchor)
         return 0;
     }
 
-    const IDocumentSettingAccess& rIDSA = 
pFly->GetFrameFormat().getIDocumentSettingAccess();
-    bool bLegacy = rIDSA.get(DocumentSettingId::TAB_OVER_MARGIN);
+    const auto& rFrameFormat = pFly->GetFrameFormat();
+    const IDocumentSettingAccess& rIDSA = 
rFrameFormat.getIDocumentSettingAccess();
+    // Allow overlap with bottom margin / footer only in case we're relative 
to the page frame.
+    bool bVertPageFrame = rFrameFormat.GetVertOrient().GetRelationOrient() == 
text::RelOrientation::PAGE_FRAME;
+    bool bInBody = rAnchor.IsInDocBody();
+    bool bLegacy = rIDSA.get(DocumentSettingId::TAB_OVER_MARGIN) && 
(bVertPageFrame || !bInBody);
     if (bLegacy)
     {
         // Word <= 2010 style: the fly can overlap with the bottom margin / 
footer area in case the

Reply via email to