sw/qa/extras/ooxmlexport/data/tdf128646.docx |binary
 sw/qa/extras/ooxmlexport/ooxmlexport20.cxx   |   27 +++++++++++++++++++++++++++
 sw/qa/extras/ooxmlexport/ooxmlexport21.cxx   |   14 +++++++++++---
 sw/qa/writerfilter/dmapper/GraphicImport.cxx |   23 ++++++++++++++++++++---
 4 files changed, 58 insertions(+), 6 deletions(-)

New commits:
commit ce0429edab26e961c73af2d4bdf1516cca05205b
Author:     Justin Luth <jl...@mail.com>
AuthorDate: Mon Jul 29 19:26:47 2024 -0400
Commit:     Justin Luth <jl...@mail.com>
CommitDate: Thu Aug 8 02:54:42 2024 +0200

    tdf#162211 layoutInCell: clean-up unit tests and make some pre-emptive
    
    These unit tests look good with FollowTextFlow killed.
    Ensure the layout, so it still looks good
    when FollowTextFlow is restored.
    
    make CppunitTest_sw_writerfilter_dmapper \
        CPPUNIT_TEST_NAME=testLayoutInCellWrapnoneColumn
    
    make CppunitTest_sw_ooxmlexport20 CPPUNIT_TEST_NAME=testTdf128646
    I tweaked tdf128646.docx's distance of the "FROM TOP"
    to emphasize the problem (that Microsoft mistakenly
    maps "page" to cell margin instead of cell frame).
    
    Change-Id: Ie7f535e4cc516411c57d5658f2b5d146b0925e16
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/171094
    Tested-by: Jenkins
    Reviewed-by: Justin Luth <jl...@mail.com>

diff --git a/sw/qa/extras/ooxmlexport/data/tdf128646.docx 
b/sw/qa/extras/ooxmlexport/data/tdf128646.docx
index 9648df35a2f3..b15c1a979e0a 100644
Binary files a/sw/qa/extras/ooxmlexport/data/tdf128646.docx and 
b/sw/qa/extras/ooxmlexport/data/tdf128646.docx differ
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport20.cxx 
b/sw/qa/extras/ooxmlexport/ooxmlexport20.cxx
index fda93305cdc0..d7fb460f8b8f 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport20.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport20.cxx
@@ -235,6 +235,33 @@ CPPUNIT_TEST_FIXTURE(Test, testTdf128646)
         // This was hidden (<w:vanish/>)
         assertXPath(pXmlDoc, 
"/w:document/w:body/w:tbl/w:tr/w:tc/w:p[7]/w:r/w:rPr/w:vanish"_ostr,
                     "val"_ostr, u"false"_ustr);
