sw/CppunitTest_sw_ooxmlexport21.mk                          |   14 +++
 sw/Module_sw.mk                                             |    1 
 sw/qa/extras/ooxmlexport/data/tdf153909_followTextFlow.docx |binary
 sw/qa/extras/ooxmlexport/ooxmlexport21.cxx                  |   50 ++++++++++++
 writerfilter/source/ooxml/OOXMLFastContextHandler.cxx       |   14 +++
 5 files changed, 78 insertions(+), 1 deletion(-)

New commits:
commit 15d19f48dc9eaf74d37b3da36a4bfc68be483547
Author:     Justin Luth <justin.l...@collabora.com>
AuthorDate: Fri Jan 19 13:50:36 2024 -0500
Commit:     Xisco Fauli <xiscofa...@libreoffice.org>
CommitDate: Mon Jan 22 22:19:58 2024 +0100

    tdf#153909 docx import: wrap through shapes shouldn't FollowTextFlow
    
    This resolves a NISZ 6.4.0 regression from
    commit 27d04f6dbf38aa28fb7215590d578c4567db5770
        tdf#119038 DOCX: fix FollowTextFlow handling
    
    MSO is all over the place in how they implement layoutInCell
    (aka FollowTextFlow in LO). There are lots of compat15 differences
    for this, but I don't notice compat coming into play with this bug.
    
    For reference, see commit e993638d5ecd33783f2eebdccfa87a81e5a8a2c5
    Author: Miklos Vajna on Mon Jan 24 12:53:25 2022 +0100
        DOCX import: fix <wp:anchor layoutInCell="1"> with <wp:wrapNone>
    
    I'm sure this is the WRONG code spot for handling FollowTextFlow,
    but anywhere else and we lose the "it came from a vml shape"
    limiting information, so I'm not going to try to relocate this code.
    
    Inline (as-character) shapes ignore layoutInCell,
    so the type of anchor (floating or inline) shouldn't matter
    and therefore doesn't need to be part of the if () clause.
    
    The header can be special (in compat14 it means everything
    is wrap through), but at least in this case it is not limited
    to IsInHeaderHeader. Using a non-header as the unit test.
    
    make CppunitTest_sw_ooxmlexport21 \
        CPPUNIT_TEST_NAME=testTdf153909_followTextFlow
    
    The first patchset contains a list of all of the unit tests
    that were impacted by this patch: nothing interesting.
    
    Change-Id: I0c4c7924833550533ad1b0b7609840a666d4d589
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/162324
    Reviewed-by: Justin Luth <jl...@mail.com>
    Tested-by: Jenkins
    (cherry picked from commit ad0266eb84eafa32ccc4e0ddf3c6392860bc9b13)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/162286
    Reviewed-by: Miklos Vajna <vmik...@collabora.com>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/162410
    Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org>

