tdf#141341 docxexport: consolidate conversion of NumTypes

so that one comprehensive function is used for Page and Footnote
numbering types (which was already being used by list numbering).

I also added support for CHARS_ARABIC_ABJAD <=> arabicAbjad,
which was my trigger for consolidating all this.

OOXML has one definition (ST_NumberFormat) that specifies the valid
values for pgNumType, numFmt (list numbering),
numFmt (Endnote and Footnote numbering), so use the same
conversion function for all of these.
[Also used for caption, but I haven't noticed that yet in export.)

In the previous code, there was no possibility for
fmt.isEmpty() [despite repeated checks for that situation].
However, I thought it made sense to not specify anything if
the conversion didn't match something known (because perhaps
the locale could take over then?). In any case, that is a
slight change, but for pgNumType we were specifying "none"
instead of decimal, which didn't make much sense either.
So I don't expect anyone crying 'regression' over that.

Change-Id: I90037eb25a0f71d22d6ad1848f43761eb6b9fe00
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/113351
Tested-by: Jenkins
Reviewed-by: Justin Luth <justin_luth@sil.org>
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport16.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport16.cxx
index 1792838..c272a58 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport16.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport16.cxx
@@ -16,6 +16,7 @@

#include <com/sun/star/beans/XPropertySet.hpp>
#include <com/sun/star/drawing/FillStyle.hpp>
#include <com/sun/star/text/XFootnotesSupplier.hpp>
#include <com/sun/star/text/XTextViewCursorSupplier.hpp>
#include <com/sun/star/text/XTextTable.hpp>
#include <com/sun/star/text/XTextTablesSupplier.hpp>
@@ -78,6 +79,12 @@ DECLARE_OOXMLEXPORT_TEST(testTdf141231_arabicHebrewNumbering, "tdf141231_arabicH
    // The page's numbering type: instead of Hebrew, this was default style::NumberingType::ARABIC (4).
    auto nActual = getProperty<sal_Int16>(getStyles("PageStyles")->getByName("Standard"), "NumberingType");
    CPPUNIT_ASSERT_EQUAL(style::NumberingType::NUMBER_HEBREW, nActual);

    // The footnote numbering type: instead of arabicAbjad, this was the default style::NumberingType::ARABIC.
    uno::Reference<text::XFootnotesSupplier> xFootnotesSupplier(mxComponent, uno::UNO_QUERY);
    uno::Reference<beans::XPropertySet> xFootnoteSettings = xFootnotesSupplier->getFootnoteSettings();
    nActual = getProperty<sal_Int16>(xFootnotesSupplier->getFootnoteSettings(), "NumberingType");
    CPPUNIT_ASSERT_EQUAL(style::NumberingType::CHARS_ARABIC_ABJAD, nActual);
}

DECLARE_OOXMLEXPORT_TEST(testGutterLeft, "gutter-left.docx")
diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx b/sw/source/filter/ww8/docxattributeoutput.cxx
index b64be1d..4149e3e 100644
--- a/sw/source/filter/ww8/docxattributeoutput.cxx
+++ b/sw/source/filter/ww8/docxattributeoutput.cxx
@@ -6806,19 +6806,21 @@ void DocxAttributeOutput::SectionBiDi( bool bBiDi )
        m_pSerializer->singleElementNS(XML_w, XML_bidi);
}

static OString impl_NumberingType( sal_uInt16 nNumberingType )
// Converting Numbering Format Code to string
static OString lcl_ConvertNumberingType(sal_Int16 nNumberingType, const SfxItemSet* pOutSet, OString& rFormat, const OString& sDefault = "" )
{
    OString aType;
    OString aType = sDefault;

    switch ( nNumberingType )
    {
        case SVX_NUM_CHARS_UPPER_LETTER:
        case SVX_NUM_CHARS_UPPER_LETTER_N:  aType = "upperLetter"; break;

        case SVX_NUM_CHARS_LOWER_LETTER:
        case SVX_NUM_CHARS_LOWER_LETTER_N:  aType = "lowerLetter"; break;

        case SVX_NUM_ROMAN_UPPER:           aType = "upperRoman";  break;
        case SVX_NUM_ROMAN_LOWER:           aType = "lowerRoman";  break;

        case SVX_NUM_ARABIC:                aType = "decimal";     break;

        case SVX_NUM_BITMAP:
@@ -6826,33 +6828,7 @@ static OString impl_NumberingType( sal_uInt16 nNumberingType )

        case style::NumberingType::CHARS_HEBREW: aType = "hebrew2"; break;
        case style::NumberingType::NUMBER_HEBREW: aType = "hebrew1"; break;

        default:                            aType = "none";        break;
    }

    return aType;
}

