diff options
author | Miklos Vajna <vmiklos@collabora.co.uk> | 2014-01-24 21:44:57 +0100 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2014-04-28 12:14:58 +0000 |
commit | 9209e07e2a724fa85ba6fee0ead5a0baad247d27 (patch) | |
tree | 613867da3a087bcbf0772db1876eca29e68d516f /writerfilter/source | |
parent | 9e3d6ec6e5333bf1fa4bd151a9897dad20d11a14 (diff) |
fdo#70853 writerfilter: refactor to avoid redundant Papx class in doctok
(cherry picked from commit f453cf1d328f96dd5ad8e94b102bff3124e06154, but
only the rtftok part, the rest is not needed to fix the bug)
Conflicts:
writerfilter/source/dmapper/DomainMapper.cxx
writerfilter/source/dmapper/StyleSheetTable.cxx
writerfilter/source/doctok/resources.xmi
writerfilter/source/rtftok/rtfdocumentimpl.cxx
Change-Id: Ic65e750bab99fb6b4c862418ccc53aa4b1f1298e
Reviewed-on: https://gerrit.libreoffice.org/9173
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Tested-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'writerfilter/source')
-rw-r--r-- | writerfilter/source/rtftok/rtfdocumentimpl.cxx | 51 | ||||
-rw-r--r-- | writerfilter/source/rtftok/rtfdocumentimpl.hxx | 6 | ||||
-rw-r--r-- | writerfilter/source/rtftok/rtfsprm.cxx | 9 |
3 files changed, 40 insertions, 26 deletions
diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.cxx b/writerfilter/source/rtftok/rtfdocumentimpl.cxx index d06f6bcd170c..ab23fb46f23d 100644 --- a/writerfilter/source/rtftok/rtfdocumentimpl.cxx +++ b/writerfilter/source/rtftok/rtfdocumentimpl.cxx @@ -632,6 +632,19 @@ int RTFDocumentImpl::getFontIndex(int nIndex) return m_pSuperstream->getFontIndex(nIndex); } +OUString RTFDocumentImpl::getStyleName(int nIndex) +{ + if (!m_pSuperstream) + { + OUString aRet; + if (m_aStyleNames.find(nIndex) != m_aStyleNames.end()) + aRet = m_aStyleNames[nIndex]; + return aRet; + } + else + return m_pSuperstream->getStyleName(nIndex); +} + RTFParserState& RTFDocumentImpl::getDefaultState() { if (!m_pSuperstream) @@ -1075,8 +1088,11 @@ void RTFDocumentImpl::text(OUString& rString) case DESTINATION_STYLEENTRY: if (m_aStates.top().aTableAttributes.find(NS_rtf::LN_SGC)) { - RTFValue::Pointer_t pValue(new RTFValue(m_aStates.top().aDestinationText.makeStringAndClear())); - m_aStates.top().aTableAttributes.set(NS_rtf::LN_XSTZNAME1, pValue); + OUString aName = m_aStates.top().aDestinationText.makeStringAndClear(); + m_aStyleNames[m_nCurrentStyleIndex] = aName; + RTFValue::Pointer_t pValue(new RTFValue(aName)); + m_aStates.top().aTableAttributes.set(NS_ooxml::LN_CT_Style_styleId, pValue); + m_aStates.top().aTableSprms.set(NS_ooxml::LN_CT_Style_name, pValue); writerfilter::Reference<Properties>::Pointer_t const pProp( new RTFReferenceProperties(mergeAttributes(), mergeSprms()) @@ -3039,6 +3055,10 @@ int RTFDocumentImpl::dispatchValue(RTFKeyword nKeyword, int nParam) case RTF_RI: nSprm = NS_sprm::LN_PDxaRight; break; case RTF_RIN: nSprm = 0x845d; break; case RTF_ITAP: nSprm = NS_sprm::LN_PTableDepth; break; + case RTF_SBASEDON: + nSprm = (nKeyword == RTF_SBASEDON) ? NS_ooxml::LN_CT_Style_basedOn : NS_ooxml::LN_CT_Style_next; + pIntValue.reset(new RTFValue(getStyleName(nParam))); + break; default: break; } if (nSprm > 0) @@ -3057,19 +3077,6 @@ int RTFDocumentImpl::dispatchValue(RTFKeyword nKeyword, int nParam) return 0; } - // Trivial table attributes. - switch (nKeyword) - { - case RTF_SBASEDON: nSprm = NS_rtf::LN_ISTDBASE; break; - case RTF_SNEXT: nSprm = NS_rtf::LN_ISTDNEXT; break; - default: break; - } - if (nSprm > 0) - { - m_aStates.top().aTableAttributes.set(nSprm, pIntValue); - return 0; - } - // Info group. switch (nKeyword) { @@ -3231,24 +3238,30 @@ int RTFDocumentImpl::dispatchValue(RTFKeyword nKeyword, int nParam) if (m_aStates.top().nDestinationState == DESTINATION_STYLESHEET || m_aStates.top().nDestinationState == DESTINATION_STYLEENTRY) { m_nCurrentStyleIndex = nParam; - m_aStates.top().aTableAttributes.set(NS_rtf::LN_ISTD, pIntValue); RTFValue::Pointer_t pValue(new RTFValue(1)); m_aStates.top().aTableAttributes.set(NS_rtf::LN_SGC, pValue); // paragraph style } else - m_aStates.top().aParagraphAttributes.set(NS_rtf::LN_ISTD, pIntValue); + { + OUString aName = getStyleName(nParam); + if (!aName.isEmpty()) + m_aStates.top().aParagraphSprms.set(NS_ooxml::LN_CT_PPrBase_pStyle, RTFValue::Pointer_t(new RTFValue(aName))); + } } break; case RTF_CS: if (m_aStates.top().nDestinationState == DESTINATION_STYLESHEET || m_aStates.top().nDestinationState == DESTINATION_STYLEENTRY) { m_nCurrentStyleIndex = nParam; - m_aStates.top().aTableAttributes.set(NS_rtf::LN_ISTD, pIntValue); RTFValue::Pointer_t pValue(new RTFValue(2)); m_aStates.top().aTableAttributes.set(NS_rtf::LN_SGC, pValue); // character style } else - m_aStates.top().aCharacterAttributes.set(NS_rtf::LN_ISTD, pIntValue); + { + OUString aName = getStyleName(nParam); + if (!aName.isEmpty()) + m_aStates.top().aCharacterSprms.set(NS_ooxml::LN_EG_RPrBase_rStyle, RTFValue::Pointer_t(new RTFValue(aName))); + } break; case RTF_DEFF: m_aDefaultState.aCharacterSprms.set(NS_sprm::LN_CRgFtc0, pIntValue); diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.hxx b/writerfilter/source/rtftok/rtfdocumentimpl.hxx index 8c8edcfbeb55..1d10b6f7047e 100644 --- a/writerfilter/source/rtftok/rtfdocumentimpl.hxx +++ b/writerfilter/source/rtftok/rtfdocumentimpl.hxx @@ -266,7 +266,7 @@ namespace writerfilter { /// Text from special destinations. OUStringBuffer aDestinationText; - /// Same as the int value of NS_rtf::LN_ISTD in aParagraphAttributes, for performance reasons. + /// Index of the current style. int nCurrentStyleIndex; /// Points to the active buffer, if there is one. @@ -356,6 +356,8 @@ namespace writerfilter { void setNeedPar(bool bNeedPar); /// Return the dmapper index of an RTF index for fonts. int getFontIndex(int nIndex); + /// Return the style name of an RTF style index. + OUString getStyleName(int nIndex); /// Return the encoding associated with a dmapper font index. rtl_TextEncoding getEncoding(sal_uInt32 nFontIndex); /// Get the default parser state. @@ -427,6 +429,8 @@ namespace writerfilter { std::map<int, rtl_TextEncoding> m_aFontEncodings; /// Maps the non-continious font indexes to the continous dmapper indexes. std::vector<int> m_aFontIndexes; + /// Maps style indexes to style names. + std::map<int, OUString> m_aStyleNames; /// Color index <-> RGB color value map std::vector<sal_uInt32> m_aColorTable; bool m_bFirstRun; diff --git a/writerfilter/source/rtftok/rtfsprm.cxx b/writerfilter/source/rtftok/rtfsprm.cxx index 2af212136027..c6d917294c4e 100644 --- a/writerfilter/source/rtftok/rtfsprm.cxx +++ b/writerfilter/source/rtftok/rtfsprm.cxx @@ -133,12 +133,9 @@ void RTFSprms::deduplicate(RTFSprms& rReference) while (i != m_pSprms->end()) { bool bIgnore = false; - if (i->first != NS_rtf::LN_ISTD) - { - RTFValue::Pointer_t pValue(rReference.find(i->first)); - if (pValue.get() && i->second->equals(*pValue)) - bIgnore = true; - } + RTFValue::Pointer_t pValue(rReference.find(i->first)); + if (pValue.get() && i->second->equals(*pValue)) + bIgnore = true; if (bIgnore) i = m_pSprms->erase(i); else |