summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.co.uk>2016-08-16 09:16:47 +0200
committerMiklos Vajna <vmiklos@collabora.co.uk>2016-08-16 10:43:09 +0200
commit2de168e99ba9cd2539f1ddbeffad7e3eb71a7b1b (patch)
tree29002b5a17d858e25cbce7230d9b6efa83504a40
parentc505ec78ddf97fbcb6e39b7865df5a455d41bf38 (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
-rw-r--r--sw/qa/extras/rtfimport/data/tdf100507.rtf22
-rw-r--r--sw/qa/extras/rtfimport/rtfimport.cxx6
-rw-r--r--writerfilter/source/rtftok/rtfdispatchflag.cxx3
-rw-r--r--writerfilter/source/rtftok/rtfdocumentimpl.cxx19
-rw-r--r--writerfilter/source/rtftok/rtfdocumentimpl.hxx4
5 files changed, 52 insertions, 2 deletions
diff --git a/sw/qa/extras/rtfimport/data/tdf100507.rtf b/sw/qa/extras/rtfimport/data/tdf100507.rtf
new file mode 100644
index 000000000000..1665c4e40dd5
--- /dev/null
+++ b/sw/qa/extras/rtfimport/data/tdf100507.rtf
@@ -0,0 +1,22 @@
+{\rtf1\ansi\ansicpg1252\deff0\dntblnsbdb\viewkind1
+{\fonttbl
+{\f0\froman\fcharset0 Times New Roman;}
+{\f1\fnil\fcharset0 Arial;}
+{\f2\fnil\fcharset0 Arial;}
+{\f3\fnil\fcharset0 Arial;}
+{\f4\fnil\fcharset0 Arial;}
+{\f5\fnil\fcharset0 Arial;}
+{\f6\fnil\fcharset0 Arial;}
+{\f7\fnil\fcharset0 Arial;}
+{\f8\fnil\fcharset0 Arial;}
+}
+{\colortbl;\red255\green255\blue0;\red0\green0\blue255;\red255\green255\blue255;}
+{\stylesheet
+{\*\cs0 Default Paragraph Font;}
+}
+\jexpand\pgwsxn12240\pghsxn15840
+\margl1748\margr1460\margt678\margb478\marglsxn1748\margrsxn1460\cols1\colno1\colw9032
+{\pard\plain \li3752\ql
+{\f2\b\fs20 Generation 1}
+\par}
+}
diff --git a/sw/qa/extras/rtfimport/rtfimport.cxx b/sw/qa/extras/rtfimport/rtfimport.cxx
index 048eecdc7d8c..f60716867cef 100644
--- a/sw/qa/extras/rtfimport/rtfimport.cxx
+++ b/sw/qa/extras/rtfimport/rtfimport.cxx
@@ -2678,6 +2678,12 @@ DECLARE_RTFIMPORT_TEST(testTdf78506, "tdf78506.rtf")
}
}
+DECLARE_RTFIMPORT_TEST(testTdf100507, "tdf100507.rtf")
+{
+ // This was 0: left margin of the first paragraph was lost on import.
+ CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(6618), getProperty<sal_Int32>(getParagraph(1), "ParaLeftMargin"));
+}
+
CPPUNIT_PLUGIN_IMPLEMENT();
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
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;