sw/source/core/layout/fly.cxx |   32 +++++++++++++++++++++++++++++++-
 1 file changed, 31 insertions(+), 1 deletion(-)

New commits:
commit 7677e16217349a0a0e94edb6a90b00089432c6ce
Author:     Miklos Vajna <vmik...@collabora.com>
AuthorDate: Mon Feb 27 08:21:01 2023 +0100
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Mon Feb 27 08:28:29 2023 +0000

    sw floattable: allow extra space on top of child content in 
SwFlyFrame::Grow_()
    
    Once a floating table with a single cell wanted to span over two pages
    ("split row"), SwTextFrame::SplitFrame() was called, but then the table
    split failed because everything moved to the next page.
    
    The reason for this was that we tried to grow the text frame (and all of
    its parents: cell, row, table, fly), but a non-test growing a fly
    normally just works by recalculating its size based on the content,
    ignoring what growth is wanted.
    
    This is fine in the non-split fly case, but we do want to increase the
    size of a split fly to control what content remains in the current fly
    frame and what goes to a follow fly frame.
    
    Fix this by extending SwFlyFrame::Grow_() so it grows more than just its
    own content in the split fly case if the request wanted that.  Now a
    single row can split, but the position of the follow fly frame is still
    bad.
    
    Change-Id: I1c6aa61996dab058c291331a795627d3fae1bca8
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/147858
    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 994d3965ce2d..37ef27e0961e 100644
--- a/sw/source/core/layout/fly.cxx
+++ b/sw/source/core/layout/fly.cxx
@@ -2054,7 +2054,37 @@ SwTwips SwFlyFrame::Grow_( SwTwips nDist, bool bTst )
             InvalidatePos();
             if ( bOldLock )
                 Lock();
-            const SwRect aNew( GetObjRectWithSpaces() );
+            SwRect aNew(GetObjRectWithSpaces());
+            if (IsFlySplitAllowed() && aNew.Height() - aOld.Height() < nDist)
+            {
+                // We are allowed to split and the actual growth is less than 
the requested growth.
+                const SwFrame* pAnchor = GetAnchorFrame();
+                if (SwFrame* pAnchorChar = FindAnchorCharFrame())
+                {
+                    pAnchor = pAnchorChar;
+                }
+                const SwFrame* pAnchorUpper = pAnchor ? pAnchor->GetUpper() : 
nullptr;
+                if (pAnchorUpper)
+                {
+                    SwTwips nDeadline = aRectFnSet.GetPrtBottom(*pAnchorUpper);
+                    SwTwips nTop = aRectFnSet.GetTop(getFrameArea());
+                    SwTwips nBottom = nTop + 
aRectFnSet.GetHeight(getFrameArea());
+                    SwTwips nMaxGrow = nDeadline - nBottom;
+                    if (nDist > nMaxGrow)
+                    {
+                        // The requested growth is more than what we can 
provide, limit it.
+                        nDist = nMaxGrow;
+                    }
+                    // Grow & invalidate the size.
+                    SwTwips nRemaining = nDist - (aNew.Height() - 
aOld.Height());
+                    {
+                        SwFrameAreaDefinition::FrameAreaWriteAccess 
aFrm(*this);
+                        aRectFnSet.AddBottom(aFrm, nRemaining);
+                    }
+                    InvalidateObjRectWithSpaces();
+                    aNew = GetObjRectWithSpaces();
+                }
+            }
             if ( aOld != aNew )
                 ::Notify( this, FindPageFrame(), aOld );
             return aRectFnSet.GetHeight(aNew)-aRectFnSet.GetHeight(aOld);

Reply via email to