From f1579d3d6c5f5f3a651825e035b93bee7a4f43c6 Mon Sep 17 00:00:00 2001 From: László Németh Date: Tue, 20 Feb 2018 11:38:24 +0100 Subject: tdf#117171 support localized number name numbering styles MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Reviewed-by: László Németh --- i18npool/inc/defaultnumberingprovider.hxx | 2 + .../defaultnumberingprovider.cxx | 47 ++++++++++++++++++++++ 2 files changed, 49 insertions(+) (limited to 'i18npool') 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 #include #include +#include #include #include @@ -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 #include +#include #include #include #include @@ -31,6 +32,9 @@ #include #include #include +#include +#include +#include // Cyrillic upper case #define C_CYR_A "\xD0\x90" @@ -634,6 +638,46 @@ DefaultNumberingProvider::makeNumberingString( const Sequence 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 > aBuff; + auto aBuffItem = aBuff.find(number); + std::map 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}, -- cgit v1.2.3