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 07ab51a3ac3d2c2af417c950d095c1fba49ab2a9 Author: Vasily Melenchuk <vasily.melenc...@cib.de> AuthorDate: Mon Mar 21 17:12:12 2022 +0300 Commit: Xisco Fauli <xiscofa...@libreoffice.org> CommitDate: Tue Mar 22 14:28:21 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> (cherry picked from commit 24b5490cb0fd8de19415509fbf452874669106ad) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/131864 Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org> 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 36bf6c839b65..297635fce37e 100644 --- a/sw/qa/extras/rtfexport/rtfexport5.cxx +++ b/sw/qa/extras/rtfexport/rtfexport5.cxx @@ -1339,6 +1339,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 072430ebe15f..af4ba47158c3 100644 --- a/writerfilter/source/rtftok/rtfdocumentimpl.cxx +++ b/writerfilter/source/rtftok/rtfdocumentimpl.cxx @@ -397,16 +397,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; }