+
+    // pre-emptive unit test - tdf#162211
+    // given a compat12 file with wrap-through DML shape anchored in cell as 
layoutInCell
+    auto xShape = getShapeByName(u"Kép 1");
+    CPPUNIT_ASSERT(getProperty<bool>(xShape, u"IsFollowingTextFlow"_ustr));
+    // the vertical offset has to be applied against the cell borders, not 
anchor paragraph (FRAME)
+    CPPUNIT_ASSERT_EQUAL(text::RelOrientation::PAGE_FRAME,
+                         getProperty<sal_Int16>(xShape, 
u"VertOrientRelation"_ustr));
+
+    // the shape is "from page top", which for layoutInCell is to be applied 
from cell top
+    xmlDocUniquePtr pDump = parseLayoutDump();
+    sal_Int32 nRectTop
+        = getXPath(pDump, 
"//cell/txt[5]/anchored[1]/fly/SwAnchoredObject/bounds"_ostr, "top"_ostr)
+              .toInt32();
+    sal_Int32 nTableTop = getXPath(pDump, "//tab/infos/bounds"_ostr, 
"top"_ostr).toInt32();
+    CPPUNIT_ASSERT(nRectTop > nTableTop); // higher numbers are farther down 
the document
+    // The shape's top should be ~ 1/4 of the way down the cell, which is 
above the anchor para top
+    sal_Int32 nPara5Top = getXPath(pDump, "//cell/txt[5]/infos/bounds"_ostr, 
"top"_ostr).toInt32();
+    CPPUNIT_ASSERT(nPara5Top > nRectTop);
+
+    // The image must not go past the end of the table (and proves we have the 
right shape)
+    sal_Int32 nTableRight = getXPath(pDump, "//tab/row/infos/bounds"_ostr, 
"right"_ostr).toInt32();
+    sal_Int32 nRectRight
+        = getXPath(pDump, 
"//cell/txt[5]/anchored[1]/fly/SwAnchoredObject/bounds"_ostr,
+                   "right"_ostr)
+              .toInt32();
+    CPPUNIT_ASSERT_EQUAL(nTableRight, nRectRight);
 }
 
 CPPUNIT_TEST_FIXTURE(Test, testTdf119800)
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport21.cxx 
b/sw/qa/extras/ooxmlexport/ooxmlexport21.cxx
index 0247edfbad87..60ae2f1ea9ea 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport21.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport21.cxx
@@ -511,7 +511,11 @@ DECLARE_OOXMLEXPORT_TEST(testTdf160049_anchorMargin15, 
"tdf160049_anchorMargin15
 DECLARE_OOXMLEXPORT_TEST(testTdf160077_layoutInCell, 
"tdf160077_layoutInCell.docx")
 {
     // given an in-table, slightly rotated image vertically aligned -1cm 
(above) the top page margin
-    // (which is actually forced to layoutInCell, so that becomes 1cm above 
the paragraph instead)
+    // (which is actually forced to layoutInCell, so that becomes 1cm above 
the cell margin instead)
+
+    // This document is particularly tricky. The image is in cell A1 with no 
special cell spacing
+    // (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
@@ -538,7 +542,10 @@ DECLARE_OOXMLEXPORT_TEST(testTdf160077_layoutInCell, 
"tdf160077_layoutInCell.doc
 DECLARE_OOXMLEXPORT_TEST(testTdf160077_layoutInCellB, 
"tdf160077_layoutInCellB.docx")
 {
     // given an in-table, group-shape vertically aligned -1.35 cm (above) the 
top page margin
-    // (which is actually forced to layoutInCell, so that turns into 1.35cm 
above the paragraph)
+    // (which is actually forced to layoutInCell, so that turns into 1.35cm 
above the cell margin)
+
+    // 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
@@ -553,10 +560,11 @@ DECLARE_OOXMLEXPORT_TEST(testTdf160077_layoutInCellB, 
"tdf160077_layoutInCellB.d
 
 DECLARE_OOXMLEXPORT_TEST(testTdf153909_followTextFlow, 
"tdf153909_followTextFlow.docx")
 {
+    // given a compat12 VML document with wrap-through blue rect that doesn't 
mention allowInCell
+
     // Although MSO's UI reports "layoutInCell" for the rectangle, it isn't 
specified or honored
     CPPUNIT_ASSERT(!getProperty<bool>(getShape(1), 
u"IsFollowingTextFlow"_ustr));
 
-    // Given a table with a rectangle anchored in it (wrap-through) that 
appears above the table...
     xmlDocUniquePtr pDump = parseLayoutDump();
     sal_Int32 nRectBottom
         = getXPath(pDump, "//anchored/SwAnchoredDrawObject/bounds"_ostr, 
"bottom"_ostr).toInt32();
diff --git a/sw/qa/writerfilter/dmapper/GraphicImport.cxx 
b/sw/qa/writerfilter/dmapper/GraphicImport.cxx
index 548f09b92da5..e3e79e8e9d9a 100644
--- a/sw/qa/writerfilter/dmapper/GraphicImport.cxx
+++ b/sw/qa/writerfilter/dmapper/GraphicImport.cxx
@@ -7,7 +7,7 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
  */
 
-#include <test/unoapi_test.hxx>
+#include <test/unoapixml_test.hxx>
 
 #include <com/sun/star/awt/Point.hpp>
 #include <com/sun/star/awt/Size.hpp>
@@ -19,6 +19,7 @@
 #include <com/sun/star/text/XTextViewCursorSupplier.hpp>
 #include <com/sun/star/view/XViewCursor.hpp>
 #include <com/sun/star/drawing/PointSequenceSequence.hpp>
+#include <com/sun/star/qa/XDumper.hpp>
 
 #include <basegfx/polygon/b2dpolypolygontools.hxx>
 #include <officecfg/Office/Common.hxx>
@@ -28,11 +29,11 @@ using namespace ::com::sun::star;
 namespace
 {
 /// Tests for sw/source/writerfilter/dmapper/GraphicImport.cxx.
-class Test : public UnoApiTest
+class Test : public UnoApiXmlTest
 {
 public:
     Test()
-        : UnoApiTest(u"/sw/qa/writerfilter/dmapper/data/"_ustr)
+        : UnoApiXmlTest(u"/sw/qa/writerfilter/dmapper/data/"_ustr)
     {
     }
 };
@@ -346,6 +347,22 @@ CPPUNIT_TEST_FIXTURE(Test, testLayoutInCellWrapnoneColumn)
     // to leave the cell, leading to incorrect layout.
     CPPUNIT_ASSERT(xShape->getPropertyValue(u"IsFollowingTextFlow"_ustr) >>= 
bFollowingTextFlow);
     CPPUNIT_ASSERT(!bFollowingTextFlow);
+
+    // dump the layout
+    uno::Reference<frame::XModel> xModel(mxComponent, uno::UNO_QUERY);
+    uno::Reference<qa::XDumper> xDumper(xModel->getCurrentController(), 
uno::UNO_QUERY);
+    const OString aDump = xDumper->dump(u"layout"_ustr).toUtf8();
+    auto pCharBuffer = reinterpret_cast<const xmlChar*>(aDump.getStr());
+    xmlDocUniquePtr pXmlDoc(xmlParseDoc(pCharBuffer));
+
+    // The entire blue, wrapthrough shape should be above the table that it is 
layoutInCell'd to.
+    const sal_Int32 nShapeBottom
+        = getXPath(pXmlDoc, 
"//tab/row/cell[2]/txt[1]/anchored/SwAnchoredDrawObject/bounds"_ostr,
+                   "bottom"_ostr)
+              .toInt32();
+    sal_Int32 nTableTop = getXPath(pXmlDoc, "//tab/row/infos/bounds"_ostr, 
"top"_ostr).toInt32();
+    // The entire table must be below the rectangle
+    CPPUNIT_ASSERT(nTableTop > nShapeBottom);
 }
 
 CPPUNIT_TEST_FIXTURE(Test, testLayoutInCellOfHraphics)

Reply via email to