sw/CppunitTest_sw_filter_xml.mk                   |   76 ++++++++++++++++++++++
 sw/Module_sw.mk                                   |    1 
 sw/qa/filter/xml/data/covered-cell-background.odt |binary
 sw/qa/filter/xml/xml.cxx                          |   61 +++++++++++++++++
 sw/source/filter/xml/xmltbli.cxx                  |    9 ++
 5 files changed, 147 insertions(+)

New commits:
commit 7ed4404a38b477bdec9c1eb463fc216dc025a881
Author:     Miklos Vajna <vmik...@collabora.com>
AuthorDate: Tue Aug 22 19:51:37 2023 +0200
Commit:     Xisco Fauli <xiscofa...@libreoffice.org>
CommitDate: Wed Aug 23 12:16:30 2023 +0200

    tdf#155510 ODT import: ignore props of covered table cells, unless in comp 
mode
    
    The problem was that the A5 cell on page 2 used to have a solid
    background, but this was lost after commit
    1001dbaef4dec2b51c25ed8343bab6910f1219e1 (ODT import: handle style name
    of covered cells, 2021-03-19).
    
    Covered cell formatting was interesting for cell borders, in Word compat
    mode the covered cell can have its own border style, so e.g. there is
    left border on a vertically merged cell till its center, but not after
    its center.
    
    Fix the problem by limiting the import of covered cell formatting to the
    case when the TABLE_ROW_KEEP compat flag is on, to keep both native ODT
    and ODT-from-Word documents happy.
    
    If there is a need, some smarter way of merging properties could be
    implemented in the future.
    
    Change-Id: Icc1e6f48d9f5a0379d9a9052a1f5b9ae3f294477
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/155957
    Tested-by: Jenkins
    Reviewed-by: Miklos Vajna <vmik...@collabora.com>
    (cherry picked from commit 7c15750cecea2aeb05653c0ee67b933d969b1f0b)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/155922
    Reviewed-by: Michael Stahl <michael.st...@allotropia.de>

diff --git a/sw/CppunitTest_sw_filter_xml.mk b/sw/CppunitTest_sw_filter_xml.mk
new file mode 100644
index 000000000000..5833d58c53a1
--- /dev/null
+++ b/sw/CppunitTest_sw_filter_xml.mk
@@ -0,0 +1,76 @@
+# -*- 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 gb_CppunitTest_CppunitTest,sw_filter_xml))
+
+$(eval $(call gb_CppunitTest_use_common_precompiled_header,sw_filter_xml))
+
+$(eval $(call gb_CppunitTest_add_exception_objects,sw_filter_xml, \
+    sw/qa/filter/xml/xml \
+))
+
+$(eval $(call gb_CppunitTest_use_libraries,sw_filter_xml, \
+    comphelper \
+    cppu \
+    cppuhelper \
+    editeng \
+    sal \
+    sfx \
+    subsequenttest \
+    svl \
+    svx \
+    svxcore \
+    sw \
+    swqahelper \
+    test \
+    unotest \
+    utl \
+    vcl \
+    tl \
+))
+
+$(eval $(call gb_CppunitTest_use_externals,sw_filter_xml,\
+    boost_headers \
+    libxml2 \
+))
+
+$(eval $(call gb_CppunitTest_set_include,sw_filter_xml,\
+    -I$(SRCDIR)/sw/inc \
+    -I$(SRCDIR)/sw/source/core/inc \
+    -I$(SRCDIR)/sw/source/uibase/inc \
+    -I$(SRCDIR)/sw/qa/inc \
+    $$(INCLUDE) \
+))
+
+$(eval $(call gb_CppunitTest_use_api,sw_filter_xml,\
+       udkapi \
+       offapi \
+       oovbaapi \
+))
+
+$(eval $(call gb_CppunitTest_use_ure,sw_filter_xml))
+$(eval $(call gb_CppunitTest_use_vcl,sw_filter_xml))
+
+$(eval $(call gb_CppunitTest_use_rdb,sw_filter_xml,services))
+
+$(eval $(call gb_CppunitTest_use_custom_headers,sw_filter_xml,\
+    officecfg/registry \
+))
+
+$(eval $(call gb_CppunitTest_use_configuration,sw_filter_xml))
+
+$(eval $(call gb_CppunitTest_use_uiconfigs,sw_filter_xml, \
+    modules/swriter \
+))
+
+$(eval $(call gb_CppunitTest_use_more_fonts,sw_filter_xml))
+
+# vim: set noet sw=4 ts=4:
diff --git a/sw/Module_sw.mk b/sw/Module_sw.mk
index 2a9cc7233d63..5be870597a2c 100644
--- a/sw/Module_sw.mk
+++ b/sw/Module_sw.mk
@@ -159,6 +159,7 @@ $(eval $(call gb_Module_add_slowcheck_targets,sw,\
     CppunitTest_sw_core_attr \
     CppunitTest_sw_filter_ww8 \
     CppunitTest_sw_filter_html \
+    CppunitTest_sw_filter_xml \
     CppunitTest_sw_a11y \
     CppunitTest_sw_core_theme \
     CppunitTest_sw_pdf_test \
diff --git a/sw/qa/filter/xml/data/covered-cell-background.odt 
b/sw/qa/filter/xml/data/covered-cell-background.odt
new file mode 100644
index 000000000000..99b77630a00d
Binary files /dev/null and b/sw/qa/filter/xml/data/covered-cell-background.odt 
differ
diff --git a/sw/qa/filter/xml/xml.cxx b/sw/qa/filter/xml/xml.cxx
new file mode 100644
index 000000000000..a0a21f5f4335
--- /dev/null
+++ b/sw/qa/filter/xml/xml.cxx
@@ -0,0 +1,61 @@
+/* -*- 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 <frameformats.hxx>
+#include <frmatr.hxx>
+#include <swtable.hxx>
+
+namespace
+{
+/**
+ * Covers sw/source/filter/xml/ fixes.
+ *
+ * Note that these tests are meant to be simple: either load a file and assert 
some result or build
+ * a document model with code, export and assert that result.
+ *
+ * Keep using the various sw_<format>import/export suites for multiple filter 
calls inside a single
+ * test.
+ */
+class Test : public SwModelTestBase
+{
+public:
+    Test()
+        : SwModelTestBase("/sw/qa/filter/xml/data/", "writer8")
+    {
+    }
+};
+
+CPPUNIT_TEST_FIXTURE(Test, testCoveredCellBackground)
+{
+    // Given a document with a table with vertically merged cells, with a 
solid background:
+    createSwDoc("covered-cell-background.odt");
+
+    // When checking the background of the last row's first covered table cell:
+    SwDoc* pDoc = getSwDoc();
+    const SwTableFormat* pTableFormat = (*pDoc->GetTableFrameFormats())[0];
+    SwTable* pTable = SwTable::FindTable(pTableFormat);
+    SwTableBox* pBox = const_cast<SwTableBox*>(pTable->GetTableBox("A5"));
+    SwFrameFormat* pCellFormat = pBox->GetFrameFormat();
+    const SvxBrushItem& rBackground = 
pCellFormat->GetAttrSet().GetBackground();
+
+    // Then make sure the covered cell has a solid background, just like other 
cells in the first
+    // column:
+    // Without the accompanying fix in place, this test would have failed with:
+    // - Expected: rgba[e8f2a1ff]
+    // - Actual  : rgba[ffffff00]
+    // i.e. part of the merged cell had a bad white background.
+    CPPUNIT_ASSERT_EQUAL(Color(0xe8f2a1), rBackground.GetColor());
+}
+}
+
+CPPUNIT_PLUGIN_IMPLEMENT();
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/filter/xml/xmltbli.cxx b/sw/source/filter/xml/xmltbli.cxx
index 7ed118565476..9578b45cdfe7 100644
--- a/sw/source/filter/xml/xmltbli.cxx
+++ b/sw/source/filter/xml/xmltbli.cxx
@@ -66,6 +66,7 @@
 #include <ndtxt.hxx>
 #include <unotextcursor.hxx>
 #include <SwStyleNameMapper.hxx>
+#include <IDocumentSettingAccess.hxx>
 
 #include <algorithm>
 #include <vector>
@@ -1502,6 +1503,14 @@ void SwXMLTableContext::InsertCell( const OUString& 
rStyleName,
 
 void SwXMLTableContext::InsertCoveredCell(const OUString& rStyleName)
 {
+    const IDocumentSettingAccess& rIDSA = 
GetSwImport().getDoc()->getIDocumentSettingAccess();
+    bool bWordTableCell = rIDSA.get(DocumentSettingId::TABLE_ROW_KEEP);
+    if (!bWordTableCell)
+    {
+        // Compatibility flag not active, ignore formatting of covered cells.
+        return;
+    }
+
     SwXMLTableCell_Impl* pCell = GetCell(m_nCurRow, m_nNonMergedCurCol);
     ++m_nNonMergedCurCol;
     if (!pCell)

Reply via email to