// Converting Level Numbering Format Code to string
static OString impl_LevelNFC(sal_uInt16 nNumberingType, const SfxItemSet* pOutSet, OString& rFormat)
{
    OString aType;

    switch ( nNumberingType )
    {
        case style::NumberingType::CHARS_UPPER_LETTER:
        case style::NumberingType::CHARS_UPPER_LETTER_N:
        case style::NumberingType::CHARS_LOWER_LETTER:
        case style::NumberingType::CHARS_LOWER_LETTER_N:
        case style::NumberingType::ROMAN_UPPER:
        case style::NumberingType::ROMAN_LOWER:
        case style::NumberingType::ARABIC:
        case style::NumberingType::BITMAP:
        case style::NumberingType::CHAR_SPECIAL:
        case style::NumberingType::CHARS_HEBREW:
        case style::NumberingType::NUMBER_HEBREW:
        case style::NumberingType::NUMBER_NONE:
            return impl_NumberingType( nNumberingType );
        case style::NumberingType::NUMBER_NONE: aType = "none"; break;
        case style::NumberingType::FULLWIDTH_ARABIC: aType="decimalFullWidth"; break;
        case style::NumberingType::TIAN_GAN_ZH: aType="ideographTraditional"; break;
        case style::NumberingType::DI_ZI_ZH: aType="ideographZodiac"; break;
@@ -6880,6 +6856,7 @@ static OString impl_LevelNFC(sal_uInt16 nNumberingType, const SfxItemSet* pOutSe
        case style::NumberingType::NUMBER_UPPER_KO: aType="koreanLegal"; break;
        case style::NumberingType::CIRCLE_NUMBER: aType="decimalEnclosedCircle"; break;
        case style::NumberingType::CHARS_ARABIC: aType="arabicAlpha"; break;
        case style::NumberingType::CHARS_ARABIC_ABJAD: aType="arabicAbjad"; break;
        case style::NumberingType::CHARS_THAI: aType="thaiLetters"; break;
        case style::NumberingType::CHARS_PERSIAN: aType="hindiVowels"; break;
        case style::NumberingType::TEXT_NUMBER: aType="ordinal"; break;
@@ -6900,7 +6877,7 @@ static OString impl_LevelNFC(sal_uInt16 nNumberingType, const SfxItemSet* pOutSe
            rFormat = "00001, 00002, 00003, ...";
            break;
/*
        Fallback the rest to decimal.
        Fallback the rest to the suggested default.
        case style::NumberingType::NATIVE_NUMBERING:
        case style::NumberingType::HANGUL_CIRCLED_JAMO_KO:
        case style::NumberingType::HANGUL_CIRCLED_SYLLABLE_KO:
@@ -6926,8 +6903,7 @@ static OString impl_LevelNFC(sal_uInt16 nNumberingType, const SfxItemSet* pOutSe
        case style::NumberingType::CHARS_CYRILLIC_UPPER_LETTER_N_SR:
        case style::NumberingType::CHARS_CYRILLIC_LOWER_LETTER_N_SR:
*/
        default:
            aType = "decimal";        break;
        default: break;
    }
    return aType;
}
@@ -6944,8 +6920,9 @@ void DocxAttributeOutput::SectionPageNumbering( sal_uInt16 nNumType, const ::std
       pAttr->add( FSNS( XML_w, XML_start ), OString::number( *oPageRestartNumber ) );

    // nNumType corresponds to w:fmt. See WW8Export::GetNumId() for more precisions
    OString aFormat( impl_NumberingType( nNumType ) );
    if ( !aFormat.isEmpty() )
    OString aCustomFormat;
    OString aFormat(lcl_ConvertNumberingType(nNumType, nullptr, aCustomFormat));
    if (!aFormat.isEmpty() && aCustomFormat.isEmpty())
        pAttr->add( FSNS( XML_w, XML_fmt ), aFormat.getStr() );

    m_pSerializer->singleElementNS( XML_w, XML_pgNumType, pAttr );
@@ -7313,9 +7290,8 @@ void DocxAttributeOutput::NumberingLevel( sal_uInt8 nLevel,
    }
    // format
    OString aCustomFormat;
    OString aFormat(impl_LevelNFC(nNumberingType, pOutSet, aCustomFormat));
    OString aFormat(lcl_ConvertNumberingType(nNumberingType, pOutSet, aCustomFormat, "decimal"));

    if ( !aFormat.isEmpty() )
    {
        if (aCustomFormat.isEmpty())
        {
@@ -8367,44 +8343,9 @@ void DocxAttributeOutput::WriteFootnoteEndnotePr( ::sax_fastparser::FSHelperPtr 
    const SwEndNoteInfo& info, int listtag )
{
    fs->startElementNS(XML_w, tag);
    const char* fmt = nullptr;
    switch( info.m_aFormat.GetNumberingType())
    {
        case SVX_NUM_CHARS_UPPER_LETTER_N: // fall through, map to upper letters
        case SVX_NUM_CHARS_UPPER_LETTER:
            fmt = "upperLetter";
            break;
        case SVX_NUM_CHARS_LOWER_LETTER_N: // fall through, map to lower letters
        case SVX_NUM_CHARS_LOWER_LETTER:
            fmt = "lowerLetter";
            break;
        case SVX_NUM_ROMAN_UPPER:
            fmt = "upperRoman";
            break;
        case SVX_NUM_ROMAN_LOWER:
            fmt = "lowerRoman";
            break;
        case SVX_NUM_ARABIC:
            fmt = "decimal";
            break;
        case SVX_NUM_NUMBER_NONE:
            fmt = "none";
            break;
        case SVX_NUM_CHAR_SPECIAL:
            fmt = "bullet";
            break;
        case SVX_NUM_SYMBOL_CHICAGO:
            fmt = "chicago";
            break;
        case SVX_NUM_ARABIC_ZERO:
            fmt = "decimalZero";
            break;
        case SVX_NUM_PAGEDESC:
        case SVX_NUM_BITMAP:
        default:
            break; // no format
    }
    if( fmt != nullptr )
    OString aCustomFormat;
    OString fmt = lcl_ConvertNumberingType(info.m_aFormat.GetNumberingType(), nullptr, aCustomFormat);
    if (!fmt.isEmpty() && aCustomFormat.isEmpty())
        fs->singleElementNS(XML_w, XML_numFmt, FSNS(XML_w, XML_val), fmt);
    if( info.m_nFootnoteOffset != 0 )
        fs->singleElementNS( XML_w, XML_numStart, FSNS( XML_w, XML_val ),
@@ -8417,9 +8358,9 @@ void DocxAttributeOutput::WriteFootnoteEndnotePr( ::sax_fastparser::FSHelperPtr 
        {
            case FTNNUM_PAGE:       fmt = "eachPage"; break;
            case FTNNUM_CHAPTER:    fmt = "eachSect"; break;
            default:                fmt = nullptr;    break;
            default:                fmt.clear();      break;
        }
        if( fmt != nullptr )
        if (!fmt.isEmpty())
            fs->singleElementNS(XML_w, XML_numRestart, FSNS(XML_w, XML_val), fmt);
    }

diff --git a/writerfilter/source/dmapper/ConversionHelper.cxx b/writerfilter/source/dmapper/ConversionHelper.cxx
index 852f581..ac877c5d 100644
--- a/writerfilter/source/dmapper/ConversionHelper.cxx
+++ b/writerfilter/source/dmapper/ConversionHelper.cxx
@@ -558,6 +558,9 @@ sal_Int16 ConvertNumberingType(const sal_Int32 nFmt, const sal_Int16 nDefault)
        case NS_ooxml::LN_Value_ST_NumberFormat_arabicAlpha:
            nRet = style::NumberingType::CHARS_ARABIC;
            break;
        case NS_ooxml::LN_Value_ST_NumberFormat_arabicAbjad:
            nRet = style::NumberingType::CHARS_ARABIC_ABJAD;
            break;
        case NS_ooxml::LN_Value_ST_NumberFormat_hindiVowels:
            nRet = style::NumberingType::CHARS_NEPALI;
            break;
@@ -611,7 +614,6 @@ sal_Int16 ConvertNumberingType(const sal_Int32 nFmt, const sal_Int16 nDefault)
    NS_ooxml::LN_Value_ST_NumberFormat_koreanLegal = 91719;
    NS_ooxml::LN_Value_ST_NumberFormat_vietnameseCounting = 91721;
    NS_ooxml::LN_Value_ST_NumberFormat_numberInDash = 91725;
    NS_ooxml::LN_Value_ST_NumberFormat_arabicAbjad:
    NS_ooxml::LN_Value_ST_NumberFormat_hindiConsonants = 91731;
    NS_ooxml::LN_Value_ST_NumberFormat_hindiNumbers = 91732;
    NS_ooxml::LN_Value_ST_NumberFormat_hindiCounting = 91733;