sw/qa/core/layout/layout.cxx | 37 +++++++++++++++++++++++++++++++++++++ sw/source/core/layout/tabfrm.cxx | 6 +++++- 2 files changed, 42 insertions(+), 1 deletion(-)
New commits: commit 6819b7eb6ca5187b82833965c8198f3ca868b27a Author: Miklos Vajna <vmik...@collabora.com> AuthorDate: Wed Jan 18 20:18:39 2023 +0100 Commit: Miklos Vajna <vmik...@collabora.com> CommitDate: Thu Jan 19 07:15:30 2023 +0000 tdf#153045 sw: fix incorrect height of row in table The bugdoc DOCX had a shape anchored in a table cell, and the cell had large enough height so the shape could fit into the cell, while the expected cell height was independent (smaller) from the shape. The problem is around the follow-text-flow feature, which is called "keep inside cell boundaries" in Word. This setting would normally increase the size of the cell, so the shape remains inside the cell. An exception from this increase request is the wrap-through wrap mode, which leaves the cell size unchanged. Fix the problem by considering two previous use-cases: 1d9221ebc86f2696a65c12287ea19eea44d680cf (tdf#145688 sw: fix misplaced images in table cells, 2022-11-29) and 489eef894e7034873ad262f9dfca554022db1b09 (tdf#124601 sw FollowTextFlow: fix vert pos of objects outside the current cell, 2019-10-01): - tdf#145688 is a legacy ODF document: do require the the "in background" wrapping, otherwise make the cells big - tdf#124601 & tdf#153045 are Word documents: here don't require the "in background" wrapping and go with small cells when the wrap type is through This requires adjusting the tdf#145688 testcase that minimized the original bugdoc incorrectly. Change-Id: Ieaf3d9c1c4477e5e57e5e1e825775648840ab32b Reviewed-on: https://gerrit.libreoffice.org/c/core/+/145756 Tested-by: Jenkins Reviewed-by: Miklos Vajna <vmik...@collabora.com> diff --git a/sw/qa/core/layout/layout.cxx b/sw/qa/core/layout/layout.cxx index 2ba7ed9a849d..b413b1390e3f 100644 --- a/sw/qa/core/layout/layout.cxx +++ b/sw/qa/core/layout/layout.cxx @@ -29,6 +29,7 @@ #include <fmtanchr.hxx> #include <fmtsrnd.hxx> #include <IDocumentContentOperations.hxx> +#include <IDocumentSettingAccess.hxx> #include <fmtfsize.hxx> #include <fmtfollowtextflow.hxx> #include <view.hxx> @@ -858,6 +859,7 @@ CPPUNIT_TEST_FIXTURE(SwCoreLayoutTest, testFollowTextFlowWrapInBackground) // through and follow-text-flow set to true: createSwDoc(); SwDoc* pDoc = getSwDoc(); + pDoc->getIDocumentSettingAccess().set(DocumentSettingId::USE_FORMER_TEXT_WRAPPING, true); SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell(); SwInsertTableOptions aTableOptions(SwInsertTableFlags::DefaultBorder, 0); pWrtShell->InsertTable(aTableOptions, 1, 1); @@ -924,6 +926,41 @@ CPPUNIT_TEST_FIXTURE(SwCoreLayoutTest, testPageRemoveFlyNoTable) calcLayout(); } +CPPUNIT_TEST_FIXTURE(SwCoreLayoutTest, testNewFollowTextFlowWrapInBackground) +{ + // Given a document with a table, and a graphic inside that table -- anchored, wrap set to + // through and follow-text-flow set to true, legacy USE_FORMER_TEXT_WRAPPING is not set: + createSwDoc(); + SwDoc* pDoc = getSwDoc(); + SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell(); + SwInsertTableOptions aTableOptions(SwInsertTableFlags::DefaultBorder, 0); + pWrtShell->InsertTable(aTableOptions, 1, 1); + pWrtShell->MoveTable(GotoPrevTable, fnTableStart); + SfxItemSet aFrameSet(pDoc->GetAttrPool(), svl::Items<RES_FRMATR_BEGIN, RES_FRMATR_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); + Graphic aGrf; + + // When inserting that image: + pWrtShell->SwFEShell::Insert(OUString(), OUString(), &aGrf, &aFrameSet); + + // 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 less than: 1000 + // - Actual : 1120 + // i.e. the cell height was too large, the image influenced it, which is not expected. + CPPUNIT_ASSERT_LESS(static_cast<sal_Int32>(1000), nCellHeight); +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/core/layout/tabfrm.cxx b/sw/source/core/layout/tabfrm.cxx index 2cf9b75a62b0..b95f8ca45b25 100644 --- a/sw/source/core/layout/tabfrm.cxx +++ b/sw/source/core/layout/tabfrm.cxx @@ -4112,7 +4112,11 @@ tools::Long CalcHeightWithFlys( const SwFrame *pFrame ) bFollowTextFlow && bIsAnchoredToTmpFrm; bool bWrapThrough = rFrameFormat.GetSurround().GetValue() == text::WrapTextMode_THROUGH; bool bInBackground = !rFrameFormat.GetOpaque().GetValue(); - if (pFrame->IsInTab() && bFollowTextFlow && bWrapThrough && bInBackground) + // Legacy render requires in-background setting, the new mode does not. + bool bConsiderFollowTextFlow = bInBackground + || !rFrameFormat.getIDocumentSettingAccess().get( + DocumentSettingId::USE_FORMER_TEXT_WRAPPING); + if (pFrame->IsInTab() && bFollowTextFlow && bWrapThrough && bConsiderFollowTextFlow) { // Ignore wrap-through objects when determining the cell height. // Normally FollowTextFlow requires a resize of the cell, but not in case of