sw/qa/extras/odfexport/data/tdf143605.odt |binary
 sw/qa/extras/odfexport/odfexport2.cxx     |    6 +
 sw/source/core/doc/number.cxx             |  168 +++++++++++++++---------------
 3 files changed, 90 insertions(+), 84 deletions(-)

New commits:
commit 214a649d7d4a2bab8c4d8829bacb16e72c24e026
Author:     Vasily Melenchuk <[email protected]>
AuthorDate: Thu Aug 5 20:40:13 2021 +0300
Commit:     Xisco Fauli <[email protected]>
CommitDate: Mon Aug 9 19:26:36 2021 +0200

    tdf#143605: sw: numbering rule is not constructed for numbering type "None"
    
    Previously during refactoring this condition was lost. And it
    is possible practically that we have all format for numbering
    (prefix, suffix, format string, etc) but numbering is disabled.
    
    Change-Id: I0c8ab446753308ad80b8d133824a936dacf6cc82
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/120082
    Tested-by: Thorsten Behrens <[email protected]>
    Reviewed-by: Thorsten Behrens <[email protected]>
    (cherry picked from commit d1f1f546b212ecd651146addeb328806bb270d5f)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/120137
    Tested-by: Xisco Fauli <[email protected]>
    Reviewed-by: Xisco Fauli <[email protected]>

diff --git a/sw/qa/extras/odfexport/data/tdf143605.odt 
b/sw/qa/extras/odfexport/data/tdf143605.odt
new file mode 100644
index 000000000000..7fb597e6d71c
Binary files /dev/null and b/sw/qa/extras/odfexport/data/tdf143605.odt differ
diff --git a/sw/qa/extras/odfexport/odfexport2.cxx 
b/sw/qa/extras/odfexport/odfexport2.cxx
index 68571cd8b863..8ed38f7eb85a 100644
--- a/sw/qa/extras/odfexport/odfexport2.cxx
+++ b/sw/qa/extras/odfexport/odfexport2.cxx
@@ -60,6 +60,12 @@ DECLARE_ODFEXPORT_TEST(testTdf137199, "tdf137199.docx")
     CPPUNIT_ASSERT_EQUAL(OUString("HELLO2WORLD!"), 
getProperty<OUString>(getParagraph(4), "ListLabelString"));
 }
 
