diff options
-rw-r--r-- | sw/qa/extras/rtfexport/data/tdf118047.rtf | 14 | ||||
-rw-r--r-- | sw/qa/extras/rtfexport/rtfexport5.cxx | 15 | ||||
-rw-r--r-- | writerfilter/source/rtftok/rtfdispatchflag.cxx | 6 | ||||
-rw-r--r-- | writerfilter/source/rtftok/rtfdocumentimpl.cxx | 27 | ||||
-rw-r--r-- | writerfilter/source/rtftok/rtfdocumentimpl.hxx | 3 |
5 files changed, 47 insertions, 18 deletions
diff --git a/sw/qa/extras/rtfexport/data/tdf118047.rtf b/sw/qa/extras/rtfexport/data/tdf118047.rtf new file mode 100644 index 000000000000..258d99de9bef --- /dev/null +++ b/sw/qa/extras/rtfexport/data/tdf118047.rtf @@ -0,0 +1,14 @@ +{\rtf1\ansi
+
+{\stylesheet
+{\fs72\sa3200 Normal;}
+}
+
+\sectd
+{
+\headerr
+Header\par
+}
+
+Text\par
+}
diff --git a/sw/qa/extras/rtfexport/rtfexport5.cxx b/sw/qa/extras/rtfexport/rtfexport5.cxx index b9a7321d724b..36bf6c839b65 100644 --- a/sw/qa/extras/rtfexport/rtfexport5.cxx +++ b/sw/qa/extras/rtfexport/rtfexport5.cxx @@ -1324,6 +1324,21 @@ DECLARE_RTFEXPORT_TEST(testTdf131234, "tdf131234.rtf") CPPUNIT_ASSERT_EQUAL(awt::FontSlant_NONE, getProperty<awt::FontSlant>(xRun, "CharPosture")); } +DECLARE_RTFEXPORT_TEST(testTdf118047, "tdf118047.rtf") +{ + uno::Reference<text::XTextRange> xPara = getParagraph(1); + + // Ensure that default "Normal" style properties are not applied to text: + // text remains with fontsize 12pt and no huge margin below + CPPUNIT_ASSERT_EQUAL(12.f, getProperty<float>(getRun(xPara, 1), "CharHeight")); + CPPUNIT_ASSERT_EQUAL(sal_Int32(0), getProperty<sal_Int32>(getParagraph(1), "ParaBottomMargin")); + + // Same for header, it should not derive props from "Normal" style + CPPUNIT_ASSERT_EQUAL(OUString("Header"), parseDump("/root/page[1]/header/txt/text()")); + sal_Int32 nHeight = parseDump("/root/page[1]/header/infos/bounds", "height").toInt32(); + CPPUNIT_ASSERT_MESSAGE("Header is too large", 1000 > nHeight); +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/source/rtftok/rtfdispatchflag.cxx b/writerfilter/source/rtftok/rtfdispatchflag.cxx index 2acb4d59f977..83c5a0966259 100644 --- a/writerfilter/source/rtftok/rtfdispatchflag.cxx +++ b/writerfilter/source/rtftok/rtfdispatchflag.cxx @@ -520,12 +520,8 @@ RTFError RTFDocumentImpl::dispatchFlag(RTFKeyword nKeyword) { m_aStates.top().getParagraphSprms().set(NS_ooxml::LN_CT_PPrBase_pStyle, new RTFValue(aName)); - m_aStates.top().setCurrentStyleIndex(0); - } - else - { - m_aStates.top().setCurrentStyleIndex(-1); } + m_aStates.top().setCurrentStyleIndex(0); } // Need to send paragraph properties again, if there will be any. m_bNeedPap = true; diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.cxx b/writerfilter/source/rtftok/rtfdocumentimpl.cxx index fb331f4b265a..072430ebe15f 100644 --- a/writerfilter/source/rtftok/rtfdocumentimpl.cxx +++ b/writerfilter/source/rtftok/rtfdocumentimpl.cxx @@ -324,6 +324,8 @@ RTFDocumentImpl::RTFDocumentImpl(uno::Reference<uno::XComponentContext> const& x m_pTokenizer = new RTFTokenizer(*this, m_pInStream.get(), m_xStatusIndicator); m_pSdrImport = new RTFSdrImport(*this, m_xDstDoc); + + m_pStyleTableEntries = std::make_shared<RTFReferenceTable::Entries_t>(); } RTFDocumentImpl::~RTFDocumentImpl() = default; @@ -363,6 +365,7 @@ void RTFDocumentImpl::resolveSubstream(std::size_t nPos, Id nId, OUString const& m_aAuthorInitials.clear(); } pImpl->m_nDefaultFontIndex = m_nDefaultFontIndex; + pImpl->m_pStyleTableEntries = m_pStyleTableEntries; pImpl->Strm().Seek(nPos); SAL_INFO("writerfilter.rtf", "substream start"); Mapper().substream(nId, pImpl); @@ -497,16 +500,16 @@ RTFDocumentImpl::getProperties(const RTFSprms& rAttributes, RTFSprms const& rSpr int nStyle = 0; if (!m_aStates.empty()) nStyle = m_aStates.top().getCurrentStyleIndex(); - auto it = m_aStyleTableEntries.find(nStyle); - if (it != m_aStyleTableEntries.end()) + auto it = m_pStyleTableEntries->find(nStyle); + if (it != m_pStyleTableEntries->end()) { // cloneAndDeduplicate() wants to know about only a single "style", so // let's merge paragraph and character style properties here. - auto itChar = m_aStyleTableEntries.end(); + auto itChar = m_pStyleTableEntries->end(); if (!m_aStates.empty()) { int nCharStyle = m_aStates.top().getCurrentCharacterStyleIndex(); - itChar = m_aStyleTableEntries.find(nCharStyle); + itChar = m_pStyleTableEntries->find(nCharStyle); } RTFSprms aStyleSprms; @@ -517,7 +520,7 @@ RTFDocumentImpl::getProperties(const RTFSprms& rAttributes, RTFSprms const& rSpr RTFReferenceProperties& rProps = *static_cast<RTFReferenceProperties*>(it->second.get()); lcl_copyFlatten(rProps, aStyleAttributes, aStyleSprms); - if (itChar != m_aStyleTableEntries.end()) + if (itChar != m_pStyleTableEntries->end()) { // Found active character style, then update aStyleSprms/Attributes. if (!nStyleType || nStyleType == NS_ooxml::LN_Value_ST_StyleType_character) @@ -1402,7 +1405,7 @@ void RTFDocumentImpl::text(OUString& rString) writerfilter::Reference<Properties>::Pointer_t const pProp( createStyleProperties()); - m_aStyleTableEntries.insert( + m_pStyleTableEntries->insert( std::make_pair(m_nCurrentStyleIndex, pProp)); } else @@ -2091,7 +2094,7 @@ writerfilter::Reference<Properties>::Pointer_t RTFDocumentImpl::createStylePrope /** 2 different representations of the styles are needed: 1) flat content, as read from the input file: - stored in m_aStyleTableEntries, used as reference input for + stored in m_pStyleTableEntries, used as reference input for deduplication both here and for hard formatting in getProperties() 2) real content, with proper override of sprms/attributes where it differs @@ -2100,7 +2103,7 @@ writerfilter::Reference<Properties>::Pointer_t RTFDocumentImpl::createStylePrope RTFReferenceTable::Entries_t RTFDocumentImpl::deduplicateStyleTable() { RTFReferenceTable::Entries_t ret; - for (auto const& it : m_aStyleTableEntries) + for (auto const& it : *m_pStyleTableEntries) { auto pStyle = it.second; ret[it.first] = pStyle; @@ -2116,8 +2119,8 @@ RTFReferenceTable::Entries_t RTFDocumentImpl::deduplicateStyleTable() if (it.first == nBasedOn) continue; - auto const itParent(m_aStyleTableEntries.find(nBasedOn)); // definition as read! - if (itParent != m_aStyleTableEntries.end()) + auto const itParent(m_pStyleTableEntries->find(nBasedOn)); // definition as read! + if (itParent != m_pStyleTableEntries->end()) { auto const pStyleType( static_cast<RTFReferenceProperties&>(*pStyle).getAttributes().find( @@ -2143,7 +2146,7 @@ RTFReferenceTable::Entries_t RTFDocumentImpl::deduplicateStyleTable() } } } - assert(ret.size() == m_aStyleTableEntries.size()); + assert(ret.size() == m_pStyleTableEntries->size()); return ret; } @@ -3668,7 +3671,7 @@ RTFParserState::RTFParserState(RTFDocumentImpl* pDocumentImpl) , m_nHour(0) , m_nMinute(0) , m_pCurrentDestinationText(nullptr) - , m_nCurrentStyleIndex(-1) + , m_nCurrentStyleIndex(0) , m_nCurrentCharacterStyleIndex(-1) , m_pCurrentBuffer(nullptr) , m_bInListpicture(false) diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.hxx b/writerfilter/source/rtftok/rtfdocumentimpl.hxx index fc5c8802b5d7..66e27a509be5 100644 --- a/writerfilter/source/rtftok/rtfdocumentimpl.hxx +++ b/writerfilter/source/rtftok/rtfdocumentimpl.hxx @@ -933,7 +933,8 @@ private: /// Raw default font index, use getFont() on it to get a real one. int m_nDefaultFontIndex; - RTFReferenceTable::Entries_t m_aStyleTableEntries; + /// To avoid copying entries between DomainMapper instances it is stored as pointer + std::shared_ptr<RTFReferenceTable::Entries_t> m_pStyleTableEntries; int m_nCurrentStyleIndex; bool m_bFormField; /// For the INCLUDEPICTURE field's argument. |