sw/qa/extras/layout/data/tdf170620.docx |binary sw/qa/extras/layout/layout6.cxx | 67 ++++++++++++++++++++++++++++++++ sw/source/core/layout/flowfrm.cxx | 19 +++++++-- 3 files changed, 83 insertions(+), 3 deletions(-)
New commits: commit e3b6e6e829c4ecf0cf44905723e82c6103fae695 Author: Mike Kaganski <[email protected]> AuthorDate: Thu Feb 5 18:58:53 2026 +0500 Commit: Mike Kaganski <[email protected]> CommitDate: Thu Feb 5 16:28:29 2026 +0100 tdf#170620: CheckMoveFwd: only ignore empty master without split fly SwFlowFrame::CheckMoveFwd decides if a keep-with-next paragraph should move to next page. When bKeep is true, and the keep-with-next frame is followed by an empty master, it ignores that empty master, and may decide to move. To check if the frame returned by GetIndNext was empty master, a call to IsEmptyMaster was used. But that function doesn't consider if the empty master (having a follow, but not having any text) is an anchor of a split fly. The bugdoc demonstrated, that in such case, keep-with- next frame would ignore the following split fly on the current page, and will move forward; that would naturally move the split fly forward, too. This change improves the check to also use HasNonLastSplitFlyDrawObj. Change-Id: I08771d7a3e48f88f4272ae8f1718615bc89a5bf4 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/198757 Reviewed-by: Mike Kaganski <[email protected]> Tested-by: Jenkins diff --git a/sw/qa/extras/layout/data/tdf170620.docx b/sw/qa/extras/layout/data/tdf170620.docx new file mode 100644 index 000000000000..2565a36b4391 Binary files /dev/null and b/sw/qa/extras/layout/data/tdf170620.docx differ diff --git a/sw/qa/extras/layout/layout6.cxx b/sw/qa/extras/layout/layout6.cxx index 854f33c44704..4e8769e7fdf6 100644 --- a/sw/qa/extras/layout/layout6.cxx +++ b/sw/qa/extras/layout/layout6.cxx @@ -2018,6 +2018,73 @@ CPPUNIT_TEST_FIXTURE(SwLayoutWriter6, testTdf170477) calcLayout(); } +CPPUNIT_TEST_FIXTURE(SwLayoutWriter6, testTdf170620_float_table_after_keep_with_next_para) +{ + // Given a document with a keep-with-next paragraph, followed by floating table containing + // another floating table which is split across pages: + createSwDoc("tdf170620.docx"); + + // The keep-with-next paragraph and the floating table must start on page 1: + + xmlDocUniquePtr pXmlDoc = parseLayoutDump(); + CPPUNIT_ASSERT(pXmlDoc); + + // Exactly two pages: + assertXPath(pXmlDoc, "//page", 2); + + // "Keep-with-next paragraph" is on the first page: + assertXPath(pXmlDoc, "//page[1]/body/txt[2]//SwLineLayout", "portion", + u"Keep-with-next paragraph"); + + // Exactly two objects anchored at each page: + assertXPath(pXmlDoc, "//page[1]/sorted_objs/fly", 2); + assertXPath(pXmlDoc, "//page[2]/sorted_objs/fly", 2); + + // Get master/follow paragraph isd: + assertXPath(pXmlDoc, "//page[1]/body/txt", 3); + assertXPath(pXmlDoc, "//page[2]/body/txt", 1); + assertXPath(pXmlDoc, "//page[1]/body/txt[3]", "follow", + getXPath(pXmlDoc, "//page[2]/body/txt", "id")); + assertXPath(pXmlDoc, "//page[2]/body/txt", "precede", + getXPath(pXmlDoc, "//page[1]/body/txt[3]", "id")); + + // Page 1's paragraph 3 has two anchored flys: + assertXPath(pXmlDoc, "//page[1]/body/txt[3]/anchored/fly", 2); + + // Get the ids of the two outer flys. + // Page 1: + OString f1 = getXPath(pXmlDoc, "//page[1]/sorted_objs/fly[1]", "ptr").toUtf8(); + OString f2 = getXPath(pXmlDoc, "//page[1]/sorted_objs/fly[2]", "ptr").toUtf8(); + CPPUNIT_ASSERT(f1 != f2); + OString filter1 = "@ptr='" + f1 + "' or @ptr='" + f2 + "'"; + OUString id = getXPath(pXmlDoc, "//page[1]/body/txt[3]/anchored/fly[" + filter1 + "]", "id"); + OString aP1OuterFlyTab = "//anchored/fly[@id='" + id.toUtf8() + "']/tab"; + + // Page 2: + f1 = getXPath(pXmlDoc, "//page[2]/sorted_objs/fly[1]", "ptr").toUtf8(); + f2 = getXPath(pXmlDoc, "//page[2]/sorted_objs/fly[2]", "ptr").toUtf8(); + CPPUNIT_ASSERT(f1 != f2); + OString filter2 = "@ptr='" + f1 + "' or @ptr='" + f2 + "'"; + id = getXPath(pXmlDoc, "//page[1]/body/txt[3]/anchored/fly[" + filter2 + "]", "id"); + OString aP2OuterFlyTab = "//anchored/fly[@id='" + id.toUtf8() + "']/tab"; + + // One row in top-level floating table on page 1, four rows on page 2: + assertXPath(pXmlDoc, aP1OuterFlyTab + "/row", 1); + assertXPath(pXmlDoc, aP2OuterFlyTab + "/row", 4); + + // One cell in top-level floating table on page 1, four cells on page 2: + assertXPath(pXmlDoc, aP1OuterFlyTab + "/row/cell", 1); + assertXPath(pXmlDoc, aP2OuterFlyTab + "/row/cell", 4); + + // First page's top-level floating table's cell has two paragraphs: + assertXPath(pXmlDoc, aP1OuterFlyTab + "/row/cell/txt", 2); + // Check text in the first paragraph: + assertXPath(pXmlDoc, aP1OuterFlyTab + "/row/cell/txt[1]//SwLineLayout", "portion", + u"Something"); + // The second paragraph has two attached inner floating tables: + assertXPath(pXmlDoc, aP1OuterFlyTab + "/row/cell/txt[2]/anchored/fly", 2); +} + } // end of anonymous namespace CPPUNIT_PLUGIN_IMPLEMENT(); diff --git a/sw/source/core/layout/flowfrm.cxx b/sw/source/core/layout/flowfrm.cxx index 441da753f810..33f6dc793c04 100644 --- a/sw/source/core/layout/flowfrm.cxx +++ b/sw/source/core/layout/flowfrm.cxx @@ -1995,10 +1995,23 @@ bool SwFlowFrame::CheckMoveFwd( bool& rbMakePage, bool bKeep, bool bIgnoreMyOwnK { if (m_rThis.IsHiddenNow()) return false; - const SwFrame* pNxt = m_rThis.GetIndNext(); + auto isIgnoredIndNext = [](const SwFrame* pNxt) + { + if (!pNxt) + return true; + // We ignore non-null next, when it's empty master, than doesn't host a split fly: + if (pNxt->IsTextFrame()) + { + auto pTextFrame = static_cast<const SwTextFrame*>(pNxt); + if (pTextFrame->IsEmptyMaster() && !pTextFrame->HasNonLastSplitFlyDrawObj()) + return true; + } + return false; + }; - if ( bKeep && //!bMovedBwd && - ( !pNxt || ( pNxt->IsTextFrame() && static_cast<const SwTextFrame*>(pNxt)->IsEmptyMaster() ) ) && + if ( const SwFrame* pNxt; + bKeep && //!bMovedBwd && + isIgnoredIndNext(m_rThis.GetIndNext()) && ( nullptr != (pNxt = m_rThis.FindNext()) ) && IsKeepFwdMoveAllowed(bIgnoreMyOwnKeepValue) ) { if( pNxt->IsSctFrame() )
