diff options
Diffstat (limited to 'i18npool/source/defaultnumberingprovider')
-rw-r--r-- | i18npool/source/defaultnumberingprovider/defaultnumberingprovider.cxx | 66 |
1 files changed, 24 insertions, 42 deletions
diff --git a/i18npool/source/defaultnumberingprovider/defaultnumberingprovider.cxx b/i18npool/source/defaultnumberingprovider/defaultnumberingprovider.cxx index e222611a2afe..af4e27d0f69f 100644 --- a/i18npool/source/defaultnumberingprovider/defaultnumberingprovider.cxx +++ b/i18npool/source/defaultnumberingprovider/defaultnumberingprovider.cxx @@ -19,7 +19,6 @@ #include <defaultnumberingprovider.hxx> #include <com/sun/star/lang/IllegalArgumentException.hpp> -#include <com/sun/star/linguistic2/NumberText.hpp> #include <com/sun/star/style/NumberingType.hpp> #include <com/sun/star/beans/PropertyValue.hpp> #include <com/sun/star/configuration/theDefaultProvider.hpp> @@ -32,9 +31,6 @@ #include <string.h> #include <comphelper/propertysequence.hxx> #include <cppuhelper/supportsservice.hxx> -#include <i18nlangtag/languagetag.hxx> -#include <unordered_map> -#include <map> // Cyrillic upper case #define C_CYR_A "\xD0\x90" @@ -588,6 +584,7 @@ DefaultNumberingProvider::makeNumberingString( const Sequence<beans::PropertyVal sal_Int16 tableSize = 0; const sal_Unicode *table = nullptr; // initialize to avoid compiler warning bool bRecycleSymbol = false; + bool bCapitalize = false; Locale locale; OUString prefix; @@ -639,45 +636,20 @@ DefaultNumberingProvider::makeNumberingString( const Sequence<beans::PropertyVal lcl_formatChars( lowerLetter, 26, number-1, result ); break; case TEXT_NUMBER: + natNum = NativeNumberMode::NATNUM14; // ordinal indicators (1st, 2nd, 3rd, ...) + locale = aLocale; + bCapitalize = true; + break; case TEXT_CARDINAL: + natNum = NativeNumberMode::NATNUM12; // cardinal number names (one, two, three, ...) + locale = aLocale; + bCapitalize = true; + break; case TEXT_ORDINAL: - { - static css::uno::Reference< css::linguistic2::XNumberText > xNumberText; - if (!xNumberText.is()) - xNumberText = linguistic2::NumberText::create( m_xContext ); - OUString aLoc = LanguageTag::convertToBcp47(aLocale); - OUString numbertext_prefix = ""; - if (numType == TEXT_NUMBER) - numbertext_prefix += "ordinal-number "; - else if (numType == TEXT_ORDINAL) - numbertext_prefix += "ordinal "; - // Several hundreds of headings could result typing lags because - // of the continuous update of the multiple number names during typing. - // We fix this by buffering the result of the conversion. - static std::unordered_map<sal_Int32,std::map<OUString, OUString> > aBuff; - auto aBuffItem = aBuff.find(number); - std::map<OUString, OUString> aItem; - if (aBuffItem == aBuff.end() || !aBuffItem->second.count(numbertext_prefix + aLoc)) - { - OUString snumber = OUString::number(number); - OUString aNum = - xNumberText->getNumberText( numbertext_prefix + snumber, aLocale); - if ( !xCharClass.is() ) - xCharClass = CharacterClassification::create( m_xContext ); - // use number at missing number to text conversion - if (aNum.getLength() == 0) - aNum = snumber; - // capitalize first letter - aItem[numbertext_prefix + aLoc] = xCharClass->toTitle(aNum, 0, 1, aLocale) + aNum.copy(1); - aBuff.insert(std::make_pair(number, aItem)); - } - else - { - aItem = aBuffItem->second; - } - result += aItem[numbertext_prefix + aLoc]; - break; - } + natNum = NativeNumberMode::NATNUM13; // ordinal number names (first, second, third, ...) + locale = aLocale; + bCapitalize = true; + break; case ROMAN_UPPER: result += toRoman( number ); break; @@ -937,7 +909,17 @@ DefaultNumberingProvider::makeNumberingString( const Sequence<beans::PropertyVal if (natNum) { rtl::Reference<NativeNumberSupplierService> xNatNum(new NativeNumberSupplierService); - result += xNatNum->getNativeNumberString(OUString::number( number ), locale, natNum); + OUString aNum + = xNatNum->getNativeNumberString(OUString::number(number), locale, natNum); + if (bCapitalize) + { + if (!xCharClass.is()) + xCharClass = CharacterClassification::create(m_xContext); + // capitalize first letter + result += xCharClass->toTitle(aNum, 0, 1, aLocale) + aNum.copy(1); + } + else + result += aNum; } else if (tableSize) { if ( number > tableSize && !bRecycleSymbol) result += OUString::number( number); |