sw/qa/extras/layout/data/tdf170477.docx |binary sw/qa/extras/layout/layout6.cxx | 7 +++++++ sw/source/core/layout/tabfrm.cxx | 27 +++++++++++++++++++++++++-- 3 files changed, 32 insertions(+), 2 deletions(-)
New commits: commit c2c33dbdbc686e7c0eb349efdd15a8c97d8f00a7 Author: Mike Kaganski <[email protected]> AuthorDate: Mon Jan 26 10:46:04 2026 +0500 Commit: Xisco Fauli <[email protected]> CommitDate: Thu Jan 29 10:18:59 2026 +0100 tdf#170477: detect MoveFwd oscillation in SwTabFrame::MakeAll In the specific bug document, some constellation of factors created the case where the last inner floating table tries to move forward, in the process creates a split fly on the same page (subject to move forward later, when outer table formats), moves to it (leaving the old fly empty), which recreates the same layout as before; and that oscillated infinitely. The fix implemented here is to detect when MoveFwd call created the described situation, and then use SwLayouter::InsertMovedFwdFrame to break the oscillation. I was not able to reproduce this problem anew; test document was simplified from the original, with the aim to minimize instability (but still, the resulting layout in Writer differs from Word's, which makes the test likely to stop testing the intended code path in the future - sigh). Change-Id: Iaa796a169cb9f97d5a6b3dd7ebf1cf5b726ca568 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/198116 Reviewed-by: Mike Kaganski <[email protected]> Tested-by: Jenkins (cherry picked from commit a5832581691c3532f24d754ed0488e7df43d82c0) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/198134 Reviewed-by: Xisco Fauli <[email protected]> diff --git a/sw/qa/extras/layout/data/tdf170477.docx b/sw/qa/extras/layout/data/tdf170477.docx new file mode 100644 index 000000000000..646d7191c92d Binary files /dev/null and b/sw/qa/extras/layout/data/tdf170477.docx differ diff --git a/sw/qa/extras/layout/layout6.cxx b/sw/qa/extras/layout/layout6.cxx index e69f42a197ab..88fd08d5113e 100644 --- a/sw/qa/extras/layout/layout6.cxx +++ b/sw/qa/extras/layout/layout6.cxx @@ -2042,6 +2042,13 @@ CPPUNIT_TEST_FIXTURE(SwLayoutWriter6, testTdf170381_split_float_table_in_float_t assertCellLines(2, r + 1, page2cells[r]); } +CPPUNIT_TEST_FIXTURE(SwLayoutWriter6, testTdf170477) +{ + // This document must not hang on layout: + createSwDoc("tdf170477.docx"); + calcLayout(); +} + } // end of anonymous namespace CPPUNIT_PLUGIN_IMPLEMENT(); diff --git a/sw/source/core/layout/tabfrm.cxx b/sw/source/core/layout/tabfrm.cxx index a5bbd2b3710b..69b37c37a47d 100644 --- a/sw/source/core/layout/tabfrm.cxx +++ b/sw/source/core/layout/tabfrm.cxx @@ -3277,6 +3277,7 @@ void SwTabFrame::MakeAll(vcl::RenderContext* pRenderContext) // #i29771# Reset bTryToSplit flag on change of upper const SwFrame* pOldUpper = GetUpper(); + const SwPageFrame* pOldUpperPage = nullptr; //Let's see if we find some place anywhere... if (!bMovedFwd) @@ -3291,6 +3292,7 @@ void SwTabFrame::MakeAll(vcl::RenderContext* pRenderContext) // If the anchor of the split has a previous frame, MoveFwd() is allowed to move // forward. bMoveAlways = true; + pOldUpperPage = pFlyFrame->FindPageFrame(); } } // don't make the effort to move fwd if its known @@ -3304,8 +3306,29 @@ void SwTabFrame::MakeAll(vcl::RenderContext* pRenderContext) // #i29771# Reset bSplitError flag on change of upper if ( GetUpper() != pOldUpper ) { - bTryToSplit = true; - nUnSplitted = 5; + bool bResetSplit = true; + if (GetUpper() && GetUpper()->IsFlyFrame() && pOldUpperPage + && GetUpper()->FindPageFrame() == pOldUpperPage + && static_cast<const SwFlyFrame*>(GetUpper())->IsFlySplitAllowed()) + { + // MoveFwd created a split (follow) fly on the same page, that was intended to move + // to the next page together with its anchor. Then the content was moved to the new + // fly, and the old fly became empty; it called its DelEmpty(). The new fly is now + // basically a copy of the old one; move to the next page and prevent oscillation. + SwTextFrame* pAnchor = static_cast<SwFlyFrame*>(GetUpper())->FindAnchorCharFrame(); + if (pAnchor) + { + bResetSplit = false; + SwPageFrame* pPage = pAnchor->FindPageFrame(); + SwLayouter::InsertMovedFwdFrame(pPage->GetFormat()->GetDoc(), *pAnchor, + pPage->GetPhyPageNum() + 1); + } + } + if (bResetSplit) + { + bTryToSplit = true; + nUnSplitted = 5; + } } aRectFnSet.Refresh(*this);
