writerfilter/CppunitTest_writerfilter_dmapper.mk                      |    1 
 writerfilter/qa/cppunittests/dmapper/DomainMapperTableManager.cxx     |   47 
++++++++++
 writerfilter/qa/cppunittests/dmapper/data/floattable-tbl-overlap.docx |binary
 writerfilter/source/dmapper/DomainMapperTableManager.cxx              |    6 +
 writerfilter/source/dmapper/TablePositionHandler.cxx                  |    6 +
 writerfilter/source/dmapper/TablePositionHandler.hxx                  |    3 
 6 files changed, 63 insertions(+)

New commits:
commit d3a0ff741f5a7ff0dcec301e5b34ee9d638acf98
Author:     Miklos Vajna <vmik...@collabora.com>
AuthorDate: Wed Aug 9 08:27:37 2023 +0200
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Wed Aug 9 09:35:00 2023 +0200

    sw floattable: import <w:tblOverlap w:val="never"> from DOCX
    
    The bugdoc has 2 floating tables, the second one is shifted down in
    Word, so it doesn't overlap, even if the positioning attributes would
    lay them out with an overlap.
    
    The bugdoc has <w:tblOverlap w:val="never"> set for the second table, we
    can import that to Writer's
    SwFormatWrapInfluenceOnObjPos::mbAllowOverlap, which was originally
    added for shapes.
    
    writerfilter/ only has access to the UNO API, so do this via the
    AllowOverlap text frame property.
    
    The layout is still missing for this, but now the doc model is correct.
    
    Change-Id: I25df9b75633c05af206b94ff0ad71bd240f393f5
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/155499
    Reviewed-by: Miklos Vajna <vmik...@collabora.com>
    Tested-by: Jenkins

diff --git a/writerfilter/CppunitTest_writerfilter_dmapper.mk 
b/writerfilter/CppunitTest_writerfilter_dmapper.mk
index 209a8e0d6bb8..21808b1d1ffd 100644
--- a/writerfilter/CppunitTest_writerfilter_dmapper.mk
+++ b/writerfilter/CppunitTest_writerfilter_dmapper.mk
@@ -18,6 +18,7 @@ $(eval $(call 
gb_CppunitTest_use_externals,writerfilter_dmapper,\
 $(eval $(call gb_CppunitTest_add_exception_objects,writerfilter_dmapper, \
     writerfilter/qa/cppunittests/dmapper/CellColorHandler \
     writerfilter/qa/cppunittests/dmapper/DomainMapperTableHandler \
+    writerfilter/qa/cppunittests/dmapper/DomainMapperTableManager \
     writerfilter/qa/cppunittests/dmapper/DomainMapper \
     writerfilter/qa/cppunittests/dmapper/DomainMapper_Impl \
     writerfilter/qa/cppunittests/dmapper/GraphicImport \
diff --git a/writerfilter/qa/cppunittests/dmapper/DomainMapperTableManager.cxx 
b/writerfilter/qa/cppunittests/dmapper/DomainMapperTableManager.cxx
new file mode 100644
index 000000000000..88b36379a2c1
--- /dev/null
+++ b/writerfilter/qa/cppunittests/dmapper/DomainMapperTableManager.cxx
@@ -0,0 +1,47 @@
+/* -*- 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 <test/unoapi_test.hxx>
+
+#include <com/sun/star/beans/XPropertySet.hpp>
+#include <com/sun/star/text/XTextFramesSupplier.hpp>
+
+using namespace ::com::sun::star;
+
+namespace
+{
+/// Tests for writerfilter/source/dmapper/DomainMapperTableManager.cxx.
+class Test : public UnoApiTest
+{
+public:
+    Test()
+        : UnoApiTest("/writerfilter/qa/cppunittests/dmapper/data/")
+    {
+    }
+};
+
+CPPUNIT_TEST_FIXTURE(Test, testTblOverlap)
+{
+    // Given a document with 2 floating tables, the second is not allowed to 
overlap:
+    // When importing that document:
+    loadFromURL(u"floattable-tbl-overlap.docx");
+
+    // Then make sure the second table is marked as "can't overlap":
+    uno::Reference<text::XTextFramesSupplier> xTextDocument(mxComponent, 
uno::UNO_QUERY);
+    uno::Reference<container::XIndexAccess> 
xFrames(xTextDocument->getTextFrames(), uno::UNO_QUERY);
+    uno::Reference<beans::XPropertySet> xFrame(xFrames->getByIndex(1), 
uno::UNO_QUERY);
+    bool bAllowOverlap{};
+    CPPUNIT_ASSERT(xFrame->getPropertyValue("AllowOverlap") >>= bAllowOverlap);
+    // Without the accompanying fix in place, this test would have failed, the 
tables were marked as
+    // "can overlap".
+    CPPUNIT_ASSERT(!bAllowOverlap);
+}
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git 
a/writerfilter/qa/cppunittests/dmapper/data/floattable-tbl-overlap.docx 
b/writerfilter/qa/cppunittests/dmapper/data/floattable-tbl-overlap.docx
new file mode 100644
index 000000000000..b5b23931a240
Binary files /dev/null and 
b/writerfilter/qa/cppunittests/dmapper/data/floattable-tbl-overlap.docx differ
diff --git a/writerfilter/source/dmapper/DomainMapperTableManager.cxx 
b/writerfilter/source/dmapper/DomainMapperTableManager.cxx
index 2c802d3ce2a9..2bbdfe86540e 100644
--- a/writerfilter/source/dmapper/DomainMapperTableManager.cxx
+++ b/writerfilter/source/dmapper/DomainMapperTableManager.cxx
@@ -348,6 +348,12 @@ bool DomainMapperTableManager::sprm(Sprm & rSprm)
                     }
                 }
                 break;
+            case NS_ooxml::LN_CT_TblPrBase_tblOverlap:
+                if (!m_aTmpPosition.empty() && m_aTmpPosition.back())
+                {
+                    m_aTmpPosition.back()->setTableOverlap(nIntValue);
+                }
+                break;
             case NS_ooxml::LN_CT_TrPrBase_gridBefore:
                 setCurrentGridBefore( nIntValue );
                 break;
diff --git a/writerfilter/source/dmapper/TablePositionHandler.cxx 
b/writerfilter/source/dmapper/TablePositionHandler.cxx
index 5eea4a00046e..62d423d29515 100644
--- a/writerfilter/source/dmapper/TablePositionHandler.cxx
+++ b/writerfilter/source/dmapper/TablePositionHandler.cxx
@@ -139,6 +139,12 @@ uno::Sequence<beans::PropertyValue> 
TablePositionHandler::getTablePosition() con
     aFrameProperties["VertOrientPosition"] <<= 
ConversionHelper::convertTwipToMM100(m_nY);
     aFrameProperties["FillTransparence"] <<= sal_Int32(100);
 
+    if (m_nTableOverlap == NS_ooxml::LN_Value_ST_TblOverlap_never)
+    {
+        // NS_ooxml::LN_Value_ST_TblOverlap_overlap is the default, both in 
OOXML and in Writer.
+        aFrameProperties["AllowOverlap"] <<= false;
+    }
+
     return aFrameProperties.getAsConstPropertyValueList();
 }
 
diff --git a/writerfilter/source/dmapper/TablePositionHandler.hxx 
b/writerfilter/source/dmapper/TablePositionHandler.hxx
index 23d042b69d2a..1b9d9c808391 100644
--- a/writerfilter/source/dmapper/TablePositionHandler.hxx
+++ b/writerfilter/source/dmapper/TablePositionHandler.hxx
@@ -30,6 +30,7 @@ class TablePositionHandler : public LoggedProperties
     sal_Int32 m_nRightFromText = 0;
     sal_Int32 m_nTopFromText = 0;
     sal_Int32 m_nBottomFromText = 0;
+    Id m_nTableOverlap = 0;
 
     // Properties
     void lcl_attribute(Id nId, Value& rVal) override;
@@ -48,6 +49,8 @@ public:
     const OUString& getHorzAnchor() const { return m_aHorzAnchor; }
     const OUString& getXSpec() const { return m_aXSpec; }
 
+    void setTableOverlap(Id nTableOverlap) { m_nTableOverlap = nTableOverlap; }
+
     TablePositionHandler();
     ~TablePositionHandler() override;
 

Reply via email to