tdf#152839 add fill cells to tables imported wrongly from RTF

In Word 'invisible' cells at the end of the row are usually marked
with \trwWidthAN. If that information is missing the table needs to
get addtional cells to smaller rows. This prevents extension of
exisition cell to the full width of the table.

Change-Id: I064f3da55665302d8198ed44d9f640a7707c34e8
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/174385
Tested-by: Jenkins
Tested-by: Gabor Kelemen <gabor.kelemen.extern@allotropia.de>
Reviewed-by: Gabor Kelemen <gabor.kelemen.extern@allotropia.de>
This commit is contained in:
Oliver Specht
2024-10-11 19:07:49 +02:00
committed by Gabor Kelemen
parent 7a0a781da0
commit 038473595e
5 changed files with 92 additions and 1 deletions
+15
View File
@@ -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
}
+9
View File
@@ -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();
@@ -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 )
{
@@ -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();
@@ -331,6 +331,11 @@ private:
*/
void endRow();
/**
* Handle rows smaller than the table width and add 'hidden' cells
*/
void HandleSmallerRows();
/**
Resolve the current table to the TableDataHandler.
*/