diff options
author | Vasily Melenchuk <vasily.melenchuk@cib.de> | 2022-03-21 17:12:12 +0300 |
---|---|---|
committer | Andras Timar <andras.timar@collabora.com> | 2022-03-25 12:59:34 +0100 |
commit | 4d2d9cf9c3165e2460466cc75e5a8453346610c8 (patch) | |
tree | f2ace9574829ed1676b63384728c1180a3d64df9 | |
parent | 36ca3df126b7497969b782a4188c8f71181b6d2d (diff) |
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 <vmiklos@collabora.com>
(cherry picked from commit 24b5490cb0fd8de19415509fbf452874669106ad)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/131864
Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org>
-rw-r--r-- | sw/qa/extras/rtfexport/data/tdf104390.rtf | 6 | ||||
-rw-r--r-- | sw/qa/extras/rtfexport/rtfexport5.cxx | 15 | ||||
-rw-r--r-- | writerfilter/source/rtftok/rtfdocumentimpl.cxx | 20 |
3 files changed, 34 insertions, 7 deletions
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; } |