Kaydet (Commit) d48b8057 authored tarafından Mike Kaganski's avatar Mike Kaganski

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/34079Reviewed-by: 's avatarMike Kaganski <mike.kaganski@collabora.com>
Tested-by: 's avatarMike Kaganski <mike.kaganski@collabora.com>
üst 60933220
{\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
......@@ -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: */
......@@ -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();
}
}
}
}
......
......@@ -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)
{
}
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment