summaryrefslogtreecommitdiff
path: root/sw
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.com>2023-05-22 15:07:16 +0200
committerMiklos Vajna <vmiklos@collabora.com>2023-05-23 13:21:46 +0200
commit28483a452da4b5c945caa7d52c96ce81ba9aa51e (patch)
tree480a2a930f74b0cdf60034aabab629efb929235d /sw
parent178b15672b0e8b7f3a0ea1d6b2d46739b3c87f0e (diff)
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 <jenkinscollaboraoffice@gmail.com> Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Diffstat (limited to 'sw')
-rw-r--r--sw/qa/core/layout/data/floattable-object-formatter.docxbin0 -> 21480 bytes
-rw-r--r--sw/qa/core/layout/flycnt.cxx25
-rw-r--r--sw/source/core/layout/fly.cxx22
3 files changed, 46 insertions, 1 deletions
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
--- /dev/null
+++ b/sw/qa/core/layout/data/floattable-object-formatter.docx
Binary files 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;