Related: tdf#150408 RTF filter: handle legal numbering
The bugdoc's 2nd para started with 'Sect I.01', while Word rendered this
as 'Sect 1.01'.
The reason for this difference is that there is an "is legal" boolean
property on the numbering that we ignored from RTF during import/export.
Fix the problem by extending RTFDocumentImpl::dispatchTableSprmValue()
for the numbering table import + RtfAttributeOutput::NumberingLevel()
for the export.
The import default for this value was also wrong, given that the default
is to enable it when the control word is present.
Change-Id: I4dcd23768000ba29d4df314b475b412bb371545e
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/164078
Reviewed-by: Miklos Vajna <[email protected]>
Tested-by: Jenkins
diff --git a/sw/qa/extras/rtfexport/data/listWithLgl.rtf b/sw/qa/extras/rtfexport/data/listWithLgl.rtf
new file mode 100644
index 0000000..4355049
--- /dev/null
+++ b/sw/qa/extras/rtfexport/data/listWithLgl.rtf
@@ -0,0 +1,23 @@
{\rtf1
{\*\listtable
{\list\listtemplateid197063698
{\listlevel\levelnfc1\levelnfcn1\leveljc0\leveljcn0\levelfollow2\levelstartat1\levelspace0\levelindent0
{\leveltext\'04CH \'00;}
{\levelnumbers\'04;}
\rtlch\fcs1 \af0 \ltrch\fcs0 \s15\fi0\li0\lin0 }
{\listlevel\levelnfc22\levelnfcn22\leveljc0\leveljcn0\levelfollow0\levelstartat1\levellegal\levelspace0\levelindent0
{\leveltext\'08Sect \'00.\'01;}
{\levelnumbers
\'06\'08;}
\rtlch\fcs1 \af0 \ltrch\fcs0 \s16\fi720\li0\jclisttab\tx2160\lin0 }
\listid1297755732}
}
{\*\listoverridetable
{\listoverride\listid1297755732\listoverridecount0\ls1}
}
\paperw12240\paperh15840\margl1440\margr1440\margt1440\margb1440
\pard\plain\ls1\par
\pard\plain\fi720\tx2160\ls1\ilvl1 Foo\par
\pard\plain\ls1\par
\pard\plain\fi720\tx2160\ls1\ilvl1 Bar\par
}
diff --git a/sw/qa/extras/rtfexport/rtfexport3.cxx b/sw/qa/extras/rtfexport/rtfexport3.cxx
index e884611..263af64 100644
--- a/sw/qa/extras/rtfexport/rtfexport3.cxx
+++ b/sw/qa/extras/rtfexport/rtfexport3.cxx
@@ -718,6 +718,32 @@ DECLARE_RTFEXPORT_TEST(testTdf158409, "tdf158409.rtf")
CPPUNIT_ASSERT_EQUAL(8.0, getProperty<double>(xRun, "CharHeight"));
}
CPPUNIT_TEST_FIXTURE(Test, testLegalNumbering)
{
auto verify = [this]() {
// Second level's numbering should use Arabic numbers for first level reference
auto xPara = getParagraph(1);
CPPUNIT_ASSERT_EQUAL(OUString("CH I"), getProperty<OUString>(xPara, "ListLabelString"));
xPara = getParagraph(2);
// Without the accompanying fix in place, this test would have failed with:
// - Expected: Sect 1.01
// - Actual : Sect I.01
// i.e. \levellegal was ignored on import/export.
CPPUNIT_ASSERT_EQUAL(OUString("Sect 1.01"),
getProperty<OUString>(xPara, "ListLabelString"));
xPara = getParagraph(3);
CPPUNIT_ASSERT_EQUAL(OUString("CH II"), getProperty<OUString>(xPara, "ListLabelString"));
xPara = getParagraph(4);
CPPUNIT_ASSERT_EQUAL(OUString("Sect 2.01"),
getProperty<OUString>(xPara, "ListLabelString"));
};
createSwDoc("listWithLgl.rtf");
verify();
saveAndReload(mpFilter);
verify();
}
} // end of anonymous namespace
CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/sw/source/filter/ww8/rtfattributeoutput.cxx b/sw/source/filter/ww8/rtfattributeoutput.cxx
index 36bb0314..b996446 100644
--- a/sw/source/filter/ww8/rtfattributeoutput.cxx
+++ b/sw/source/filter/ww8/rtfattributeoutput.cxx
@@ -1632,7 +1632,7 @@ void RtfAttributeOutput::NumberingLevel(sal_uInt8 nLevel, sal_uInt16 nStart,
const wwFont* pFont, const SfxItemSet* pOutSet,
sal_Int16 nIndentAt, sal_Int16 nFirstLineIndex,
sal_Int16 /*nListTabPos*/, const OUString& rNumberingString,
const SvxBrushItem* pBrush, bool /*isLegal*/)
const SvxBrushItem* pBrush, bool isLegal)
{
m_rExport.Strm().WriteOString(SAL_NEWLINE_STRING);
if (nLevel > 8) // RTF knows only 9 levels
@@ -1771,6 +1771,11 @@ void RtfAttributeOutput::NumberingLevel(sal_uInt8 nLevel, sal_uInt16 nStart,
m_rExport.Strm().WriteOString(OOO_STRING_SVTOOLS_RTF_LEVELSTARTAT);
m_rExport.Strm().WriteNumberAsString(nStart);
if (isLegal)
{
m_rExport.Strm().WriteOString(OOO_STRING_SVTOOLS_RTF_LEVELLEGAL);
}
m_rExport.Strm().WriteOString(OOO_STRING_SVTOOLS_RTF_LEVELFOLLOW);
m_rExport.Strm().WriteNumberAsString(nFollow);
diff --git a/writerfilter/source/rtftok/rtfcontrolwords.cxx b/writerfilter/source/rtftok/rtfcontrolwords.cxx
index 3f5a082..8b035b3 100644
--- a/writerfilter/source/rtftok/rtfcontrolwords.cxx
+++ b/writerfilter/source/rtftok/rtfcontrolwords.cxx
@@ -715,7 +715,7 @@ RTFSymbol const aRTFControlWords[] = {
{ "levelindent", RTFControlType::VALUE, RTFKeyword::LEVELINDENT, 0 },
{ "leveljc", RTFControlType::VALUE, RTFKeyword::LEVELJC, 0 },
{ "leveljcn", RTFControlType::VALUE, RTFKeyword::LEVELJCN, 0 },
{ "levellegal", RTFControlType::VALUE, RTFKeyword::LEVELLEGAL, 0 },
{ "levellegal", RTFControlType::VALUE, RTFKeyword::LEVELLEGAL, 1 },
{ "levelnfc", RTFControlType::VALUE, RTFKeyword::LEVELNFC, 0 },
{ "levelnfcn", RTFControlType::VALUE, RTFKeyword::LEVELNFCN, 0 },
{ "levelnorestart", RTFControlType::VALUE, RTFKeyword::LEVELNORESTART, 0 },
diff --git a/writerfilter/source/rtftok/rtfdispatchvalue.cxx b/writerfilter/source/rtftok/rtfdispatchvalue.cxx
index f699b0e..1e7552d 100644
--- a/writerfilter/source/rtftok/rtfdispatchvalue.cxx
+++ b/writerfilter/source/rtftok/rtfdispatchvalue.cxx
@@ -135,6 +135,9 @@ bool RTFDocumentImpl::dispatchTableSprmValue(RTFKeyword nKeyword, int nParam)
nSprm = NS_ooxml::LN_CT_Style_next;
pIntValue = new RTFValue(getStyleName(nParam));
break;
case RTFKeyword::LEVELLEGAL:
nSprm = NS_ooxml::LN_CT_Lvl_isLgl;
break;
default:
break;
}