tdf#136587 rtf writerfilter: don't deduplicate yourself
The default style was not being imported because it
was based on itself, and therefore deduplicated itself away,
or something like that.
Probably this is the only scenario that truly would
end up deduplicating itself, but I made it generic
just in case. Why not?
Change-Id: I621092bf2e067933b5d23d27689a5d3a7f8cf2bd
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/102328
Tested-by: Jenkins
Tested-by: Justin Luth <justin_luth@sil.org>
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Reviewed-by: Justin Luth <justin_luth@sil.org>
diff --git a/sw/qa/extras/rtfexport/rtfexport4.cxx b/sw/qa/extras/rtfexport/rtfexport4.cxx
index 3ae227a..dbf8cf0 100644
--- a/sw/qa/extras/rtfexport/rtfexport4.cxx
+++ b/sw/qa/extras/rtfexport/rtfexport4.cxx
@@ -338,6 +338,9 @@ DECLARE_RTFEXPORT_TEST(testTdf136587_noStyleName, "tdf136587_noStyleName.rtf")
uno::UNO_QUERY_THROW);
CPPUNIT_ASSERT_EQUAL(sal_Int16(style::ParagraphAdjust_CENTER),
getProperty<sal_Int16>(xStyleProps, "ParaAdjust"));
xStyleProps.set(paragraphStyles->getByName("Default Paragraph Style"), uno::UNO_QUERY_THROW);
CPPUNIT_ASSERT_EQUAL(32.0f, getProperty<float>(xStyleProps, "CharHeight"));
}
CPPUNIT_TEST_FIXTURE(Test, testPageBorder)
diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.cxx b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
index cf757dd..7edeccd 100644
--- a/writerfilter/source/rtftok/rtfdocumentimpl.cxx
+++ b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
@@ -2093,6 +2093,7 @@ RTFReferenceTable::Entries_t RTFDocumentImpl::deduplicateStyleTable()
for (auto const& it : m_aStyleTableEntries)
{
auto pStyle = it.second;
ret[it.first] = pStyle;
// ugly downcasts here, but can't easily replace the members with
// RTFReferenceProperties because dmapper wants SvRef<Properties> anyway
RTFValue::Pointer_t const pBasedOn(
@@ -2101,6 +2102,10 @@ RTFReferenceTable::Entries_t RTFDocumentImpl::deduplicateStyleTable()
if (pBasedOn)
{
int const nBasedOn(pBasedOn->getInt());
// don't deduplicate yourself - especially a potential problem for the default style.
if (it.first == nBasedOn)
continue;
auto const itParent(m_aStyleTableEntries.find(nBasedOn)); // definition as read!
if (itParent != m_aStyleTableEntries.end())
{
@@ -2120,14 +2125,13 @@ RTFReferenceTable::Entries_t RTFDocumentImpl::deduplicateStyleTable()
static_cast<RTFReferenceProperties&>(*itParent->second).getAttributes(),
nStyleType));
pStyle = new RTFReferenceProperties(attributes, sprms);
ret[it.first] = new RTFReferenceProperties(attributes, sprms);
}
else
{
SAL_WARN("writerfilter.rtf", "parent style not found: " << nBasedOn);
}
}
ret[it.first] = pStyle;
}
assert(ret.size() == m_aStyleTableEntries.size());
return ret;