summaryrefslogtreecommitdiff
path: root/writerfilter
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.co.uk>2016-08-16 09:16:47 +0200
committerCaolán McNamara <caolanm@redhat.com>2016-08-17 07:46:36 +0000
commitfaaec32b1b6f2a9f8fb0541a5355beddfec37432 (patch)
tree244ba79c6288ce4e0ffeb51c064db86d8944b817 /writerfilter
parente24ab8340c9e903431a724ea6559517bbdd9e99e (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 (cherry picked from commit 2de168e99ba9cd2539f1ddbeffad7e3eb71a7b1b) Reviewed-on: https://gerrit.libreoffice.org/28167 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/rtfdispatchflag.cxx3
-rw-r--r--writerfilter/source/rtftok/rtfdocumentimpl.cxx19
-rw-r--r--writerfilter/source/rtftok/rtfdocumentimpl.hxx4
3 files changed, 24 insertions, 2 deletions
diff --git a/writerfilter/source/rtftok/rtfdispatchflag.cxx b/writerfilter/source/rtftok/rtfdispatchflag.cxx
index 88445031e612..b8f5b7f179ca 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 8268a2f05ef5..93f120718685 100644
--- a/writerfilter/source/rtftok/rtfdocumentimpl.cxx
+++ b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
@@ -699,6 +699,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)
@@ -1246,10 +1259,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);
@@ -1260,6 +1276,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 88707378c9a9..1663b90550c6 100644
--- a/writerfilter/source/rtftok/rtfdocumentimpl.hxx
+++ b/writerfilter/source/rtftok/rtfdocumentimpl.hxx
@@ -437,6 +437,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.
@@ -518,6 +520,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;