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 a3a2f52bfc0c5665d535f334aaec8cf05f93d1a5
Author:     Miklos Vajna <vmik...@collabora.com>
AuthorDate: Tue Jul 18 08:30:04 2023 +0200
Commit:     Mike Kaganski <mike.kagan...@collabora.com>
CommitDate: Wed Jul 19 11:08:47 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/+/154638
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>
    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 edd079b6a819..1a89f19b0d51 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 1fea57c33873..2586ad9c0ffa 100644
--- a/sw/source/core/layout/fly.cxx
+++ b/sw/source/core/layout/fly.cxx
@@ -98,8 +98,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