sw/qa/core/layout/data/floattable-multi-col.docx |binary sw/qa/core/layout/flycnt.cxx | 22 ++++++++++++++++++++++ sw/source/core/layout/fly.cxx | 9 +++++++++ 3 files changed, 31 insertions(+)
New commits: commit 8c34ed6e8d62c5fe558b11bb91c5405e5bf2798e Author: Miklos Vajna <vmik...@collabora.com> AuthorDate: Thu May 4 08:26:57 2023 +0200 Commit: Miklos Vajna <vmik...@collabora.com> CommitDate: Thu May 4 10:27:37 2023 +0200 sw floattable, crashtesting: fix PDF export of ooo9470-1.doc Converting the bugdoc to PDF crashed Writer layout since commit ce3308a926f036b87515b8cd97d2b197063dc77a (tdf#61594 sw floattable: import floating tables as split flys by default, 2023-04-12). The immediate problem was a failing assert(GetPageFrame().GetPhyPageNum() == GetPgNumOfCollected(nIdx)) in SwObjectFormatterTextFrame::DoFormatObj(), becase the floating table was in a multi-column section and no code handled that correctly. Fix this by just disabling the split of floating tables in multi-column sections, seeing that Word does the same. Note how FindAnchorCharFrame() is not used to get the fly's anchor, because that would call IsFlySplitAllowed(), leading to an infinite recursion. Additionally, the first IsFlySplitAllowed() call is on a non-split fly, so GetAnchorFrame() gives us the correct frame in this specific case. Change-Id: Ibd163018d6d71ee613549ec835075653f7c20755 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/151347 Reviewed-by: Miklos Vajna <vmik...@collabora.com> Tested-by: Jenkins diff --git a/sw/qa/core/layout/data/floattable-multi-col.docx b/sw/qa/core/layout/data/floattable-multi-col.docx new file mode 100644 index 000000000000..10e63bad39f0 Binary files /dev/null and b/sw/qa/core/layout/data/floattable-multi-col.docx differ diff --git a/sw/qa/core/layout/flycnt.cxx b/sw/qa/core/layout/flycnt.cxx index 1ad1443dd392..8ae6b28648c0 100644 --- a/sw/qa/core/layout/flycnt.cxx +++ b/sw/qa/core/layout/flycnt.cxx @@ -762,6 +762,28 @@ CPPUNIT_TEST_FIXTURE(Test, testSplitFlyDeletedAnchor) // page was anchored to a text frame on the 2nd page, leading to a negative frame height. CPPUNIT_ASSERT(pAnchor3); } + +CPPUNIT_TEST_FIXTURE(Test, testSplitFlyMultiCol) +{ + // Given a document with a floating table that is in a multi-col section: + createSwDoc("floattable-multi-col.docx"); + + // When laying out that document: + calcLayout(); + + // Then make sure that the fly frame is not split, matching Word: + 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 pPage1Fly = dynamic_cast<SwFlyAtContentFrame*>(rPage1Objs[0]); + CPPUNIT_ASSERT(pPage1Fly); + // Without the accompanying fix in place, this test would have failed, we tried to split and + // then hit an assertion failure. + CPPUNIT_ASSERT(!pPage1Fly->GetFollow()); +} } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/core/layout/fly.cxx b/sw/source/core/layout/fly.cxx index c79f9f2080e9..387095bbdeed 100644 --- a/sw/source/core/layout/fly.cxx +++ b/sw/source/core/layout/fly.cxx @@ -660,6 +660,15 @@ bool SwFlyFrame::IsFlySplitAllowed() const return false; } + const SwFrame* pFlyAnchor = GetAnchorFrame(); + if (pFlyAnchor && pFlyAnchor->FindColFrame()) + { + // No split in multi-column sections, so GetFlyAnchorBottom() can assume that our innermost + // body frame and the page's body frame is the same. + // This is also consistent with the Word behavior. + return false; + } + return GetFormat()->GetFlySplit().GetValue(); }