sw/qa/core/objectpositioning/data/do-not-capture-draw-objs-on-page-draw-wrap-none.docx
 |binary
 sw/qa/core/objectpositioning/objectpositioning.cxx                             
        |   31 ++++++++++
 sw/source/core/objectpositioning/anchoredobjectposition.cxx                    
        |    4 -
 3 files changed, 33 insertions(+), 2 deletions(-)

New commits:
commit a0b6587c4acb1d74e1b00904147821640c98b323
Author:     Miklos Vajna <vmik...@collabora.com>
AuthorDate: Thu Jun 13 08:04:30 2024 +0200
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Thu Jun 13 09:44:46 2024 +0200

    tdf#161199 sw DoNotCaptureDrawObjsOnPage: capture wrap=none draw objects
    
    Regression from commit af313fc149f80adb0f1680ca20e19745ccb7fede
    (tdf#105143 DOCX import: enable DoNotCaptureDrawObjsOnPage layout compat
    option, 2017-01-06), the second page of the document has an off-page
    positioned draw shape, which is still kept inside the page frame in
    Word, but not in Writer anymore.
    
    Reading the SwAnchoredObjectPosition::GetInfoAboutObj() code, there are
    a number of conditions at play here, but the relevant one is that fly
    frames have the restriction that the "do not capture" behavior is
    restricted to wrap=through, but the wrap type was ignored in the draw
    shape case.
    
    Fix the problem by being consistent here: require wrap=through for both
    fly frames and draw shapes that moves the shape back inside the page
    frame.
    
    Note that Word goes a bit further here and even keeps the shape inside
    the body text area, but that doesn't seem to be a regression, so leave
    that unchanged for now.
    
    Change-Id: I3b6331c13d2376cac9b0de90f6f57289a7a0f0e7
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/168762
    Reviewed-by: Miklos Vajna <vmik...@collabora.com>
    Tested-by: Jenkins

diff --git 
a/sw/qa/core/objectpositioning/data/do-not-capture-draw-objs-on-page-draw-wrap-none.docx
 
b/sw/qa/core/objectpositioning/data/do-not-capture-draw-objs-on-page-draw-wrap-none.docx
new file mode 100644
index 000000000000..8eea3a7e0df2
Binary files /dev/null and 
b/sw/qa/core/objectpositioning/data/do-not-capture-draw-objs-on-page-draw-wrap-none.docx
 differ
diff --git a/sw/qa/core/objectpositioning/objectpositioning.cxx 
b/sw/qa/core/objectpositioning/objectpositioning.cxx
index ba2e225e7d07..e8d9f0d445cc 100644
--- a/sw/qa/core/objectpositioning/objectpositioning.cxx
+++ b/sw/qa/core/objectpositioning/objectpositioning.cxx
@@ -475,6 +475,37 @@ CPPUNIT_TEST_FIXTURE(Test, 
testDoNotMirrorRtlDrawObjsLayout)
     // i.e. the graphic was on the left margin, not on the right margin.
     CPPUNIT_ASSERT_GREATER(nBodyRight, aAnchoredCenter.getX());
 }
+
+CPPUNIT_TEST_FIXTURE(Test, testDoNotCaptureDrawObjsOnPageDrawWrapNone)
+{
+    // Given a document with a draw object on page 2, wrap type is set to none 
(not through):
+    createSwDoc("do-not-capture-draw-objs-on-page-draw-wrap-none.docx");
+
+    // When laying out that document:
+    calcLayout();
+
+    // Then make sure the draw object is captured on page 2:
+    SwDoc* pDoc = getSwDoc();
+    SwRootFrame* pLayout = pDoc->getIDocumentLayoutAccess().GetCurrentLayout();
+    auto pPage1 = pLayout->Lower()->DynCastPageFrame();
+    CPPUNIT_ASSERT(pPage1);
+    auto pPage2 = pPage1->GetNext()->DynCastPageFrame();
+    CPPUNIT_ASSERT(pPage2);
+    CPPUNIT_ASSERT(pPage2->GetSortedObjs());
+    const SwSortedObjs& rPage2Objs = *pPage2->GetSortedObjs();
+    CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), rPage2Objs.size());
+    SwAnchoredObject* pDrawObj = rPage2Objs[0];
+    CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt16>(RES_DRAWFRMFMT),
+                         pDrawObj->GetFrameFormat()->Which());
+    SwTwips nDrawObjTop = pDrawObj->GetObjRect().Top();
+    SwTwips nPage2Top = pPage2->getFrameArea().Top();
+    // Without the accompanying fix in place, this test would have failed with:
+    // - Expected greater than: 17383
+    // - Actual  : 13518
+    // i.e. the draw object was way above the page 2 rectangle, instead of 
inside it (apart from
+    // some <1px difference).
+    CPPUNIT_ASSERT_GREATER(nPage2Top - MINFLY, nDrawObjTop);
+}
 }
 
 CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/sw/source/core/objectpositioning/anchoredobjectposition.cxx 
b/sw/source/core/objectpositioning/anchoredobjectposition.cxx
index 4af3af542b27..9d61d9cd3054 100644
--- a/sw/source/core/objectpositioning/anchoredobjectposition.cxx
+++ b/sw/source/core/objectpositioning/anchoredobjectposition.cxx
@@ -119,12 +119,12 @@ 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 wrap-though fly frame
+    // - it's a drawing object or it's a non-textbox fly frame with wrap-though
     // - 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 &&
+        mbDoNotCaptureAnchoredObj = ((!mbIsObjFly || !bTextBox) && 
bWrapThrough) && !mbFollowTextFlow &&
                                     
mpFrameFormat->getIDocumentSettingAccess().get(DocumentSettingId::DO_NOT_CAPTURE_DRAW_OBJS_ON_PAGE);
     }
 }

Reply via email to