From 726d0a2d54da3e97de242c2c10be3afd2aedf943 Mon Sep 17 00:00:00 2001 From: Vasily Melenchuk Date: Fri, 28 May 2021 09:10:35 +0300 Subject: tdf#137199: sw: convert list format string to prefix/suffix for ODF Since internally LO is able right now to use list level format strings and prefixes/suffixes only for backward compatibility, there is a need for conversion from format string (like "%1.") to prefix ("") and suffix (".") still used by ODT. Change-Id: If4b459e1b25b7f0ce511e6ac2de0824bb2c43d05 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/116288 Tested-by: Jenkins Reviewed-by: Thorsten Behrens --- sw/qa/extras/odfexport/data/tdf137199.docx | Bin 0 -> 13281 bytes sw/qa/extras/odfexport/odfexport2.cxx | 11 +++++++++++ xmloff/source/style/xmlnume.cxx | 19 ++++++++++++++++++- 3 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 sw/qa/extras/odfexport/data/tdf137199.docx diff --git a/sw/qa/extras/odfexport/data/tdf137199.docx b/sw/qa/extras/odfexport/data/tdf137199.docx new file mode 100644 index 000000000000..25b52977beca Binary files /dev/null and b/sw/qa/extras/odfexport/data/tdf137199.docx differ diff --git a/sw/qa/extras/odfexport/odfexport2.cxx b/sw/qa/extras/odfexport/odfexport2.cxx index 21455b9d343d..b58e9e9a1d1a 100644 --- a/sw/qa/extras/odfexport/odfexport2.cxx +++ b/sw/qa/extras/odfexport/odfexport2.cxx @@ -39,6 +39,17 @@ DECLARE_ODFEXPORT_TEST(testTdf52065_centerTabs, "testTdf52065_centerTabs.odt") CPPUNIT_ASSERT_EQUAL(OUString(u"Pečiatka zamestnávateľa"), parseDump("//body/txt[4]/Text[4]", "Portion")); } +DECLARE_ODFEXPORT_TEST(testTdf137199, "tdf137199.docx") +{ + CPPUNIT_ASSERT_EQUAL(OUString(">1<"), getProperty(getParagraph(1), "ListLabelString")); + + CPPUNIT_ASSERT_EQUAL(OUString("1)"), getProperty(getParagraph(2), "ListLabelString")); + + CPPUNIT_ASSERT_EQUAL(OUString("HELLO1WORLD!"), getProperty(getParagraph(3), "ListLabelString")); + + CPPUNIT_ASSERT_EQUAL(OUString("HELLO2WORLD!"), getProperty(getParagraph(4), "ListLabelString")); +} + // This test started in LO 7.2. Use the odfexport.cxx if you intend to backport to 7.1. CPPUNIT_PLUGIN_IMPLEMENT(); diff --git a/xmloff/source/style/xmlnume.cxx b/xmloff/source/style/xmlnume.cxx index 027bef033031..132e3f701a2e 100644 --- a/xmloff/source/style/xmlnume.cxx +++ b/xmloff/source/style/xmlnume.cxx @@ -121,7 +121,24 @@ void SvxXMLNumRuleExport::exportLevelStyle( sal_Int32 nLevel, { rProp.Value >>= sSuffix; } - else if( rProp.Name == "BulletChar" ) + else if (rProp.Name == "ListFormat") + { + OUString sListFormat; + rProp.Value >>= sListFormat; + + // Since we have no support for entire format string it should be converted + // to prefix and suffix. Of course, it is not so flexible as format string, + // but it is the only option + sal_Int32 nFirstReplacement = sListFormat.indexOf('%'); + sal_Int32 nLastReplacement = sListFormat.lastIndexOf('%') + 1; + if (nFirstReplacement > 0) + // Everything before first '%' will be prefix + sPrefix = sListFormat.copy(0, nFirstReplacement); + if (nLastReplacement >= 0 && nLastReplacement < sListFormat.getLength() -1 ) + // Everything beyond last '%' (+1 for follow up id) is a suffix + sSuffix = sListFormat.copy(nLastReplacement + 1); + } + else if (rProp.Name == "BulletChar") { OUString sValue; rProp.Value >>= sValue; -- cgit