diff --git a/sw/CppunitTest_sw_ooxmlexport21.mk 
b/sw/CppunitTest_sw_ooxmlexport21.mk
new file mode 100644
index 000000000000..999314b9c6c4
--- /dev/null
+++ b/sw/CppunitTest_sw_ooxmlexport21.mk
@@ -0,0 +1,14 @@
+# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
+#*************************************************************************
+#
+# This file is part of the LibreOffice project.
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+#*************************************************************************
+
+$(eval $(call sw_ooxmlexport_test,21))
+
+# vim: set noet sw=4 ts=4:
diff --git a/sw/Module_sw.mk b/sw/Module_sw.mk
index 9b81a6f961fa..ab92e8d11571 100644
--- a/sw/Module_sw.mk
+++ b/sw/Module_sw.mk
@@ -94,6 +94,7 @@ $(eval $(call gb_Module_add_slowcheck_targets,sw,\
     CppunitTest_sw_ooxmlexport17 \
     CppunitTest_sw_ooxmlexport18 \
     CppunitTest_sw_ooxmlexport19 \
+    CppunitTest_sw_ooxmlexport21 \
     CppunitTest_sw_ooxmlexport_template \
     CppunitTest_sw_ooxmlfieldexport \
     CppunitTest_sw_ooxmllinks \
diff --git a/sw/qa/extras/ooxmlexport/data/tdf153909_followTextFlow.docx 
b/sw/qa/extras/ooxmlexport/data/tdf153909_followTextFlow.docx
new file mode 100644
index 000000000000..712e37aceabd
Binary files /dev/null and 
b/sw/qa/extras/ooxmlexport/data/tdf153909_followTextFlow.docx differ
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport21.cxx 
b/sw/qa/extras/ooxmlexport/ooxmlexport21.cxx
new file mode 100644
index 000000000000..9f6de0d155d5
--- /dev/null
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport21.cxx
@@ -0,0 +1,50 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include <swmodeltestbase.hxx>
+
+#include <com/sun/star/beans/XPropertyState.hpp>
+#include <com/sun/star/text/XDocumentIndex.hpp>
+#include <com/sun/star/text/XTextTable.hpp>
+#include <com/sun/star/style/LineSpacing.hpp>
+#include <com/sun/star/style/LineSpacingMode.hpp>
+
+#include <pam.hxx>
+#include <unotxdoc.hxx>
+#include <docsh.hxx>
+
+namespace
+{
+class Test : public SwModelTestBase
+{
+public:
+    Test()
+        : SwModelTestBase("/sw/qa/extras/ooxmlexport/data/", "Office Open XML 
Text")
+    {
+    }
+};
+
+DECLARE_OOXMLEXPORT_TEST(testTdf153909_followTextFlow, 
"tdf153909_followTextFlow.docx")
+{
+    // Although MSO's UI reports "layoutInCell" for the rectangle, it isn't 
specified or honored
+    CPPUNIT_ASSERT(!getProperty<bool>(getShape(1), "IsFollowingTextFlow"));
+
+    // 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", 
"bottom").toInt32();
+    sal_Int32 nTableTop = getXPath(pDump, "//tab/row/infos/bounds", 
"top").toInt32();
+    // The entire table must be below the rectangle
+    CPPUNIT_ASSERT(nTableTop > nRectBottom);
+}
+
+} // end of anonymous namespace
+CPPUNIT_PLUGIN_IMPLEMENT();
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/writerfilter/source/ooxml/OOXMLFastContextHandler.cxx 
b/writerfilter/source/ooxml/OOXMLFastContextHandler.cxx
index a8b9dcb22a72..2f7076578270 100644
--- a/writerfilter/source/ooxml/OOXMLFastContextHandler.cxx
+++ b/writerfilter/source/ooxml/OOXMLFastContextHandler.cxx
@@ -1826,8 +1826,20 @@ void OOXMLFastContextHandlerShape::sendShape( Token_t 
Element )
     uno::Reference<beans::XPropertySet> xShapePropSet(xShape, uno::UNO_QUERY);
     if (mnTableDepth > 0 && xShapePropSet.is() && mbIsVMLfound) //if we had a 
table
     {
+        bool bForceShapeIntoCell = mbAllowInCell;
+        // According to tdf#153909 and GraphicImport's LN_shape handling,
+        // through-anchored shapes should not force the shape into the cell
+        if (bForceShapeIntoCell)
+        {
+            text::WrapTextMode nSurround = text::WrapTextMode_NONE;
+            xShapePropSet->getPropertyValue("Surround") >>= nSurround;
+            sal_Int32 nHoriRelation = -1;
+            xShapePropSet->getPropertyValue("HoriOrientRelation") >>= 
nHoriRelation;
+            bForceShapeIntoCell = (nSurround != text::WrapTextMode_THROUGH)
+                                   || (nHoriRelation != 
text::RelOrientation::FRAME);
+        }
         
xShapePropSet->setPropertyValue(dmapper::getPropertyName(dmapper::PROP_FOLLOW_TEXT_FLOW),
-                                        uno::Any(mbAllowInCell));
+                                        uno::Any(bForceShapeIntoCell));
     }
     // Notify the dmapper that the shape is ready to use
     if ( !bIsPicture )

Reply via email to