sw/qa/extras/rtfimport/data/tdf105852.rtf | 50 +++++++++++++++ sw/qa/extras/rtfimport/rtfimport.cxx | 14 ++++ writerfilter/source/dmapper/DomainMapperTableHandler.cxx | 14 ++-- writerfilter/source/dmapper/DomainMapperTableHandler.hxx | 4 - 4 files changed, 75 insertions(+), 7 deletions(-)
New commits: commit d48b805794a6317e13826d52bbeaa37576ac57bb Author: Mike Kaganski <mike.kagan...@collabora.com> Date: Thu Feb 9 15:00:33 2017 +0300 tdf#105852: don't merge cells if there were no merge continuation In RTF, it's possible to start a cells merge using \clmgf, and simply omit following cells in the row - they must merge automatically. This makes HorizontallyMergedCell::m_nLastCol/Row uninitialized. Previously, the uninitialized values arrived as 0,0 - thus the first range's cell got merged with cell 0,0. This change prevents the merge; in scenario above, absence of additional cells in row will create merged cell automatically. Change-Id: I68b84b7ec70d9512c541a077689369fa4a8dc0c5 Reviewed-on: https://gerrit.libreoffice.org/34079 Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com> Tested-by: Mike Kaganski <mike.kagan...@collabora.com> diff --git a/sw/qa/extras/rtfimport/data/tdf105852.rtf b/sw/qa/extras/rtfimport/data/tdf105852.rtf new file mode 100644 index 0000000..bf3e073 --- /dev/null +++ b/sw/qa/extras/rtfimport/data/tdf105852.rtf @@ -0,0 +1,50 @@ +{\rtf1\ansicpg1251 + +{\trowd +\cellx720 +\cellx6240 +\cellx7680 +\cellx9360 +A1\cell +A2\cell +A3\cell +A4\cell +\row} +{\trowd +\cellx720 +\cellx6240 +\cellx7680 +\cellx9360 +B1\cell +B2\cell +B3\cell +B4\cell +\row} +{\trowd +\clmgf\cellx9360 +C1\cell +\row} +{\trowd +\cellx720 +\cellx6240 +\cellx7680 +\cellx9360 +D1\cell +D2\cell +D3\cell +D4\cell +\row} +{\trowd +\clmgf\cellx9360 +E1\cell +\row} +{\trowd +\cellx720 +\cellx6240 +\cellx7680 +\cellx9360 +F1\cell +F2\cell +F3\cell +F4\cell +\row}\par} \ No newline at end of file diff --git a/sw/qa/extras/rtfimport/rtfimport.cxx b/sw/qa/extras/rtfimport/rtfimport.cxx index 63608a0..855b2da 100644 --- a/sw/qa/extras/rtfimport/rtfimport.cxx +++ b/sw/qa/extras/rtfimport/rtfimport.cxx @@ -2765,6 +2765,20 @@ DECLARE_RTFIMPORT_TEST(testTdf104744, "tdf104744.rtf") CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(1270), getProperty<sal_Int32>(getParagraph(1), "ParaLeftMargin")); } +DECLARE_RTFIMPORT_TEST(testTdf105852, "tdf105852.rtf") +{ + uno::Reference<text::XTextTablesSupplier> xTablesSupplier(mxComponent, uno::UNO_QUERY); + uno::Reference<container::XIndexAccess> xTables(xTablesSupplier->getTextTables(), uno::UNO_QUERY); + uno::Reference<text::XTextTable> xTextTable(xTables->getByIndex(0), uno::UNO_QUERY); + uno::Reference<table::XTableRows> xTableRows(xTextTable->getRows(), uno::UNO_QUERY); + // All rows but last were merged -> there were only 2 rows + CPPUNIT_ASSERT_EQUAL(sal_Int32(6), xTableRows->getCount()); + // The first row must have 4 cells. + CPPUNIT_ASSERT_EQUAL(sal_Int32(3), getProperty< uno::Sequence<text::TableColumnSeparator> >(xTableRows->getByIndex(0), "TableColumnSeparators").getLength()); + // The third row must have 1 merged cell. + CPPUNIT_ASSERT_EQUAL(sal_Int32(0), getProperty< uno::Sequence<text::TableColumnSeparator> >(xTableRows->getByIndex(2), "TableColumnSeparators").getLength()); +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/source/dmapper/DomainMapperTableHandler.cxx b/writerfilter/source/dmapper/DomainMapperTableHandler.cxx index 975f6d8..2ce6301 100644 --- a/writerfilter/source/dmapper/DomainMapperTableHandler.cxx +++ b/writerfilter/source/dmapper/DomainMapperTableHandler.cxx @@ -1042,12 +1042,16 @@ void DomainMapperTableHandler::endTable(unsigned int nestedTableLevel, bool bTab uno::Reference<table::XCellRange> xCellRange(xTable, uno::UNO_QUERY_THROW); uno::Reference<beans::XPropertySet> xCell(xCellRange->getCellByPosition(it->m_nFirstCol, it->m_nFirstRow), uno::UNO_QUERY_THROW); OUString aFirst = xCell->getPropertyValue("CellName").get<OUString>(); - xCell.set(xCellRange->getCellByPosition(it->m_nLastCol, it->m_nLastRow), uno::UNO_QUERY_THROW); - OUString aLast = xCell->getPropertyValue("CellName").get<OUString>(); + // tdf#105852: Only try to merge if m_nLastCol is set (i.e. there were some merge continuation cells) + if (it->m_nLastCol != -1) + { + xCell.set(xCellRange->getCellByPosition(it->m_nLastCol, it->m_nLastRow), uno::UNO_QUERY_THROW); + OUString aLast = xCell->getPropertyValue("CellName").get<OUString>(); - uno::Reference<text::XTextTableCursor> xCursor = xTable->createCursorByCellName(aFirst); - xCursor->gotoCellByName(aLast, true); - xCursor->mergeRange(); + uno::Reference<text::XTextTableCursor> xCursor = xTable->createCursorByCellName(aFirst); + xCursor->gotoCellByName(aLast, true); + xCursor->mergeRange(); + } } } } diff --git a/writerfilter/source/dmapper/DomainMapperTableHandler.hxx b/writerfilter/source/dmapper/DomainMapperTableHandler.hxx index 6097be3..83dafa4 100644 --- a/writerfilter/source/dmapper/DomainMapperTableHandler.hxx +++ b/writerfilter/source/dmapper/DomainMapperTableHandler.hxx @@ -50,8 +50,8 @@ struct HorizontallyMergedCell HorizontallyMergedCell(sal_Int32 nFirstRow, sal_Int32 nFirstCol) : m_nFirstRow(nFirstRow) , m_nFirstCol(nFirstCol) - , m_nLastRow(0) - , m_nLastCol(0) + , m_nLastRow(nFirstRow) + , m_nLastCol(-1) { } }; _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits