diff options
-rw-r--r-- | sw/qa/extras/rtfimport/data/tdf152839.rtf | 15 | ||||
-rw-r--r-- | sw/qa/extras/rtfimport/rtfimport.cxx | 9 | ||||
-rw-r--r-- | sw/source/writerfilter/dmapper/DomainMapperTableManager.cxx | 4 | ||||
-rw-r--r-- | sw/source/writerfilter/dmapper/TableManager.cxx | 60 | ||||
-rw-r--r-- | sw/source/writerfilter/dmapper/TableManager.hxx | 5 |
5 files changed, 92 insertions, 1 deletions
diff --git a/sw/qa/extras/rtfimport/data/tdf152839.rtf b/sw/qa/extras/rtfimport/data/tdf152839.rtf new file mode 100644 index 000000000000..e95f72af0b78 --- /dev/null +++ b/sw/qa/extras/rtfimport/data/tdf152839.rtf @@ -0,0 +1,15 @@ +{\rtf1
+
+\trowd
+\clbrdrb\brdrs\brdrw100
+\cellx3000
+\pard\intbl A\cell\row
+
+\trowd
+
+\cellx3000
+\cellx6000
+\pard\intbl B\cell
+\pard\intbl C\cell
+\row
+}
diff --git a/sw/qa/extras/rtfimport/rtfimport.cxx b/sw/qa/extras/rtfimport/rtfimport.cxx index 31bc5b6a39b8..4ff36a7f7988 100644 --- a/sw/qa/extras/rtfimport/rtfimport.cxx +++ b/sw/qa/extras/rtfimport/rtfimport.cxx @@ -1933,6 +1933,15 @@ CPPUNIT_TEST_FIXTURE(Test, testTdf163003) getProperty<sal_Int32>(getShape(1), u"VertOrientPosition"_ustr)); } +CPPUNIT_TEST_FIXTURE(Test, testTdf152839) +{ + createSwDoc("tdf152839.rtf"); + 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); + CPPUNIT_ASSERT_EQUAL(sal_Int32(4), xTable->getCellNames().getLength()); +} // tests should only be added to rtfIMPORT *if* they fail round-tripping in rtfEXPORT } // end of anonymous namespace CPPUNIT_PLUGIN_IMPLEMENT(); diff --git a/sw/source/writerfilter/dmapper/DomainMapperTableManager.cxx b/sw/source/writerfilter/dmapper/DomainMapperTableManager.cxx index f8d3a762871a..312d2abf10b3 100644 --- a/sw/source/writerfilter/dmapper/DomainMapperTableManager.cxx +++ b/sw/source/writerfilter/dmapper/DomainMapperTableManager.cxx @@ -147,6 +147,10 @@ bool DomainMapperTableManager::sprm(Sprm & rSprm) pPropMap->setValue( TablePropertyMap::TABLE_WIDTH_TYPE, text::SizeType::FIX ); pPropMap->setValue( TablePropertyMap::TABLE_WIDTH, m_nTableWidth ); m_bTableSizeTypeInserted = true; + // add current row width to add 'hidden' before inserting the table + TablePropertyMapPtr pRowPropMap( new TablePropertyMap ); + pRowPropMap->setValue( TablePropertyMap::TABLE_WIDTH, m_nTableWidth ); + insertRowProps(pRowPropMap); } else if( sal::static_int_cast<Id>(pMeasureHandler->getUnit()) == NS_ooxml::LN_Value_ST_TblWidth_pct ) { diff --git a/sw/source/writerfilter/dmapper/TableManager.cxx b/sw/source/writerfilter/dmapper/TableManager.cxx index 473967d26b02..f73d61b145ac 100644 --- a/sw/source/writerfilter/dmapper/TableManager.cxx +++ b/sw/source/writerfilter/dmapper/TableManager.cxx @@ -23,7 +23,7 @@ #include "DomainMapperTableHandler.hxx" #include "DomainMapper_Impl.hxx" #include "util.hxx" - +#include <comphelper/sequence.hxx> #include <comphelper/diagnose_ex.hxx> using namespace com::sun::star; @@ -373,6 +373,62 @@ void TableManager::startParagraphGroup() mnTableDepthNew = 0; } +void TableManager::HandleSmallerRows() +{ + TableData::Pointer_t pTableData = mTableDataStack.back(); + unsigned int nRows = pTableData->getRowCount(); + sal_Int32 nMaxRowWidth = 0; + bool bIsDiffRowWidth = false; + for (unsigned int nRow = 0; nRow < nRows; ++nRow) + { + RowData::Pointer_t pRowData = pTableData->getRow(nRow); + sal_Int32 nRowWidth = 0; + const TablePropertyMapPtr pRowProps = pRowData->getProperties(); + if (pRowProps) + pRowProps->getValue(TablePropertyMap::TABLE_WIDTH, nRowWidth); + if (nRowWidth == 0) + return; + if (nRowWidth > nMaxRowWidth) + { + if (nMaxRowWidth > 0) + bIsDiffRowWidth = true; + nMaxRowWidth = nRowWidth; + } + } + // + if (bIsDiffRowWidth) + { + uno::Reference<text::XTextAppendAndConvert> xTextAppendAndConvert( + mpTableDataHandler->getDomainMapperImpl().GetTopTextAppend(), uno::UNO_QUERY); + + for (unsigned int nRow = 0; nRow < nRows; ++nRow) + { + RowData::Pointer_t pRowData = pTableData->getRow(nRow); + sal_Int32 nRowWidth = 0; + pRowData->getProperties()->getValue(TablePropertyMap::TABLE_WIDTH, nRowWidth); + if (nRowWidth < nMaxRowWidth) + { + uno::Reference<text::XTextRange> xTextRange + = pRowData->getCellEnd(pRowData->getCellCount() - 1); + std::vector<beans::PropertyValue> aProperties; + //TODO: is there a simpler way to create a new paragraph behind the current cell and get that range back? + uno::Reference<text::XTextRange> xNewCellTextRange + = xTextAppendAndConvert->finishParagraphInsert( + comphelper::containerToSequence(aProperties), xTextRange); + uno::Reference<text::XTextCursor> xNewCellTextCursor + = xTextAppendAndConvert->createTextCursorByRange(xNewCellTextRange); + xNewCellTextCursor->collapseToEnd(); + xNewCellTextCursor->goRight(1, false); + + TablePropertyMapPtr pCellPropMap(new TablePropertyMap); + pRowData->addCell(xNewCellTextCursor, pCellPropMap); + pRowData->endCell(xNewCellTextCursor); + pRowData->getProperties()->setValue(TablePropertyMap::TABLE_WIDTH, nMaxRowWidth); + } + } + } +} + void TableManager::resolveCurrentTable() { #ifdef DBG_UTIL @@ -383,6 +439,8 @@ void TableManager::resolveCurrentTable() { try { + // add cells to the rows that are smaller than the maximum width + HandleSmallerRows(); TableData::Pointer_t pTableData = mTableDataStack.back(); unsigned int nRows = pTableData->getRowCount(); diff --git a/sw/source/writerfilter/dmapper/TableManager.hxx b/sw/source/writerfilter/dmapper/TableManager.hxx index f98c992a3595..18baf49c5333 100644 --- a/sw/source/writerfilter/dmapper/TableManager.hxx +++ b/sw/source/writerfilter/dmapper/TableManager.hxx @@ -332,6 +332,11 @@ private: void endRow(); /** + * Handle rows smaller than the table width and add 'hidden' cells + */ + void HandleSmallerRows(); + + /** Resolve the current table to the TableDataHandler. */ void resolveCurrentTable(); |