sw/qa/core/objectpositioning/data/do-not-capture-draw-objs-draw-obj-no-capture.docx |binary sw/qa/core/objectpositioning/objectpositioning.cxx | 28 ++++++++++ sw/source/core/objectpositioning/anchoredobjectposition.cxx | 18 +++++- 3 files changed, 43 insertions(+), 3 deletions(-)
New commits: commit 69296ae46f00c4066d983fe112a8bf0a8111c93b Author: Miklos Vajna <vmik...@collabora.com> AuthorDate: Mon Mar 17 08:23:35 2025 +0100 Commit: Caolán McNamara <caolan.mcnam...@collabora.com> CommitDate: Tue Mar 18 09:32:24 2025 +0100 tdf#164902 sw DoNotCaptureDrawObjsOnPage: enable non-textbox wrap=no draw objs Open the bugdoc, the poor layout expects Writer to not capture the shape at the top of the page, but we captured it. This went wrong with commit a0b6587c4acb1d74e1b00904147821640c98b323 (tdf#161199 sw DoNotCaptureDrawObjsOnPage: capture wrap=none draw objects, 2024-06-13), which had a draw obj (part of a draw-fly format pair, forming a textbox), that was captured in Word, but not in Writer. Notice how the old bugdoc was a textbox draw obj, but the new draw obj is not a textbox one. Fix the problem by once again refining the condition when to capture objects inside the page frame. When it comes to draw objects, continue to capture wrap=none ones, but only in case they are part of a textbox. This keeps the wanted capturing for the old case and restores the lack of capturing for the new case. Note that the in-header shape is actually wrap-through in Word, and at the moment not in Writer, which would be also nice to fix, but that's not done here. Change-Id: I163ea9366bb34b09b2319c91c4cd53b82c19964a Reviewed-on: https://gerrit.libreoffice.org/c/core/+/183020 Reviewed-by: Caolán McNamara <caolan.mcnam...@collabora.com> Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com> diff --git a/sw/qa/core/objectpositioning/data/do-not-capture-draw-objs-draw-obj-no-capture.docx b/sw/qa/core/objectpositioning/data/do-not-capture-draw-objs-draw-obj-no-capture.docx new file mode 100644 index 000000000000..636179fd60ce Binary files /dev/null and b/sw/qa/core/objectpositioning/data/do-not-capture-draw-objs-draw-obj-no-capture.docx differ diff --git a/sw/qa/core/objectpositioning/objectpositioning.cxx b/sw/qa/core/objectpositioning/objectpositioning.cxx index ae228ebaf7fb..e290a0c1e77f 100644 --- a/sw/qa/core/objectpositioning/objectpositioning.cxx +++ b/sw/qa/core/objectpositioning/objectpositioning.cxx @@ -512,6 +512,34 @@ CPPUNIT_TEST_FIXTURE(Test, testInsertShapeOnAsCharImg_tdf16890) // - Expression: pShape->GetAnchor().GetAnchorNode() CPPUNIT_ASSERT(pShape->GetAnchor().GetAnchorNode()); } + +CPPUNIT_TEST_FIXTURE(Test, testDoNotCaptureDrawObjsDrawObjNoCapture) +{ + // Given a document with a draw object, which is positined outside the page frame: + createSwDoc("do-not-capture-draw-objs-draw-obj-no-capture.docx"); + + // When laying out that document: + calcLayout(); + + // Then make sure the draw object is not captured on page 1: + SwDoc* pDoc = getSwDoc(); + SwRootFrame* pLayout = pDoc->getIDocumentLayoutAccess().GetCurrentLayout(); + auto pPage = pLayout->Lower()->DynCastPageFrame(); + CPPUNIT_ASSERT(pPage); + CPPUNIT_ASSERT(pPage->GetSortedObjs()); + const SwSortedObjs& rPageObjs = *pPage->GetSortedObjs(); + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), rPageObjs.size()); + SwAnchoredObject* pDrawObj = rPageObjs[0]; + CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt16>(RES_DRAWFRMFMT), + pDrawObj->GetFrameFormat()->Which()); + SwTwips nDrawObjLeft = pDrawObj->GetObjRect().Left(); + SwTwips nPageLeft = pPage->getFrameArea().Left(); + // Without the accompanying fix in place, this test would have failed with: + // - Expected greater than: 284 + // - Actual : 284 + // i.e. the draw object was captured inside the page frame, but it was not in Word. + CPPUNIT_ASSERT_GREATER(nDrawObjLeft, nPageLeft); +} } CPPUNIT_PLUGIN_IMPLEMENT(); diff --git a/sw/source/core/objectpositioning/anchoredobjectposition.cxx b/sw/source/core/objectpositioning/anchoredobjectposition.cxx index fffa50e1948e..0e6b702cc6db 100644 --- a/sw/source/core/objectpositioning/anchoredobjectposition.cxx +++ b/sw/source/core/objectpositioning/anchoredobjectposition.cxx @@ -122,12 +122,24 @@ void SwAnchoredObjectPosition::GetInfoAboutObj() // determine, if anchored object has not to be captured on the page. // the following conditions must be hold to *not* capture it: // - corresponding document compatibility flag is set - // - it's a drawing object or it's a non-textbox fly frame with wrap-though + // - shape is considered: + // - draw case: wrap through or is not part of a textbox + // - fly case: wrap through and is not part of a textbox // - it doesn't follow the text flow { - bool bTextBox = SwTextBoxHelper::isTextBox(mpFrameFormat, RES_FLYFRMFMT); bool bWrapThrough = mpFrameFormat->GetSurround().GetSurround() == css::text::WrapTextMode_THROUGH; - mbDoNotCaptureAnchoredObj = ((!mbIsObjFly || !bTextBox) && bWrapThrough) && !mbFollowTextFlow && + bool bConsidered{}; + if (mbIsObjFly) + { + bool bTextBox = SwTextBoxHelper::isTextBox(mpFrameFormat, RES_FLYFRMFMT); + bConsidered = bWrapThrough && !bTextBox; + } + else + { + bool bTextBox = SwTextBoxHelper::isTextBox(mpFrameFormat, RES_DRAWFRMFMT); + bConsidered = bWrapThrough || !bTextBox; + } + mbDoNotCaptureAnchoredObj = bConsidered && !mbFollowTextFlow && mpFrameFormat->getIDocumentSettingAccess().get(DocumentSettingId::DO_NOT_CAPTURE_DRAW_OBJS_ON_PAGE); } }