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 <vmiklos@collabora.com>
Tested-by: Jenkins
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 0000000..5b377dd
--- /dev/null
+++ b/sw/qa/core/layout/data/floattable-in-text-section.docx
Binary files differ
diff --git a/sw/qa/core/layout/flycnt.cxx b/sw/qa/core/layout/flycnt.cxx
index 0bdd70c..b23edb7 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 f5d4c76..ca7ae9d 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<SwTabFrame*>(this)->FindLastContentOrTable();