summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.co.uk>2017-09-19 09:17:25 +0200
committerMichael Stahl <mstahl@redhat.com>2017-09-26 17:44:31 +0200
commitc324c0aa25d35e1f580079c80d40b80cd4bc3bf3 (patch)
tree5dc6c3ee66a7d13d27dd03049706980b8add1a2a
parentef9ac6e14cf2a5446136c2d4b3daf28418f56351 (diff)
tdf#112211 RTF import: fix unwanted direct formatting for left indents
This is a combination of 2 commits: 1st commit: Related: tdf#112211 DOCX import: fix handling of missing first ind in <w:lvl> Usually a DOCX numbering definition has multiple levels, each level containing a <w:ind ... w:hanging="..."/> element. When this is missing, we should default to the Word default, not to the Writer one. This makes the DOCX version of tdf#106953 imported correctly, in preparation of dropping the original fix that helped RTF only. [ The DOC version of the bugdoc is still not imported correctly. ] Reviewed-on: https://gerrit.libreoffice.org/42447 Reviewed-by: Miklos Vajna <vmiklos@collabora.co.uk> Tested-by: Jenkins <ci@libreoffice.org> (cherry picked from commit c72a1a74b5b1064fc9cdf9994b11fce26d866e26) Commit #2: Commit f528f9499bd91b700c549575e88fa102cfffede9 (tdf#106953 RTF import: fix missing paragraph left margin, 2017-05-16) fixed a problem around inheriting indents from numbering styles vs paragraph styles, but it turns out that document was rather special and in general the old behavior was correct. So fix that bug in a different way again, this time without less side-effects. The trick is that in case the level numbers group in a list definition ends with \u59 (instead of an ASCII ';'), then that group is considered to be invalid by Word. RTF import already was aware of this, but it wasn't known that when this invalid state is reached, that also means that the indents of the list level definitions should be ignored. So in general not putting direct formatting on a paragraph is a good thing: that way in case the paragraph style and the number style both has indent infos, then the numbering style wins, and that is what we want -- but in case \u59 appears in the list definition, then the indentation from the numbering style should be ignored. So fix up the tokenizer to import the indentation from list levels in general, ignore it for invalid list levels, and then we can remove the direct formatting from the paragraphs, which fixes this bug and keeps the old one fixed as well. This required fixing up two poor testcases, which tested paragraph properties, but in fact are interested in the real source of indentation, which is now the numbering style. Visually both bugdocs are unchanged. (cherry picked from commit 56a695fddb915bcba13b088b5b2b4e0841d4acbc) Conflicts: sw/qa/extras/rtfexport/rtfexport2.cxx writerfilter/source/dmapper/NumberingManager.cxx Change-Id: I6390aa870659a8ad02ba5512d84dea34dba29e9f Reviewed-on: https://gerrit.libreoffice.org/42793 Reviewed-by: Michael Stahl <mstahl@redhat.com> Tested-by: Michael Stahl <mstahl@redhat.com>
-rw-r--r--sw/qa/extras/ooxmlexport/data/tdf106953.docxbin0 -> 13833 bytes
-rw-r--r--sw/qa/extras/ooxmlexport/ooxmlexport.cxx7
-rw-r--r--sw/qa/extras/rtfexport/data/tdf112211.rtf31
-rw-r--r--sw/qa/extras/rtfexport/rtfexport.cxx8
-rw-r--r--sw/qa/extras/rtfimport/rtfimport.cxx16
-rw-r--r--writerfilter/source/dmapper/NumberingManager.cxx3
-rw-r--r--writerfilter/source/rtftok/rtfdispatchvalue.cxx10
-rw-r--r--writerfilter/source/rtftok/rtfdocumentimpl.cxx6
-rw-r--r--writerfilter/source/rtftok/rtfsprm.cxx1
9 files changed, 69 insertions, 13 deletions
diff --git a/sw/qa/extras/ooxmlexport/data/tdf106953.docx b/sw/qa/extras/ooxmlexport/data/tdf106953.docx
new file mode 100644
index 000000000000..31dc0e28e42f
--- /dev/null
+++ b/sw/qa/extras/ooxmlexport/data/tdf106953.docx
Binary files differ
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport.cxx
index e9d76b3da301..87afe90684d7 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport.cxx
@@ -846,6 +846,13 @@ DECLARE_OOXMLEXPORT_TEST(testTdf44986, "tdf44986.docx")
CPPUNIT_ASSERT_EQUAL(sal_Int32(1), getProperty< uno::Sequence<text::TableColumnSeparator> >(xTableRows->getByIndex(0), "TableColumnSeparators").getLength());
}
+DECLARE_OOXMLEXPORT_TEST(testTdf106953, "tdf106953.docx")
+{
+ uno::Reference<container::XIndexAccess> xRules = getProperty< uno::Reference<container::XIndexAccess> >(getStyles("NumberingStyles")->getByName("WWNum1"), "NumberingRules");
+ // This was -635, so the tab of the numbering expanded to a small value instead of matching Word's larger value.
+ CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(0), comphelper::SequenceAsHashMap(xRules->getByIndex(0))["FirstLineIndent"].get<sal_Int32>());
+}
+
CPPUNIT_PLUGIN_IMPLEMENT();
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/qa/extras/rtfexport/data/tdf112211.rtf b/sw/qa/extras/rtfexport/data/tdf112211.rtf
new file mode 100644
index 000000000000..d5b8010e953b
--- /dev/null
+++ b/sw/qa/extras/rtfexport/data/tdf112211.rtf
@@ -0,0 +1,31 @@
+{\rtf1\adeflang1037\ansi\ansicpg1252\uc1\adeff1\deff0\stshfdbch0\stshfloch0\stshfhich0\stshfbi0\deflang1033
+{\fonttbl
+{\f0\fbidi \froman\fcharset238\fprq2 Times New Roman;}
+{\f1\fbidi \fswiss\fcharset238\fprq2 Arial;}
+{\f2\fbidi \fmodern\fcharset238\fprq1 Courier New;}
+{\f3\fbidi \froman\fcharset2\fprq2 Symbol;}
+}
+\noqfpromote
+{\stylesheet
+{\s66 \li720 List Paragraph;}
+}
+{\*\listtable
+{\list\listtemplateid1644085804\listhybrid
+{\listlevel\levelnfc23\levelnfcn23\leveljc0\leveljcn0\levelfollow0
+\levelstartat1\levelspace0\levelindent0
+{\leveltext\leveltemplateid67698689\'01\u-3913 ?;}
+{\levelnumbers;}
+\f3\fbias0 \fi-360\li720 }
+{\listname ;}
+\listid2028170298}
+}
+{\*\listoverridetable
+{\listoverride\listid2028170298\listoverridecount0\ls1}
+}
+\paperw12240\paperh15840\margl1440\margr1440\margt1800\margb1440\gutter0\ltrsect
+\pard\plain \li0
+{Instance Size\par}
+\pard\plain \s66 \fi-360\li720
+\ls1
+{P\par}
+}
diff --git a/sw/qa/extras/rtfexport/rtfexport.cxx b/sw/qa/extras/rtfexport/rtfexport.cxx
index 1a4831f35b21..d3b1a4375492 100644
--- a/sw/qa/extras/rtfexport/rtfexport.cxx
+++ b/sw/qa/extras/rtfexport/rtfexport.cxx
@@ -1272,6 +1272,14 @@ DECLARE_RTFEXPORT_TEST(testTdf109790, "tdf109790.rtf")
CPPUNIT_ASSERT_EQUAL(10.f, getProperty<float>(getRun(getParagraphOfText(1, xCell->getText()), 1), "CharHeight"));
}
+DECLARE_RTFEXPORT_TEST(testTdf112211, "tdf112211.rtf")
+{
+ // This was 0, \fi in a list level definition was not imported.
+ auto xRules = getProperty< uno::Reference<container::XIndexAccess> >(getStyles("NumberingStyles")->getByName("WWNum1"), "NumberingRules");
+ comphelper::SequenceAsHashMap aRule(xRules->getByIndex(0));
+ CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(-635), aRule["FirstLineIndent"].get<sal_Int32>());
+}
+
CPPUNIT_PLUGIN_IMPLEMENT();
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/qa/extras/rtfimport/rtfimport.cxx b/sw/qa/extras/rtfimport/rtfimport.cxx
index f7f2e89d70a3..a69e8185fbeb 100644
--- a/sw/qa/extras/rtfimport/rtfimport.cxx
+++ b/sw/qa/extras/rtfimport/rtfimport.cxx
@@ -1373,11 +1373,10 @@ DECLARE_RTFIMPORT_TEST(testN825305, "n825305.rtf")
DECLARE_RTFIMPORT_TEST(testTdf106953, "tdf106953.rtf")
{
- CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(1270), getProperty<sal_Int32>(getParagraph(1), "ParaLeftMargin"));
- uno::Reference<beans::XPropertyState> xPropertyState(getParagraph(1), uno::UNO_QUERY);
- beans::PropertyState ePropertyState = xPropertyState->getPropertyState("ParaLeftMargin");
- // Was beans::PropertyState_DEFAULT_VALUE.
- CPPUNIT_ASSERT_EQUAL(beans::PropertyState_DIRECT_VALUE, ePropertyState);
+ auto xRules = getProperty< uno::Reference<container::XIndexAccess> >(getStyles("NumberingStyles")->getByName("WWNum1"), "NumberingRules");
+ comphelper::SequenceAsHashMap aRule(xRules->getByIndex(0));
+ CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(1270), aRule["IndentAt"].get<sal_Int32>());
+ CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(0), aRule["FirstLineIndent"].get<sal_Int32>());
}
DECLARE_RTFIMPORT_TEST(testParaBottomMargin, "para-bottom-margin.rtf")
@@ -2826,9 +2825,10 @@ DECLARE_RTFIMPORT_TEST(testTdf104317, "tdf104317.rtf")
DECLARE_RTFIMPORT_TEST(testTdf104744, "tdf104744.rtf")
{
- // This was 0, as an unexpected "left margin is 0" token was created during
- // import.
- CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(1270), getProperty<sal_Int32>(getParagraph(1), "ParaLeftMargin"));
+ auto xRules = getProperty< uno::Reference<container::XIndexAccess> >(getStyles("NumberingStyles")->getByName("WWNum1"), "NumberingRules");
+ comphelper::SequenceAsHashMap aRule(xRules->getByIndex(0));
+ // This was 0.
+ CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(1270), aRule["IndentAt"].get<sal_Int32>());
}
DECLARE_RTFIMPORT_TEST(testTdf105852, "tdf105852.rtf")
diff --git a/writerfilter/source/dmapper/NumberingManager.cxx b/writerfilter/source/dmapper/NumberingManager.cxx
index ee2c8afe3370..970992f99151 100644
--- a/writerfilter/source/dmapper/NumberingManager.cxx
+++ b/writerfilter/source/dmapper/NumberingManager.cxx
@@ -309,6 +309,9 @@ uno::Sequence< beans::PropertyValue > ListLevel::GetLevelProperties( )
aNumberingProperties.push_back(
beans::PropertyValue( getPropertyName(aProp->first), 0, aProp->second, beans::PropertyState_DIRECT_VALUE )
);
+ else if (rReadId == PROP_FIRST_LINE_INDENT)
+ // Writer default is -360 twips, Word default seems to be 0.
+ aNumberingProperties.push_back(beans::PropertyValue("FirstLineIndent", 0, uno::makeAny(static_cast<sal_Int32>(0)), beans::PropertyState_DIRECT_VALUE));
}
boost::optional<PropertyMap::Property> aPropFont = getProperty(PROP_CHAR_FONT_NAME);
diff --git a/writerfilter/source/rtftok/rtfdispatchvalue.cxx b/writerfilter/source/rtftok/rtfdispatchvalue.cxx
index f6a243e2fbc0..3125cab27b70 100644
--- a/writerfilter/source/rtftok/rtfdispatchvalue.cxx
+++ b/writerfilter/source/rtftok/rtfdispatchvalue.cxx
@@ -1370,8 +1370,16 @@ RTFError RTFDocumentImpl::dispatchValue(RTFKeyword nKeyword, int nParam)
}
break;
case RTF_FI:
- putNestedAttribute(m_aStates.top().aParagraphSprms, NS_ooxml::LN_CT_PPrBase_ind, NS_ooxml::LN_CT_Ind_firstLine, pIntValue);
+ {
+ if (m_aStates.top().eDestination == Destination::LISTLEVEL)
+ {
+ if (m_aStates.top().bLevelNumbersValid)
+ putNestedAttribute(m_aStates.top().aTableSprms, NS_ooxml::LN_CT_PPrBase_ind, NS_ooxml::LN_CT_Ind_firstLine, pIntValue);
+ }
+ else
+ putNestedAttribute(m_aStates.top().aParagraphSprms, NS_ooxml::LN_CT_PPrBase_ind, NS_ooxml::LN_CT_Ind_firstLine, pIntValue);
break;
+ }
case RTF_LI:
{
putNestedAttribute(m_aStates.top().aParagraphSprms, NS_ooxml::LN_CT_PPrBase_ind, NS_ooxml::LN_CT_Ind_left, pIntValue);
diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.cxx b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
index 2150266930be..229dc02781ba 100644
--- a/writerfilter/source/rtftok/rtfdocumentimpl.cxx
+++ b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
@@ -2964,9 +2964,9 @@ RTFError RTFDocumentImpl::popState()
if (!m_aStates.empty())
{
m_aStates.top().aTableSprms = aState.aTableSprms;
- if (aState.eDestination == Destination::LEVELNUMBERS)
- // Both current and parent state is levelnumbers: mark parent
- // as invalid as well if necessary.
+ if (m_aStates.top().eDestination == Destination::LEVELNUMBERS || m_aStates.top().eDestination == Destination::LISTLEVEL)
+ // Parent state is level number or list level, current state is
+ // level numbers: mark parent as invalid as well if necessary.
m_aStates.top().bLevelNumbersValid = aState.bLevelNumbersValid;
}
break;
diff --git a/writerfilter/source/rtftok/rtfsprm.cxx b/writerfilter/source/rtftok/rtfsprm.cxx
index 783d3b952473..5ff40c8cd9cc 100644
--- a/writerfilter/source/rtftok/rtfsprm.cxx
+++ b/writerfilter/source/rtftok/rtfsprm.cxx
@@ -166,7 +166,6 @@ static bool isSPRMDeduplicateBlacklist(Id nId)
// Erasing these just because they equal to the style one is
// problematic, as then the used value won't be from the style, but
// possibly from the numbering.
- case NS_ooxml::LN_CT_Ind_left:
case NS_ooxml::LN_CT_Ind_right:
case NS_ooxml::LN_CT_Ind_firstLine:
case NS_ooxml::LN_CT_Ind_hanging: