sw/qa/core/layout/data/floattable-2cols.docx |binary sw/qa/core/layout/flycnt.cxx | 30 +++++++++++++++++++++++++++ sw/source/core/layout/fly.cxx | 6 +++++ 3 files changed, 36 insertions(+)
New commits: commit 5d5dca66e17c90e20197d0d76113254b13ff0bb7 Author: Miklos Vajna <vmik...@collabora.com> AuthorDate: Tue Mar 7 08:25:56 2023 +0100 Commit: Miklos Vajna <vmik...@collabora.com> CommitDate: Tue Mar 7 08:25:06 2023 +0000 sw floattable: grow the print area as well in SwFlyFrame::Grow_() The bugdoc should be of 3 pages, but the last for of the floating table went to the 3rd page. The reason for this was that SwTabFrame::MakeAll() calculated nDistanceToUpperPrtBottom, then determined that the upper has to grow, and called GetUpper()->Grow(LONG_MAX, /*bTest=*/true). Now this growth was less than what would be possible, because a previous invocation of SwFlyFrame::Grow_() increased the frame area (with margins) but not the print area (with margins). This meant that the frame can't grow too much because its frame height is already 7044 twips but its print height is only 548. This combination of "not enough inner space" and "can't grow too much, either" resulted in moving the last row to an unwanted 3rd page. Fix the problem by not only increasing the frame height but also the print height in SwFlyFrame::Grow_(), this keeps the last row on the 2nd page, like Word does. Change-Id: I7850b54b030c42034e0a117d52d2148fa6ba2f83 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/148373 Reviewed-by: Miklos Vajna <vmik...@collabora.com> Tested-by: Jenkins diff --git a/sw/qa/core/layout/data/floattable-2cols.docx b/sw/qa/core/layout/data/floattable-2cols.docx new file mode 100644 index 000000000000..c43779f2aac9 Binary files /dev/null and b/sw/qa/core/layout/data/floattable-2cols.docx differ diff --git a/sw/qa/core/layout/flycnt.cxx b/sw/qa/core/layout/flycnt.cxx index d400fd85de0a..254a316886c7 100644 --- a/sw/qa/core/layout/flycnt.cxx +++ b/sw/qa/core/layout/flycnt.cxx @@ -390,6 +390,36 @@ CPPUNIT_TEST_FIXTURE(Test, testSplitFlyFooter2Rows) // 2nd half of the split row and the last row went to a 3rd page. CPPUNIT_ASSERT(!pPage2->GetNext()); } + +CPPUNIT_TEST_FIXTURE(Test, testSplitFly2Cols) +{ + // Given a document with a 2nd page that contains the second half of a split row and 2 columns: + std::shared_ptr<comphelper::ConfigurationChanges> pChanges( + comphelper::ConfigurationChanges::create()); + officecfg::Office::Writer::Filter::Import::DOCX::ImportFloatingTableAsSplitFly::set(true, + pChanges); + pChanges->commit(); + comphelper::ScopeGuard g([pChanges] { + officecfg::Office::Writer::Filter::Import::DOCX::ImportFloatingTableAsSplitFly::set( + false, pChanges); + pChanges->commit(); + }); + createSwDoc("floattable-2cols.docx"); + + // When laying out that document: + calcLayout(); + + // Then make sure that the table is split to 2 pages: + SwDoc* pDoc = getSwDoc(); + SwRootFrame* pLayout = pDoc->getIDocumentLayoutAccess().GetCurrentLayout(); + auto pPage1 = dynamic_cast<SwPageFrame*>(pLayout->Lower()); + CPPUNIT_ASSERT(pPage1); + auto pPage2 = dynamic_cast<SwPageFrame*>(pPage1->GetNext()); + CPPUNIT_ASSERT(pPage2); + // Without the accompanying fix in place, this test would have failed. The 2nd page only had the + // 2nd half of the split row and the very last row went to a 3rd page. + CPPUNIT_ASSERT(!pPage2->GetNext()); +} } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/core/layout/fly.cxx b/sw/source/core/layout/fly.cxx index 4df2b690eb0c..b1955e845af6 100644 --- a/sw/source/core/layout/fly.cxx +++ b/sw/source/core/layout/fly.cxx @@ -2083,6 +2083,12 @@ SwTwips SwFlyFrame::Grow_( SwTwips nDist, bool bTst ) aRectFnSet.AddBottom(aFrm, nRemaining); } InvalidateObjRectWithSpaces(); + { + // Margins are unchanged, so increase the print height similar to the frame + // height. + SwFrameAreaDefinition::FramePrintAreaWriteAccess aPrt(*this); + aRectFnSet.AddBottom(aPrt, nRemaining ); + } aNew = GetObjRectWithSpaces(); } }