diff options
author | Miklos Vajna <vmiklos@collabora.co.uk> | 2018-02-26 21:17:59 +0100 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2018-02-28 10:20:00 +0100 |
commit | 7963353a816f22a66330923f90f500820784313a (patch) | |
tree | 0f1d639afd54b6f68977f92673886b9c5afb0985 /writerfilter | |
parent | 46fe7d8928baa4762fba723aaed22ff018be716a (diff) |
tdf#115715 RTF import: ignore zero para indents in styles without parents
The only reason the DOCX equivalent of the bugdoc was imported correctly
is that these default zero margins are simply missing from the DOCX
markup, suggesting Word ignores them. We now do the same, this way
the stripped down document's 3 paragraphs all have different margins as
expected.
(Also rework the testTdf112211_2 testcase to test the original problem
better: I verified that the layout is unchanged before/after this
patch.)
(cherry picked from commit 59363e639b67a8acbd6da240635de47921b2c955)
Change-Id: I88d56c27c19e070e983c3392f99bca96597cd56e
Reviewed-on: https://gerrit.libreoffice.org/50435
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Tested-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'writerfilter')
-rw-r--r-- | writerfilter/source/rtftok/rtfdocumentimpl.cxx | 30 | ||||
-rw-r--r-- | writerfilter/source/rtftok/rtfdocumentimpl.hxx | 4 |
2 files changed, 29 insertions, 5 deletions
diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.cxx b/writerfilter/source/rtftok/rtfdocumentimpl.cxx index bfb40c83b8be..9c4c714baeb3 100644 --- a/writerfilter/source/rtftok/rtfdocumentimpl.cxx +++ b/writerfilter/source/rtftok/rtfdocumentimpl.cxx @@ -114,7 +114,7 @@ void putNestedSprm(RTFSprms& rSprms, Id nParent, Id nId, const RTFValue::Pointer putNestedAttribute(rSprms, nParent, nId, pValue, eOverwrite, false); } -static RTFValue::Pointer_t lcl_getNestedAttribute(RTFSprms& rSprms, Id nParent, Id nId) +RTFValue::Pointer_t getNestedAttribute(RTFSprms& rSprms, Id nParent, Id nId) { RTFValue::Pointer_t pParent = rSprms.find(nParent); if (!pParent) @@ -377,11 +377,11 @@ void RTFDocumentImpl::checkFirstRun() // set the requested default font, if there are none RTFValue::Pointer_t pFont - = lcl_getNestedAttribute(m_aDefaultState.aCharacterSprms, - NS_ooxml::LN_EG_RPrBase_rFonts, NS_ooxml::LN_CT_Fonts_ascii); + = getNestedAttribute(m_aDefaultState.aCharacterSprms, NS_ooxml::LN_EG_RPrBase_rFonts, + NS_ooxml::LN_CT_Fonts_ascii); RTFValue::Pointer_t pCurrentFont - = lcl_getNestedAttribute(m_aStates.top().aCharacterSprms, - NS_ooxml::LN_EG_RPrBase_rFonts, NS_ooxml::LN_CT_Fonts_ascii); + = getNestedAttribute(m_aStates.top().aCharacterSprms, NS_ooxml::LN_EG_RPrBase_rFonts, + NS_ooxml::LN_CT_Fonts_ascii); if (pFont && !pCurrentFont) putNestedAttribute(m_aStates.top().aCharacterSprms, NS_ooxml::LN_EG_RPrBase_rFonts, NS_ooxml::LN_CT_Fonts_ascii, pFont); @@ -1943,6 +1943,26 @@ RTFError RTFDocumentImpl::pushState() writerfilter::Reference<Properties>::Pointer_t RTFDocumentImpl::createStyleProperties() { + int nBasedOn = 0; + RTFValue::Pointer_t pBasedOn = m_aStates.top().aTableSprms.find(NS_ooxml::LN_CT_Style_basedOn); + if (pBasedOn) + nBasedOn = pBasedOn->getInt(); + if (nBasedOn == 0) + { + // No parent style, then mimic what Word does: ignore attributes which + // would set a margin as formatting, but with a default value. + for (const auto& nId : + { NS_ooxml::LN_CT_Ind_firstLine, NS_ooxml::LN_CT_Ind_left, NS_ooxml::LN_CT_Ind_right, + NS_ooxml::LN_CT_Ind_start, NS_ooxml::LN_CT_Ind_end }) + { + RTFValue::Pointer_t pValue = getNestedAttribute(m_aStates.top().aParagraphSprms, + NS_ooxml::LN_CT_PPrBase_ind, nId); + if (pValue && pValue->getInt() == 0) + eraseNestedAttribute(m_aStates.top().aParagraphSprms, NS_ooxml::LN_CT_PPrBase_ind, + nId); + } + } + RTFValue::Pointer_t pParaProps = std::make_shared<RTFValue>( m_aStates.top().aParagraphAttributes, m_aStates.top().aParagraphSprms); RTFValue::Pointer_t pCharProps = std::make_shared<RTFValue>( diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.hxx b/writerfilter/source/rtftok/rtfdocumentimpl.hxx index 5fbfb9a46975..d17fbf7844b7 100644 --- a/writerfilter/source/rtftok/rtfdocumentimpl.hxx +++ b/writerfilter/source/rtftok/rtfdocumentimpl.hxx @@ -371,6 +371,10 @@ Id getParagraphBorder(sal_uInt32 nIndex); void putNestedAttribute(RTFSprms& rSprms, Id nParent, Id nId, const RTFValue::Pointer_t& pValue, RTFOverwrite eOverwrite = RTFOverwrite::YES, bool bAttribute = true); bool eraseNestedAttribute(RTFSprms& rSprms, Id nParent, Id nId); + +/// Looks up the nParent then the nested nId key in rSprms. +RTFValue::Pointer_t getNestedAttribute(RTFSprms& rSprms, Id nParent, Id nId); + /// Checks if rName is contained at least once in rProperties as a key. bool findPropertyName(const std::vector<css::beans::PropertyValue>& rProperties, const OUString& rName); |