sw/source/core/layout/tabfrm.cxx |   11 +++++++++++
 1 file changed, 11 insertions(+)

New commits:
commit 534d3818aedfa95ad73935235462f5ec2817f5da
Author:     Michael Stahl <[email protected]>
AuthorDate: Wed May 15 14:43:10 2024 +0200
Commit:     Michael Stahl <[email protected]>
CommitDate: Wed May 15 17:58:21 2024 +0200

    tdf#160897 sw: layout: fail SwTabFrame::Split on footnote overlap
    
    The bugdoc has a table in a section, and the cells contain many
    footnotes.
    
    Somehow commit c303981cfd95ce1c3881366023d5495ae2edce97 introduced some
    layout looping, and it also looks worse than in 7.5.
    
    During lcl_RecalcRow(rLastLine) it may happen that first some footnotes
    are moved off the page, then the table/section grow during text
    formatting, then the footnotes are moved back onto the page, so the
    footnote container is the same size as before, the body is the same size
    as before (because it shrinks whenever the footnote container grows),
    but the section and table don't fit into the body any more.
    
    This fixes the layout loops, and also there are no visible overlaps of
    body(table) and footnotes any more; however, the layout is obviously not
    perfect, many footnotes are on the wrong page and there are some gaps of
    empty space on some pages, but at least none of the footnotes are
    numbered "0" any more.
    
    In 7.5, there was overlap of the body and the footnotes on page 1 and 3,
    and also the irritating effect that moving the mouse over
    the bottom of page 3 would relayout the document multiple times...
    
    Some other ideas that don't work:
    
    * it doesn't help to call Shrink() on the section frame, because it has
      ToMaximize() and does not actually shrink.
    * one aspect of the loop is that the section is always size-invalidated
      even when it doesn't change its size during SwTabFormat::MakeAll()
      and the idea was to detect this (invalidation flag set on upper but
      same area as before) and reset the flag, but this prevents shrinking
      the section to fit on the page
    
    Change-Id: I6074b5c2615a0d7f613edebe92b5350efdd7fe02
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/167693
    Tested-by: Jenkins
    Reviewed-by: Michael Stahl <[email protected]>

diff --git a/sw/source/core/layout/tabfrm.cxx b/sw/source/core/layout/tabfrm.cxx
index 41ea720609b1..8cd16b8d80ce 100644
--- a/sw/source/core/layout/tabfrm.cxx
+++ b/sw/source/core/layout/tabfrm.cxx
@@ -760,6 +760,9 @@ static bool lcl_RecalcSplitLine( SwRowFrame& rLastLine, 
SwRowFrame& rFollowLine,
     // #i26945# - include check, if objects fit
     const SwTwips nDistanceToUpperPrtBottom =
         aRectFnSet.BottomDist(rTab.getFrameArea(), 
aRectFnSet.GetPrtBottom(*rTab.GetUpper()));
+    // also check the footnote boss - it *may* be smaller than the upper now!
+    const SwTwips nDistanceToFootnoteBodyPrtBottom =
+        aRectFnSet.BottomDist(rTab.getFrameArea(), 
aRectFnSet.GetPrtBottom(*rTab.FindFootnoteBossFrame()->FindBodyCont()));
     // tdf#125685 ignore footnotes that are anchored in follow-table of this
     // table - if split is successful they move to the next page/column anyway
     assert(rTab.GetFollow() == rFollowLine.GetUpper());
@@ -803,6 +806,14 @@ static bool lcl_RecalcSplitLine( SwRowFrame& rLastLine, 
SwRowFrame& rFollowLine,
     if (nDistanceToUpperPrtBottom + nFollowFootnotes < 0 || 
!rTab.DoesObjsFit())
         bRet = false;
 
+    // apparently checking nFootnoteHeight here does *not* guarantee that it 
fits into the body
+    if (bRet && nDistanceToFootnoteBodyPrtBottom + nFollowFootnotes < 0)
+    {
+        assert(rTab.GetUpper() != 
rTab.FindFootnoteBossFrame()->FindBodyCont());
+        SAL_INFO("sw.layout", "SwTabFrame Split failed because of footnote 
growth");
+        bRet = false; // tdf#160897
+    }
+
     // 2. Check if each cell in the last line has at least one content frame.
 
     // Note: a FollowFlowRow may contains empty cells!

Reply via email to