writerfilter/qa/cppunittests/rtftok/data/char-hidden-intbl.rtf |    6 ++
 writerfilter/qa/cppunittests/rtftok/rtfdocumentimpl.cxx        |   28 
++++++++++
 writerfilter/source/rtftok/rtfdocumentimpl.cxx                 |   16 ++++-
 3 files changed, 46 insertions(+), 4 deletions(-)

New commits:
commit 4d0252ad7a7b59b514cd0f514047b9a9538ccf02
Author:     Miklos Vajna <[email protected]>
AuthorDate: Thu Sep 1 08:35:06 2022 +0200
Commit:     Xisco Fauli <[email protected]>
CommitDate: Mon Sep 5 15:54:19 2022 +0200

    tdf#150474 RTF import: fix missing char props for in-table newline 
characters
    
    I forgot about this in b9508dd55f82d35f09a58021dc001cf79b390e08
    (fdo#50665 rtftok: don't ignore character properties of text fields,
    2012-06-06), which handled the plain body text case, but not the
    buffered case.
    
    Change-Id: I5c5ebb58becc44a6cf1e0bb8984b2b8c212c3c2b
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/139143
    Reviewed-by: Miklos Vajna <[email protected]>
    Tested-by: Jenkins
    (cherry picked from commit 2a403bcbbe0f45cd14a74ae76c4647096463e8ca)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/139418
    Reviewed-by: Xisco Fauli <[email protected]>

diff --git a/writerfilter/qa/cppunittests/rtftok/data/char-hidden-intbl.rtf 
b/writerfilter/qa/cppunittests/rtftok/data/char-hidden-intbl.rtf
new file mode 100644
index 000000000000..76fea92fac49
--- /dev/null
+++ b/writerfilter/qa/cppunittests/rtftok/data/char-hidden-intbl.rtf
@@ -0,0 +1,6 @@
+{\rtf1
+\paperw11906\paperh16838\margl1440\margr1440\margt1440\margb1440\pard\plain 
before\par
+\trowd\cellx4475\cellx9058\pard\plain\intbl A1\cell
+\pard\intbl{\v \line}B1\cell\row
+\pard\plain after\par
+}
diff --git a/writerfilter/qa/cppunittests/rtftok/rtfdocumentimpl.cxx 
b/writerfilter/qa/cppunittests/rtftok/rtfdocumentimpl.cxx
index 0d6425c33afd..1898e0057695 100644
--- a/writerfilter/qa/cppunittests/rtftok/rtfdocumentimpl.cxx
+++ b/writerfilter/qa/cppunittests/rtftok/rtfdocumentimpl.cxx
@@ -14,6 +14,8 @@
 #include <com/sun/star/drawing/XDrawPageSupplier.hpp>
 #include <com/sun/star/frame/Desktop.hpp>
 #include <com/sun/star/graphic/XGraphic.hpp>
+#include <com/sun/star/text/XTextTablesSupplier.hpp>
+#include <com/sun/star/text/XTextTable.hpp>
 
 #include <vcl/graph.hxx>
 
@@ -73,6 +75,32 @@ CPPUNIT_TEST_FIXTURE(Test, testPicwPich)
     // i.e. the graphic width didn't match 2.62 cm from the Word UI.
     CPPUNIT_ASSERT_EQUAL(static_cast<tools::Long>(2619), aPrefSize.Width());
 }
+
+CPPUNIT_TEST_FIXTURE(Test, testCharHiddenInTable)
+{
+    // Given a document with a table, and a hidden \line in it:
+    OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + 
"char-hidden-intbl.rtf";
+
+    // When loading that document:
+    getComponent() = loadFromDesktop(aURL);
+
+    // Then make sure that line is indeed hidden:
+    uno::Reference<text::XTextTablesSupplier> xTextDocument(getComponent(), 
uno::UNO_QUERY);
+    uno::Reference<container::XIndexAccess> 
xTables(xTextDocument->getTextTables(), uno::UNO_QUERY);
+    uno::Reference<text::XTextTable> xTable(xTables->getByIndex(0), 
uno::UNO_QUERY);
+    uno::Reference<container::XEnumerationAccess> 
xCell(xTable->getCellByName("B1"),
+                                                        uno::UNO_QUERY);
+    uno::Reference<container::XEnumeration> xParagraphs = 
xCell->createEnumeration();
+    uno::Reference<container::XEnumerationAccess> 
xParagraph(xParagraphs->nextElement(),
+                                                             uno::UNO_QUERY);
+    uno::Reference<container::XEnumeration> xPortions = 
xParagraph->createEnumeration();
+    uno::Reference<beans::XPropertySet> xPortion(xPortions->nextElement(), 
uno::UNO_QUERY);
+    bool bCharHidden{};
+    xPortion->getPropertyValue("CharHidden") >>= bCharHidden;
+    // Without the accompanying fix in place, this test would have failed, the 
newline was not
+    // hidden.
+    CPPUNIT_ASSERT(bCharHidden);
+}
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.cxx 
b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
index c428759e4c7c..5effc8d81bbf 100644
--- a/writerfilter/source/rtftok/rtfdocumentimpl.cxx
+++ b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
@@ -1338,15 +1338,23 @@ void RTFDocumentImpl::singleChar(sal_uInt8 nValue, bool 
bRunProps)
     if (!pCurrentBuffer)
     {
         Mapper().startCharacterGroup();
-        // Should we send run properties?
-        if (bRunProps)
-            runProps();
+    }
+    else
+    {
+        pCurrentBuffer->push_back(Buf_t(BUFFER_STARTRUN, nullptr, nullptr));
+    }
+
+    // Should we send run properties?
+    if (bRunProps)
+        runProps();
+
+    if (!pCurrentBuffer)
+    {
         Mapper().text(sValue, 1);
         Mapper().endCharacterGroup();
     }
     else
     {
-        pCurrentBuffer->push_back(Buf_t(BUFFER_STARTRUN, nullptr, nullptr));
         auto pValue = new RTFValue(*sValue);
         pCurrentBuffer->push_back(Buf_t(BUFFER_TEXT, pValue, nullptr));
         pCurrentBuffer->push_back(Buf_t(BUFFER_ENDRUN, nullptr, nullptr));

Reply via email to