tdf#138892 writerfilter: cancel style list if bNoNumbering

This fixes 6.1 regression e24e2d2fb02239753c1520a0458b44683ea4cc2e.

Starting in 7.0 (tdf#131321), paragraph styles kept their
numbering property. But even before that, non-paragraphs
marked by bNoNumbering we having their direct numbering
removed, and then finishParagraph applied para-style
numbering since there was no direct numbering.

So, we need to pass the bNoNumbering to finishParagraph
so that it can cancel out a style-assigned numbering.

Change-Id: I0c24af4e9bd0ea3712179a47ed3550f91c8f44b7
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/107738
Tested-by: Jenkins
Reviewed-by: Justin Luth <justin_luth@sil.org>
(cherry picked from commit bfcd952dc7820c4cf8761c4222d29ede039391dc)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/107795
diff --git a/solenv/clang-format/excludelist b/solenv/clang-format/excludelist
index 8ea69fb..7c4d0e0 100644
--- a/solenv/clang-format/excludelist
+++ b/solenv/clang-format/excludelist
@@ -12466,6 +12466,7 @@ sw/qa/extras/ooxmlexport/ooxmlexport11.cxx
sw/qa/extras/ooxmlexport/ooxmlexport13.cxx
sw/qa/extras/ooxmlexport/ooxmlexport14.cxx
sw/qa/extras/ooxmlexport/ooxmlexport15.cxx
sw/qa/extras/ooxmlexport/ooxmlexport16.cxx
sw/qa/extras/ooxmlexport/ooxmlexport2.cxx
sw/qa/extras/ooxmlexport/ooxmlexport3.cxx
sw/qa/extras/ooxmlexport/ooxmlexport4.cxx
diff --git a/sw/CppunitTest_sw_ooxmlexport16.mk b/sw/CppunitTest_sw_ooxmlexport16.mk
new file mode 100644
index 0000000..4e78cef
--- /dev/null
+++ b/sw/CppunitTest_sw_ooxmlexport16.mk
@@ -0,0 +1,14 @@
# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
#*************************************************************************
#
# This file is part of the LibreOffice project.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
#*************************************************************************

$(eval $(call sw_ooxmlexport_test,16))

# vim: set noet sw=4 ts=4:
diff --git a/sw/Module_sw.mk b/sw/Module_sw.mk
index 0142cf3..947d329 100644
--- a/sw/Module_sw.mk
+++ b/sw/Module_sw.mk
@@ -82,6 +82,7 @@ $(eval $(call gb_Module_add_slowcheck_targets,sw,\
    CppunitTest_sw_ooxmlexport13 \
    CppunitTest_sw_ooxmlexport14 \
    CppunitTest_sw_ooxmlexport15 \
    CppunitTest_sw_ooxmlexport16 \
    CppunitTest_sw_ooxmlexport_template \
    CppunitTest_sw_ooxmlfieldexport \
    CppunitTest_sw_ooxmllinks \
diff --git a/sw/qa/extras/ooxmlexport/data/tdf138892_noNumbering.docx b/sw/qa/extras/ooxmlexport/data/tdf138892_noNumbering.docx
new file mode 100644
index 0000000..5c0a017
--- /dev/null
+++ b/sw/qa/extras/ooxmlexport/data/tdf138892_noNumbering.docx
Binary files differ
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport16.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport16.cxx
new file mode 100644
index 0000000..174f2f0
--- /dev/null
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport16.cxx
@@ -0,0 +1,43 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */

#include <swmodeltestbase.hxx>

#include <com/sun/star/beans/XPropertySet.hpp>
#include <com/sun/star/text/XTextViewCursorSupplier.hpp>
#include <com/sun/star/text/XTextTable.hpp>
#include <com/sun/star/text/XTextTablesSupplier.hpp>

char const DATA_DIRECTORY[] = "/sw/qa/extras/ooxmlexport/data/";

class Test : public SwModelTestBase
{
public:
    Test() : SwModelTestBase(DATA_DIRECTORY, "Office Open XML Text") {}

protected:
    /**
     * Denylist handling
     */
    bool mustTestImportOf(const char* filename) const override {
        // If the testcase is stored in some other format, it's pointless to test.
        return OString(filename).endsWith(".docx");
    }
};

DECLARE_OOXMLEXPORT_TEST(testTdf138892_noNumbering, "tdf138892_noNumbering.docx")
{
    CPPUNIT_ASSERT_MESSAGE("Para1: Bullet point", !getProperty<OUString>(getParagraph(1), "NumberingStyleName").isEmpty());
    CPPUNIT_ASSERT_MESSAGE("Para2: <blank line>", getProperty<OUString>(getParagraph(2), "NumberingStyleName").isEmpty());
    CPPUNIT_ASSERT_MESSAGE("Para3: <blank line>", getProperty<OUString>(getParagraph(3), "NumberingStyleName").isEmpty());
}

CPPUNIT_PLUGIN_IMPLEMENT();

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/writerfilter/source/dmapper/DomainMapper.cxx b/writerfilter/source/dmapper/DomainMapper.cxx
index aac420a..ec93ba4 100644
--- a/writerfilter/source/dmapper/DomainMapper.cxx
+++ b/writerfilter/source/dmapper/DomainMapper.cxx
@@ -3572,7 +3572,7 @@ void DomainMapper::lcl_utext(const sal_uInt8 * data_, size_t len)
                xContext->Erase(PROP_NUMBERING_LEVEL);
            }
            m_pImpl->SetParaSectpr(false);
            finishParagraph(bRemove);
            finishParagraph(bRemove, bNoNumbering);
            if (bRemove)
                m_pImpl->RemoveLastParagraph();
        }
@@ -4058,11 +4058,11 @@ void DomainMapper::HandleRedline( Sprm& rSprm )
    m_pImpl->SetCurrentRedlineIsRead();
}

