tdf#106541 doc import: allow listLevel to be inherited

RegisterNumFormat always ran earlier since it forced
the listLevel to be in the valid range.
So that can automatically be simplified.

Secondly, just because the listLevel was not specified
doesn't mean that it will be a level 1. It could
inherit a listlevel from the style. So just leave
it as undefined here, and let it be handled later on.

ww8export's testListNolevel already ensures that
SetStylesList must handle unspecified listLevel.

chapterNumberingTortureTest21.doc matches the assert,
so I have found my document, but this already works.

Change-Id: Idf8850980b92054104c16200b2dea6bd7dde1f46
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/117481
Tested-by: Jenkins
Reviewed-by: Justin Luth <justin_luth@sil.org>
diff --git a/sw/qa/extras/ww8export/ww8export3.cxx b/sw/qa/extras/ww8export/ww8export3.cxx
index 4428744..a09edd7 100644
--- a/sw/qa/extras/ww8export/ww8export3.cxx
+++ b/sw/qa/extras/ww8export/ww8export3.cxx
@@ -803,7 +803,7 @@ DECLARE_WW8EXPORT_TEST(testTdf106541_inheritChapterNumberingB, "tdf106541_inheri
    uno::Reference<beans::XPropertySet> xPara(getParagraph(1, "Chapter 1, level 1"), uno::UNO_QUERY);
    CPPUNIT_ASSERT_EQUAL(OUString("1"), getProperty<OUString>(xPara, "ListLabelString"));
    xPara.set(getParagraph(2, "Chapter 1, level 2"), uno::UNO_QUERY);
    //TEMPORARY CPPUNIT_ASSERT_EQUAL(OUString("1.1"), getProperty<OUString>(xPara, "ListLabelString"));
    CPPUNIT_ASSERT_EQUAL(OUString("1.1"), getProperty<OUString>(xPara, "ListLabelString"));
}

DECLARE_WW8EXPORT_TEST(testTdf120394, "tdf120394.doc")
diff --git a/sw/source/filter/ww8/ww8par.cxx b/sw/source/filter/ww8/ww8par.cxx
index 20e85c4c..9c9f06e 100644
--- a/sw/source/filter/ww8/ww8par.cxx
+++ b/sw/source/filter/ww8/ww8par.cxx
@@ -5933,6 +5933,13 @@ void SwWW8ImplReader::SetOutlineStyles()
                bReRegister = true;
            }

            // Undefined listLevel is treated as the first level with valid numbering rule.
            if (rSI.m_nLFOIndex < USHRT_MAX && rSI.m_nListLevel == MAXLEVEL)
            {
                rSI.m_nListLevel = 0;
                bReRegister = true;
            }

            if (bReRegister)
                RegisterNumFormatOnStyle(nStyle);

diff --git a/sw/source/filter/ww8/ww8par3.cxx b/sw/source/filter/ww8/ww8par3.cxx
index 64670b7..2a74217 100644
--- a/sw/source/filter/ww8/ww8par3.cxx
+++ b/sw/source/filter/ww8/ww8par3.cxx
@@ -1815,6 +1815,11 @@ void SwWW8ImplReader::RegisterNumFormatOnTextNode(sal_uInt16 nCurrentLFO,
    if (!pTextNd)
        return;

    // Undefined listLevel is treated as the first level with valid numbering rule.
    // TODO:This doesn't allow for inheriting from a style(HOW?), but it matches previous behaviour.
    if (nCurrentLFO < USHRT_MAX && nCurrentLevel == MAXLEVEL)
        nCurrentLevel = 0;

    std::vector<sal_uInt8> aParaSprms;
    const SwNumRule* pRule = bSetAttr ?
        m_xLstManager->GetNumRuleForActivation( nCurrentLFO, nCurrentLevel,
@@ -2040,21 +2045,9 @@ void SwWW8ImplReader::Read_LFOPosition(sal_uInt16, const sal_uInt8* pData,
            // here the stream data is 1-based, we subtract ONE
            if (m_nLFOPosition != 2047-1) //Normal ww8+ list behaviour
            {
                if (WW8ListManager::nMaxLevel <= m_nListLevel)
                {
                    // This looks like a mistake. What should happen here?
                    // If iLvl is undefined, then treat as level 1? (yes - list-nolevel.doc)
                    // What about inheritance? (good question - inheritance completely ignored)
                    // What about if iLvl is specified as Body Text(nMaxLevel)?
                    assert(MAXLEVEL == m_nListLevel && "Looking for proof document showing a specified body text level should not become numbered.");
                    m_nListLevel = 0;
                }
                if (WW8ListManager::nMaxLevel > m_nListLevel)
                {
                    RegisterNumFormat(m_nLFOPosition, m_nListLevel);
                    m_nLFOPosition = USHRT_MAX;
                    m_nListLevel = MAXLEVEL;
                }
                RegisterNumFormat(m_nLFOPosition, m_nListLevel);
                m_nLFOPosition = USHRT_MAX;
                m_nListLevel = MAXLEVEL;
            }
            else if (m_xPlcxMan && m_xPlcxMan->HasParaSprm(NS_sprm::LN_PAnld).pSprm)
            {