diff options
author | Miklos Vajna <vmiklos@collabora.co.uk> | 2018-02-26 21:17:59 +0100 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.co.uk> | 2018-02-27 09:10:10 +0100 |
commit | 59363e639b67a8acbd6da240635de47921b2c955 (patch) | |
tree | 60d08c8f643275cf5fef45b6d0acfbd3de4693ea /writerfilter | |
parent | 61e4c00eee8c5d07a29cf7ec97bad653e3e8f8ce (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.)
Change-Id: I88d56c27c19e070e983c3392f99bca96597cd56e
Reviewed-on: https://gerrit.libreoffice.org/50391
Reviewed-by: Miklos Vajna <vmiklos@collabora.co.uk>
Tested-by: Jenkins <ci@libreoffice.org>
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 44b671de27bc..a499234f1d80 100644 --- a/writerfilter/source/rtftok/rtfdocumentimpl.cxx +++ b/writerfilter/source/rtftok/rtfdocumentimpl.cxx @@ -103,7 +103,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) @@ -368,11 +368,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); @@ -1937,6 +1937,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 71e7657036f8..ae05d7a0647d 100644 --- a/writerfilter/source/rtftok/rtfdocumentimpl.hxx +++ b/writerfilter/source/rtftok/rtfdocumentimpl.hxx @@ -393,6 +393,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); |