tdf#149258 sw ms export: no separator for NONE numbering level
This is to benefit ODT->DOCX.
LO does not show the separators specified after a numbering level
that has no numbering type (since LO 7.2.5).
However, MSO does show any specified separators.
So export this the way that LO sees it.
Note that in the very odd case where an MSO user actually wanted
these separators to be visible, LO fails to show them,
and thus this will end up exporting as "data loss". How sad.
make CppunitTest_sw_ooxmlexport21 \
CPPUNIT_TEST_NAME=testTdf156105_percentSuffix
Change-Id: I2c084de319ef4b1e77b6f377708c71a62dcc5910
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/167898
Tested-by: Jenkins
Reviewed-by: Justin Luth <jluth@mail.com>
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport21.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport21.cxx
index baeba73..e487bbf 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport21.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport21.cxx
@@ -298,6 +298,17 @@ DECLARE_OOXMLEXPORT_TEST(testTdf156105_percentSuffix, "tdf156105_percentSuffix.o
// given a numbered list with a non-escaping percent symbol in the prefix and suffix
CPPUNIT_ASSERT_EQUAL(OUString("(%)[%]"),
getProperty<OUString>(getParagraph(3), "ListLabelString"));
// tdf#149258 - NONE number should not export separator since LO doesn't currently show it
CPPUNIT_ASSERT_EQUAL_MESSAGE("showing levels 1, 2, and 4", OUString("(%)1.1.1[%]"),
getProperty<OUString>(getParagraph(4), "ListLabelString"));
if (isExported())
{
xmlDocUniquePtr pXmlNum = parseExport("word/numbering.xml");
// The 3rd level is NONE. If we include the separator, MS Word will display it.
assertXPath(pXmlNum, "/w:numbering/w:abstractNum[1]/w:lvl[4]/w:lvlText"_ostr, "val"_ostr,
"(%)%1.%2.%3%4[%]");
}
}
DECLARE_OOXMLEXPORT_TEST(testTdf160049_anchorMarginVML, "tdf160049_anchorMarginVML.docx")
diff --git a/sw/source/core/doc/number.cxx b/sw/source/core/doc/number.cxx
index f43ab14..e811f7b 100644
--- a/sw/source/core/doc/number.cxx
+++ b/sw/source/core/doc/number.cxx
@@ -763,8 +763,11 @@ OUString SwNumRule::MakeNumString( const SwNumberTree::tNumberVector & rNumVecto
// Numbering disabled - replacement is empty
// And we should skip all level string content until next level marker:
// so %1%.%2%.%3% with second level as NONE will result 1.1, not 1..1
// NOTE: if changed, fix MSWordExportBase::NumberingLevel to match new behaviour.
sal_Int32 nPositionNext = sLevelFormat.indexOf('%', nPosition + sFind.getLength());
if (nPosition >= 0 && nPositionNext >= nPosition)
if (nPosition >= 0 && nPositionNext > nPosition)
{
sLevelFormat = sLevelFormat.replaceAt(nPosition, nPositionNext - nPosition, u"");
}
diff --git a/sw/source/filter/ww8/wrtw8num.cxx b/sw/source/filter/ww8/wrtw8num.cxx
index 4c56472..e8f7b19 100644
--- a/sw/source/filter/ww8/wrtw8num.cxx
+++ b/sw/source/filter/ww8/wrtw8num.cxx
@@ -489,9 +489,18 @@ void MSWordExportBase::NumberingLevel(
sal_Int32 nFnd = sNumStr.indexOf(sSrch);
if (-1 != nFnd)
{
sal_Int32 nLen = sSrch.getLength();
if (i < nLvl && rRule.Get(i).GetNumberingType() == SVX_NUM_NUMBER_NONE)
{
// LO doesn't show this level, so don't export its separator
const OUString sSrch2("%" + OUString::number(i + 2) + "%");
const sal_Int32 nFnd2 = sNumStr.indexOf(sSrch2, nFnd);
if (-1 != nFnd2)
nLen = nFnd2 - nFnd;
}
*pLvlPos = static_cast<sal_uInt8>(nFnd + 1);
++pLvlPos;
sNumStr = sNumStr.replaceAt(nFnd, sSrch.getLength(), rtl::OUStringChar(static_cast<char>(i)));
sNumStr = sNumStr.replaceAt(nFnd, nLen, OUStringChar(static_cast<char>(i)));
}
}
}