+DECLARE_ODFEXPORT_TEST(testTdf143605, "tdf143605.odt")
+{
+    // With numering type "none" there should be nothing
+    CPPUNIT_ASSERT_EQUAL(OUString(""), getProperty<OUString>(getParagraph(1), 
"ListLabelString"));
+}
+
 DECLARE_ODFEXPORT_TEST(testListFormatDocx, "listformat.docx")
 {
     // Ensure in resulting ODT we also have not just prefix/suffux, but custom 
delimiters
diff --git a/sw/source/core/doc/number.cxx b/sw/source/core/doc/number.cxx
index 7d82a12623b6..a86668fa1936 100644
--- a/sw/source/core/doc/number.cxx
+++ b/sw/source/core/doc/number.cxx
@@ -657,102 +657,102 @@ OUString SwNumRule::MakeNumString( const 
SwNumberTree::tNumberVector & rNumVecto
         nLevel = _nRestrictToThisLevel;
     }
 
-    if (nLevel < MAXLEVEL)
-    {
-        const SwNumFormat& rMyNFormat = Get( 
o3tl::narrowing<sal_uInt16>(nLevel) );
+    assert(nLevel < MAXLEVEL);
 
-        {
-            css::lang::Locale aLocale( LanguageTag::convertToLocale(nLang));
+    const SwNumFormat& rMyNFormat = Get( o3tl::narrowing<sal_uInt16>(nLevel) );
 
-            if (rMyNFormat.HasListFormat())
-            {
-                OUString sLevelFormat = rMyNFormat.GetListFormat(bInclStrings);
+    if (rMyNFormat.GetNumberingType() == SVX_NUM_NUMBER_NONE)
+        return OUString();
 
-                // In this case we are ignoring GetIncludeUpperLevels: we put 
all
-                // level numbers requested by level format
-                for (SwNumberTree::tNumberVector::size_type i=0; i <= nLevel; 
++i)
-                {
-                    OUString sReplacement;
-                    if (rNumVector[i])
-                    {
-                        if (bOnlyArabic)
-                            sReplacement = OUString::number(rNumVector[i]);
-                        else
-                            sReplacement = Get(i).GetNumStr(rNumVector[i], 
aLocale);
-                    }
-                    else
-                        sReplacement = "0";        // all 0 level are a 0
+    css::lang::Locale aLocale( LanguageTag::convertToLocale(nLang));
 
-                    OUString sFind("%" + OUString::number(i + 1) + "%");
-                    sal_Int32 nPosition = sLevelFormat.indexOf(sFind);
-                    if (nPosition >= 0)
-                        sLevelFormat = sLevelFormat.replaceAt(nPosition, 
sFind.getLength(), sReplacement);
-                }
+    if (rMyNFormat.HasListFormat())
+    {
+        OUString sLevelFormat = rMyNFormat.GetListFormat(bInclStrings);
 
-                aStr = sLevelFormat;
+        // In this case we are ignoring GetIncludeUpperLevels: we put all
+        // level numbers requested by level format
+        for (SwNumberTree::tNumberVector::size_type i=0; i <= nLevel; ++i)
+        {
+            OUString sReplacement;
+            if (rNumVector[i])
+            {
+                if (bOnlyArabic)
+                    sReplacement = OUString::number(rNumVector[i]);
+                else
+                    sReplacement = Get(i).GetNumStr(rNumVector[i], aLocale);
             }
             else
+                sReplacement = "0";        // all 0 level are a 0
+
+            OUString sFind("%" + OUString::number(i + 1) + "%");
+            sal_Int32 nPosition = sLevelFormat.indexOf(sFind);
+            if (nPosition >= 0)
+                sLevelFormat = sLevelFormat.replaceAt(nPosition, 
sFind.getLength(), sReplacement);
+        }
+
+        aStr = sLevelFormat;
+    }
+    else
+    {
+        // Fallback case: level format is not defined
+        // So use old way with levels joining by dot "."
+        SwNumberTree::tNumberVector::size_type i = nLevel;
+
+        if (!IsContinusNum() &&
+            // - do not include upper levels, if level isn't numbered.
+            rMyNFormat.GetNumberingType() != SVX_NUM_NUMBER_NONE &&
+            rMyNFormat.GetIncludeUpperLevels())  // Just the own level?
+        {
+            sal_uInt8 n = rMyNFormat.GetIncludeUpperLevels();
+            if (1 < n)
             {
-                // Fallback case: level format is not defined
-                // So use old way with levels joining by dot "."
-                SwNumberTree::tNumberVector::size_type i = nLevel;
-
-                if (!IsContinusNum() &&
-                    // - do not include upper levels, if level isn't numbered.
-                    rMyNFormat.GetNumberingType() != SVX_NUM_NUMBER_NONE &&
-                    rMyNFormat.GetIncludeUpperLevels())  // Just the own level?
-                {
-                    sal_uInt8 n = rMyNFormat.GetIncludeUpperLevels();
-                    if (1 < n)
-                    {
-                        if (i + 1 >= n)
-                            i -= n - 1;
-                        else
-                            i = 0;
-                    }
-                }
+                if (i + 1 >= n)
+                    i -= n - 1;
+                else
+                    i = 0;
+            }
+        }
 
-                for (; i <= nLevel; ++i)
-                {
-                    const SwNumFormat& rNFormat = Get(i);
-                    if (SVX_NUM_NUMBER_NONE == rNFormat.GetNumberingType())
-                    {
-                        // Should 1.1.1 --> 2. NoNum --> 1..1 or 1.1 ??
-                        //                 if( i != rNum.nMyLevel )
-                        //                    aStr += ".";
-                        continue;
-                    }
+        for (; i <= nLevel; ++i)
+        {
+            const SwNumFormat& rNFormat = Get(i);
+            if (SVX_NUM_NUMBER_NONE == rNFormat.GetNumberingType())
+            {
+                // Should 1.1.1 --> 2. NoNum --> 1..1 or 1.1 ??
+                //                 if( i != rNum.nMyLevel )
+                //                    aStr += ".";
+                continue;
+            }
 
-                    if (rNumVector[i])
-                    {
-                        if (bOnlyArabic)
-                            aStr.append(rNumVector[i]);
-                        else
-                            aStr.append(rNFormat.GetNumStr(rNumVector[i], 
aLocale));
-                    }
-                    else
-                        aStr.append("0");        // all 0 level are a 0
-                    if (i != nLevel && !aStr.isEmpty())
-                        aStr.append(".");
-                }
+            if (rNumVector[i])
+            {
+                if (bOnlyArabic)
+                    aStr.append(rNumVector[i]);
+                else
+                    aStr.append(rNFormat.GetNumStr(rNumVector[i], aLocale));
+            }
+            else
+                aStr.append("0");        // all 0 level are a 0
+            if (i != nLevel && !aStr.isEmpty())
+                aStr.append(".");
+        }
 
-                // The type doesn't have any number, so don't append
-                // the post-/prefix string
-                if (bInclStrings && !bOnlyArabic &&
-                    SVX_NUM_CHAR_SPECIAL != rMyNFormat.GetNumberingType() &&
-                    SVX_NUM_BITMAP != rMyNFormat.GetNumberingType())
-                {
-                    const OUString& sPrefix = rMyNFormat.GetPrefix();
-                    const OUString& sSuffix = rMyNFormat.GetSuffix();
+        // The type doesn't have any number, so don't append
+        // the post-/prefix string
+        if (bInclStrings && !bOnlyArabic &&
+            SVX_NUM_CHAR_SPECIAL != rMyNFormat.GetNumberingType() &&
+            SVX_NUM_BITMAP != rMyNFormat.GetNumberingType())
+        {
+            const OUString& sPrefix = rMyNFormat.GetPrefix();
+            const OUString& sSuffix = rMyNFormat.GetSuffix();
 
-                    aStr.insert(0, sPrefix);
-                    aStr.append(sSuffix);
-                    if (pExtremities)
-                    {
-                        pExtremities->nPrefixChars = sPrefix.getLength();
-                        pExtremities->nSuffixChars = sSuffix.getLength();
-                    }
-                }
+            aStr.insert(0, sPrefix);
+            aStr.append(sSuffix);
+            if (pExtremities)
+            {
+                pExtremities->nPrefixChars = sPrefix.getLength();
+                pExtremities->nSuffixChars = sSuffix.getLength();
             }
         }
     }

Reply via email to