diff options
author | Miklos Vajna <vmiklos@collabora.co.uk> | 2016-08-16 09:16:47 +0200 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.co.uk> | 2016-08-16 10:43:09 +0200 |
commit | 2de168e99ba9cd2539f1ddbeffad7e3eb71a7b1b (patch) | |
tree | 29002b5a17d858e25cbce7230d9b6efa83504a40 /writerfilter | |
parent | c505ec78ddf97fbcb6e39b7865df5a455d41bf38 (diff) |
tdf#100507 RTF import: don't set default para style to the 0th char style
Regression from commit 1be0a3fa9ebb22b607c54b47739d4467acfed259
(n#825305: writerfilter RTF import: override style properties like Word,
2014-06-17), the problem was that the RTF_PARD handler wanted to set a
default paragraph style, but it didn't check if the 0th style is
actually a paragraph one. This resulted in using a character style name
as a paragraph one, throwing in SwUnoCursorHelper::SetTextFormatColl()
-> all paragraph properties were lost, including the left indent.
Fix this by tracking the style type, and filtering out character styles
when looking up a default paragraph style.
Change-Id: I41faab0e72667b89ec9a507014b395a675847abf
Diffstat (limited to 'writerfilter')
-rw-r--r-- | writerfilter/source/rtftok/rtfdispatchflag.cxx | 3 | ||||
-rw-r--r-- | writerfilter/source/rtftok/rtfdocumentimpl.cxx | 19 | ||||
-rw-r--r-- | writerfilter/source/rtftok/rtfdocumentimpl.hxx | 4 |
3 files changed, 24 insertions, 2 deletions
diff --git a/writerfilter/source/rtftok/rtfdispatchflag.cxx b/writerfilter/source/rtftok/rtfdispatchflag.cxx index 8fa7f8fc2108..b99876edbc19 100644 --- a/writerfilter/source/rtftok/rtfdispatchflag.cxx +++ b/writerfilter/source/rtftok/rtfdispatchflag.cxx @@ -485,7 +485,8 @@ RTFError RTFDocumentImpl::dispatchFlag(RTFKeyword nKeyword) // By default the style with index 0 is applied. { OUString const aName = getStyleName(0); - if (!aName.isEmpty()) + // But only in case it's not a character style. + if (!aName.isEmpty() && getStyleType(0) != NS_ooxml::LN_Value_ST_StyleType_character) { m_aStates.top().aParagraphSprms.set(NS_ooxml::LN_CT_PPrBase_pStyle, std::make_shared<RTFValue>(aName)); m_aStates.top().nCurrentStyleIndex = 0; diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.cxx b/writerfilter/source/rtftok/rtfdocumentimpl.cxx index 578751e85dfd..b01137383c5a 100644 --- a/writerfilter/source/rtftok/rtfdocumentimpl.cxx +++ b/writerfilter/source/rtftok/rtfdocumentimpl.cxx @@ -700,6 +700,19 @@ OUString RTFDocumentImpl::getStyleName(int nIndex) return m_pSuperstream->getStyleName(nIndex); } +Id RTFDocumentImpl::getStyleType(int nIndex) +{ + if (!m_pSuperstream) + { + Id nRet = 0; + if (m_aStyleTypes.find(nIndex) != m_aStyleTypes.end()) + nRet = m_aStyleTypes[nIndex]; + return nRet; + } + else + return m_pSuperstream->getStyleType(nIndex); +} + RTFParserState& RTFDocumentImpl::getDefaultState() { if (!m_pSuperstream) @@ -1247,10 +1260,13 @@ void RTFDocumentImpl::text(OUString& rString) } break; case Destination::STYLEENTRY: - if (m_aStates.top().aTableAttributes.find(NS_ooxml::LN_CT_Style_type)) + { + RTFValue::Pointer_t pType = m_aStates.top().aTableAttributes.find(NS_ooxml::LN_CT_Style_type); + if (pType) { // Word strips whitespace around style names. m_aStyleNames[m_nCurrentStyleIndex] = aName.trim(); + m_aStyleTypes[m_nCurrentStyleIndex] = pType->getInt(); auto pValue = std::make_shared<RTFValue>(aName.trim()); m_aStates.top().aTableAttributes.set(NS_ooxml::LN_CT_Style_styleId, pValue); m_aStates.top().aTableSprms.set(NS_ooxml::LN_CT_Style_name, pValue); @@ -1261,6 +1277,7 @@ void RTFDocumentImpl::text(OUString& rString) else SAL_INFO("writerfilter", "no RTF style type defined, ignoring"); break; + } case Destination::LISTNAME: // TODO: what can be done with a list name? break; diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.hxx b/writerfilter/source/rtftok/rtfdocumentimpl.hxx index 0c46d80935d7..50fc2986a019 100644 --- a/writerfilter/source/rtftok/rtfdocumentimpl.hxx +++ b/writerfilter/source/rtftok/rtfdocumentimpl.hxx @@ -438,6 +438,8 @@ public: OUString getFontName(int nIndex); /// Return the style name of an RTF style index. OUString getStyleName(int nIndex); + /// Return the style type of an RTF style index. + Id getStyleType(int nIndex); /// Return the encoding associated with a font index. rtl_TextEncoding getEncoding(int nFontIndex); /// Get the default parser state. @@ -519,6 +521,8 @@ private: std::vector<int> m_aFontIndexes; /// Maps style indexes to style names. std::map<int, OUString> m_aStyleNames; + /// Maps style indexes to style types. + std::map<int, Id> m_aStyleTypes; /// Color index <-> RGB color value map std::vector<sal_uInt32> m_aColorTable; bool m_bFirstRun; |