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
1001dbaef4 (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 <vmiklos@collabora.com>
This commit is contained in:
Miklos Vajna 2023-08-22 19:51:37 +02:00
parent 1530584a72
commit 7c15750cec
5 changed files with 147 additions and 0 deletions

View file

@ -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:

View file

@ -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 \

Binary file not shown.

61
sw/qa/filter/xml/xml.cxx Normal file
View file

@ -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: */

View file

@ -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)