sw/qa/core/layout/data/floattable-object-formatter.docx |binary sw/qa/core/layout/flycnt.cxx | 25 ++++++++++++++++ sw/source/core/layout/fly.cxx | 22 +++++++++++++- 3 files changed, 46 insertions(+), 1 deletion(-)
New commits: commit 28483a452da4b5c945caa7d52c96ce81ba9aa51e Author: Miklos Vajna <vmik...@collabora.com> AuthorDate: Mon May 22 15:07:16 2023 +0200 Commit: Miklos Vajna <vmik...@collabora.com> CommitDate: Tue May 23 13:21:46 2023 +0200 sw floattable: fix assert fail when object formatter gets the wrong anchor A subset of the tdf#155002 bugdoc hit an assertion failure in SwObjectFormatterTextFrame::DoFormatObj() for multi-page floating tables. What happens is that a section frame wants to format its content, calls CalcContent(), which assumes that the text frame's all draw objects are also on the same page, as long as they are at-para anchored. This is true for at-para anchored images, but not for split flys. Fix the problem by using FindAnchorCharFrame() to know if the anchored object should be inside the master anchor or a follow anchor: that allows invoking SwObjectFormatter::FormatObj() with the correct anchor and page frames, so we don't hit the assertion failure. The hang with the original tdf#155002 bugdoc needs more work, still. (cherry picked from commit b47401e12d9c45386899df0aa26653bd26c9abd4) Change-Id: I2b4d88ccb2ff251c0b0811c31d2aa85053143443 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/152141 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com> Reviewed-by: Miklos Vajna <vmik...@collabora.com> diff --git a/sw/qa/core/layout/data/floattable-object-formatter.docx b/sw/qa/core/layout/data/floattable-object-formatter.docx new file mode 100644 index 000000000000..2582af0eb863 Binary files /dev/null and b/sw/qa/core/layout/data/floattable-object-formatter.docx differ diff --git a/sw/qa/core/layout/flycnt.cxx b/sw/qa/core/layout/flycnt.cxx index 3c6a061cb962..83889ceecef0 100644 --- a/sw/qa/core/layout/flycnt.cxx +++ b/sw/qa/core/layout/flycnt.cxx @@ -885,6 +885,31 @@ CPPUNIT_TEST_FIXTURE(Test, testSplitFlyTabJoinLegacy) CPPUNIT_ASSERT(pPage3); CPPUNIT_ASSERT(!pPage3->GetSortedObjs()); } + +CPPUNIT_TEST_FIXTURE(Test, testSplitFlyObjectFormatter) +{ + // Given a document with 3 pages and 2 tables: table on first and second page, 3rd page has no + // table: + createSwDoc("floattable-object-formatter.docx"); + + // When calculating the layout: + calcLayout(); + + // Then make sure we don't crash and also that all pages have the expected amount of fly frames: + SwDoc* pDoc = getSwDoc(); + SwRootFrame* pLayout = pDoc->getIDocumentLayoutAccess().GetCurrentLayout(); + auto pPage1 = dynamic_cast<SwPageFrame*>(pLayout->Lower()); + CPPUNIT_ASSERT(pPage1); + const SwSortedObjs& rPage1Objs = *pPage1->GetSortedObjs(); + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), rPage1Objs.size()); + auto pPage2 = dynamic_cast<SwPageFrame*>(pPage1->GetNext()); + CPPUNIT_ASSERT(pPage2); + const SwSortedObjs& rPage2Objs = *pPage2->GetSortedObjs(); + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), rPage2Objs.size()); + auto pPage3 = dynamic_cast<SwPageFrame*>(pPage2->GetNext()); + CPPUNIT_ASSERT(pPage3); + CPPUNIT_ASSERT(!pPage3->GetSortedObjs()); +} } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/core/layout/fly.cxx b/sw/source/core/layout/fly.cxx index b598346216ee..054e86525180 100644 --- a/sw/source/core/layout/fly.cxx +++ b/sw/source/core/layout/fly.cxx @@ -1679,7 +1679,27 @@ void CalcContent( SwLayoutFrame *pLay, bool bNoColl ) // anchored objects. //pAnchoredObj->InvalidateObjPos(); SwRect aRect( pAnchoredObj->GetObjRect() ); - if ( !SwObjectFormatter::FormatObj( *pAnchoredObj, pFrame, pPageFrame ) ) + + SwFrame* pAnchorFrame = pFrame; + SwPageFrame* pAnchorPageFrame = pPageFrame; + if (SwFlyFrame* pFlyFrame = pAnchoredObj->DynCastFlyFrame()) + { + if (pFlyFrame->IsFlySplitAllowed()) + { + // Split flys are at-para anchored, but the follow fly's anchor char + // frame is not the master frame but can be also a follow of pFrame. + SwTextFrame* pAnchorCharFrame = pFlyFrame->FindAnchorCharFrame(); + if (pAnchorCharFrame) + { + // Found an anchor char frame, update the anchor frame and the + // anchor page frame accordingly. + pAnchorFrame = pAnchorCharFrame; + pAnchorPageFrame = pAnchorCharFrame->FindPageFrame(); + } + } + } + + if ( !SwObjectFormatter::FormatObj( *pAnchoredObj, pAnchorFrame, pAnchorPageFrame ) ) { bRestartLayoutProcess = true; break;