summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.com>2022-09-01 08:35:06 +0200
committerMiklos Vajna <vmiklos@collabora.com>2022-09-01 10:39:23 +0200
commit2a403bcbbe0f45cd14a74ae76c4647096463e8ca (patch)
treee7cbb020f1d9e234401a8c25277add41f6e26b03
parentc9c68f0ddb6625fd86a6e172e15d1c943bb81911 (diff)
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 <vmiklos@collabora.com> Tested-by: Jenkins
-rw-r--r--writerfilter/qa/cppunittests/rtftok/data/char-hidden-intbl.rtf6
-rw-r--r--writerfilter/qa/cppunittests/rtftok/rtfdocumentimpl.cxx28
-rw-r--r--writerfilter/source/rtftok/rtfdocumentimpl.cxx16
3 files changed, 46 insertions, 4 deletions
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 4a5961f19355..5c8f058d710f 100644
--- a/writerfilter/source/rtftok/rtfdocumentimpl.cxx
+++ b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
@@ -1330,15 +1330,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));