sw/qa/extras/ooxmlexport/ooxmlexport21.cxx                         |   43 
++++------
 sw/source/core/objectpositioning/tocntntanchoredobjectposition.cxx |    9 ++
 2 files changed, 30 insertions(+), 22 deletions(-)

New commits:
commit 10bc43d6885a38ca4cccaf201df33ebea64736c3
Author:     Justin Luth <jl...@mail.com>
AuthorDate: Wed Aug 7 13:48:23 2024 -0400
Commit:     Justin Luth <jl...@mail.com>
CommitDate: Sat Aug 17 22:29:06 2024 +0200

    tdf#162211 tdf#160077 layoutInCell: use row margin for MSOLayout
    
    I think the bottom margin functions might be buggy,
    so I'm glad I don't need to use them
    (since MSO only does vertical layout against the top).
    
    This is only needed for "from top",
    because the only other choice, "top",
    is based on the print area, while this function
    uses GetFrameArea. GetFramePrintArea is invalid,
    so that can't be used directly.
    
    make CppunitTest_sw_ooxmlexport21 \
        CPPUNIT_TEST_NAME=testTdf160077_layoutInCell
    make CppunitTest_sw_ooxmlexport21 \
        CPPUNIT_TEST_NAME=testTdf160077_layoutInCellB
    
    Before this patch could pass sw.check,
    I had to fix the following unit test in a previous patch
    make CppunitTest_sw_layoutwriter2 CPPUNIT_TEST_NAME=testTdf116256
    
    Change-Id: Iac487b94c81ce44165356f447eb37964da1985ee
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/171507
    Tested-by: Jenkins
    Reviewed-by: Justin Luth <jl...@mail.com>

diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport21.cxx 
b/sw/qa/extras/ooxmlexport/ooxmlexport21.cxx
index 170e04f26c89..062e779386ae 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport21.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport21.cxx
@@ -517,19 +517,18 @@ DECLARE_OOXMLEXPORT_TEST(testTdf160077_layoutInCell, 
"tdf160077_layoutInCell.doc
     // (no top/bottom margins), but Cell A2 has a custom top margin of 2cm,
     // so that effectively drops A1's print area down as well!
 
-    // xmlDocUniquePtr pDump = parseLayoutDump();
-    // const sal_Int32 nCellTop
-    //     = getXPath(pDump, "//row[1]/cell[1]/infos/bounds"_ostr, 
"top"_ostr).toInt32();
-    // const sal_Int32 nParaTop
-    //     = getXPath(pDump, "//row[1]/cell[1]/txt/infos/bounds"_ostr, 
"top"_ostr).toInt32();
-    // const sal_Int32 nImageTop
-    //     = getXPath(pDump, 
"//row[1]/cell[1]/txt/anchored/SwAnchoredDrawObject/bounds"_ostr,
-    //                 "top"_ostr)
-    //             .toInt32();
-    // // The image is approximately half-way between cell top and the start 
of the text
-    // // correct ImageTop: 3588, while incorrect value was 1117. Cell top is 
3051, ParaTop is 4195
-    // const sal_Int32 nHalfway = nCellTop + (nParaTop - nCellTop) / 2;
-    // CPPUNIT_ASSERT_DOUBLES_EQUAL(nHalfway, nImageTop, 50); // +/- 4.4%
+    xmlDocUniquePtr pDump = parseLayoutDump();
+    const sal_Int32 nCellTop
+        = getXPath(pDump, "//row[1]/cell[1]/infos/bounds"_ostr, 
"top"_ostr).toInt32();
+    const sal_Int32 nImageTop
+        = getXPath(pDump, 
"//row[1]/cell[1]/txt/anchored/SwAnchoredDrawObject/bounds"_ostr,
+                   "top"_ostr)
+              .toInt32();
+    // The image should be 1 cm above the 2cm cell margin (thus 1cm below the 
top of the cell)
+    // 1cm is 567 twips. The numbers are not exactly what I would have 
expected, but close.
+    // correct ImageTop: ~ 3588, while incorrect value was 1117. Cell top is 
3051, ParaTop is 4195
+    const SwTwips n1cm = o3tl::convert(tools::Long(1), o3tl::Length::cm, 
o3tl::Length::twip);
+    CPPUNIT_ASSERT_DOUBLES_EQUAL(nCellTop + n1cm, nImageTop, 50); // +/- 4.4%
 
     CPPUNIT_ASSERT_EQUAL(css::text::RelOrientation::PAGE_PRINT_AREA,
                          getProperty<sal_Int16>(getShape(1), 
u"VertOrientRelation"_ustr));
@@ -545,15 +544,15 @@ DECLARE_OOXMLEXPORT_TEST(testTdf160077_layoutInCellB, 
"tdf160077_layoutInCellB.d
     // This unit test is virtually the same idea as the previous one, with the 
main benefit being
     // that it causes an NS_ooxml::LN_Shape exception.
 
-    // xmlDocUniquePtr pDump = parseLayoutDump();
-    // const sal_Int32 nShapeTop
-    //     = getXPath(pDump,
-    //                 
"//body/tab[1]/row[1]/cell[1]/txt[1]/anchored/SwAnchoredDrawObject/bounds"_ostr,
-    //                 "top"_ostr)
-    //             .toInt32();
-    // // The shape is approximately 1 cm below the top of the page, and 
~0.5cm above the cell
-    // // correct ShapeTop: 888 TWIPS, while incorrect value was -480. Cell 
top is 1148, PageTop is 284
-    // CPPUNIT_ASSERT_DOUBLES_EQUAL(888, nShapeTop, 50);
+    xmlDocUniquePtr pDump = parseLayoutDump();
+    const sal_Int32 nShapeTop
+        = getXPath(pDump,
+                   
"//body/tab[1]/row[1]/cell[1]/txt[1]/anchored/SwAnchoredDrawObject/bounds"_ostr,
+                   "top"_ostr)
+              .toInt32();
+    // The shape is approximately 1 cm below the top of the page, and ~0.5cm 
above the cell
+    // correct ShapeTop: 888 TWIPS, while incorrect value was -480. Cell top 
is 1148, PageTop is 284
+    CPPUNIT_ASSERT_DOUBLES_EQUAL(888, nShapeTop, 50);
 
     const auto& xShape = getShapeByName(u"Group 1");
     CPPUNIT_ASSERT_EQUAL(css::text::RelOrientation::PAGE_PRINT_AREA,
diff --git a/sw/source/core/objectpositioning/tocntntanchoredobjectposition.cxx 
b/sw/source/core/objectpositioning/tocntntanchoredobjectposition.cxx
index bc2f4ac608ad..710adff493eb 100644
--- a/sw/source/core/objectpositioning/tocntntanchoredobjectposition.cxx
+++ b/sw/source/core/objectpositioning/tocntntanchoredobjectposition.cxx
@@ -40,6 +40,7 @@
 #include <environmentofanchoredobject.hxx>
 #include <frmatr.hxx>
 #include <fmtwrapinfluenceonobjpos.hxx>
+#include <rowfrm.hxx>
 #include <sortedobjs.hxx>
 #include <textboxhelper.hxx>
 #include <flyfrms.hxx>
@@ -607,6 +608,14 @@ void SwToContentAnchoredObjectPosition::CalcPosition()
                     nVertOffsetToFrameAnchorPos += aRectFnSet.YDiff(
                                                 aRectFnSet.GetTop(aPgPrtRect),
                                                 nTopOfOrient );
+
+                    if (bMSOLayoutInCell && rPageAlignLayFrame.IsCellFrame())
+                    {
+                        // Cell upper/lower comes from the max margin of the 
entire row of cells
+                        const auto pRow = 
const_cast<SwLayoutFrame&>(rPageAlignLayFrame).FindRowFrame();
+                        assert(pRow);
+                        nVertOffsetToFrameAnchorPos += 
pRow->GetTopMarginForLowers();
+                    }
                 }
                 else if (aVert.GetRelationOrient() == 
text::RelOrientation::PAGE_PRINT_AREA_BOTTOM)
                 {

Reply via email to