summaryrefslogtreecommitdiff
path: root/writerfilter
diff options
context:
space:
mode:
authorLászló Németh <nemeth@numbertext.org>2020-07-08 10:36:29 +0200
committerLászló Németh <nemeth@numbertext.org>2020-07-08 23:43:35 +0200
commit5483d4e10aad27889b961b9cb94d7ba6c86aed0b (patch)
tree69ca542c9928b6614c49044329c9740d05ae9f26 /writerfilter
parent7ead920f7015bb8e7a4343b863333bb26187d9a3 (diff)
tdf#134606 DOCX table import: fix gridBefore + nesting
Nested tables in a table row with gridBefore could result of broken outer table, if the row doesn't contain text before the nested table, resulting invalid TextRange for insertion of gridBefore cells. Regression from commit 70274f86cdc1c023ffdd0130c262c1479262d76b (tdf#116194 DOCX import: fix missing tables with w:gridBefore) Change-Id: I6bb3948b6522d8785a1ea0ccf8d7c7f3c2bde189 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/98320 Tested-by: Jenkins Reviewed-by: László Németh <nemeth@numbertext.org>
Diffstat (limited to 'writerfilter')
-rw-r--r--writerfilter/source/dmapper/TableManager.cxx45
1 files changed, 30 insertions, 15 deletions
diff --git a/writerfilter/source/dmapper/TableManager.cxx b/writerfilter/source/dmapper/TableManager.cxx
index 651922fc3998..582b4d4705a6 100644
--- a/writerfilter/source/dmapper/TableManager.cxx
+++ b/writerfilter/source/dmapper/TableManager.cxx
@@ -441,23 +441,38 @@ void TableManager::endRow()
TableData::Pointer_t pTableData = mTableDataStack.top();
// Add borderless w:gridBefore cell(s) to the row
- if (pTableData)
+ sal_uInt32 nGridBefore = getCurrentGridBefore();
+ if (pTableData && nGridBefore > 0 && pTableData->getCurrentRow()->getCellCount() > 0)
{
- sal_uInt32 nGridBefore
- = mpTableDataHandler->getDomainMapperImpl().getTableManager().getCurrentGridBefore();
- for (unsigned int i = 0; i < nGridBefore; ++i)
+ const css::uno::Reference<css::text::XTextRange>& xRowStart
+ = pTableData->getCurrentRow()->getCellStart(0);
+ if (xRowStart.is())
{
- css::table::BorderLine2 aBorderLine;
- aBorderLine.Color = 0;
- aBorderLine.InnerLineWidth = 0;
- aBorderLine.OuterLineWidth = 0;
- TablePropertyMapPtr pCellProperties(new TablePropertyMap);
- pCellProperties->Insert(PROP_TOP_BORDER, css::uno::makeAny(aBorderLine));
- pCellProperties->Insert(PROP_LEFT_BORDER, css::uno::makeAny(aBorderLine));
- pCellProperties->Insert(PROP_BOTTOM_BORDER, css::uno::makeAny(aBorderLine));
- pCellProperties->Insert(PROP_RIGHT_BORDER, css::uno::makeAny(aBorderLine));
- pTableData->getCurrentRow()->addCell(pTableData->getCurrentRow()->getCellStart(0),
- pCellProperties, /*bAddBefore=*/true);
+ try
+ {
+ // valid TextRange for table creation (not a nested table)?
+ xRowStart->getText()->createTextCursorByRange(xRowStart);
+
+ for (unsigned int i = 0; i < nGridBefore; ++i)
+ {
+ css::table::BorderLine2 aBorderLine;
+ aBorderLine.Color = 0;
+ aBorderLine.InnerLineWidth = 0;
+ aBorderLine.OuterLineWidth = 0;
+ TablePropertyMapPtr pCellProperties(new TablePropertyMap);
+ pCellProperties->Insert(PROP_TOP_BORDER, css::uno::makeAny(aBorderLine));
+ pCellProperties->Insert(PROP_LEFT_BORDER, css::uno::makeAny(aBorderLine));
+ pCellProperties->Insert(PROP_BOTTOM_BORDER, css::uno::makeAny(aBorderLine));
+ pCellProperties->Insert(PROP_RIGHT_BORDER, css::uno::makeAny(aBorderLine));
+ pTableData->getCurrentRow()->addCell(xRowStart, pCellProperties,
+ /*bAddBefore=*/true);
+ }
+ }
+ catch (css::uno::Exception const&)
+ {
+ // don't add gridBefore cells in not valid TextRange
+ setCurrentGridBefore(0);
+ }
}
}