sw/qa/extras/rtfexport/data/tdf103956.rtf       |    8 +++++
 sw/qa/extras/rtfexport/rtfexport4.cxx           |   37 ++++++++++++++++++++++++
 writerfilter/source/rtftok/rtfdispatchvalue.cxx |   13 ++++++--
 3 files changed, 55 insertions(+), 3 deletions(-)

New commits:
commit 26d74a57d54327b9fd562065d04d867852ce8e8a
Author:     Vasily Melenchuk <vasily.melenc...@cib.de>
AuthorDate: Fri Jan 6 17:31:16 2023 +0300
Commit:     Vasily Melenchuk <vasily.melenc...@cib.de>
CommitDate: Tue Jan 10 08:05:43 2023 +0000

    tdf#103956: RTF import: fix for \cellx0 or no params.
    
    If cell width is not given or zero lets not confuse it with too
    narrow cell. Lets keep zero to allow domain mapper define some
    width.
    
    This patch does not solves autofit issue completely, but finally
    tables with autofit are visible somehow and do not contain cells
    with minimal almost invisible width (41).
    
    Change-Id: I640228ed117f1d65dde9753a00b8403dda45dd40
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/145148
    Tested-by: Jenkins
    Reviewed-by: Vasily Melenchuk <vasily.melenc...@cib.de>

diff --git a/sw/qa/extras/rtfexport/data/tdf103956.rtf 
b/sw/qa/extras/rtfexport/data/tdf103956.rtf
new file mode 100644
index 000000000000..f41be5b54aba
--- /dev/null
+++ b/sw/qa/extras/rtfexport/data/tdf103956.rtf
@@ -0,0 +1,8 @@
+{\rtf\ansi\deff0
+
+\trowd\trautofit0\cellx \cellx \pard \intbl 1 \cell \pard \intbl 2 \cell \row 
+\pard\par
+\trowd\trautofit0\trgaph100\cellx0 \cellx0 \pard \intbl 1 \cell \pard \intbl 2 
\cell \row
+\pard\par
+\trowd\trautofit0\cellx500 \cellx1000 \pard \intbl 1 \cell \pard \intbl 2 
\cell \row
+}
\ No newline at end of file
diff --git a/sw/qa/extras/rtfexport/rtfexport4.cxx 
b/sw/qa/extras/rtfexport/rtfexport4.cxx
index c55c74a4f6b3..6912948c57db 100644
--- a/sw/qa/extras/rtfexport/rtfexport4.cxx
+++ b/sw/qa/extras/rtfexport/rtfexport4.cxx
@@ -784,6 +784,43 @@ DECLARE_RTFEXPORT_TEST(testTdf139948, "tdf139948.rtf")
         sal_uInt32(0), getProperty<table::BorderLine2>(getParagraph(5), 
"BottomBorder").LineWidth);
 }
 
+DECLARE_RTFEXPORT_TEST(testTdf103956, "tdf103956.rtf")
+{
+    // Ensure that RTF tables without column width (\cellx or \cellx0) are 
displayed with some
+    // suitable width. Currently there is no good support for autofit for RTF 
docs, so ensure
+    // that table cells are somehow visible. Width for it is not clear, so 
here we will check
+    // table & cell widths are more than default minimal value of 41.
+    CPPUNIT_ASSERT_MESSAGE(
+        "Table #1 is too narrow!",
+        82 < parseDump("/root/page/body/tab[1]/row/infos/bounds", 
"width").toInt32());
+    CPPUNIT_ASSERT_MESSAGE(
+        "Table #1 cell#1 is too narrow!",
+        41 < parseDump("/root/page/body/tab[1]/row/cell[1]/infos/bounds", 
"width").toInt32());
+    CPPUNIT_ASSERT_MESSAGE(
+        "Table #1 cell#2 is too narrow!",
+        41 < parseDump("/root/page/body/tab[1]/row/cell[2]/infos/bounds", 
"width").toInt32());
+
+    CPPUNIT_ASSERT_MESSAGE(
+        "Table #2 is too narrow!",
+        82 < parseDump("/root/page/body/tab[2]/row/infos/bounds", 
"width").toInt32());
+    CPPUNIT_ASSERT_MESSAGE(
+        "Table #2 cell#1 is too narrow!",
+        41 < parseDump("/root/page/body/tab[2]/row/cell[1]/infos/bounds", 
"width").toInt32());
+    CPPUNIT_ASSERT_MESSAGE(
+        "Table #2 cell#2 is too narrow!",
+        41 < parseDump("/root/page/body/tab[2]/row/cell[2]/infos/bounds", 
"width").toInt32());
+
+    CPPUNIT_ASSERT_MESSAGE(
+        "Table #3 is too narrow!",
+        82 < parseDump("/root/page/body/tab[3]/row/infos/bounds", 
"width").toInt32());
+    CPPUNIT_ASSERT_MESSAGE(
+        "Table #3 cell#1 is too narrow!",
+        41 < parseDump("/root/page/body/tab[3]/row/cell[1]/infos/bounds", 
"width").toInt32());
+    CPPUNIT_ASSERT_MESSAGE(
+        "Table #3 cell#2 is too narrow!",
+        41 < parseDump("/root/page/body/tab[3]/row/cell[2]/infos/bounds", 
"width").toInt32());
+}
+
 DECLARE_RTFEXPORT_TEST(testTdf148515, "tdf148515.rtf")
 {
     uno::Reference<text::XTextTable> xTable(getParagraphOrTable(1), 
uno::UNO_QUERY);
diff --git a/writerfilter/source/rtftok/rtfdispatchvalue.cxx 
b/writerfilter/source/rtftok/rtfdispatchvalue.cxx
index 2bea9dc9ec8f..a56d8e00d819 100644
--- a/writerfilter/source/rtftok/rtfdispatchvalue.cxx
+++ b/writerfilter/source/rtftok/rtfdispatchvalue.cxx
@@ -393,10 +393,17 @@ bool RTFDocumentImpl::dispatchTableValue(RTFKeyword 
nKeyword, int nParam)
                     ? m_nNestedCurrentCellX
                     : m_nTopLevelCurrentCellX);
             int nCellX = nParam - rCurrentCellX;
-            const int COL_DFLT_WIDTH
-                = 41; // sw/source/filter/inc/wrtswtbl.hxx, minimal possible 
width of cells.
-            if (!nCellX)
+
+            if (!nCellX && nParam > 0)
+            {
+                // If width of cell is 0, BUT there is a value for \cellxN use 
minimal
+                // possible width. But if \cellxN has no value leave 0 so 
autofit will
+                // try to resolve this.
+
+                // sw/source/filter/inc/wrtswtbl.hxx, minimal possible width 
of cells.
+                const int COL_DFLT_WIDTH = 41;
                 nCellX = COL_DFLT_WIDTH;
+            }
 
             // If there is a negative left margin, then the first cellx is 
relative to that.
             RTFValue::Pointer_t pTblInd

Reply via email to