diff options
author | Miklos Vajna <vmiklos@collabora.co.uk> | 2017-01-03 08:49:43 +0100 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.co.uk> | 2017-01-03 11:56:29 +0100 |
commit | a9e029ace41562e28e9242d63230ad1ca275f5d3 (patch) | |
tree | 605fee980e467c8a5896bdf5053fd7422865091a /writerfilter | |
parent | avoid some numeric type conversions (diff) | |
download | core-a9e029ace41562e28e9242d63230ad1ca275f5d3.tar.gz core-a9e029ace41562e28e9242d63230ad1ca275f5d3.zip |
tdf#104744 RTF import: fix unexpected zero para left margin wrt style dedup
See commit 1be0a3fa9ebb22b607c54b47739d4467acfed259 (n#825305:
writerfilter RTF import: override style properties like Word,
2014-06-17) for the details on style override in RTF.
Here the problem was that we added an unneeded "reset to 0" property, the
opposite situation that commit 657c6cc3acec0528209a8584b838cd6de581c437
(tdf#104228 RTF import: fix override of style left/right para margin,
2016-12-13) was fixing (there a "reset to 0" was missing).
Change-Id: I37f079b9cb4773214d2531c2e34920b3b8927211
Diffstat (limited to 'writerfilter')
-rw-r--r-- | writerfilter/source/rtftok/rtfsprm.cxx | 74 |
1 files changed, 45 insertions, 29 deletions
diff --git a/writerfilter/source/rtftok/rtfsprm.cxx b/writerfilter/source/rtftok/rtfsprm.cxx index c7096f1c8754..da7bc815c6ca 100644 --- a/writerfilter/source/rtftok/rtfsprm.cxx +++ b/writerfilter/source/rtftok/rtfsprm.cxx @@ -153,6 +153,43 @@ static RTFValue::Pointer_t getDefaultSPRM(Id const id) } } +/// Does the clone / deduplication of a single sprm. +static void cloneAndDeduplicateSprm(std::pair<Id, RTFValue::Pointer_t>& rSprm, RTFSprms& ret) +{ + RTFValue::Pointer_t const pValue(ret.find(rSprm.first)); + if (pValue) + { + if (rSprm.second->equals(*pValue)) + { + ret.erase(rSprm.first); // duplicate to style + } + else if (!rSprm.second->getSprms().empty() || !rSprm.second->getAttributes().empty()) + { + RTFSprms const sprms(pValue->getSprms().cloneAndDeduplicate(rSprm.second->getSprms())); + RTFSprms const attributes(pValue->getAttributes().cloneAndDeduplicate(rSprm.second->getAttributes())); + ret.set(rSprm.first, RTFValue::Pointer_t(pValue->CloneWithSprms(attributes, sprms))); + } + } + else + { + // not found - try to override style with default + RTFValue::Pointer_t const pDefault(getDefaultSPRM(rSprm.first)); + if (pDefault) + { + ret.set(rSprm.first, pDefault); + } + else if (!rSprm.second->getSprms().empty() || !rSprm.second->getAttributes().empty()) + { + RTFSprms const sprms(RTFSprms().cloneAndDeduplicate(rSprm.second->getSprms())); + RTFSprms const attributes(RTFSprms().cloneAndDeduplicate(rSprm.second->getAttributes())); + if (!sprms.empty() || !attributes.empty()) + { + ret.set(rSprm.first, std::make_shared<RTFValue>(attributes, sprms)); + } + } + } +} + RTFSprms RTFSprms::cloneAndDeduplicate(RTFSprms& rReference) const { RTFSprms ret(*this); @@ -162,38 +199,17 @@ RTFSprms RTFSprms::cloneAndDeduplicate(RTFSprms& rReference) const // it is probably a bad idea to mess with those in any way here? for (auto& rSprm : rReference) { - RTFValue::Pointer_t const pValue(ret.find(rSprm.first)); - if (pValue) + // Paragraph formatting sprms are directly contained in case of + // paragraphs, but they are below NS_ooxml::LN_CT_Style_pPr in case of + // styles. So handle those children directly, to avoid unexpected + // addition of direct formatting sprms at the paragraph level. + if (rSprm.first == NS_ooxml::LN_CT_Style_pPr) { - if (rSprm.second->equals(*pValue)) - { - ret.erase(rSprm.first); // duplicate to style - } - else if (!rSprm.second->getSprms().empty() || !rSprm.second->getAttributes().empty()) - { - RTFSprms const sprms(pValue->getSprms().cloneAndDeduplicate(rSprm.second->getSprms())); - RTFSprms const attributes(pValue->getAttributes().cloneAndDeduplicate(rSprm.second->getAttributes())); - ret.set(rSprm.first, RTFValue::Pointer_t(pValue->CloneWithSprms(attributes, sprms))); - } + for (auto& i : rSprm.second->getSprms()) + cloneAndDeduplicateSprm(i, ret); } else - { - // not found - try to override style with default - RTFValue::Pointer_t const pDefault(getDefaultSPRM(rSprm.first)); - if (pDefault) - { - ret.set(rSprm.first, pDefault); - } - else if (!rSprm.second->getSprms().empty() || !rSprm.second->getAttributes().empty()) - { - RTFSprms const sprms(RTFSprms().cloneAndDeduplicate(rSprm.second->getSprms())); - RTFSprms const attributes(RTFSprms().cloneAndDeduplicate(rSprm.second->getAttributes())); - if (!sprms.empty() || !attributes.empty()) - { - ret.set(rSprm.first, std::make_shared<RTFValue>(attributes, sprms)); - } - } - } + cloneAndDeduplicateSprm(rSprm, ret); } return ret; } |