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

New commits:
commit 6068ae5df9da179e1d187e27117a9d761116f968
Author:     Miklos Vajna <vmik...@collabora.com>
AuthorDate: Fri Feb 24 08:21:22 2023 +0100
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Fri Feb 24 09:24:56 2023 +0000

    sw floattable: don't promise infinite growth in SwFlyFrame::Grow_()
    
    In case the document has a single cell in the floating table with
    multiple lines, we may need to split the cell, but currently we don't.
    
    One problem is that SwTabFrame::MakeAll() for the master table gets an
    error from Split(). Digging deeper, SwTextFrame::SplitFrame() is not
    called at all, because SwTextFrame::FormatAdjust() thinks that the
    content will fit, because SwTextFrameBreak::IsInside() says so. This
    happens because it tries to do a test grow on the fly frame, and
    that promises to grow as much as wanted.
    
    Infinite grow for fly frames is reasonable by default, but we want to
    limit the size for split flys, so a follow fly will be created. Fix the
    problem by improving SwFlyFrame::Grow_() to handle the
    IsFlySplitAllowed() case explicitly. Now we split the text frame, which
    is needed but not enough to split the entire fly -> table -> row -> cell
    -> text frame hierarchy.
    
    SwSectionFrame::Grow_() has a similar limit in place already.
    
    Change-Id: Ie07362a8dc3aa8c4fbb69eaf7e35717ba79b99a0
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/147593
    Reviewed-by: Miklos Vajna <vmik...@collabora.com>
    Tested-by: Jenkins

diff --git a/sw/source/core/layout/fly.cxx b/sw/source/core/layout/fly.cxx
index 398452d603be..994d3965ce2d 100644
--- a/sw/source/core/layout/fly.cxx
+++ b/sw/source/core/layout/fly.cxx
@@ -2059,6 +2059,30 @@ SwTwips SwFlyFrame::Grow_( SwTwips nDist, bool bTst )
                 ::Notify( this, FindPageFrame(), aOld );
             return aRectFnSet.GetHeight(aNew)-aRectFnSet.GetHeight(aOld);
         }
+        else
+        {
+            // We're in test mode. Don't promise infinite growth for split 
flys, rather limit the
+            // max size to the bottom of the upper.
+            const SwFrame* pAnchor = GetAnchorFrame();
+            if (SwFrame* pAnchorChar = FindAnchorCharFrame())
+            {
+                pAnchor = pAnchorChar;
+            }
+            const SwFrame* pAnchorUpper = pAnchor ? pAnchor->GetUpper() : 
nullptr;
+            if (pAnchorUpper && IsFlySplitAllowed())
+            {
+                SwTwips nDeadline = aRectFnSet.GetPrtBottom(*pAnchorUpper);
+                SwTwips nTop = aRectFnSet.GetTop(getFrameArea());
+                SwTwips nBottom = nTop + aRectFnSet.GetHeight(getFrameArea());
+                // Calculate max grow and compare to the requested growth, 
adding to nDist may
+                // overflow when it's LONG_MAX.
+                SwTwips nMaxGrow = nDeadline - nBottom;
+                if (nDist > nMaxGrow)
+                {
+                    nDist = nMaxGrow;
+                }
+            }
+        }
         return nDist;
     }
     return 0;

Reply via email to