sw/qa/extras/ooxmlexport/data/table-style-border.docx |binary sw/qa/extras/ooxmlexport/ooxmlexport.cxx | 15 +++++ writerfilter/source/dmapper/DomainMapperTableHandler.cxx | 42 +++++++++++++++ 3 files changed, 57 insertions(+)
New commits: commit 95b4f258c439575f0ace02e1672ebd748d832616 Author: Miklos Vajna <vmik...@collabora.co.uk> Date: Fri Oct 3 15:42:30 2014 +0200 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 diff --git a/sw/qa/extras/ooxmlexport/data/table-style-border.docx b/sw/qa/extras/ooxmlexport/data/table-style-border.docx new file mode 100644 index 0000000..ceb0bd8 Binary files /dev/null and b/sw/qa/extras/ooxmlexport/data/table-style-border.docx differ diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport.cxx index 19ea3a1..c35b404 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport.cxx @@ -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: */ diff --git a/writerfilter/source/dmapper/DomainMapperTableHandler.cxx b/writerfilter/source/dmapper/DomainMapperTableHandler.cxx index 0287adf..3fc80f8 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 ); } _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits