sw/qa/extras/ww8export/data/tdf162541_notLayoutInCell_paraLeft.doc |binary
 sw/qa/extras/ww8export/ww8export4.cxx                              |   20 
++++++++++
 sw/source/filter/ww8/ww8graf.cxx                                   |   16 
++++----
 3 files changed, 29 insertions(+), 7 deletions(-)

New commits:
commit 34f04196575fd52bb117696df92177c3b7d2d190
Author:     Justin Luth <jl...@mail.com>
AuthorDate: Thu Aug 22 10:43:56 2024 -0400
Commit:     Justin Luth <jl...@mail.com>
CommitDate: Sat Aug 24 14:36:28 2024 +0200

    tdf#162541 doc import NOT-layoutInCell: hori-para => PAGE_PRINT_AREA
    
    If the fly is not layoutInCell,
    then MSO applies the para-orientation
    against the paragraph that contains the entire table,
    not the cell paragraph it is anchored to.
    
    For the horizontal case, this table-paragraph is equivalent
    to the page margin, so change it to a meaningful value.
    
    The vertical case cannot be meaningfully mapped to an equivalent,
    so someone will need to implement that in layout code.
    
    Wrap through has NOTHING to do with this.
    
    make CppunitTest_sw_ww8export4 CPPUNIT_TEST_NAME=testTdf162541
    
    Change-Id: I66212a9cda89e63e7b17daba0661a90f681fc0e3
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/172218
    Tested-by: Jenkins
    Reviewed-by: Justin Luth <jl...@mail.com>

diff --git a/sw/qa/extras/ww8export/data/tdf162541_notLayoutInCell_paraLeft.doc 
b/sw/qa/extras/ww8export/data/tdf162541_notLayoutInCell_paraLeft.doc
new file mode 100644
index 000000000000..2ce0cab293c2
Binary files /dev/null and 
b/sw/qa/extras/ww8export/data/tdf162541_notLayoutInCell_paraLeft.doc differ
diff --git a/sw/qa/extras/ww8export/ww8export4.cxx 
b/sw/qa/extras/ww8export/ww8export4.cxx
index 3e881a5114c2..007e7f70cac4 100644
--- a/sw/qa/extras/ww8export/ww8export4.cxx
+++ b/sw/qa/extras/ww8export/ww8export4.cxx
@@ -191,6 +191,26 @@ DECLARE_WW8EXPORT_TEST(testTdf91632_layoutInCellD, 
"tdf91632_layoutInCellD.doc")
     CPPUNIT_ASSERT(getProperty<bool>(xShape2, u"IsFollowingTextFlow"_ustr));
 }
 
+DECLARE_WW8EXPORT_TEST(testTdf162541, "tdf162541_notLayoutInCell_paraLeft.doc")
+{
+    // Note: this file looks very strange in MS Word. The image splits the 
table into two...
+
+    // given cell B2 with a para-left para-fromTop image that is NOT 
layoutInCell
+    xmlDocUniquePtr pDump = parseLayoutDump();
+    sal_Int32 nShapeLeft
+        = getXPath(pDump, 
"//tab/row[2]/cell[2]/txt/anchored/fly/SwAnchoredObject/bounds"_ostr,
+                   "left"_ostr)
+              .toInt32();
+    sal_Int32 nParaLeft
+        = getXPath(pDump, "//tab/row[2]/cell[2]/txt/infos/bounds"_ostr, 
"left"_ostr).toInt32();
+    sal_Int32 nTableLeft
+        = getXPath(pDump, "//tab/infos/bounds"_ostr, "left"_ostr).toInt32();
+    // The image uses the table-paragraph to orient to the left (bizarre MSO 
layout anomaly)
+    CPPUNIT_ASSERT(nShapeLeft < nParaLeft); // shape is located in column A, 
not column B
+    CPPUNIT_ASSERT_EQUAL(nTableLeft, nShapeLeft);
+    CPPUNIT_ASSERT(!getProperty<bool>(getShape(1), 
u"IsFollowingTextFlow"_ustr));
+}
+
 DECLARE_WW8EXPORT_TEST(testTdf162542, 
"tdf162542_notLayoutInCell_charLeft_wrapThrough.doc")
 {
     // given cell B2 with a char-oriented-left wrapThrough image that is NOT 
layoutInCell
diff --git a/sw/source/filter/ww8/ww8graf.cxx b/sw/source/filter/ww8/ww8graf.cxx
index 222685102019..9724ee3709d3 100644
--- a/sw/source/filter/ww8/ww8graf.cxx
+++ b/sw/source/filter/ww8/ww8graf.cxx
@@ -2463,7 +2463,9 @@ RndStdIds 
SwWW8ImplReader::ProcessEscherAlign(SvxMSDffImportRec& rRecord, WW8_FS
              && eHoriRel == text::RelOrientation::FRAME)
     {
         // relative left/right honors paragraph margins, but not with center 
or none/absolute offset
-        eHoriRel = text::RelOrientation::PRINT_AREA;
+
+        if (bIsObjectLayoutInTableCell || !m_nInTable)
+            eHoriRel = text::RelOrientation::PRINT_AREA;
     }
 
     // #i24255# - position of floating screen objects in
@@ -2481,12 +2483,12 @@ RndStdIds 
SwWW8ImplReader::ProcessEscherAlign(SvxMSDffImportRec& rRecord, WW8_FS
         }
     }
 
-    // if the object is anchored inside a table cell, is horizontal aligned
-    // at frame and has wrap through, but its attribute
-    // 'layout in table cell' isn't set, convert its horizontal alignment to 
page text area.
-    if (!bIsObjectLayoutInTableCell && m_nInTable &&
-            (eHoriRel == text::RelOrientation::FRAME) &&
-            rFSPA.nwr == 3)
+    // if the object is anchored inside a table cell, is horizontally aligned 
to the paragraph,
+    // but it is not being forced to 'layout in table cell',
+    // then convert its horizontal alignment to page text area
+    // because MSO strangely doesn't orient the object to the cell paragraph 
it is anchored to
+    // but to the paragraph that contains the entire table (which is 
equivalent to page margins).
+    if (!bIsObjectLayoutInTableCell && m_nInTable && eHoriRel == 
text::RelOrientation::FRAME)
     {
         eHoriRel = text::RelOrientation::PAGE_PRINT_AREA;
     }

Reply via email to