diff options
author | László Németh <nemeth@numbertext.org> | 2020-06-04 13:32:53 +0200 |
---|---|---|
committer | László Németh <nemeth@numbertext.org> | 2020-06-04 18:43:16 +0200 |
commit | da8ea444b004a0be36964ae9a778f73e752b2673 (patch) | |
tree | b70266a75d36d735a7d853544aa629937fe9051c | |
parent | c39738eabfb9edde552832581bf85e717b00cc79 (diff) |
tdf#133455 DOCX import: fix table border regression
caused by commit 8ffc1299ebf83450e67cf2a89304859e2558cd27
(tdf#95033 DOCX import: apply tblPrEx table border).
Change-Id: Ief4da3bce3282b5dab1ce4dabb4e075efcc1abaf
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/95504
Tested-by: Jenkins
Reviewed-by: László Németh <nemeth@numbertext.org>
-rw-r--r-- | sw/qa/extras/ooxmlexport/data/tdf133455.docx | bin | 0 -> 15724 bytes | |||
-rw-r--r-- | sw/qa/extras/ooxmlexport/ooxmlexport5.cxx | 17 | ||||
-rw-r--r-- | writerfilter/source/dmapper/DomainMapperTableHandler.cxx | 39 | ||||
-rw-r--r-- | writerfilter/source/dmapper/TableManager.cxx | 16 | ||||
-rw-r--r-- | writerfilter/source/dmapper/TableManager.hxx | 33 | ||||
-rw-r--r-- | writerfilter/source/dmapper/TablePropertiesHandler.cxx | 4 | ||||
-rw-r--r-- | writerfilter/source/dmapper/TablePropertiesHandler.hxx | 11 |
7 files changed, 81 insertions, 39 deletions
diff --git a/sw/qa/extras/ooxmlexport/data/tdf133455.docx b/sw/qa/extras/ooxmlexport/data/tdf133455.docx Binary files differnew file mode 100644 index 000000000000..e852976995e6 --- /dev/null +++ b/sw/qa/extras/ooxmlexport/data/tdf133455.docx diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport5.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport5.cxx index 6018c417ad47..690309b6827f 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport5.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport5.cxx @@ -726,6 +726,23 @@ DECLARE_OOXMLEXPORT_TEST(testTdf95033, "tdf95033.docx") assertXPath(pXmlDocument, "/w:document/w:body/w:tbl/w:tr[9]/w:tc[2]/w:tcPr/w:tcBorders/w:bottom[@w:val = 'nil']", 0); } +DECLARE_OOXMLEXPORT_TEST(testTdf133455, "tdf133455.docx") +{ + xmlDocUniquePtr pXmlDocument = parseExport("word/document.xml"); + if (!pXmlDocument) + return; + + //Not disabled table cell borders + assertXPath(pXmlDocument, "/w:document/w:body/w:tbl/w:tr[1]/w:tc[1]/w:tcPr/w:tcBorders/w:top[@w:val = 'nil']", 0); + assertXPath(pXmlDocument, "/w:document/w:body/w:tbl/w:tr[1]/w:tc[1]/w:tcPr/w:tcBorders/w:start[@w:val = 'nil']", 0); + assertXPath(pXmlDocument, "/w:document/w:body/w:tbl/w:tr[1]/w:tc[1]/w:tcPr/w:tcBorders/w:end[@w:val = 'nil']", 0); + assertXPath(pXmlDocument, "/w:document/w:body/w:tbl/w:tr[2]/w:tc[1]/w:tcPr/w:tcBorders/w:start[@w:val = 'nil']", 0); + assertXPath(pXmlDocument, "/w:document/w:body/w:tbl/w:tr[2]/w:tc[1]/w:tcPr/w:tcBorders/w:end[@w:val = 'nil']", 0); + assertXPath(pXmlDocument, "/w:document/w:body/w:tbl/w:tr[11]/w:tc[1]/w:tcPr/w:tcBorders/w:start[@w:val = 'nil']", 0); + assertXPath(pXmlDocument, "/w:document/w:body/w:tbl/w:tr[11]/w:tc[1]/w:tcPr/w:tcBorders/w:end[@w:val = 'nil']", 0); + assertXPath(pXmlDocument, "/w:document/w:body/w:tbl/w:tr[11]/w:tc[1]/w:tcPr/w:tcBorders/w:bottom[@w:val = 'nil']", 0); +} + DECLARE_OOXMLEXPORT_EXPORTONLY_TEST(testTdf128646, "tdf128646.docx") { // The problem was that not hidden shapes anchored to empty hidden paragraphs were imported as hidden. diff --git a/writerfilter/source/dmapper/DomainMapperTableHandler.cxx b/writerfilter/source/dmapper/DomainMapperTableHandler.cxx index a42478a2b0df..9c3d87de1552 100644 --- a/writerfilter/source/dmapper/DomainMapperTableHandler.cxx +++ b/writerfilter/source/dmapper/DomainMapperTableHandler.cxx @@ -762,11 +762,6 @@ CellPropertyValuesSeq_t DomainMapperTableHandler::endTableGetCellProperties(Tabl pCellProperties[nRow].realloc( aRowOfCellsIterator->size() ); beans::PropertyValues* pSingleCellProperties = pCellProperties[nRow].getArray(); - static const PropertyIds pBorders[] = - { - PROP_TOP_BORDER, PROP_LEFT_BORDER, PROP_BOTTOM_BORDER, PROP_RIGHT_BORDER - }; - while( aCellIterator != aCellIteratorEnd ) { PropertyMapPtr pAllCellProps( new PropertyMap ); @@ -823,33 +818,15 @@ CellPropertyValuesSeq_t DomainMapperTableHandler::endTableGetCellProperties(Tabl PropertyMapPtr pStyleProps = rInfo.pTableStyle->GetProperties( nCnfStyleMask ); // Check if we need to clean up some empty border definitions to match what Word does. - // Apply also possible tblPrEx borders on cells + static const PropertyIds pBorders[] = + { + PROP_TOP_BORDER, PROP_LEFT_BORDER, PROP_BOTTOM_BORDER, PROP_RIGHT_BORDER + }; for (const PropertyIds& rBorder : pBorders) { std::optional<PropertyMap::Property> oStyleCellBorder = pStyleProps->getProperty(rBorder); std::optional<PropertyMap::Property> oRowCellBorder; - // we can have table border exception in row properties - if (*aRowIter && (*aRowIter)->isSet(rBorder)) - oRowCellBorder = (*aRowIter)->getProperty(rBorder); std::optional<PropertyMap::Property> oDirectCellBorder = (*aCellIterator)->getProperty(rBorder); - if (oRowCellBorder && oDirectCellBorder) - { - table::BorderLine2 aRowCellBorder = oRowCellBorder->second.get<table::BorderLine2>(); - table::BorderLine2 aDirectCellBorder = oDirectCellBorder->second.get<table::BorderLine2>(); - if (aRowCellBorder.LineStyle != table::BorderLineStyle::NONE && aDirectCellBorder.LineStyle == table::BorderLineStyle::NONE) - oDirectCellBorder = std::optional<PropertyMap::Property>(); - } - if (oRowCellBorder && !oDirectCellBorder) - { - table::BorderLine2 aRowCellBorder = oRowCellBorder->second.get<table::BorderLine2>(); - if ( (rBorder == PROP_LEFT_BORDER && nCnfStyleMask&CNF_FIRST_COLUMN) - || (rBorder == PROP_RIGHT_BORDER && bIsEndCol) - || (rBorder != PROP_LEFT_BORDER && rBorder != PROP_RIGHT_BORDER) ) - { - (*aCellIterator)->Insert(rBorder, uno::makeAny(aRowCellBorder)); - oDirectCellBorder = (*aCellIterator)->getProperty(rBorder); - } - } if (oStyleCellBorder && oDirectCellBorder) { // We have a cell border from the table style and as direct formatting as well. @@ -972,14 +949,6 @@ CellPropertyValuesSeq_t DomainMapperTableHandler::endTableGetCellProperties(Tabl ++nCell; ++aCellIterator; } - - // remove tblPrEx table border properties stored in row properties temporarily - for (const PropertyIds& rBorder : pBorders) - { - if (*aRowIter && (*aRowIter)->isSet(rBorder)) - (*aRowIter)->Erase(rBorder); - } - ++nRow; ++aRowOfCellsIterator; ++aRowIter; diff --git a/writerfilter/source/dmapper/TableManager.cxx b/writerfilter/source/dmapper/TableManager.cxx index 7ce34d988996..50e948b00eba 100644 --- a/writerfilter/source/dmapper/TableManager.cxx +++ b/writerfilter/source/dmapper/TableManager.cxx @@ -101,6 +101,22 @@ void TableManager::cellProps(const TablePropertyMapPtr& pProps) #endif } +void TableManager::tableExceptionProps(const TablePropertyMapPtr& pProps) +{ +#ifdef DBG_UTIL + TagLogger::getInstance().startElement("tablemanager.tableExceptionProps"); +#endif + + if (getTableExceptionProps()) + getTableExceptionProps()->InsertProps(pProps.get()); + else + mState.setTableExceptionProps(pProps); + +#ifdef DBG_UTIL + TagLogger::getInstance().endElement(); +#endif +} + void TableManager::utext(const sal_uInt8* data, std::size_t len) { // optimization: cell/row end characters are the last characters in a run diff --git a/writerfilter/source/dmapper/TableManager.hxx b/writerfilter/source/dmapper/TableManager.hxx index d5814df6d8e7..5e18becab606 100644 --- a/writerfilter/source/dmapper/TableManager.hxx +++ b/writerfilter/source/dmapper/TableManager.hxx @@ -58,6 +58,11 @@ class TableManager : public virtual SvRefBase TablePropertyMapPtr mpRowProps; /** + table exception properties of the current row + */ + TablePropertyMapPtr mpTableExceptionProps; + + /** properties of the current table */ std::stack<TablePropertyMapPtr> mTableProps; @@ -109,7 +114,7 @@ class TableManager : public virtual SvRefBase void resetCellProps() { - mpCellProps.clear(); + mpCellProps = getTableExceptionProps(); } void setCellProps(TablePropertyMapPtr pProps) @@ -124,6 +129,10 @@ class TableManager : public virtual SvRefBase void resetRowProps() { + // reset also table exception and + // its copy set by the previous resetCellProps() + mpTableExceptionProps.clear(); + resetCellProps(); mpRowProps.clear(); } @@ -137,6 +146,16 @@ class TableManager : public virtual SvRefBase return mpRowProps; } + void setTableExceptionProps(TablePropertyMapPtr pProps) + { + mpTableExceptionProps = pProps; + } + + const TablePropertyMapPtr& getTableExceptionProps() const + { + return mpTableExceptionProps; + } + void resetTableProps() { if (mTableProps.size() > 0) @@ -209,6 +228,11 @@ public: return mState.getRowProps(); } + TablePropertyMapPtr const & getTableExceptionProps() const + { + return mState.getTableExceptionProps(); + } + protected: void setInCell(bool bInCell) { @@ -455,6 +479,13 @@ public: virtual void insertRowProps(const TablePropertyMapPtr& pProps); /** + Handle table exception properties of the current row. + + @param pProps the properties + */ + virtual void tableExceptionProps(const TablePropertyMapPtr& pProps); + + /** Handle properties of the current table. @param pProps the properties diff --git a/writerfilter/source/dmapper/TablePropertiesHandler.cxx b/writerfilter/source/dmapper/TablePropertiesHandler.cxx index a0185eaa735a..d37b6b314e94 100644 --- a/writerfilter/source/dmapper/TablePropertiesHandler.cxx +++ b/writerfilter/source/dmapper/TablePropertiesHandler.cxx @@ -224,9 +224,7 @@ namespace writerfilter::dmapper { #ifdef DBG_UTIL pTablePropMap->dumpXml(); #endif - // store row-level table border exceptions in row properties temporarily - // and apply them on cells later - insertRowProps( pTablePropMap ); + tableExceptionProps( pTablePropMap ); } } break; diff --git a/writerfilter/source/dmapper/TablePropertiesHandler.hxx b/writerfilter/source/dmapper/TablePropertiesHandler.hxx index 16c28da8c9d1..d35ad7f114f0 100644 --- a/writerfilter/source/dmapper/TablePropertiesHandler.hxx +++ b/writerfilter/source/dmapper/TablePropertiesHandler.hxx @@ -74,6 +74,17 @@ private: m_pCurrentProperties->InsertProps(pProps.get()); }; + void tableExceptionProps( TablePropertyMapPtr pProps ) + { + if ( m_pTableManager ) + { + m_pTableManager->tableExceptionProps( pProps ); + cellProps( pProps ); + } + else + m_pCurrentProperties->InsertProps(pProps.get()); + }; + void insertTableProps( TablePropertyMapPtr pProps ) { if ( m_pTableManager ) |