sw/qa/filter/ww8/ww8.cxx               |   31 +++++++++++++++++++++++++++++++
 sw/source/filter/ww8/docxsdrexport.cxx |    9 +++++++++
 2 files changed, 40 insertions(+)

New commits:
commit 8d0acd88214180f93cd09730baa1ed9a8169e987
Author:     Miklos Vajna <vmik...@collabora.com>
AuthorDate: Tue Apr 25 20:04:24 2023 +0200
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Wed Apr 26 08:03:22 2023 +0200

    tdf#154855 DOCX export: fix <wp:anchor layoutInCell="1"> with <wp:wrapNone>
    
    The bugdoc has a table where shapes are anchored in cells. The wrap type
    is set to "none" ("in front of text" in Word UI terms) and the follow
    text flow ("layout in table ell" in Word UI terms) option is enabled.
    The import into Writer is fine, but saving back to DOCX and checking in
    Word is not: all shapes move to the left cells.
    
    What happens is that since commit
    e993638d5ecd33783f2eebdccfa87a81e5a8a2c5 (DOCX import: fix <wp:anchor
    layoutInCell="1"> with <wp:wrapNone>, 2022-01-24), we ignore
    layoutInCell in case wrapNone is used with a suitable horizontal
    relation orient, since Word doesn't capture anchored shapes inside the
    cells in practice in that case. This helps for the old bugdoc, but
    introduces the problem that we now lose the layoutInCell
    setting on export, which is not wanted.
    
    Fix the problem by leaving the import and the layout unchanged, but do
    the opposite mapping on export: if we have the relevant wrap and
    horizontal relation orient case, then enable layoutInCell, even if the
    doc model doesn't have it.
    
    Note that Word itself behaves inconsistently here: if you change the
    vertical offset of one of these shapes to position the shapes outside
    the cell, Word does it, even if "layout in cell" is enabled.
    
    Change-Id: I980a995d76afdee4716f7669081c688065427ee8
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/151000
    Tested-by: Jenkins
    Reviewed-by: Miklos Vajna <vmik...@collabora.com>

diff --git a/sw/qa/filter/ww8/ww8.cxx b/sw/qa/filter/ww8/ww8.cxx
index f965d2cdae63..b732a37eff40 100644
--- a/sw/qa/filter/ww8/ww8.cxx
+++ b/sw/qa/filter/ww8/ww8.cxx
@@ -10,7 +10,9 @@
 #include <swmodeltestbase.hxx>
 
 #include <com/sun/star/awt/CharSet.hpp>
+#include <com/sun/star/drawing/XDrawPageSupplier.hpp>
 #include <com/sun/star/text/XTextDocument.hpp>
+#include <com/sun/star/text/WrapTextMode.hpp>
 
 #include <docsh.hxx>
 #include <formatcontentcontrol.hxx>
@@ -247,6 +249,35 @@ CPPUNIT_TEST_FIXTURE(Test, testDocFloatingTableImport)
     // split between page 1 and page 2.
     CPPUNIT_ASSERT(pPage1->GetNext());
 }
+
+CPPUNIT_TEST_FIXTURE(Test, testWrapThroughLayoutInCell)
+{
+    // Given a document with a shape, "keep inside text boundaries" is off, 
wrap type is set to
+    // "through":
+    createSwDoc();
+    uno::Reference<css::lang::XMultiServiceFactory> xFactory(mxComponent, 
uno::UNO_QUERY);
+    uno::Reference<drawing::XShape> xShape(
+        xFactory->createInstance("com.sun.star.drawing.RectangleShape"), 
uno::UNO_QUERY);
+    xShape->setSize(awt::Size(10000, 10000));
+    uno::Reference<beans::XPropertySet> xShapeProps(xShape, uno::UNO_QUERY);
+    xShapeProps->setPropertyValue("AnchorType", 
uno::Any(text::TextContentAnchorType_AT_CHARACTER));
+    xShapeProps->setPropertyValue("Surround", 
uno::Any(text::WrapTextMode_THROUGH));
+    xShapeProps->setPropertyValue("HoriOrientRelation", 
uno::Any(text::RelOrientation::FRAME));
+    uno::Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(mxComponent, 
uno::UNO_QUERY);
+    xDrawPageSupplier->getDrawPage()->add(xShape);
+
+    // When saving to docx:
+    save("Office Open XML Text");
+
+    // Then make sure that layoutInCell is undoing the effect of the 
import-time tweak:
+    xmlDocUniquePtr pXmlDoc = parseExport("word/document.xml");
+    // Without the accompanying fix in place, this test would have failed with:
+    // - Expected: 1
+    // - Actual  : 0
+    // - attribute 'layoutInCell' of '//wp:anchor' incorrect value.
+    // i.e. layoutInCell was disabled, leading to bad layout in Word.
+    assertXPath(pXmlDoc, "//wp:anchor", "layoutInCell", "1");
+}
 }
 
 CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/sw/source/filter/ww8/docxsdrexport.cxx 
b/sw/source/filter/ww8/docxsdrexport.cxx
index fa6cd25bbb7e..4b3e53196a29 100644
--- a/sw/source/filter/ww8/docxsdrexport.cxx
+++ b/sw/source/filter/ww8/docxsdrexport.cxx
@@ -870,6 +870,15 @@ void DocxSdrExport::startDMLAnchorInline(const 
SwFrameFormat* pFrameFormat, cons
             if (xShapeProps.is())
                 xShapeProps->getPropertyValue("IsFollowingTextFlow") >>= 
bLclInTabCell;
         }
+
+        if (pFrameFormat->GetSurround().GetValue() == 
text::WrapTextMode_THROUGH
+            && pFrameFormat->GetHoriOrient().GetRelationOrient() == 
text::RelOrientation::FRAME)
+        {
+            // "In front of text" and horizontal positioning relative to 
Column is ignored on
+            // import, add it back here.
+            bLclInTabCell = true;
+        }
+
         if (bLclInTabCell)
             attrList->add(XML_layoutInCell, "1");
         else

Reply via email to