summaryrefslogtreecommitdiff
path: root/writerfilter
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.co.uk>2014-10-03 15:42:30 +0200
committerMiklos Vajna <vmiklos@collabora.co.uk>2014-10-03 16:24:57 +0200
commit95b4f258c439575f0ace02e1672ebd748d832616 (patch)
treec7859b1659824ac732988c0dbd6a949bdf8ca5cd /writerfilter
parent8f539e3f711d6253e65180f6c0f9567e5247a322 (diff)
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
Diffstat (limited to 'writerfilter')
-rw-r--r--writerfilter/source/dmapper/DomainMapperTableHandler.cxx42
1 files changed, 42 insertions, 0 deletions
diff --git a/writerfilter/source/dmapper/DomainMapperTableHandler.cxx b/writerfilter/source/dmapper/DomainMapperTableHandler.cxx
index 0287adf12479..3fc80f8546ed 100644
--- a/writerfilter/source/dmapper/DomainMapperTableHandler.cxx
+++ b/writerfilter/source/dmapper/DomainMapperTableHandler.cxx
@@ -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 );
}