summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.co.uk>2015-05-18 07:38:32 +0200
committerCaolán McNamara <caolanm@redhat.com>2015-06-03 11:01:52 +0000
commit4c3afdb31382099005a16d2dd64a742c749f06ab (patch)
tree45a3fb1c9e195be46f3f9c7eba276ec074b9e30e
parentf4207428ea76157219a20a2d27ae5f52c713f199 (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 (cherry picked from commit cbe79789a0fc9b80b2fd14a5abfe0973a2cb69dc) Reviewed-on: https://gerrit.libreoffice.org/16051 Reviewed-by: Caolán McNamara <caolanm@redhat.com> Tested-by: Caolán McNamara <caolanm@redhat.com>
-rw-r--r--sw/qa/extras/rtfimport/data/tdf86814.rtf8
-rw-r--r--sw/qa/extras/rtfimport/rtfimport.cxx6
-rw-r--r--writerfilter/source/rtftok/rtfdocumentimpl.cxx57
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 0a57d66337fe..bfa13c53b2f1 100644
--- a/sw/qa/extras/rtfimport/rtfimport.cxx
+++ b/sw/qa/extras/rtfimport/rtfimport.cxx
@@ -2290,6 +2290,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 0941d8505dcb..75978e45a16d 100644
--- a/writerfilter/source/rtftok/rtfdocumentimpl.cxx
+++ b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
@@ -417,6 +417,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;
@@ -431,34 +457,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.