sw/qa/extras/rtfexport/data/substream-reusing-parent-encoding.rtf | 5 + sw/qa/extras/rtfexport/rtfexport8.cxx | 27 ++++++++++ sw/source/writerfilter/rtftok/rtfdocumentimpl.cxx | 3 + 3 files changed, 35 insertions(+)
New commits: commit 41b1542326d4924730ffad51cd01399f3b6ca237 Author: Mike Kaganski <mike.kagan...@collabora.com> AuthorDate: Sat Jun 14 19:43:00 2025 +0500 Commit: Mike Kaganski <mike.kagan...@collabora.com> CommitDate: Sat Jun 14 17:55:03 2025 +0200 tdf#155835: copy current encoding into newly created substream state RTF is defined to copy the current state whenever a new destination appears. Before the change, RTFDocumentImpl::resolveSubstream didn't keep its current encoding in the child RTFDocumentImpl; that led to its m_aDefaultState having the default RTL_TEXTENCODING_MS_1252; and when the destination didn't define its own encoding (e.g. using N), the non-ASCII octets were treated incorrectly. I don't know if other members of m_aDefaultState should be set to parent's current state. In theory, this could even be a full copy. Change-Id: I6f53bfd519598b5a4b5cd1f04f13575a5aa1fa2f Reviewed-on: https://gerrit.libreoffice.org/c/core/+/186499 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com> diff --git a/sw/qa/extras/rtfexport/data/substream-reusing-parent-encoding.rtf b/sw/qa/extras/rtfexport/data/substream-reusing-parent-encoding.rtf new file mode 100644 index 000000000000..897de277fb63 --- /dev/null +++ b/sw/qa/extras/rtfexport/data/substream-reusing-parent-encoding.rtf @@ -0,0 +1,5 @@ +{ tf1nsi +{onttbl{0swisscharset204prq2 Arial Cyr;}} +{\stylesheet{\*+0s16 �������� ����� +} \ No newline at end of file diff --git a/sw/qa/extras/rtfexport/rtfexport8.cxx b/sw/qa/extras/rtfexport/rtfexport8.cxx index 0cd6317abd6e..f255fbde2a20 100644 --- a/sw/qa/extras/rtfexport/rtfexport8.cxx +++ b/sw/qa/extras/rtfexport/rtfexport8.cxx @@ -722,6 +722,33 @@ CPPUNIT_TEST_FIXTURE(Test, testTdf166620) } } +CPPUNIT_TEST_FIXTURE(Test, testTdf155835) +{ + // Given a document with an encoding defined for a specific font that is defined for a main + // text run, which has a footnote substream; but the substream doesn't specify own font, and + // therefore depends on the parent current state: + createSwDoc("substream-reusing-parent-encoding.rtf"); + { + auto xSupplier = mxComponent.queryThrow<text::XFootnotesSupplier>(); + auto xFootnotes = xSupplier->getFootnotes(); + CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xFootnotes->getCount()); + auto xEndnoteText = xFootnotes->getByIndex(0).queryThrow<text::XText>(); + // Check that the footnote encoding was correct; without the fix, this would fail with + // - Expected: Текст сноски + // - Actual : Òåêñò ñíîñêè + CPPUNIT_ASSERT_EQUAL(u"Текст сноски"_ustr, xEndnoteText->getString()); + } + // Check export, too + saveAndReload(mpFilter); + { + auto xSupplier = mxComponent.queryThrow<text::XFootnotesSupplier>(); + auto xFootnotes = xSupplier->getFootnotes(); + CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xFootnotes->getCount()); + auto xEndnoteText = xFootnotes->getByIndex(0).queryThrow<text::XText>(); + CPPUNIT_ASSERT_EQUAL(u"Текст сноски"_ustr, xEndnoteText->getString()); + } +} + } // end of anonymous namespace CPPUNIT_PLUGIN_IMPLEMENT(); diff --git a/sw/source/writerfilter/rtftok/rtfdocumentimpl.cxx b/sw/source/writerfilter/rtftok/rtfdocumentimpl.cxx index 32a20cb09c80..b6a08f364c5f 100644 --- a/sw/source/writerfilter/rtftok/rtfdocumentimpl.cxx +++ b/sw/source/writerfilter/rtftok/rtfdocumentimpl.cxx @@ -401,6 +401,9 @@ void RTFDocumentImpl::resolveSubstream(std::size_t nPos, Id nId, OUString const& pImpl->m_aAuthorInitials = m_aAuthorInitials; m_aAuthorInitials.clear(); } + // Copy current encoding. Do we need to copy more state? + pImpl->m_aDefaultState.setCurrentEncoding( + (m_aStates.empty() ? m_aDefaultState : m_aStates.top()).getCurrentEncoding()); pImpl->m_nDefaultFontIndex = m_nDefaultFontIndex; pImpl->m_pStyleTableEntries = m_pStyleTableEntries; pImpl->Strm().Seek(nPos);