diff options
author | László Németh <nemeth@numbertext.org> | 2018-02-20 11:38:24 +0100 |
---|---|---|
committer | László Németh <nemeth@numbertext.org> | 2018-05-03 11:42:20 +0200 |
commit | f1579d3d6c5f5f3a651825e035b93bee7a4f43c6 (patch) | |
tree | 302e93db63f5029f521a0dba446e2c7b91d08a10 /i18npool | |
parent | f5a56c367fba1c42b4f9719b10ff3e86ad5e2ab1 (diff) |
tdf#117171 support localized number name numbering styles
in page number, chapter and outline numbering
in ~30 languages by integrating libnumbertext library.
- offapi: add linguistic2::NumberText
New NumberingType constants:
- ordinal indicators (1st, 2nd, 3rd...)
- cardinal number names (One, Two, Three...)
- ordinal number names (First, Second, Third...)
Note: these numberings are parts of OOXML, too.
Plain text files of Libnumbertext's language data
are installed in share/numbertext (similar to
share/fingerprint), allowing further customization.
Change-Id: I4034da0a40a8c926f14a3f591749a89a8d807d5a
Reviewed-on: https://gerrit.libreoffice.org/53313
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: László Németh <nemeth@numbertext.org>
Diffstat (limited to 'i18npool')
-rw-r--r-- | i18npool/inc/defaultnumberingprovider.hxx | 2 | ||||
-rw-r--r-- | i18npool/source/defaultnumberingprovider/defaultnumberingprovider.cxx | 47 |
2 files changed, 49 insertions, 0 deletions
diff --git a/i18npool/inc/defaultnumberingprovider.hxx b/i18npool/inc/defaultnumberingprovider.hxx index 1320b7e41a73..97608c122000 100644 --- a/i18npool/inc/defaultnumberingprovider.hxx +++ b/i18npool/inc/defaultnumberingprovider.hxx @@ -25,6 +25,7 @@ #include <com/sun/star/lang/XServiceInfo.hpp> #include <com/sun/star/i18n/XTransliteration.hpp> #include <com/sun/star/container/XHierarchicalNameAccess.hpp> +#include <com/sun/star/i18n/CharacterClassification.hpp> #include <cppuhelper/implbase.hxx> #include <rtl/ref.hxx> @@ -80,6 +81,7 @@ private: OUString makeNumberingIdentifier( sal_Int16 index ); /// @throws css::uno::RuntimeException bool isScriptFlagEnabled(const OUString& aName ); + mutable css::uno::Reference< css::i18n::XCharacterClassification > xCharClass; }; } diff --git a/i18npool/source/defaultnumberingprovider/defaultnumberingprovider.cxx b/i18npool/source/defaultnumberingprovider/defaultnumberingprovider.cxx index e9f584a617cd..e222611a2afe 100644 --- a/i18npool/source/defaultnumberingprovider/defaultnumberingprovider.cxx +++ b/i18npool/source/defaultnumberingprovider/defaultnumberingprovider.cxx @@ -19,6 +19,7 @@ #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> @@ -31,6 +32,9 @@ #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" @@ -634,6 +638,46 @@ DefaultNumberingProvider::makeNumberingString( const Sequence<beans::PropertyVal case CHARS_LOWER_LETTER: lcl_formatChars( lowerLetter, 26, number-1, result ); break; + case TEXT_NUMBER: + case TEXT_CARDINAL: + 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; + } case ROMAN_UPPER: result += toRoman( number ); break; @@ -928,6 +972,9 @@ static const Supported_NumberingType aSupportedTypes[] = {style::NumberingType::CHAR_SPECIAL, "Bullet", LANG_ALL}, {style::NumberingType::PAGE_DESCRIPTOR, "Page", LANG_ALL}, {style::NumberingType::BITMAP, "Bitmap", LANG_ALL}, + {style::NumberingType::TEXT_NUMBER, "1st", LANG_ALL}, + {style::NumberingType::TEXT_CARDINAL, "One", LANG_ALL}, + {style::NumberingType::TEXT_ORDINAL, "First", LANG_ALL}, {style::NumberingType::CHARS_UPPER_LETTER_N, "AAA", LANG_ALL}, {style::NumberingType::CHARS_LOWER_LETTER_N, "aaa", LANG_ALL}, {style::NumberingType::NATIVE_NUMBERING, "Native Numbering", LANG_CJK|LANG_CTL}, |