sw/CppunitTest_sw_core_layout.mk | 1 sw/qa/core/layout/layout.cxx | 43 +++++++++++++++++++++++++++++++++++++++ sw/source/core/doc/notxtfrm.cxx | 2 - sw/source/core/layout/tabfrm.cxx | 3 +- 4 files changed, 47 insertions(+), 2 deletions(-)
New commits: commit 145b942359b7d2c14f162d9417873ae097ea3b7c Author: Miklos Vajna <vmik...@collabora.com> AuthorDate: Tue Nov 29 21:20:50 2022 +0100 Commit: Miklos Vajna <vmik...@collabora.com> CommitDate: Wed Nov 30 14:14:39 2022 +0100 tdf#145688 sw: fix misplaced images in table cells The bugdoc had a table with anchored images which were FollowTextFlow=true and WrapThrough=true. This used to still make the table cell larger, but instead the images were overlapping due to the not increased cell height. The problem happens since commit 489eef894e7034873ad262f9dfca554022db1b09 (tdf#124601 sw FollowTextFlow: fix vert pos of objects outside the current cell, 2019-10-01), which wanted to ignore anchored images in a similar situation. Fix the problem by making the "ignore image for cell height calculation" condition more strict: if we also require wrapping in background, then the old bugdoc keeps working but this fixes the new bugdoc. Also change the font name in lcl_PaintReplacement() to a font that we bundle, otherwise the testcase would abort in psp::PrintFontManager::Substitute() for a document that doesn't specify any font name explicitly. Change-Id: Ie512aa4ffd368774825c5243ecd6bce7f09e1442 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/143472 Tested-by: Jenkins Reviewed-by: Miklos Vajna <vmik...@collabora.com> Signed-off-by: Xisco Fauli <xiscofa...@libreoffice.org> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/143478 Reviewed-by: Michael Stahl <michael.st...@allotropia.de> Tested-by: Miklos Vajna <vmik...@collabora.com> diff --git a/sw/CppunitTest_sw_core_layout.mk b/sw/CppunitTest_sw_core_layout.mk index 80dc1530fdb3..d95d2b59327e 100644 --- a/sw/CppunitTest_sw_core_layout.mk +++ b/sw/CppunitTest_sw_core_layout.mk @@ -18,6 +18,7 @@ $(eval $(call gb_CppunitTest_add_exception_objects,sw_core_layout, \ )) $(eval $(call gb_CppunitTest_use_libraries,sw_core_layout, \ + editeng \ comphelper \ cppu \ cppuhelper \ diff --git a/sw/qa/core/layout/layout.cxx b/sw/qa/core/layout/layout.cxx index a6a949b5337b..c961ac5c8d8d 100644 --- a/sw/qa/core/layout/layout.cxx +++ b/sw/qa/core/layout/layout.cxx @@ -23,6 +23,12 @@ #include <IDocumentState.hxx> #include <IDocumentLayoutAccess.hxx> #include <rootfrm.hxx> +#include <itabenum.hxx> +#include <fmtanchr.hxx> +#include <fmtsrnd.hxx> +#include <IDocumentContentOperations.hxx> +#include <fmtfsize.hxx> +#include <fmtfollowtextflow.hxx> constexpr OUStringLiteral DATA_DIRECTORY = u"/sw/qa/core/layout/data/"; @@ -814,6 +820,43 @@ CPPUNIT_TEST_FIXTURE(SwCoreLayoutTest, testNegativePageBorderNoMargin) assertXPath(pXmlDoc, "//polyline[@style='solid']/point[2]", "y", "899"); } +CPPUNIT_TEST_FIXTURE(SwCoreLayoutTest, testFollowTextFlowWrapInBackground) +{ + // Given a document with a table, and a graphic inside that table -- anchored, wrap set to + // through and follow-text-flow set to true: + SwDoc* pDoc = createSwDoc(); + SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell(); + SwInsertTableOptions aTableOptions(SwInsertTableFlags::DefaultBorder, 0); + pWrtShell->InsertTable(aTableOptions, 1, 1); + pWrtShell->MoveTable(GotoPrevTable, fnTableStart); + IDocumentContentOperations& rIDCO = pDoc->getIDocumentContentOperations(); + SfxItemSet aFrameSet(pDoc->GetAttrPool(), svl::Items<RES_FRMATR_BEGIN, RES_FRMATR_END - 1>); + SfxItemSet aGrfSet(pDoc->GetAttrPool(), svl::Items<RES_GRFATR_BEGIN, RES_GRFATR_END - 1>); + SwFormatAnchor aAnchor(RndStdIds::FLY_AT_CHAR); + aFrameSet.Put(aAnchor); + SwFormatSurround aSurround(text::WrapTextMode_THROUGH); + aFrameSet.Put(aSurround); + SwFormatFrameSize aSize(SwFrameSize::Fixed, 1000, 1000); + aFrameSet.Put(aSize); + SwFormatFollowTextFlow aFlow(true); + aFrameSet.Put(aFlow); + GraphicObject aGrf; + rIDCO.InsertGraphicObject(*pWrtShell->GetCursor(), aGrf, &aFrameSet, &aGrfSet); + + // When laying out that document: + calcLayout(); + + // Then make sure that the cell height grows to have space for the graphic, given that + // background=true is not specified. + xmlDocUniquePtr pXmlDoc = parseLayoutDump(); + sal_Int32 nCellHeight = getXPath(pXmlDoc, "//cell[1]/infos/bounds", "height").toInt32(); + // Without the accompanying fix in place, this test would have failed with: + // - Expected greater than: 1000 + // - Actual : 396 + // i.e. the image was larger than the containing cell. + CPPUNIT_ASSERT_GREATER(static_cast<sal_Int32>(1000), nCellHeight); +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/core/doc/notxtfrm.cxx b/sw/source/core/doc/notxtfrm.cxx index a4cbbe7cd531..9239d09d6ca1 100644 --- a/sw/source/core/doc/notxtfrm.cxx +++ b/sw/source/core/doc/notxtfrm.cxx @@ -103,7 +103,7 @@ static void lcl_PaintReplacement( const SwRect &rRect, const OUString &rText, vcl::Font tmp; tmp.SetWeight( WEIGHT_BOLD ); tmp.SetStyleName( OUString() ); - tmp.SetFamilyName("Arial Unicode"); + tmp.SetFamilyName("Noto Sans"); tmp.SetFamily( FAMILY_SWISS ); tmp.SetTransparent( true ); return tmp; diff --git a/sw/source/core/layout/tabfrm.cxx b/sw/source/core/layout/tabfrm.cxx index 25213d481fa5..9b3816685560 100644 --- a/sw/source/core/layout/tabfrm.cxx +++ b/sw/source/core/layout/tabfrm.cxx @@ -4111,7 +4111,8 @@ tools::Long CalcHeightWithFlys( const SwFrame *pFrame ) bIsFarAway && bFollowTextFlow && bIsAnchoredToTmpFrm; bool bWrapThrough = rFrameFormat.GetSurround().GetValue() == text::WrapTextMode_THROUGH; - if (pFrame->IsInTab() && bFollowTextFlow && bWrapThrough) + bool bInBackground = !rFrameFormat.GetOpaque().GetValue(); + if (pFrame->IsInTab() && bFollowTextFlow && bWrapThrough && bInBackground) { // Ignore wrap-through objects when determining the cell height. // Normally FollowTextFlow requires a resize of the cell, but not in case of