void DomainMapper::finishParagraph(const bool bRemove)
void DomainMapper::finishParagraph(const bool bRemove, const bool bNoNumbering)
{
    if (m_pImpl->m_pSdtHelper->validateDateFormat())
        m_pImpl->m_pSdtHelper->createDateContentControl();
    m_pImpl->finishParagraph(m_pImpl->GetTopContextOfType(CONTEXT_PARAGRAPH), bRemove);
    m_pImpl->finishParagraph(m_pImpl->GetTopContextOfType(CONTEXT_PARAGRAPH), bRemove, bNoNumbering);
}

} //namespace writerfilter
diff --git a/writerfilter/source/dmapper/DomainMapper.hxx b/writerfilter/source/dmapper/DomainMapper.hxx
index 9cc1966..d2e08a0 100644
--- a/writerfilter/source/dmapper/DomainMapper.hxx
+++ b/writerfilter/source/dmapper/DomainMapper.hxx
@@ -161,7 +161,7 @@ private:
    // Table
    virtual void lcl_entry(writerfilter::Reference<Properties>::Pointer_t ref) override;

    void finishParagraph(const bool bRemove = false);
    void finishParagraph(const bool bRemove = false, const bool bNoNumbering = false);

    static void handleUnderlineType(const Id nId, const ::tools::SvRef<PropertyMap>& rContext);
    void handleParaJustification(const sal_Int32 nIntValue, const ::tools::SvRef<PropertyMap>& rContext, const bool bExchangeLeftRight);
diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.cxx b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
index 86dcf63..e8a45ef 100644
--- a/writerfilter/source/dmapper/DomainMapper_Impl.cxx
+++ b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
@@ -1393,7 +1393,7 @@ static sal_Int32 lcl_getListId(const StyleSheetEntryPtr& rEntry, const StyleShee
    return lcl_getListId(pParent, rStyleTable, rNumberingFromBaseStyle);
}

void DomainMapper_Impl::finishParagraph( const PropertyMapPtr& pPropertyMap, const bool bRemove )
void DomainMapper_Impl::finishParagraph( const PropertyMapPtr& pPropertyMap, const bool bRemove, const bool bNoNumbering )
{
    if (m_bDiscardHeaderFooter)
        return;
@@ -1448,7 +1448,7 @@ void DomainMapper_Impl::finishParagraph( const PropertyMapPtr& pPropertyMap, con
        //apply numbering level/style to paragraph if it was set at the style, but only if the paragraph itself
        //does not specify the numbering
        const sal_Int16 nListLevel = pStyleSheetProperties->GetListLevel();
        if ( !isNumberingViaRule && nListLevel >= 0 )
        if ( !bNoNumbering && !isNumberingViaRule && nListLevel >= 0 )
            pParaContext->Insert( PROP_NUMBERING_LEVEL, uno::makeAny(nListLevel), false );

        bool bNumberingFromBaseStyle = false;
@@ -1456,7 +1456,9 @@ void DomainMapper_Impl::finishParagraph( const PropertyMapPtr& pPropertyMap, con
        auto const pList(GetListTable()->GetList(nListId));
        if (pList && nListId >= 0 && !pParaContext->isSet(PROP_NUMBERING_STYLE_NAME))
        {
            if ( !isNumberingViaRule )
            if ( bNoNumbering )
                pParaContext->Insert( PROP_NUMBERING_STYLE_NAME, uno::makeAny(OUString()) );
            else if ( !isNumberingViaRule )
            {
                isNumberingViaStyle = true;
                // Since LO7.0/tdf#131321 fixed the loss of numbering in styles, this OUGHT to be obsolete,
diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.hxx b/writerfilter/source/dmapper/DomainMapper_Impl.hxx
index e3501da..b6c1cc1 100644
--- a/writerfilter/source/dmapper/DomainMapper_Impl.hxx
+++ b/writerfilter/source/dmapper/DomainMapper_Impl.hxx
@@ -681,7 +681,7 @@ public:
    void setParaSdtEndDeferred(bool bParaSdtEndDeferred);
    bool isParaSdtEndDeferred() const;

    void finishParagraph( const PropertyMapPtr& pPropertyMap, const bool bRemove = false);
    void finishParagraph( const PropertyMapPtr& pPropertyMap, const bool bRemove = false, const bool bNoNumbering = false);
    void appendTextPortion( const OUString& rString, const PropertyMapPtr& pPropertyMap );
    void appendTextContent(const css::uno::Reference<css::text::XTextContent>&, const css::uno::Sequence<css::beans::PropertyValue>&);
    void appendOLE( const OUString& rStreamName, const std::shared_ptr<OLEHandler>& pOleHandler );