sw/qa/extras/rtfimport/data/tdf152839.rtf                   |   15 +++
 sw/qa/extras/rtfimport/rtfimport.cxx                        |    9 +
 sw/source/writerfilter/dmapper/DomainMapperTableManager.cxx |    4 
 sw/source/writerfilter/dmapper/TableManager.cxx             |   60 +++++++++++-
 sw/source/writerfilter/dmapper/TableManager.hxx             |    5 +
 5 files changed, 92 insertions(+), 1 deletion(-)

New commits:
commit 038473595ed266d15a788d8f97781cbaf066cfe7
Author:     Oliver Specht <oliver.spe...@cib.de>
AuthorDate: Wed Oct 2 14:48:08 2024 +0200
Commit:     Gabor Kelemen <gabor.kelemen.ext...@allotropia.de>
CommitDate: Fri Oct 11 19:07:49 2024 +0200

    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        rwWidthAN. 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.ext...@allotropia.de>
    Reviewed-by: Gabor Kelemen <gabor.kelemen.ext...@allotropia.de>

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 @@
+{ tf1
+
+       rowd
+++\pard\intbl A+
+       rowd
+
+++\pard\intbl B+\pard\intbl C+ ow
+}
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
@@ -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.
      */

Reply via email to