diff options
author | Miklos Vajna <vmiklos@collabora.com> | 2023-04-26 11:44:43 +0200 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.com> | 2023-04-26 14:58:51 +0200 |
commit | 73bada774ef37efd5a4498ccc083b1358314557d (patch) | |
tree | d51922818238753c10c84339b84073f13b358584 /sw | |
parent | 4348f878284b53fa4e8ca670a8461a30ad0cba70 (diff) |
sw floattable, crashtesting: fix PDF export of fdo72790-1.docx, part 3
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).
Part 1 already fixed the crash, but a layout loop remains. The current
problem is that we could have a document of 3 pages where the last page
had no anchor for the fly frame, so it took the anchor from the previous
page, but this lead to negative frame heights and at the end an empty
3rd page.
To fix the problem:
1) Make sure SwTextFrame::FormatAdjust() doesn't break the invariant
that only the last frame of a floattable anchor has text content.
2) Make sure SwTextFrame::AdjustFollow_() doesn't join a frame that
still hosts non-last split flys.
With this, we have exactly 3 anchor frames (in a flow frame chain) for
the 3 pages and the 3rd page looks correct. The original document still
needs more work to fix the layout loop, though.
Change-Id: I2fc9c4728fdf191ac5b5b435a10d553a699bae75
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/151048
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Tested-by: Jenkins
Diffstat (limited to 'sw')
-rw-r--r-- | sw/qa/core/layout/data/floattable-deleted-anchor.docx | bin | 0 -> 41531 bytes | |||
-rw-r--r-- | sw/qa/core/layout/flycnt.cxx | 25 | ||||
-rw-r--r-- | sw/source/core/text/frmform.cxx | 13 |
3 files changed, 37 insertions, 1 deletions
diff --git a/sw/qa/core/layout/data/floattable-deleted-anchor.docx b/sw/qa/core/layout/data/floattable-deleted-anchor.docx Binary files differnew file mode 100644 index 000000000000..cab5b68ff94d --- /dev/null +++ b/sw/qa/core/layout/data/floattable-deleted-anchor.docx diff --git a/sw/qa/core/layout/flycnt.cxx b/sw/qa/core/layout/flycnt.cxx index bd3e98a38a62..1ad1443dd392 100644 --- a/sw/qa/core/layout/flycnt.cxx +++ b/sw/qa/core/layout/flycnt.cxx @@ -737,6 +737,31 @@ CPPUNIT_TEST_FIXTURE(Test, testSplitFlyTableRowKeep) auto pCell3 = dynamic_cast<SwCellFrame*>(pRow3->GetLower()); CPPUNIT_ASSERT(pCell3->GetFollowCell()); } + +CPPUNIT_TEST_FIXTURE(Test, testSplitFlyDeletedAnchor) +{ + // Given a document with a floating table that spans over 3 pages: + createSwDoc("floattable-deleted-anchor.docx"); + + // When laying out that document: + calcLayout(); + + // Then make sure that there are 3 anchors for the 3 pages: + SwDoc* pDoc = getSwDoc(); + SwRootFrame* pLayout = pDoc->getIDocumentLayoutAccess().GetCurrentLayout(); + auto pPage1 = dynamic_cast<SwPageFrame*>(pLayout->Lower()); + CPPUNIT_ASSERT(pPage1); + SwFrame* pBody1 = pPage1->GetLower(); + CPPUNIT_ASSERT(pBody1); + auto pAnchor1 = dynamic_cast<SwTextFrame*>(pBody1->GetLower()->GetNext()); + CPPUNIT_ASSERT(pAnchor1); + SwTextFrame* pAnchor2 = pAnchor1->GetFollow(); + CPPUNIT_ASSERT(pAnchor2); + SwTextFrame* pAnchor3 = pAnchor2->GetFollow(); + // Without the accompanying fix in place, this test would have failed, the fly frame on the 3rd + // page was anchored to a text frame on the 2nd page, leading to a negative frame height. + CPPUNIT_ASSERT(pAnchor3); +} } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/core/text/frmform.cxx b/sw/source/core/text/frmform.cxx index 2f3024f1bb0a..912047487a64 100644 --- a/sw/source/core/text/frmform.cxx +++ b/sw/source/core/text/frmform.cxx @@ -633,6 +633,13 @@ void SwTextFrame::AdjustFollow_( SwTextFormatter &rLine, while( GetFollow() && GetFollow()->GetFollow() && nNewOfst >= GetFollow()->GetFollow()->GetOffset() ) { + if (HasNonLastSplitFlyDrawObj()) + { + // A non-last split fly is anchored to us, don't move content from the last frame to + // this one and don't join. + return; + } + JoinFrame(); } } @@ -1109,7 +1116,11 @@ void SwTextFrame::FormatAdjust( SwTextFormatter &rLine, // AdjustFollow might execute JoinFrame() because of this. // Else, nEnd is the end of the last line in the Master. TextFrameIndex nOld = nEnd; - nEnd = rLine.GetEnd(); + // Make sure content from the last floating table anchor is not shifted to previous anchors. + if (!HasNonLastSplitFlyDrawObj()) + { + nEnd = rLine.GetEnd(); + } if( GetFollow() ) { if( nNew && nOld < nEnd ) |