sw/qa/extras/ooxmlexport/ooxmlexport21.cxx                  |   11 ++----
 sw/source/core/objectpositioning/anchoredobjectposition.cxx |   22 +++++++++++-
 2 files changed, 25 insertions(+), 8 deletions(-)

New commits:
commit 23a97ce1d501a7b98d438007c4cfe5b5c77fa295
Author:     Justin Luth <jl...@mail.com>
AuthorDate: Thu Aug 29 21:24:16 2024 -0400
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Mon Sep 2 09:32:07 2024 +0200

    tdf#162539 layoutInCell: limit vert to cell margin
    
    Although horizontal offsets can go to the cell edge,
    vertical offsets are limited to the cell margin.
    Don't ask me why.
    
    make CppunitTest_sw_ooxmlexport21 CPPUNIT_TEST_NAME=testTdf162551
    
    Change-Id: I3741b46396b67f5e7ea3596e49730aea24e40c03
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/172612
    Tested-by: Justin Luth <jl...@mail.com>
    Reviewed-by: Justin Luth <jl...@mail.com>
    Reviewed-by: Miklos Vajna <vmik...@collabora.com>

diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport21.cxx 
b/sw/qa/extras/ooxmlexport/ooxmlexport21.cxx
index fb263897adda..a7b8e92ca56f 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport21.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport21.cxx
@@ -715,13 +715,10 @@ DECLARE_OOXMLEXPORT_TEST(testTdf162551, 
"tdf162551_notLayoutInCell_charLeft_from
         = getXPath(pDump, 
"//tab/row[2]/cell[2]/txt/anchored/fly/SwAnchoredObject/bounds"_ostr,
                    "top"_ostr)
               .toInt32();
-    // sal_Int32 nPara1Top
-    //     = getXPath(pDump, "//tab/row[2]/cell[2]/txt/infos/bounds"_ostr, 
"top"_ostr).toInt32();
-    sal_Int32 nCellTop
-        = getXPath(pDump, "//tab/row[2]/cell[2]/infos/bounds"_ostr, 
"top"_ostr).toInt32();
-    // The image is limited by the cell boundaries (should be limited to cell 
margin actually)
-    CPPUNIT_ASSERT(nCellTop <= nShapeTop);
-    // CPPUNIT_ASSERT_EQUAL(nPara1Top, nShapeTop); // tdf#162539
+    sal_Int32 nPara1Top
+        = getXPath(pDump, "//tab/row[2]/cell[2]/txt/infos/bounds"_ostr, 
"top"_ostr).toInt32();
+    // The image is limited by the cell margin
+    CPPUNIT_ASSERT_EQUAL(nPara1Top, nShapeTop); // tdf#162539
 
     // since in fact layoutInCell is supposed to be applied, we mark (and 
export) as layoutInCell
     CPPUNIT_ASSERT(getProperty<bool>(getShape(1), 
u"IsFollowingTextFlow"_ustr));
diff --git a/sw/source/core/objectpositioning/anchoredobjectposition.cxx 
b/sw/source/core/objectpositioning/anchoredobjectposition.cxx
index 9d61d9cd3054..11f14c3a41a3 100644
--- a/sw/source/core/objectpositioning/anchoredobjectposition.cxx
+++ b/sw/source/core/objectpositioning/anchoredobjectposition.cxx
@@ -37,6 +37,7 @@
 #include <IDocumentSettingAccess.hxx>
 #include <textboxhelper.hxx>
 #include <fmtsrnd.hxx>
+#include <rowfrm.hxx>
 #include <osl/diagnose.h>
 
 using namespace ::com::sun::star;
@@ -456,9 +457,17 @@ SwTwips SwAnchoredObjectPosition::ImplAdjustVertRelPos( 
const SwTwips nTopOfAnch
     // to its environment (e.g. page header/footer).
     SwRect aPgAlignArea;
     {
+        const IDocumentSettingAccess& rIDSA = 
mpFrameFormat->getIDocumentSettingAccess();
+        const bool bMSOLayout = 
rIDSA.get(DocumentSettingId::CONSIDER_WRAP_ON_OBJECT_POSITION);
+        const SwFormatSurround& rSurround = mpFrameFormat->GetSurround();
+        bool bWrapThrough = rSurround.GetSurround() == 
css::text::WrapTextMode_THROUGH;
+        // If the frame format is a TextBox of a draw shape, then use the
+        // surround of the original shape.
+        SwTextBoxHelper::getShapeWrapThrough(mpFrameFormat, bWrapThrough);
+
         // #i26945# - no extension of restricted area, if
         // object's attribute follow text flow is set and its inside a table
-        if ( 
GetFrameFormat().getIDocumentSettingAccess().get(DocumentSettingId::CONSIDER_WRAP_ON_OBJECT_POSITION)
 &&
+        if (bMSOLayout &&
              ( !bFollowTextFlow ||
                !GetAnchoredObj().GetAnchorFrame()->IsInTab() ) )
         {
@@ -467,6 +476,17 @@ SwTwips SwAnchoredObjectPosition::ImplAdjustVertRelPos( 
const SwTwips nTopOfAnch
         else
         {
             aPgAlignArea = rPageAlignLayFrame.getFrameArea();
+
+            // When Microsoft follows text flow,
+            // it prevents vertical movement beyond the cell margin (unless 
wrap-through).
+            // Don't touch bVert to avoid issues: who knows what should happen 
in that case
+            if (bMSOLayout && bFollowTextFlow && 
rPageAlignLayFrame.IsCellFrame() && !bWrapThrough
+                && !bVert)
+            {
+                const auto pRow = 
const_cast<SwFrame&>(rPageAlignLayFrame).FindRowFrame();
+                assert(pRow);
+                aPgAlignArea.AddTop(pRow->GetTopMarginForLowers()); //reduces 
size and lowers
+            }
         }
     }
 

Reply via email to