Kaydet (Commit) 95b4f258 authored tarafından Miklos Vajna's avatar Miklos Vajna

DOCX import: improve table style handling wrt. cell borders

The symptom was that some cell borders were missing. It's because in
Word, cell borders are additions to table borders, so if a table border
is single, but the cell border is none, then the outcome should be
single, not none. In Writer, this is a single UNO property, so if it's
set to SOLID then to NONE, the latter wins.

There are two situations where we now do the right thing:

1) style-cell-border is set, direct-cell-border is none -> outcome is
now inheriting (style-table-border, direct-table-border, etc.)

2) style-cell-border is none, direct-cell-border is none, but
direct-table-border is set -> outcome is now direct-table-border.

Change-Id: I320ae908c61221c8020e3b5323c31dec11c15b2f
üst 8f539e3f
......@@ -378,6 +378,21 @@ DECLARE_OOXMLEXPORT_TEST(testTableStyleCellBackColor, "table-style-cell-back-col
CPPUNIT_ASSERT_EQUAL(sal_Int32(0x00ff00), getProperty<sal_Int32>(xCell, "BackColor"));
}
DECLARE_OOXMLEXPORT_TEST(testTableStyleBorder, "table-style-border.docx")
{
uno::Reference<text::XTextTablesSupplier> xTextTablesSupplier(mxComponent, uno::UNO_QUERY);
uno::Reference<container::XIndexAccess> xTables(xTextTablesSupplier->getTextTables(), uno::UNO_QUERY);
uno::Reference<text::XTextTable> xTable(xTables->getByIndex(0), uno::UNO_QUERY);
// This was 0, the second cell was missing its right border.
uno::Reference<table::XCell> xCell = xTable->getCellByName("A2");
CPPUNIT_ASSERT(getProperty<table::BorderLine2>(xCell, "RightBorder").LineWidth > 0);
// This was also 0 (even after fixing the previous problem), the first cell was missing its right border, too.
xCell = xTable->getCellByName("A1");
CPPUNIT_ASSERT(getProperty<table::BorderLine2>(xCell, "RightBorder").LineWidth > 0);
}
CPPUNIT_PLUGIN_IMPLEMENT();
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
......@@ -24,6 +24,7 @@
#include <com/sun/star/table/TableBorderDistances.hpp>
#include <com/sun/star/table/TableBorder.hpp>
#include <com/sun/star/table/BorderLine2.hpp>
#include <com/sun/star/table/BorderLineStyle.hpp>
#include <com/sun/star/table/XCellRange.hpp>
#include <com/sun/star/text/HoriOrientation.hpp>
#include <com/sun/star/text/RelOrientation.hpp>
......@@ -714,6 +715,47 @@ CellPropertyValuesSeq_t DomainMapperTableHandler::endTableGetCellProperties(Tabl
if ( rInfo.pTableStyle )
{
PropertyMapPtr pStyleProps = rInfo.pTableStyle->GetProperties( nCnfStyleMask );
// Check if we need to clean up some empty border definitions to match what Word does.
static const PropertyIds pBorders[] =
{
PROP_TOP_BORDER, PROP_LEFT_BORDER, PROP_BOTTOM_BORDER, PROP_RIGHT_BORDER
};
for (size_t i = 0; i < SAL_N_ELEMENTS(pBorders); ++i)
{
boost::optional<PropertyMap::Property> oStyleCellBorder = pStyleProps->getProperty(pBorders[i]);
boost::optional<PropertyMap::Property> oDirectCellBorder = (*aCellIterator)->getProperty(pBorders[i]);
if (oStyleCellBorder && oDirectCellBorder)
{
// We have a cell border from the table style and as direct formatting as well.
table::BorderLine2 aStyleCellBorder = oStyleCellBorder->second.get<table::BorderLine2>();
table::BorderLine2 aDirectCellBorder = oDirectCellBorder->second.get<table::BorderLine2>();
if (aStyleCellBorder.LineStyle != table::BorderLineStyle::NONE && aDirectCellBorder.LineStyle == table::BorderLineStyle::NONE)
{
// The style one would be visible, but then cleared away as direct formatting.
// Delete both, so that table formatting can become visible.
pStyleProps->Erase(pBorders[i]);
(*aCellIterator)->Erase(pBorders[i]);
}
else
{
boost::optional<PropertyMap::Property> oTableBorder = rInfo.pTableBorders->getProperty(pBorders[i]);
if (oTableBorder)
{
table::BorderLine2 aTableBorder = oTableBorder->second.get<table::BorderLine2>();
// Both style and direct formatting says that the cell has no border.
bool bNoCellBorder = aStyleCellBorder.LineStyle == table::BorderLineStyle::NONE && aDirectCellBorder.LineStyle == table::BorderLineStyle::NONE;
if (aTableBorder.LineStyle != table::BorderLineStyle::NONE && bNoCellBorder)
{
// But at a table-level, there is a border, then again delete both cell properties.
pStyleProps->Erase(pBorders[i]);
(*aCellIterator)->Erase(pBorders[i]);
}
}
}
}
}
pAllCellProps->InsertProps( pStyleProps );
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment