sw/source/core/layout/tabfrm.cxx |   21 ---------------------
 sw/source/core/text/txtfly.cxx   |   16 ++++++++++++++++
 2 files changed, 16 insertions(+), 21 deletions(-)

New commits:
commit 4d5a536685a8c83be6c602d18c074074b71bfe42
Author:     Mike Kaganski <[email protected]>
AuthorDate: Thu Feb 19 09:07:17 2026 +0500
Commit:     Mike Kaganski <[email protected]>
CommitDate: Thu Feb 19 08:29:43 2026 +0100

    tdf#170846: Use tall SwTextFly/SwFlyPortion to move floating table forward
    
    Again try to avoid InsertMovedFwdFrame for floating tables (after commit
    52172dbd3e290fb92fd8169803c6df5498990466). This time, take into account
    that a fly frame may be shorter than its table, because SwFlyFrame::Grow_
    will limit to the available space. In this case, when the table cannot
    split, it must move forward as a whole; but the fly's height is small
    enough to fit in the available space. Previously, table's MoveFwd was
    used to force the move - which started a complex sequence of finding the
    next fly; creating it on the next page by splitting the anchor; moving
    the table; removing the now-empty master fly; merging the split anchor
    (and possibly starting oscillations in the process). Then, in the commit
    52172dbd3e290fb92fd8169803c6df5498990466, InsertMovedFwdFrame was used
    to force move of anchor forward - but that's a hack, which could prevent
    normal reflow.
    
    With this change, the move forward is expected to happen because last
    line height will calculate too high (taking into account not only the
    fly height itself, but also its table). For flys correctly matching
    their tables, nothing would change; but for too short flys, the correct
    height will force the normal mechanism of "line is too high -> move it
    forward".
    
    Change-Id: I5319b9539cbe53e776ba5a186b2df314e9fd6b0e
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/199678
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <[email protected]>

diff --git a/sw/source/core/layout/tabfrm.cxx b/sw/source/core/layout/tabfrm.cxx
index c61b39a6c02f..23c8337b4e55 100644
--- a/sw/source/core/layout/tabfrm.cxx
+++ b/sw/source/core/layout/tabfrm.cxx
@@ -3287,27 +3287,6 @@ void SwTabFrame::MakeAll(vcl::RenderContext* 
pRenderContext)
                 {
                     // Don't try to move floating table forward. It's done 
elsewhere moving its fly.
                     bSkipMoveFwd = true;
-                    // Only limit the InsertMovedFwdFrame hack to non-split 
floating tables for now:
-                    // it seems that split tables don't need it.
-                    if (!IsFollow() && !HasFollow())
-                    {
-                        // This floating table doesn't fit on this page. 
Instead of the complex
-                        // MoveFwd sequence (split anchor, create follow fly, 
move table, destroy
-                        // old fly, merge anchor - which may oscillate), 
signal the anchor to move
-                        // forward. The fly will follow.
-                        SwTextFrame* pAnchor = 
pFlyFrame->FindAnchorCharFrame();
-                        if (pAnchor)
-                        {
-                            SwPageFrame* pPage = pAnchor->FindPageFrame();
-                            if (pPage)
-                            {
-                                
SwLayouter::InsertMovedFwdFrame(pPage->GetFormat()->GetDoc(),
-                                                                *pAnchor,
-                                                                
pPage->GetPhyPageNum() + 1);
-                                pAnchor->InvalidatePos();
-                            }
-                        }
-                    }
                 }
             }
             // don't make the effort to move fwd if its known
diff --git a/sw/source/core/text/txtfly.cxx b/sw/source/core/text/txtfly.cxx
index fba5e1b06120..2530e8a62080 100644
--- a/sw/source/core/text/txtfly.cxx
+++ b/sw/source/core/text/txtfly.cxx
@@ -1376,6 +1376,22 @@ SwRect SwTextFly::AnchoredObjToRect( const 
SwAnchoredObject* pAnchoredObj,
     if( !aFly.Width() )
         return aFly;
 
+    if (auto pFlyFrame = pAnchoredObj->DynCastFlyFrame())
+    {
+        if (pFlyFrame->IsFlySplitAllowed() && pFlyFrame->Lower())
+        {
+            // The floating table could be too tall for its fly frame at this 
point, because the
+            // fly's Grow_ would limit to only available space. Take the 
excessive height into
+            // account here, so that the line can be forced to move to next 
page (via SwFlyPortion).
+
+            auto aLowerHeight = 
aRectFnSet.GetHeight(pFlyFrame->Lower()->getFrameArea());
+            if (aLowerHeight > aRectFnSet.GetHeight(aFly))
+            {
+                aRectFnSet.SetHeight(aFly, aLowerHeight);
+            }
+        }
+    }
+
     // so the line may grow up to the lower edge of the frame
     SetNextTop( aRectFnSet.GetBottom(aFly) );
     SwAnchoredObjList::size_type nFlyPos = GetPos( pAnchoredObj );

Reply via email to