From 3c2e4d454aaabcd61593e670a90638a185046539 Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Tue, 25 Apr 2023 08:05:55 +0200 Subject: sw floattable, crashtesting: fix PDF export of fdo72790-1.docx, part 1 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). What happens is that the DOCX file has a continuous section break, that is mapped to a Writer section, but then the fly splitting code didn't expect that the anchor might be inside a section frame. Fix this by explicitly checking for an in-section anchor in SwFrame::GetNextFlyLeaf(), which will give us a suitable insertion point on the next page. This does not fully fix the handling of the bugdoc, but at least now a reduced sample doesn't crash and is handled correctly. Change-Id: I52b5c901d899533bbb78131f443789d55db41000 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/150956 Reviewed-by: Miklos Vajna Tested-by: Jenkins --- sw/qa/core/layout/data/floattable-in-text-section.docx | Bin 0 -> 12452 bytes sw/qa/core/layout/flycnt.cxx | 8 ++++++++ sw/source/core/layout/flycnt.cxx | 9 ++++++++- 3 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 sw/qa/core/layout/data/floattable-in-text-section.docx diff --git a/sw/qa/core/layout/data/floattable-in-text-section.docx b/sw/qa/core/layout/data/floattable-in-text-section.docx new file mode 100644 index 000000000000..5b377dd0379f Binary files /dev/null and b/sw/qa/core/layout/data/floattable-in-text-section.docx differ diff --git a/sw/qa/core/layout/flycnt.cxx b/sw/qa/core/layout/flycnt.cxx index 0bdd70ceb511..b23edb72ef16 100644 --- a/sw/qa/core/layout/flycnt.cxx +++ b/sw/qa/core/layout/flycnt.cxx @@ -699,6 +699,14 @@ CPPUNIT_TEST_FIXTURE(Test, testSplitFlyThenTable) // This crashed, due to a stack overflow in layout code. save("writer_pdf_Export"); } + +CPPUNIT_TEST_FIXTURE(Test, testSplitFlyInTextSection) +{ + // The document contains a DOCX cont sect break, which is mapped to a TextSection. + // This crashed, the anchor was split directly, so the follow anchor was moved outside the + // section frame, which is broken. + createSwDoc("floattable-in-text-section.docx"); +} } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/core/layout/flycnt.cxx b/sw/source/core/layout/flycnt.cxx index f5d4c76c936f..ca7ae9d28626 100644 --- a/sw/source/core/layout/flycnt.cxx +++ b/sw/source/core/layout/flycnt.cxx @@ -1558,7 +1558,14 @@ SwLayoutFrame *SwFrame::GetNextFlyLeaf( MakePageType eMakePage ) bool bBody = pFlyAnchor && pFlyAnchor->IsInDocBody(); SwLayoutFrame *pLayLeaf = nullptr; // Look up the first candidate. - if (IsTabFrame()) + SwSectionFrame* pFlyAnchorSection = pFlyAnchor ? pFlyAnchor->FindSctFrame() : nullptr; + if (pFlyAnchorSection) + { + // We can't just move the split anchor to the next page, that would be outside the section. + // Rather split that section as well. + pLayLeaf = pFlyAnchorSection->GetNextSctLeaf(eMakePage); + } + else if (IsTabFrame()) { // If we're in a table, try to find the next frame of the table's last content. SwFrame* pContent = static_cast(this)->FindLastContentOrTable(); -- cgit