sw/qa/extras/rtfexport/data/tdf104390.rtf | 6 ++++++ sw/qa/extras/rtfexport/rtfexport5.cxx | 15 +++++++++++++++ writerfilter/source/rtftok/rtfdocumentimpl.cxx | 20 +++++++++++++------- 3 files changed, 34 insertions(+), 7 deletions(-)
New commits: commit 24b5490cb0fd8de19415509fbf452874669106ad Author: Vasily Melenchuk <vasily.melenc...@cib.de> AuthorDate: Mon Mar 21 17:12:12 2022 +0300 Commit: Miklos Vajna <vmik...@collabora.com> CommitDate: Tue Mar 22 09:38:07 2022 +0100 tdf#104390: rtf import: init default font for entire state stack If first document element is buried deep in destinations and thus deep in state stack (m_aStates) initialization of default font is very local and will be lost after closing these destinations. So let's initialize entire states stack with default font if none is provided istead of initialization just a top element. Change-Id: I966c282f43b84baece909a4c3cd359cbcd317e63 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/131906 Tested-by: Jenkins Reviewed-by: Miklos Vajna <vmik...@collabora.com> diff --git a/sw/qa/extras/rtfexport/data/tdf104390.rtf b/sw/qa/extras/rtfexport/data/tdf104390.rtf new file mode 100644 index 000000000000..842e73e19a85 --- /dev/null +++ b/sw/qa/extras/rtfexport/data/tdf104390.rtf @@ -0,0 +1,6 @@ +{\rtf1\deff0 +{\fonttbl +{\f0 Courier New;}} +\fs72 +{{{{Hello }}}{World!}} +} \ No newline at end of file diff --git a/sw/qa/extras/rtfexport/rtfexport5.cxx b/sw/qa/extras/rtfexport/rtfexport5.cxx index 7a7d4b8b2216..55074102a1ec 100644 --- a/sw/qa/extras/rtfexport/rtfexport5.cxx +++ b/sw/qa/extras/rtfexport/rtfexport5.cxx @@ -1362,6 +1362,21 @@ DECLARE_RTFEXPORT_TEST(testTdf118047, "tdf118047.rtf") CPPUNIT_ASSERT_MESSAGE("Header is too large", 1000 > nHeight); } +DECLARE_RTFEXPORT_TEST(testTdf104390, "tdf104390.rtf") +{ + uno::Reference<text::XTextRange> xPara = getParagraph(1); + uno::Reference<container::XEnumerationAccess> xRunEnumAccess(xPara, uno::UNO_QUERY); + uno::Reference<container::XEnumeration> xRunEnum = xRunEnumAccess->createEnumeration(); + + // Check font in first run + uno::Reference<text::XTextRange> xRun(xRunEnum->nextElement(), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(36.f, getProperty<float>(xRun, "CharHeight")); + CPPUNIT_ASSERT_EQUAL(OUString("Courier New"), getProperty<OUString>(xRun, "CharFontName")); + + // Ensure there is only one run + CPPUNIT_ASSERT_MESSAGE("Extra elements in paragraph", !xRunEnum->hasMoreElements()); +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.cxx b/writerfilter/source/rtftok/rtfdocumentimpl.cxx index 75d6ae193ffc..bceea94c5980 100644 --- a/writerfilter/source/rtftok/rtfdocumentimpl.cxx +++ b/writerfilter/source/rtftok/rtfdocumentimpl.cxx @@ -396,16 +396,22 @@ void RTFDocumentImpl::checkFirstRun() assert(!m_bNeedSect || m_bFirstRunException); setNeedSect(true); // first call that succeeds - // set the requested default font, if there are none + // set the requested default font, if there are none for each state in stack RTFValue::Pointer_t pFont = getNestedAttribute(m_aDefaultState.getCharacterSprms(), NS_ooxml::LN_EG_RPrBase_rFonts, NS_ooxml::LN_CT_Fonts_ascii); - RTFValue::Pointer_t pCurrentFont - = getNestedAttribute(m_aStates.top().getCharacterSprms(), NS_ooxml::LN_EG_RPrBase_rFonts, - NS_ooxml::LN_CT_Fonts_ascii); - if (pFont && !pCurrentFont) - putNestedAttribute(m_aStates.top().getCharacterSprms(), NS_ooxml::LN_EG_RPrBase_rFonts, - NS_ooxml::LN_CT_Fonts_ascii, pFont); + if (!pFont) + return; + + for (size_t i = 0; i < m_aStates.size(); i++) + { + RTFValue::Pointer_t pCurrentFont + = getNestedAttribute(m_aStates[i].getCharacterSprms(), NS_ooxml::LN_EG_RPrBase_rFonts, + NS_ooxml::LN_CT_Fonts_ascii); + if (!pCurrentFont) + putNestedAttribute(m_aStates[i].getCharacterSprms(), NS_ooxml::LN_EG_RPrBase_rFonts, + NS_ooxml::LN_CT_Fonts_ascii, pFont); + } } void RTFDocumentImpl::setNeedPar(bool bNeedPar) { m_bNeedPar = bNeedPar; }