sw/qa/extras/odfimport/data/tdf146257.odt |binary
 sw/qa/extras/odfimport/odfimport.cxx      |   32 ++++++++++++++++++++++++++++++
 sw/source/core/doc/number.cxx             |   27 ++++++++++++++++++++++++-
 3 files changed, 58 insertions(+), 1 deletion(-)

New commits:
commit b7f50e070fb21b8b4e444bb2cf12e500e615d7cf
Author:     Vasily Melenchuk <vasily.melenc...@cib.de>
AuthorDate: Sun Dec 26 20:38:30 2021 +0300
Commit:     Adolfo Jayme Barrientos <fit...@ubuntu.com>
CommitDate: Wed Dec 29 04:32:19 2021 +0100

    tdf#146257: sw: better handling for list numbering = NONE
    
    Previously during refactoring were lost some corner cases with
    some level having disabled numbering. In this case LO should
    strip useless delimiters up to next level.
    
    For example, if second level has disabled numbering, third level
    should look like "1.1", but not "1..1".
    
    Change-Id: I259a16b456f51bc76d5c8360974d0acadfc36776
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/127517
    Tested-by: Jenkins
    Reviewed-by: Vasily Melenchuk <vasily.melenc...@cib.de>
    (cherry picked from commit bf2b46aa15665dde63ceff4e7686b99b3990354f)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/127570
    Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org>
    (cherry picked from commit a732b9125af7fa3a960b6f16fe5ffe32f3788a2f)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/127573
    Reviewed-by: Hossein <hoss...@libreoffice.org>
    Reviewed-by: Adolfo Jayme Barrientos <fit...@ubuntu.com>
    Tested-by: Adolfo Jayme Barrientos <fit...@ubuntu.com>

diff --git a/sw/qa/extras/odfimport/data/tdf146257.odt 
b/sw/qa/extras/odfimport/data/tdf146257.odt
new file mode 100644
index 000000000000..2431fc0a8ff0
Binary files /dev/null and b/sw/qa/extras/odfimport/data/tdf146257.odt differ
diff --git a/sw/qa/extras/odfimport/odfimport.cxx 
b/sw/qa/extras/odfimport/odfimport.cxx
index 00c958ba1543..bd936937475d 100644
--- a/sw/qa/extras/odfimport/odfimport.cxx
+++ b/sw/qa/extras/odfimport/odfimport.cxx
@@ -1290,5 +1290,37 @@ CPPUNIT_TEST_FIXTURE(Test, 
testPageAnchorZIndexSecondPage)
         sal_Int32(3), getProperty<sal_Int32>(getShapeByName(u"Shape2"), 
"ZOrder"));
 }
 
+CPPUNIT_TEST_FIXTURE(Test, testTdf146257)
+{
+    load(mpTestDocumentPath, "tdf146257.odt");
+
+    // First list should contain no labels
+    {
+        uno::Reference<beans::XPropertySet> xPara(getParagraph(2), 
uno::UNO_QUERY);
+        CPPUNIT_ASSERT_EQUAL(OUString(""), getProperty<OUString>(xPara, 
"ListLabelString"));
+    }
+    {
+        uno::Reference<beans::XPropertySet> xPara(getParagraph(3), 
uno::UNO_QUERY);
+        CPPUNIT_ASSERT_EQUAL(OUString(""), getProperty<OUString>(xPara, 
"ListLabelString"));
+    }
+    {
+        uno::Reference<beans::XPropertySet> xPara(getParagraph(4), 
uno::UNO_QUERY);
+        CPPUNIT_ASSERT_EQUAL(OUString(""), getProperty<OUString>(xPara, 
"ListLabelString"));
+    }
+    // For second list ensure second level empty and thord level should not 
contain extra dots
+    {
+        uno::Reference<beans::XPropertySet> xPara(getParagraph(6), 
uno::UNO_QUERY);
+        CPPUNIT_ASSERT_EQUAL(OUString("1"), getProperty<OUString>(xPara, 
"ListLabelString"));
+    }
+    {
+        uno::Reference<beans::XPropertySet> xPara(getParagraph(7), 
uno::UNO_QUERY);
+        CPPUNIT_ASSERT_EQUAL(OUString(""), getProperty<OUString>(xPara, 
"ListLabelString"));
+    }
+    {
+        uno::Reference<beans::XPropertySet> xPara(getParagraph(8), 
uno::UNO_QUERY);
+        CPPUNIT_ASSERT_EQUAL(OUString("1.1"), getProperty<OUString>(xPara, 
"ListLabelString"));
+    }
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/core/doc/number.cxx b/sw/source/core/doc/number.cxx
index aae3d54e08d6..462910580782 100644
--- a/sw/source/core/doc/number.cxx
+++ b/sw/source/core/doc/number.cxx
@@ -661,6 +661,21 @@ OUString SwNumRule::MakeNumString( const 
SwNumberTree::tNumberVector & rNumVecto
 
     const SwNumFormat& rMyNFormat = Get( o3tl::narrowing<sal_uInt16>(nLevel) );
 
+    if (rMyNFormat.GetNumberingType() == SVX_NUM_NUMBER_NONE)
+    {
+        if (!rMyNFormat.HasListFormat())
+            return OUString();
+
+        // If numbering is disabled for this level we should emit just 
prefix/suffix
+        // Remove everything between first %1% and last %n% (including markers)
+        OUString sLevelFormat = rMyNFormat.GetListFormat(bInclStrings);
+        sal_Int32 nFirstPosition = sLevelFormat.indexOf("%");
+        sal_Int32 nLastPosition = sLevelFormat.lastIndexOf("%");
+        if (nFirstPosition >= 0 && nLastPosition >= nFirstPosition)
+            sLevelFormat = sLevelFormat.replaceAt(nFirstPosition, 
nLastPosition - nFirstPosition + 1, u"");
+        return sLevelFormat;
+    }
+
     css::lang::Locale aLocale( LanguageTag::convertToLocale(nLang));
 
     if (rMyNFormat.HasListFormat())
@@ -672,9 +687,19 @@ OUString SwNumRule::MakeNumString( const 
SwNumberTree::tNumberVector & rNumVecto
         for (SwNumberTree::tNumberVector::size_type i=0; i <= nLevel; ++i)
         {
             OUString sReplacement;
-            if (rMyNFormat.GetNumberingType() == SVX_NUM_NUMBER_NONE)
+            const SwNumFormat& rNFormat = Get(i);
+            if (rNFormat.GetNumberingType() == SVX_NUM_NUMBER_NONE)
             {
                 // 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
+                OUString sFind("%" + OUString::number(i + 1) + "%");
+                sal_Int32 nPositionToken = sLevelFormat.indexOf(sFind);
+                sal_Int32 nPositionNextToken = sLevelFormat.indexOf('%', 
nPositionToken + sFind.getLength());
+                if (nPositionToken > 0 && nPositionNextToken >= nPositionToken)
+                {
+                    sLevelFormat = sLevelFormat.replaceAt(nPositionToken, 
nPositionNextToken - nPositionToken, u"");
+                }
             }
             else if (rNumVector[i])
             {

Reply via email to