From 8cc753d54ad1834709c5802115580adf65def89e Mon Sep 17 00:00:00 2001 From: Justin Luth Date: Fri, 17 Aug 2018 14:35:51 +0300 Subject: tdf#116436 docx export: add missing table background fill MS formats only have support for Table and Cell fill. Interestingly, MS Word doesn't let the cells inherit from the Table fill setting (even though LO docx import currently does), so that value also needs to be written out into every cell. Change-Id: Ib49fddf52758ff641428de747ea290d1fcb894f3 Reviewed-on: https://gerrit.libreoffice.org/59260 Reviewed-by: Justin Luth Tested-by: Justin Luth --- .../extras/ooxmlexport/data/tdf116436_rowFill.odt | Bin 0 -> 10835 bytes sw/qa/extras/ooxmlexport/ooxmlexport11.cxx | 9 +++++++ sw/qa/extras/ooxmlexport/ooxmlexport5.cxx | 7 ++++++ sw/source/filter/ww8/docxattributeoutput.cxx | 27 ++++++++++++++++++++- 4 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 sw/qa/extras/ooxmlexport/data/tdf116436_rowFill.odt diff --git a/sw/qa/extras/ooxmlexport/data/tdf116436_rowFill.odt b/sw/qa/extras/ooxmlexport/data/tdf116436_rowFill.odt new file mode 100644 index 000000000000..45f4a1c54b02 Binary files /dev/null and b/sw/qa/extras/ooxmlexport/data/tdf116436_rowFill.odt differ diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport11.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport11.cxx index aba24b3f2d57..6974cb776550 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport11.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport11.cxx @@ -51,6 +51,15 @@ DECLARE_OOXMLEXPORT_TEST(testTdf92524_autoColor, "tdf92524_autoColor.doc") CPPUNIT_ASSERT_EQUAL(COL_AUTO, Color(getProperty(getParagraph(1), "ParaBackColor"))); } +DECLARE_OOXMLEXPORT_TEST(testTdf116436_rowFill, "tdf116436_rowFill.odt") +{ + uno::Reference xTextTablesSupplier(mxComponent, uno::UNO_QUERY); + uno::Reference xTables(xTextTablesSupplier->getTextTables(), uno::UNO_QUERY); + uno::Reference xTable(xTables->getByIndex(0), uno::UNO_QUERY); + uno::Reference xCell = xTable->getCellByName("A1"); + CPPUNIT_ASSERT_EQUAL(sal_Int32(0xF8DF7C), getProperty(xCell, "BackColor")); +} + DECLARE_OOXMLEXPORT_TEST(testTdf46938_clearTabStop, "tdf46938_clearTabStop.docx") { // Number of tabstops should be zero, overriding the one in the style diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport5.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport5.cxx index e9b02ed948ef..eba875d4cbe3 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport5.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport5.cxx @@ -1070,6 +1070,13 @@ DECLARE_OOXMLEXPORT_TEST(testOO47778_2, "ooo47778-4.odt") { if (xmlDocPtr pXmlDoc = parseExport("word/document.xml")) assertXPathContent(pXmlDoc, "(//w:t)[4]", "c"); + + // tdf116436: The problem was that the table background was undefined, not white. + uno::Reference xTextTablesSupplier(mxComponent, uno::UNO_QUERY); + uno::Reference xTables(xTextTablesSupplier->getTextTables(), uno::UNO_QUERY); + uno::Reference xTable(xTables->getByIndex(0), uno::UNO_QUERY); + uno::Reference xCell = xTable->getCellByName("A1"); + CPPUNIT_ASSERT_EQUAL(sal_Int32(0xffffff), getProperty(xCell, "BackColor")); } DECLARE_OOXMLEXPORT_TEST(testOO67471, "ooo67471-2.odt") diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx b/sw/source/filter/ww8/docxattributeoutput.cxx index 3696f11070ef..00412096bbde 100644 --- a/sw/source/filter/ww8/docxattributeoutput.cxx +++ b/sw/source/filter/ww8/docxattributeoutput.cxx @@ -3749,6 +3749,18 @@ void DocxAttributeOutput::TableDefinition( ww8::WW8TableNodeInfoInner::Pointer_t FSNS( XML_w, XML_val ), pJcVal, FSEND ); + // Output the table background color (although cell value still needs to be specified) + const SvxBrushItem *pColorProp = pTableFormat->GetAttrSet().GetItem(RES_BACKGROUND); + Color aColor = pColorProp ? pColorProp->GetColor() : COL_AUTO; + if ( aColor != COL_AUTO ) + { + OString sColor = msfilter::util::ConvertColor( aColor ); + m_pSerializer->singleElementNS( XML_w, XML_shd, + FSNS( XML_w, XML_fill ), sColor.getStr( ), + FSNS( XML_w, XML_val ), "clear", + FSEND ); + } + // Output the table borders TableDefaultBorders( pTableTextNodeInfoInner ); @@ -3811,12 +3823,25 @@ void DocxAttributeOutput::TableDefaultCellMargins( ww8::WW8TableNodeInfoInner::P void DocxAttributeOutput::TableBackgrounds( ww8::WW8TableNodeInfoInner::Pointer_t pTableTextNodeInfoInner ) { + const SwTable *pTable = pTableTextNodeInfoInner->getTable(); const SwTableBox *pTableBox = pTableTextNodeInfoInner->getTableBox( ); + const SwTableLine *pTableRow = pTableBox->GetUpper(); const SwFrameFormat *pFormat = pTableBox->GetFrameFormat( ); const SvxBrushItem *pColorProp = pFormat->GetAttrSet().GetItem(RES_BACKGROUND); Color aColor = pColorProp ? pColorProp->GetColor() : COL_AUTO; - OString sColor = msfilter::util::ConvertColor( aColor ); + + const SwFrameFormat *pRowFormat = pTableRow->GetFrameFormat( ); + const SvxBrushItem *pRowColorProp = pRowFormat->GetAttrSet().GetItem(RES_BACKGROUND); + if ( pRowColorProp && aColor == COL_AUTO) + aColor = pRowColorProp->GetColor(); + + const SwFrameFormat *pTableFormat = pTable->GetFrameFormat( ); + const SvxBrushItem *pTableColorProp = pTableFormat->GetAttrSet().GetItem(RES_BACKGROUND); + if ( pTableColorProp && aColor == COL_AUTO ) + aColor = pTableColorProp->GetColor(); + + const OString sColor = msfilter::util::ConvertColor( aColor ); std::map aGrabBag = pFormat->GetAttrSet().GetItem(RES_FRMATR_GRABBAG)->GetGrabBag(); -- cgit v1.2.3