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 + +#include +#include +#include + +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_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(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 #include #include +#include #include #include @@ -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)