summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLászló Németh <nemeth@numbertext.org>2020-01-27 12:14:52 +0100
committerLászló Németh <nemeth@numbertext.org>2020-01-27 17:06:53 +0100
commit8ffc1299ebf83450e67cf2a89304859e2558cd27 (patch)
tree6c5b1ec12afb43729d38c7bad99a9e945a049a3b
parent2be03a8e8159165d6a2f911d0c94f55b3d9e41d4 (diff)
tdf#95033 DOCX import: apply tblPrEx table border
exceptions of table rows, fixing for example missing cell borders. Change-Id: Id66af2706f564f46a1afd04bad65d1bf086a3232 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/87514 Tested-by: Jenkins Reviewed-by: László Németh <nemeth@numbertext.org>
-rw-r--r--sw/qa/extras/ooxmlexport/data/tdf95033.docxbin0 -> 22773 bytes
-rw-r--r--sw/qa/extras/ooxmlexport/ooxmlexport5.cxx17
-rw-r--r--writerfilter/source/dmapper/DomainMapperTableHandler.cxx41
-rw-r--r--writerfilter/source/dmapper/TablePropertiesHandler.cxx19
-rw-r--r--writerfilter/source/ooxml/model.xml1
5 files changed, 74 insertions, 4 deletions
diff --git a/sw/qa/extras/ooxmlexport/data/tdf95033.docx b/sw/qa/extras/ooxmlexport/data/tdf95033.docx
new file mode 100644
index 000000000000..5d2cc73db9b1
--- /dev/null
+++ b/sw/qa/extras/ooxmlexport/data/tdf95033.docx
Binary files differ
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport5.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport5.cxx
index b59a14a89619..3fb80c0850d1 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport5.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport5.cxx
@@ -593,6 +593,23 @@ DECLARE_OOXMLEXPORT_TEST(testfdo80097, "fdo80097.docx")
assertXPath(pXmlDocument, "/w:document/w:body/w:tbl/w:tr[1]/w:tc[1]/w:tbl/w:tr[1]/w:tc[1]/w:tcPr/w:tcBorders/w:insideV",0);
}
+DECLARE_OOXMLEXPORT_TEST(testTdf95033, "tdf95033.docx")
+{
+ //tdf#95033 : Table borders defined by row-level tblPrEx are not getting preserved.
+
+ xmlDocPtr pXmlDocument = parseExport("word/document.xml");
+ if (!pXmlDocument)
+ return;
+
+ //Not disabled table cell borders
+ assertXPath(pXmlDocument, "/w:document/w:body/w:tbl/w:tr[5]/w:tc[1]/w:tcPr/w:tcBorders/w:start[@w:val = 'nil']", 0);
+ assertXPath(pXmlDocument, "/w:document/w:body/w:tbl/w:tr[5]/w:tc[2]/w:tcPr/w:tcBorders/w:end[@w:val = 'nil']", 0);
+ assertXPath(pXmlDocument, "/w:document/w:body/w:tbl/w:tr[9]/w:tc[1]/w:tcPr/w:tcBorders/w:start[@w:val = 'nil']", 0);
+ assertXPath(pXmlDocument, "/w:document/w:body/w:tbl/w:tr[9]/w:tc[2]/w:tcPr/w:tcBorders/w:end[@w:val = 'nil']", 0);
+ assertXPath(pXmlDocument, "/w:document/w:body/w:tbl/w:tr[9]/w:tc[1]/w:tcPr/w:tcBorders/w:bottom[@w:val = 'nil']", 0);
+ 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_EXPORTONLY_TEST(testFdo77129, "fdo77129.docx")
{
// The problem was that text after TOC field was missing if footer reference comes in field.
diff --git a/writerfilter/source/dmapper/DomainMapperTableHandler.cxx b/writerfilter/source/dmapper/DomainMapperTableHandler.cxx
index 31ce6b21d2c9..fe9f6e8863a8 100644
--- a/writerfilter/source/dmapper/DomainMapperTableHandler.cxx
+++ b/writerfilter/source/dmapper/DomainMapperTableHandler.cxx
@@ -738,6 +738,12 @@ CellPropertyValuesSeq_t DomainMapperTableHandler::endTableGetCellProperties(Tabl
sal_Int32 nCell = 0;
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 );
@@ -794,14 +800,33 @@ 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.
- static const PropertyIds pBorders[] =
- {
- PROP_TOP_BORDER, PROP_LEFT_BORDER, PROP_BOTTOM_BORDER, PROP_RIGHT_BORDER
- };
+ // Apply also possible tblPrEx borders on cells
for (const PropertyIds& rBorder : pBorders)
{
o3tl::optional<PropertyMap::Property> oStyleCellBorder = pStyleProps->getProperty(rBorder);
+ o3tl::optional<PropertyMap::Property> oRowCellBorder;
+ // we can have table border exception in row properties
+ if (*aRowIter && (*aRowIter)->isSet(rBorder))
+ oRowCellBorder = (*aRowIter)->getProperty(rBorder);
o3tl::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 = o3tl::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.
@@ -914,6 +939,14 @@ 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/TablePropertiesHandler.cxx b/writerfilter/source/dmapper/TablePropertiesHandler.cxx
index 91a31800c740..aa9ad66b5903 100644
--- a/writerfilter/source/dmapper/TablePropertiesHandler.cxx
+++ b/writerfilter/source/dmapper/TablePropertiesHandler.cxx
@@ -213,6 +213,25 @@ namespace dmapper {
pManager->SetLayoutType(static_cast<sal_uInt32>(nIntValue));
}
break;
+ case NS_ooxml::LN_CT_TblPrEx_tblBorders:
+ {
+ writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps();
+ if( pProperties.get())
+ {
+ auto pBorderHandler = std::make_shared<BorderHandler>(true);
+ pProperties->resolve(*pBorderHandler);
+ TablePropertyMapPtr pTablePropMap( new TablePropertyMap );
+ pTablePropMap->InsertProps(pBorderHandler->getProperties());
+
+#ifdef DBG_UTIL
+ pTablePropMap->dumpXml();
+#endif
+ // store row-level table border exceptions in row properties temporarily
+ // and apply them on cells later
+ insertRowProps( pTablePropMap );
+ }
+ }
+ break;
case NS_ooxml::LN_CT_TcPrBase_tcBorders ://cell borders
//contains CT_TcBorders_left, right, top, bottom
{
diff --git a/writerfilter/source/ooxml/model.xml b/writerfilter/source/ooxml/model.xml
index 17c8f5217fec..b36aa89527f9 100644
--- a/writerfilter/source/ooxml/model.xml
+++ b/writerfilter/source/ooxml/model.xml
@@ -18491,6 +18491,7 @@
</resource>
<resource name="CT_TblPrEx" resource="Properties">
<element name="tblPrExChange" tokenid="ooxml:CT_TblPrEx_tblPrExChange"/>
+ <element name="tblBorders" tokenid="ooxml:CT_TblPrEx_tblBorders"/>
</resource>
<resource name="CT_Tbl" resource="TextTable"/>
<!-- tdf#111550 : allow <w:tbl> at paragraph level (despite this is illegal according to ECMA-376-1:2016) - bug-to-bug compatibility with Word -->