From 5710898ee78db405d61d52be14d26860877bea73 Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Fri, 17 Jun 2011 22:12:22 +0200 Subject: [PATCH] introduce lcl_putNestedAttribute --- .../source/rtftok/rtfdocumentimpl.cxx | 37 +++++++++++-------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.cxx b/writerfilter/source/rtftok/rtfdocumentimpl.cxx index 01078ebd451d..a85abb8e00e2 100644 --- a/writerfilter/source/rtftok/rtfdocumentimpl.cxx +++ b/writerfilter/source/rtftok/rtfdocumentimpl.cxx @@ -117,6 +117,21 @@ void lcl_putBorderProperty(std::stack& aStates, Id nId, RTFValue } } +// This works on any container (sprm, attribute), as long as the nested value is an attribute. +void lcl_putNestedAttribute(RTFSprms_t& rSprms, Id nParent, Id nId, RTFValue::Pointer_t pValue) +{ + RTFValue::Pointer_t pParent = RTFSprm::find(rSprms, nParent); + if (!pParent.get()) + { + RTFSprms_t aAttributes; + RTFValue::Pointer_t pParentValue(new RTFValue(aAttributes)); + rSprms.push_back(make_pair(nParent, pParentValue)); + pParent = pParentValue; + } + RTFSprms_t& rAttributes = pParent->getAttributes(); + rAttributes.push_back(make_pair(nId, pValue)); +} + RTFDocumentImpl::RTFDocumentImpl(uno::Reference const& xContext, uno::Reference const& xInputStream, uno::Reference const& xDstDoc, @@ -1055,29 +1070,21 @@ int RTFDocumentImpl::dispatchValue(RTFKeyword nKeyword, int nParam) break; case RTF_CHCBPAT: { - RTFSprms_t aAttributes; - RTFValue::Pointer_t pInnerValue(new RTFValue(getColorTable(nParam))); - aAttributes.push_back(make_pair(NS_ooxml::LN_CT_Shd_fill, pInnerValue)); - RTFValue::Pointer_t pValue(new RTFValue(aAttributes)); - m_aStates.top().aCharacterSprms.push_back(make_pair(NS_sprm::LN_CShd, pValue)); + RTFValue::Pointer_t pValue(new RTFValue(getColorTable(nParam))); + lcl_putNestedAttribute(m_aStates.top().aCharacterSprms, NS_sprm::LN_CShd, NS_ooxml::LN_CT_Shd_fill, pValue); } break; case RTF_CLCBPAT: { - RTFSprms_t aAttributes; - RTFValue::Pointer_t pInnerValue(new RTFValue(getColorTable(nParam))); - aAttributes.push_back(make_pair(NS_ooxml::LN_CT_Shd_fill, pInnerValue)); - RTFValue::Pointer_t pValue(new RTFValue(aAttributes)); - m_aStates.top().aTableCellsSprms.back()->push_back(make_pair(NS_ooxml::LN_CT_TcPrBase_shd, pValue)); + RTFValue::Pointer_t pValue(new RTFValue(getColorTable(nParam))); + lcl_putNestedAttribute(*m_aStates.top().aTableCellsSprms.back(), + NS_ooxml::LN_CT_TcPrBase_shd, NS_ooxml::LN_CT_Shd_fill, pValue); } break; case RTF_CBPAT: { - RTFSprms_t aAttributes; - RTFValue::Pointer_t pInnerValue(new RTFValue(getColorTable(nParam))); - aAttributes.push_back(make_pair(NS_ooxml::LN_CT_Shd_fill, pInnerValue)); - RTFValue::Pointer_t pValue(new RTFValue(aAttributes)); - m_aStates.top().aParagraphSprms.push_back(make_pair(NS_sprm::LN_PShd, pValue)); + RTFValue::Pointer_t pValue(new RTFValue(getColorTable(nParam))); + lcl_putNestedAttribute(m_aStates.top().aParagraphSprms, NS_sprm::LN_PShd, NS_ooxml::LN_CT_Shd_fill, pValue); } break; case RTF_ULC: