diff options
author | Miklos Vajna <vmiklos@collabora.co.uk> | 2015-05-18 07:38:32 +0200 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.co.uk> | 2015-05-18 07:47:20 +0200 |
commit | cbe79789a0fc9b80b2fd14a5abfe0973a2cb69dc (patch) | |
tree | 11b1f41d7a05a6787513b0ef2efb3f2ce9085465 | |
parent | 3aebc670e1816a8f4f0759e97d8f39b6aab05044 (diff) |
tdf#86814 RTF import: fix sometimes lost bold style
The problem was that commit 76c0d0abc89cd8948706083c2660b71a2dad670c
(RTF import: adapt getProperties() to createStyleProperties(),
2014-09-07) only made the character style sprms/attributes a flat list,
but not the paragraph style ones. Fixing that inconsistency avoids the
tokenizer adding unwanted default sprms, which cause the bold sprms go
away in the bugdoc.
Change-Id: I86bd1b26af18cd968375c9b39be9c8e71d51271f
-rw-r--r-- | sw/qa/extras/rtfimport/data/tdf86814.rtf | 8 | ||||
-rw-r--r-- | sw/qa/extras/rtfimport/rtfimport.cxx | 6 | ||||
-rw-r--r-- | writerfilter/source/rtftok/rtfdocumentimpl.cxx | 57 |
3 files changed, 47 insertions, 24 deletions
diff --git a/sw/qa/extras/rtfimport/data/tdf86814.rtf b/sw/qa/extras/rtfimport/data/tdf86814.rtf new file mode 100644 index 000000000000..6fb394e1a153 --- /dev/null +++ b/sw/qa/extras/rtfimport/data/tdf86814.rtf @@ -0,0 +1,8 @@ +{\rtf1 +{\stylesheet +{\s0 Normal;} +{\s23\sbasedon0\snext23\sl288\slmult1\ql\widctlpar\faauto\li0\ri0\lin0\rin0\fi0\sb100\sa100\ltrpar\b\dbch\af10\langfe1049\dbch\af11\afs20\alang1025\ab\loch\f5\fs20\lang1049 Style 23;} +} +\pard\plain \s23\sl288\slmult1\ql\widctlpar\faauto\li0\ri0\lin0\rin0\fi0\sb100\sa100\ltrpar\b\dbch\af10\langfe1049\dbch\af11\afs20\alang1025\ab\loch\f5\fs20\lang1049\ql\widctlpar\faauto\li0\ri0\lin0\rin0\fi0 +{\b\langfe1049\dbch\af11\afs20\alang1025\ab\rtlch \ltrch\loch\fs20\lang1049 hello} +\par} diff --git a/sw/qa/extras/rtfimport/rtfimport.cxx b/sw/qa/extras/rtfimport/rtfimport.cxx index 1a4dbfe286c4..e74d69401687 100644 --- a/sw/qa/extras/rtfimport/rtfimport.cxx +++ b/sw/qa/extras/rtfimport/rtfimport.cxx @@ -2286,6 +2286,12 @@ DECLARE_RTFIMPORT_TEST(testTdf90260Par, "hello.rtf") CPPUNIT_ASSERT_EQUAL(2, getParagraphs()); } +DECLARE_RTFIMPORT_TEST(testTdf86814, "tdf86814.rtf") +{ + // This was awt::FontWeight::NORMAL, i.e. the first run wasn't bold, when it should be bold (applied paragraph style with direct formatting). + CPPUNIT_ASSERT_EQUAL(awt::FontWeight::BOLD, getProperty<float>(getRun(getParagraph(1), 1), "CharWeight")); +} + 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 625818cd88f7..b351bef227b9 100644 --- a/writerfilter/source/rtftok/rtfdocumentimpl.cxx +++ b/writerfilter/source/rtftok/rtfdocumentimpl.cxx @@ -415,6 +415,32 @@ void RTFDocumentImpl::setNeedSect(bool bNeedSect) } } +/// Copy rProps to rStyleAttributes and rStyleSprms, but in case of nested sprms, copy their children as toplevel sprms/attributes. +static void lcl_copyFlatten(RTFReferenceProperties& rProps, RTFSprms& rStyleAttributes, RTFSprms& rStyleSprms) +{ + for (RTFSprms::Iterator_t it = rProps.getSprms().begin(); it != rProps.getSprms().end(); ++it) + { + // createStyleProperties() puts properties to rPr, but here we need a flat list. + if (it->first == NS_ooxml::LN_CT_Style_rPr) + { + // rPr can have both attributes and SPRMs, copy over both types. + RTFSprms& rRPrSprms = it->second->getSprms(); + for (RTFSprms::Iterator_t itRPrSprm = rRPrSprms.begin(); itRPrSprm != rRPrSprms.end(); ++itRPrSprm) + rStyleSprms.set(itRPrSprm->first, itRPrSprm->second); + + RTFSprms& rRPrAttributes = it->second->getAttributes(); + for (RTFSprms::Iterator_t itRPrAttribute = rRPrAttributes.begin(); itRPrAttribute != rRPrAttributes.end(); ++itRPrAttribute) + rStyleAttributes.set(itRPrAttribute->first, itRPrAttribute->second); + } + else + rStyleSprms.set(it->first, it->second); + } + + RTFSprms& rAttributes = rProps.getAttributes(); + for (RTFSprms::Iterator_t itAttr = rAttributes.begin(); itAttr != rAttributes.end(); ++itAttr) + rStyleAttributes.set(itAttr->first, itAttr->second); +} + writerfilter::Reference<Properties>::Pointer_t RTFDocumentImpl::getProperties(RTFSprms& rAttributes, RTFSprms& rSprms) { int nStyle = 0; @@ -429,34 +455,17 @@ writerfilter::Reference<Properties>::Pointer_t RTFDocumentImpl::getProperties(RT // let's merge paragraph and character style properties here. int nCharStyle = m_aStates.top().nCurrentCharacterStyleIndex; RTFReferenceTable::Entries_t::iterator itChar = m_aStyleTableEntries.find(nCharStyle); - RTFSprms aStyleSprms = rProps.getSprms(); - RTFSprms aStyleAttributes = rProps.getAttributes(); + RTFSprms aStyleSprms; + RTFSprms aStyleAttributes; + + // Ensure the paragraph style is a flat list. + lcl_copyFlatten(rProps, aStyleAttributes, aStyleSprms); + if (itChar != m_aStyleTableEntries.end()) { // Found active character style, then update aStyleSprms/Attributes. RTFReferenceProperties& rCharProps = *static_cast<RTFReferenceProperties*>(itChar->second.get()); - RTFSprms& rCharStyleSprms = rCharProps.getSprms(); - for (RTFSprms::Iterator_t itSprm = rCharStyleSprms.begin(); itSprm != rCharStyleSprms.end(); ++itSprm) - { - // createStyleProperties() puts properties to rPr, but here we need a flat list. - if (itSprm->first == NS_ooxml::LN_CT_Style_rPr) - { - // rPr can have both attributes and SPRM's, copy over both types. - RTFSprms& rRPrSprms = itSprm->second->getSprms(); - for (RTFSprms::Iterator_t itRPrSprm = rRPrSprms.begin(); itRPrSprm != rRPrSprms.end(); ++itRPrSprm) - aStyleSprms.set(itRPrSprm->first, itRPrSprm->second); - - RTFSprms& rRPrAttributes = itSprm->second->getAttributes(); - for (RTFSprms::Iterator_t itRPrAttribute = rRPrAttributes.begin(); itRPrAttribute != rRPrAttributes.end(); ++itRPrAttribute) - aStyleAttributes.set(itRPrAttribute->first, itRPrAttribute->second); - } - else - aStyleSprms.set(itSprm->first, itSprm->second); - } - - RTFSprms& rCharStyleAttributes = rCharProps.getAttributes(); - for (RTFSprms::Iterator_t itAttr = rCharStyleAttributes.begin(); itAttr != rCharStyleAttributes.end(); ++itAttr) - aStyleAttributes.set(itAttr->first, itAttr->second); + lcl_copyFlatten(rCharProps, aStyleAttributes, aStyleSprms); } // Get rid of direct formatting what is already in the style. |