From aa5c6d127559912ad60a63fbd972b78fb8f9691b Mon Sep 17 00:00:00 2001 From: Vasily Melenchuk Date: Mon, 14 Jun 2021 14:27:56 +0300 Subject: new ODF numbered list parameter loext:num-list-format Instead of style:num-prefix and style:num-suffix new list format is much more flexible for storing list multilevel numberings. Now it is possible to have not just prefix/suffix but any random separators between levels, arbitrary levels order, etc. Internal LO format for list format is changed: instead of placeholders like %1, %2, etc we right now use %1%, %2%... Reason: for ODT documents, having more than 9 levels there is ambiguity in "%10": it is "%1" followed by "0" suffix, or "%10"? Aux changes: * removed zero width space hack: since format string is always defined this hack is interfering with standard list numbers printing (see changes in ooxmlexport14.cxx, ww8export3.cxx tests) * changed cross-references values to lists: they are now including full list label string: previously this was bit self-contradictory (see changes in odfexport.cxx and check_cross_references.py tests) Change-Id: I9696cc4846375c5f6222539aeaadbca5ae58ce27 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/117156 Tested-by: Jenkins Reviewed-by: Michael Stahl --- sw/qa/extras/odfexport/data/listformat.docx | Bin 0 -> 13082 bytes sw/qa/extras/odfexport/data/listformat.odt | Bin 0 -> 9221 bytes sw/qa/extras/odfexport/odfexport.cxx | 2 +- sw/qa/extras/odfexport/odfexport2.cxx | 66 ++++++++++++++++++++++++++++ sw/qa/extras/ooxmlexport/ooxmlexport14.cxx | 8 ++-- sw/qa/extras/rtfexport/rtfexport.cxx | 2 +- sw/qa/extras/ww8export/ww8export2.cxx | 18 +++----- sw/qa/extras/ww8export/ww8export3.cxx | 6 +-- 8 files changed, 80 insertions(+), 22 deletions(-) create mode 100644 sw/qa/extras/odfexport/data/listformat.docx create mode 100644 sw/qa/extras/odfexport/data/listformat.odt (limited to 'sw/qa/extras') diff --git a/sw/qa/extras/odfexport/data/listformat.docx b/sw/qa/extras/odfexport/data/listformat.docx new file mode 100644 index 000000000000..338678d82d3f Binary files /dev/null and b/sw/qa/extras/odfexport/data/listformat.docx differ diff --git a/sw/qa/extras/odfexport/data/listformat.odt b/sw/qa/extras/odfexport/data/listformat.odt new file mode 100644 index 000000000000..ec3992c8fde9 Binary files /dev/null and b/sw/qa/extras/odfexport/data/listformat.odt differ diff --git a/sw/qa/extras/odfexport/odfexport.cxx b/sw/qa/extras/odfexport/odfexport.cxx index c117591d9ad8..06e675f48ee9 100644 --- a/sw/qa/extras/odfexport/odfexport.cxx +++ b/sw/qa/extras/odfexport/odfexport.cxx @@ -2697,7 +2697,7 @@ DECLARE_ODFEXPORT_TEST(testReferenceLanguage, "referencelanguage.odt") OUString const aFieldTexts[] = { "A 2", "Az Isten", "Az 50-esek", "A 2018-asok", "Az egyebek", "A fejezetek", u"Az „Őseinket...”", "a 2", - "Az v", "az 1", "Az e", "az 1", + "Az v.", "az 1", "Az e)", "az 1", "Az (5)", "az 1", "A 2", "az 1" }; uno::Reference xTextFieldsSupplier(mxComponent, uno::UNO_QUERY); // update "A (4)" to "Az (5)" diff --git a/sw/qa/extras/odfexport/odfexport2.cxx b/sw/qa/extras/odfexport/odfexport2.cxx index b58e9e9a1d1a..bbe5d7f193e7 100644 --- a/sw/qa/extras/odfexport/odfexport2.cxx +++ b/sw/qa/extras/odfexport/odfexport2.cxx @@ -50,6 +50,72 @@ DECLARE_ODFEXPORT_TEST(testTdf137199, "tdf137199.docx") CPPUNIT_ASSERT_EQUAL(OUString("HELLO2WORLD!"), getProperty(getParagraph(4), "ListLabelString")); } +DECLARE_ODFEXPORT_TEST(testListFormatDocx, "listformat.docx") +{ + // Ensure in resulting ODT we also have not just prefix/suffux, but custom delimiters + CPPUNIT_ASSERT_EQUAL(OUString(">1<"), getProperty(getParagraph(1), "ListLabelString")); + CPPUNIT_ASSERT_EQUAL(OUString(">>1/1<<"), getProperty(getParagraph(2), "ListLabelString")); + CPPUNIT_ASSERT_EQUAL(OUString(">>1/1/1<<"), getProperty(getParagraph(3), "ListLabelString")); + CPPUNIT_ASSERT_EQUAL(OUString(">>1/1/2<<"), getProperty(getParagraph(4), "ListLabelString")); + + // Check also that in numbering styles we have num-list-format defined + xmlDocUniquePtr pXmlDoc = parseExport("styles.xml"); + assertXPath(pXmlDoc, "/office:document-styles/office:styles/text:list-style[@style:name='WWNum1']/" + "text:list-level-style-number[@text:level='1']", "num-list-format", ">%1%<"); + assertXPath(pXmlDoc, "/office:document-styles/office:styles/text:list-style[@style:name='WWNum1']/" + "text:list-level-style-number[@text:level='2']", "num-list-format", ">>%1%/%2%<<"); + assertXPath(pXmlDoc, "/office:document-styles/office:styles/text:list-style[@style:name='WWNum1']/" + "text:list-level-style-number[@text:level='3']", "num-list-format", ">>%1%/%2%/%3%<<"); + + // But for compatibility there are still prefix/suffix + assertXPath(pXmlDoc, "/office:document-styles/office:styles/text:list-style[@style:name='WWNum1']/" + "text:list-level-style-number[@text:level='1']", "num-prefix", ">"); + assertXPath(pXmlDoc, "/office:document-styles/office:styles/text:list-style[@style:name='WWNum1']/" + "text:list-level-style-number[@text:level='1']", "num-suffix", "<"); + assertXPath(pXmlDoc, "/office:document-styles/office:styles/text:list-style[@style:name='WWNum1']/" + "text:list-level-style-number[@text:level='2']", "num-prefix", ">>"); + assertXPath(pXmlDoc, "/office:document-styles/office:styles/text:list-style[@style:name='WWNum1']/" + "text:list-level-style-number[@text:level='2']", "num-suffix", "<<"); + assertXPath(pXmlDoc, "/office:document-styles/office:styles/text:list-style[@style:name='WWNum1']/" + "text:list-level-style-number[@text:level='3']", "num-prefix", ">>"); + assertXPath(pXmlDoc, "/office:document-styles/office:styles/text:list-style[@style:name='WWNum1']/" + "text:list-level-style-number[@text:level='3']", "num-suffix", "<<"); +} + +DECLARE_ODFEXPORT_TEST(testListFormatOdt, "listformat.odt") +{ + // Ensure in resulting ODT we also have not just prefix/suffux, but custom delimiters + CPPUNIT_ASSERT_EQUAL(OUString(">1<"), getProperty(getParagraph(1), "ListLabelString")); + CPPUNIT_ASSERT_EQUAL(OUString(">>1.1<<"), getProperty(getParagraph(2), "ListLabelString")); + CPPUNIT_ASSERT_EQUAL(OUString(">>1.1.1<<"), getProperty(getParagraph(3), "ListLabelString")); + CPPUNIT_ASSERT_EQUAL(OUString(">>1.1.2<<"), getProperty(getParagraph(4), "ListLabelString")); + + if (xmlDocUniquePtr pXmlDoc = parseExport("content.xml")) + { + // Check how conversion from prefix/suffix to list format did work + assertXPath(pXmlDoc, "/office:document-content/office:automatic-styles/text:list-style[@style:name='L1']/" + "text:list-level-style-number[@text:level='1']", "num-list-format", ">%1%<"); + assertXPath(pXmlDoc, "/office:document-content/office:automatic-styles/text:list-style[@style:name='L1']/" + "text:list-level-style-number[@text:level='2']", "num-list-format", ">>%1%.%2%<<"); + assertXPath(pXmlDoc, "/office:document-content/office:automatic-styles/text:list-style[@style:name='L1']/" + "text:list-level-style-number[@text:level='3']", "num-list-format", ">>%1%.%2%.%3%<<"); + + // But for compatibility there are still prefix/suffix as they were before + assertXPath(pXmlDoc, "/office:document-content/office:automatic-styles/text:list-style[@style:name='L1']/" + "text:list-level-style-number[@text:level='1']", "num-prefix", ">"); + assertXPath(pXmlDoc, "/office:document-content/office:automatic-styles/text:list-style[@style:name='L1']/" + "text:list-level-style-number[@text:level='1']", "num-suffix", "<"); + assertXPath(pXmlDoc, "/office:document-content/office:automatic-styles/text:list-style[@style:name='L1']/" + "text:list-level-style-number[@text:level='2']", "num-prefix", ">>"); + assertXPath(pXmlDoc, "/office:document-content/office:automatic-styles/text:list-style[@style:name='L1']/" + "text:list-level-style-number[@text:level='2']", "num-suffix", "<<"); + assertXPath(pXmlDoc, "/office:document-content/office:automatic-styles/text:list-style[@style:name='L1']/" + "text:list-level-style-number[@text:level='3']", "num-prefix", ">>"); + assertXPath(pXmlDoc, "/office:document-content/office:automatic-styles/text:list-style[@style:name='L1']/" + "text:list-level-style-number[@text:level='3']", "num-suffix", "<<"); + } +} + // 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/sw/qa/extras/ooxmlexport/ooxmlexport14.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport14.cxx index d309e3577b80..e383984c1170 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport14.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport14.cxx @@ -1070,12 +1070,12 @@ DECLARE_OOXMLEXPORT_TEST(testTdf120394, "tdf120394.docx") { uno::Reference xPara(getParagraph(2), uno::UNO_QUERY); CPPUNIT_ASSERT_EQUAL(static_cast(1), getProperty(xPara, "NumberingLevel")); - CPPUNIT_ASSERT_EQUAL(OUString(CHAR_ZWSP), getProperty(xPara, "ListLabelString")); + CPPUNIT_ASSERT_EQUAL(OUString(), getProperty(xPara, "ListLabelString")); } { uno::Reference xPara(getParagraph(3), uno::UNO_QUERY); CPPUNIT_ASSERT_EQUAL(static_cast(1), getProperty(xPara, "NumberingLevel")); - CPPUNIT_ASSERT_EQUAL(OUString(CHAR_ZWSP), getProperty(xPara, "ListLabelString")); + CPPUNIT_ASSERT_EQUAL(OUString(), getProperty(xPara, "ListLabelString")); } { uno::Reference xPara(getParagraph(5), uno::UNO_QUERY); @@ -1090,7 +1090,7 @@ DECLARE_OOXMLEXPORT_TEST(testTdf133605, "tdf133605.docx") { uno::Reference xPara(getParagraph(3), uno::UNO_QUERY); CPPUNIT_ASSERT_EQUAL(static_cast(0), getProperty(xPara, "NumberingLevel")); - CPPUNIT_ASSERT_EQUAL(OUString(CHAR_ZWSP), getProperty(xPara, "ListLabelString")); + CPPUNIT_ASSERT_EQUAL(OUString(), getProperty(xPara, "ListLabelString")); } { uno::Reference xPara(getParagraph(4), uno::UNO_QUERY); @@ -1116,7 +1116,7 @@ DECLARE_OOXMLEXPORT_TEST(testTdf133605_2, "tdf133605_2.docx") { uno::Reference xPara(getParagraph(3), uno::UNO_QUERY); CPPUNIT_ASSERT_EQUAL(static_cast(0), getProperty(xPara, "NumberingLevel")); - CPPUNIT_ASSERT_EQUAL(OUString(CHAR_ZWSP), getProperty(xPara, "ListLabelString")); + CPPUNIT_ASSERT_EQUAL(OUString(), getProperty(xPara, "ListLabelString")); } { uno::Reference xPara(getParagraph(4), uno::UNO_QUERY); diff --git a/sw/qa/extras/rtfexport/rtfexport.cxx b/sw/qa/extras/rtfexport/rtfexport.cxx index 75c4382324e5..714aa8f468b1 100644 --- a/sw/qa/extras/rtfexport/rtfexport.cxx +++ b/sw/qa/extras/rtfexport/rtfexport.cxx @@ -672,7 +672,7 @@ DECLARE_RTFEXPORT_TEST(testFdo66682, "fdo66682.rtf") aListFormat = rProp.Value.get(); } // Suffix was '\0' instead of ' '. - CPPUNIT_ASSERT_EQUAL(OUString(" %1 "), aListFormat); + CPPUNIT_ASSERT_EQUAL(OUString(" %1% "), aListFormat); } DECLARE_RTFEXPORT_TEST(testParaShadow, "para-shadow.rtf") diff --git a/sw/qa/extras/ww8export/ww8export2.cxx b/sw/qa/extras/ww8export/ww8export2.cxx index a1f8fe239d7a..3dc101b6f626 100644 --- a/sw/qa/extras/ww8export/ww8export2.cxx +++ b/sw/qa/extras/ww8export/ww8export2.cxx @@ -387,19 +387,11 @@ DECLARE_WW8EXPORT_TEST(testTdf119232_startEvenPage, "tdf119232_startEvenPage.doc DECLARE_WW8EXPORT_TEST(testTdf104805, "tdf104805.doc") { - uno::Reference xPropertySet(getStyles("NumberingStyles")->getByName("WW8Num1"), uno::UNO_QUERY); - uno::Reference xLevels(xPropertySet->getPropertyValue("NumberingRules"), uno::UNO_QUERY); - uno::Sequence aNumberingRule; - xLevels->getByIndex(1) >>= aNumberingRule; // 2nd level - for (const auto& rPair : std::as_const(aNumberingRule)) - { - if (rPair.Name == "Prefix") - // This was "." instead of empty, so the second paragraph was - // rendered as ".1" instead of "1.". - CPPUNIT_ASSERT_EQUAL(OUString(), rPair.Value.get()); - else if (rPair.Name == "Suffix") - CPPUNIT_ASSERT_EQUAL(OUString("."), rPair.Value.get()); - } + // Prefix was "." instead of empty, so the second paragraph was + // rendered as ".1" instead of "1.". + // Unittest modified due to Prefix/Suffix support obsolete + uno::Reference xPara(getParagraph(2), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString("1."), getProperty(xPara, "ListLabelString")); } DECLARE_WW8EXPORT_TEST(testTdf104334, "tdf104334.doc") diff --git a/sw/qa/extras/ww8export/ww8export3.cxx b/sw/qa/extras/ww8export/ww8export3.cxx index 9ccf3ea19a31..a69ddb7d989d 100644 --- a/sw/qa/extras/ww8export/ww8export3.cxx +++ b/sw/qa/extras/ww8export/ww8export3.cxx @@ -881,12 +881,12 @@ DECLARE_WW8EXPORT_TEST(testTdf120394, "tdf120394.doc") { uno::Reference xPara(getParagraph(5), uno::UNO_QUERY); CPPUNIT_ASSERT_EQUAL(static_cast(0), getProperty(xPara, "NumberingLevel")); - CPPUNIT_ASSERT_EQUAL(OUString(CHAR_ZWSP), getProperty(xPara, "ListLabelString")); + CPPUNIT_ASSERT_EQUAL(OUString(), getProperty(xPara, "ListLabelString")); } { uno::Reference xPara(getParagraph(8), uno::UNO_QUERY); CPPUNIT_ASSERT_EQUAL(static_cast(2), getProperty(xPara, "NumberingLevel")); - CPPUNIT_ASSERT_EQUAL(OUString(CHAR_ZWSP), getProperty(xPara, "ListLabelString")); + CPPUNIT_ASSERT_EQUAL(OUString(), getProperty(xPara, "ListLabelString")); } { uno::Reference xPara(getParagraph(9), uno::UNO_QUERY); @@ -896,7 +896,7 @@ DECLARE_WW8EXPORT_TEST(testTdf120394, "tdf120394.doc") { uno::Reference xPara(getParagraph(10), uno::UNO_QUERY); CPPUNIT_ASSERT_EQUAL(static_cast(2), getProperty(xPara, "NumberingLevel")); - CPPUNIT_ASSERT_EQUAL(OUString(CHAR_ZWSP), getProperty(xPara, "ListLabelString")); + CPPUNIT_ASSERT_EQUAL(OUString(), getProperty(xPara, "ListLabelString")); } } -- cgit