sw/CppunitTest_sw_core_text.mk | 1 sw/qa/core/text/data/clearing-break-wrap-through.docx |binary sw/qa/core/text/txtfly.cxx | 52 ++++++++++++++++++ sw/source/core/text/txtfly.cxx | 7 ++ 4 files changed, 60 insertions(+)
New commits: commit 304cc248f15d795bc9fe8b751b0d98841b8ff5d1 Author: Miklos Vajna <vmik...@collabora.com> AuthorDate: Thu May 30 08:10:13 2024 +0200 Commit: Miklos Vajna <vmik...@collabora.com> CommitDate: Thu May 30 13:30:40 2024 +0200 tdf#161318 sw clearing break: ignore wrap-through anchored objects Import the bugdoc: we expect just a single page for the 2 paragraphs, but the second paragraph goes to a 2nd page. What seems to happen since commit f86d1482bef285f90079b5130e410646db96cf58 (sw clearing breaks: add DOCX import, 2022-03-08) is that on one hand, SwTextFly::ForEach() ignores wrap-through shapes, but at the same time SwTextFly::GetMaxBottom() did not, and this lead to a loop: the first paragraph kept growing till the shape was shifted to page 2, but then the same first paragraph was reduced to just 2 lines, goto 1. Fix the problem by extending SwTextFly::GetMaxBottom() to also ignore wrap-though shapes: this is the intention, just clearing breaks were not tested with wrap-though wrap mode before. This is a reduced bugdoc, the original one even produced warnings like: warn:legacy.osl:12034:12034:sw/source/core/layout/flowfrm.cxx:2667: <SwFlowFrame::MoveBwd(..)> - layout loop control for layout action <Move Backward> applied! without the fix, and these are now gone. Change-Id: Iaf9849dbf8e1a8e5d625d3c19b99636247804cdd Reviewed-on: https://gerrit.libreoffice.org/c/core/+/168239 Reviewed-by: Miklos Vajna <vmik...@collabora.com> Tested-by: Jenkins diff --git a/sw/CppunitTest_sw_core_text.mk b/sw/CppunitTest_sw_core_text.mk index 95b69b90113b..8c215dfab4e1 100644 --- a/sw/CppunitTest_sw_core_text.mk +++ b/sw/CppunitTest_sw_core_text.mk @@ -20,6 +20,7 @@ $(eval $(call gb_CppunitTest_add_exception_objects,sw_core_text, \ sw/qa/core/text/porlay \ sw/qa/core/text/porrst \ sw/qa/core/text/text \ + sw/qa/core/text/txtfly \ sw/qa/core/text/widorp \ )) diff --git a/sw/qa/core/text/data/clearing-break-wrap-through.docx b/sw/qa/core/text/data/clearing-break-wrap-through.docx new file mode 100644 index 000000000000..c96e8c27da5e Binary files /dev/null and b/sw/qa/core/text/data/clearing-break-wrap-through.docx differ diff --git a/sw/qa/core/text/txtfly.cxx b/sw/qa/core/text/txtfly.cxx new file mode 100644 index 000000000000..461ed81e2203 --- /dev/null +++ b/sw/qa/core/text/txtfly.cxx @@ -0,0 +1,52 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include <swmodeltestbase.hxx> + +#include <memory> + +#include <IDocumentLayoutAccess.hxx> +#include <doc.hxx> +#include <frame.hxx> +#include <pagefrm.hxx> +#include <rootfrm.hxx> + +namespace +{ +/// Covers sw/source/core/text/txtfly.cxx fixes. +class Test : public SwModelTestBase +{ +public: + Test() + : SwModelTestBase("/sw/qa/core/text/data/") + { + } +}; + +CPPUNIT_TEST_FIXTURE(Test, testClearingBreakWrapThrough) +{ + // Given a document with a clearing break, then a shape in the next paragraph: + createSwDoc("clearing-break-wrap-through.docx"); + + // When laying out that document: + calcLayout(); + + // Then make sure we layout these 2 paragraphs on a single page, since there is enough space for + // them: + SwDoc* pDoc = getSwDoc(); + SwRootFrame* pLayout = pDoc->getIDocumentLayoutAccess().GetCurrentLayout(); + auto pPage = pLayout->Lower()->DynCastPageFrame(); + CPPUNIT_ASSERT(pPage); + // Without the accompanying fix in place, this test would have failed, we had an unexpected 2nd + // page. + CPPUNIT_ASSERT(!pPage->GetNext()); +} +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/core/text/txtfly.cxx b/sw/source/core/text/txtfly.cxx index 7c4d9a2e160d..45eea8eeee53 100644 --- a/sw/source/core/text/txtfly.cxx +++ b/sw/source/core/text/txtfly.cxx @@ -1051,6 +1051,13 @@ SwTwips SwTextFly::GetMaxBottom(const SwBreakPortion& rPortion, const SwTextForm continue; } + const SwFormatSurround& rSurround = pAnchoredObj->GetFrameFormat()->GetSurround(); + if (rSurround.GetValue() == text::WrapTextMode_THROUGH) + { + // Wrap through has no influence on clearing breaks. + continue; + } + SwRect aRect(pAnchoredObj->GetObjRectWithSpaces()); if (m_pCurrFrame->IsVertical())