sw/CppunitTest_sw_core_text.mk | 1 sw/qa/core/text/data/hide-whitespace-widorp.odt |binary sw/qa/core/text/widorp.cxx | 65 ++++++++++++++++++++++++ sw/source/core/text/widorp.cxx | 5 - 4 files changed, 66 insertions(+), 5 deletions(-)
New commits: commit c5ac0ffae47dd2da74aaddd26e100aeb3b814c0b Author: Miklos Vajna <[email protected]> AuthorDate: Tue Mar 5 08:07:47 2024 +0100 Commit: Miklos Vajna <[email protected]> CommitDate: Tue Mar 5 12:57:01 2024 +0100 tdf#159706 sw hide whitespace: fix lost follow on enabling this Regression from commit 6d8da2b2deb4be2182ca1852cec7eb38a4c654eb (tdf#96943 sw Hide Whitespace: don't create pages for widow / orphan ..., 2016-01-07), the reduced bugdoc has 3 paragraphs, 1.5 paragraphs are on page 1, 1.5 paragraphs are on page 2. Hiding whitespace moves the entire paragraph 2 to page 1, which is unexpected. Checking the original use-case, the CheckPageHeightValidForHideWhitespace() call in SwTextFrameBreak::IsInside() can be removed, and still the original "type character at the end of the document results in a new, unwanted page" problem is not back. Likely at some point in the meantime we gave up on these reduced page heights for the last page, so the original tweak for widow/orphan lines is not needed anymore. Fix the problem reverting the original, no longer needed fix, but keeping its testTdf96943 test in the CppunitTest_sw_uiwriter4 suite. Such reducing of last page doesn't happen with Word 2021, so probably this change in behavior is wanted. Change-Id: I5d46d0cd84d0071ffb9ef3f8e4ca7335e61bb226 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/164408 Reviewed-by: Miklos Vajna <[email protected]> Tested-by: Jenkins diff --git a/sw/CppunitTest_sw_core_text.mk b/sw/CppunitTest_sw_core_text.mk index ce27696b3c4c..95b69b90113b 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/widorp \ )) $(eval $(call gb_CppunitTest_use_libraries,sw_core_text, \ diff --git a/sw/qa/core/text/data/hide-whitespace-widorp.odt b/sw/qa/core/text/data/hide-whitespace-widorp.odt new file mode 100644 index 000000000000..a073f36a70a8 Binary files /dev/null and b/sw/qa/core/text/data/hide-whitespace-widorp.odt differ diff --git a/sw/qa/core/text/widorp.cxx b/sw/qa/core/text/widorp.cxx new file mode 100644 index 000000000000..9b2d65352f00 --- /dev/null +++ b/sw/qa/core/text/widorp.cxx @@ -0,0 +1,65 @@ +/* -*- 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 <layfrm.hxx> +#include <pagefrm.hxx> +#include <rootfrm.hxx> +#include <txtfrm.hxx> +#include <docsh.hxx> +#include <wrtsh.hxx> +#include <viewopt.hxx> + +namespace +{ +/// Covers sw/source/core/text/widorp.cxx fixes. +class Test : public SwModelTestBase +{ +public: + Test() + : SwModelTestBase("/sw/qa/core/text/data/") + { + } +}; + +CPPUNIT_TEST_FIXTURE(Test, testHideWhitespaceWidorp) +{ + // Given a document with 3 paragraphs: 1.5 on page 1, 1.5 on page 2: + createSwDoc("hide-whitespace-widorp.odt"); + + // When hiding whitespace: + SwDocShell* pDocShell = getSwDocShell(); + SwWrtShell* pWrtShell = pDocShell->GetWrtShell(); + SwViewOption aViewOptions(*pWrtShell->GetViewOptions()); + aViewOptions.SetHideWhitespaceMode(true); + pWrtShell->ApplyViewOptions(aViewOptions); + calcLayout(); + + // Then make sure that paragraph 2 is still split: + SwDoc* pDoc = pDocShell->GetDoc(); + SwRootFrame* pLayout = pDoc->getIDocumentLayoutAccess().GetCurrentLayout(); + auto pPage = pLayout->Lower()->DynCastPageFrame(); + CPPUNIT_ASSERT(pPage); + SwFrame* pBody = pPage->FindBodyCont(); + SwFrame* pPara1 = pBody->GetLower(); + auto pPara2 = pPara1->GetNext()->DynCastTextFrame(); + CPPUNIT_ASSERT(pPara2); + // Without the accompanying fix in place, this test would have failed, the entire paragraph 2 + // went to page 1, so it was not split anymore. + CPPUNIT_ASSERT(pPara2->HasFollow()); +} +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/core/text/widorp.cxx b/sw/source/core/text/widorp.cxx index bc6586c2f0f6..e2457cb1ed6c 100644 --- a/sw/source/core/text/widorp.cxx +++ b/sw/source/core/text/widorp.cxx @@ -131,11 +131,6 @@ bool SwTextFrameBreak::IsInside( SwTextMargin const &rLine ) const aRectFnSet.YDiff( aRectFnSet.GetPrtBottom(*m_pFrame->GetUpper()), m_nOrigin ); SwTwips nDiff = nHeight - nLineHeight; - // Hide whitespace may require not to insert a new page. - SwPageFrame* pPageFrame = m_pFrame->FindPageFrame(); - if (!pPageFrame->CheckPageHeightValidForHideWhitespace(nDiff)) - nDiff = 0; - // If everything is inside the existing frame the result is true; bFit = nDiff >= 0;
