Kaydet (Commit) cbe79789 authored tarafından Miklos Vajna's avatar Miklos Vajna

tdf#86814 RTF import: fix sometimes lost bold style

The problem was that commit 76c0d0ab
(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
üst 3aebc670
{\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}
......@@ -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: */
......@@ -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.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment