[Libreoffice-commits] core.git: sw/qa writerfilter/source
Miklos Vajna
vmiklos at collabora.co.uk
Tue Aug 16 08:43:39 UTC 2016
sw/qa/extras/rtfimport/data/tdf100507.rtf | 22 ++++++++++++++++++++++
sw/qa/extras/rtfimport/rtfimport.cxx | 6 ++++++
writerfilter/source/rtftok/rtfdispatchflag.cxx | 3 ++-
writerfilter/source/rtftok/rtfdocumentimpl.cxx | 19 ++++++++++++++++++-
writerfilter/source/rtftok/rtfdocumentimpl.hxx | 4 ++++
5 files changed, 52 insertions(+), 2 deletions(-)
New commits:
commit 2de168e99ba9cd2539f1ddbeffad7e3eb71a7b1b
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date: Tue Aug 16 09:16:47 2016 +0200
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
diff --git a/sw/qa/extras/rtfimport/data/tdf100507.rtf b/sw/qa/extras/rtfimport/data/tdf100507.rtf
new file mode 100644
index 0000000..1665c4e
--- /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 048eecd..f607168 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 8fa7f8f..b99876e 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 578751e..b011373 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 0c46d80..50fc298 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;
More information about the Libreoffice-commits
mailing list