diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-15 05:54:39 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-15 05:54:39 +0000 |
commit | 267c6f2ac71f92999e969232431ba04678e7437e (patch) | |
tree | 358c9467650e1d0a1d7227a21dac2e3d08b622b2 /i18npool/inc | |
parent | Initial commit. (diff) | |
download | libreoffice-267c6f2ac71f92999e969232431ba04678e7437e.tar.xz libreoffice-267c6f2ac71f92999e969232431ba04678e7437e.zip |
Adding upstream version 4:24.2.0.upstream/4%24.2.0
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'i18npool/inc')
45 files changed, 4204 insertions, 0 deletions
diff --git a/i18npool/inc/breakiteratorImpl.hxx b/i18npool/inc/breakiteratorImpl.hxx new file mode 100644 index 0000000000..a2700b7a9b --- /dev/null +++ b/i18npool/inc/breakiteratorImpl.hxx @@ -0,0 +1,125 @@ +/* -*- 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/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#pragma once + +#include <com/sun/star/lang/XServiceInfo.hpp> +#include <com/sun/star/i18n/XBreakIterator.hpp> +#include <cppuhelper/implbase.hxx> + +#include <utility> +#include <vector> + +namespace com::sun::star::uno { class XComponentContext; } + +namespace i18npool { + + + +class BreakIteratorImpl : public cppu::WeakImplHelper +< + css::i18n::XBreakIterator, + css::lang::XServiceInfo +> +{ +public: + BreakIteratorImpl( const css::uno::Reference < css::uno::XComponentContext >& rxContext ); + BreakIteratorImpl(); + virtual ~BreakIteratorImpl() override; + + virtual sal_Int32 SAL_CALL nextCharacters( const OUString& Text, sal_Int32 nStartPos, + const css::lang::Locale& rLocale, sal_Int16 nCharacterIteratorMode, sal_Int32 nCount, + sal_Int32& nDone ) override; + virtual sal_Int32 SAL_CALL previousCharacters( const OUString& Text, sal_Int32 nStartPos, + const css::lang::Locale& nLocale, sal_Int16 nCharacterIteratorMode, sal_Int32 nCount, + sal_Int32& nDone ) override; + + virtual css::i18n::Boundary SAL_CALL previousWord( const OUString& Text, sal_Int32 nStartPos, + const css::lang::Locale& nLocale, sal_Int16 WordType) override; + virtual css::i18n::Boundary SAL_CALL nextWord( const OUString& Text, sal_Int32 nStartPos, + const css::lang::Locale& nLocale, sal_Int16 WordType) override; + virtual css::i18n::Boundary SAL_CALL getWordBoundary( const OUString& Text, sal_Int32 nPos, + const css::lang::Locale& nLocale, sal_Int16 WordType, sal_Bool bDirection ) override; + + virtual sal_Bool SAL_CALL isBeginWord( const OUString& Text, sal_Int32 nPos, + const css::lang::Locale& nLocale, sal_Int16 WordType ) override; + virtual sal_Bool SAL_CALL isEndWord( const OUString& Text, sal_Int32 nPos, + const css::lang::Locale& nLocale, sal_Int16 WordType ) override; + virtual sal_Int16 SAL_CALL getWordType( const OUString& Text, sal_Int32 nPos, + const css::lang::Locale& nLocale ) override; + + virtual sal_Int32 SAL_CALL beginOfSentence( const OUString& Text, sal_Int32 nStartPos, + const css::lang::Locale& nLocale ) override; + virtual sal_Int32 SAL_CALL endOfSentence( const OUString& Text, sal_Int32 nStartPos, + const css::lang::Locale& nLocale ) override; + + virtual css::i18n::LineBreakResults SAL_CALL getLineBreak( const OUString& Text, sal_Int32 nStartPos, + const css::lang::Locale& nLocale, sal_Int32 nMinBreakPos, + const css::i18n::LineBreakHyphenationOptions& hOptions, + const css::i18n::LineBreakUserOptions& bOptions ) override; + + virtual sal_Int16 SAL_CALL getScriptType( const OUString& Text, sal_Int32 nPos ) override; + virtual sal_Int32 SAL_CALL beginOfScript( const OUString& Text, sal_Int32 nStartPos, + sal_Int16 ScriptType ) override; + virtual sal_Int32 SAL_CALL endOfScript( const OUString& Text, sal_Int32 nStartPos, + sal_Int16 ScriptType ) override; + virtual sal_Int32 SAL_CALL previousScript( const OUString& Text, sal_Int32 nStartPos, + sal_Int16 ScriptType ) override; + virtual sal_Int32 SAL_CALL nextScript( const OUString& Text, sal_Int32 nStartPos, + sal_Int16 ScriptType ) override; + + virtual sal_Int32 SAL_CALL beginOfCharBlock( const OUString& Text, sal_Int32 nStartPos, + const css::lang::Locale& nLocale, sal_Int16 CharType ) override; + virtual sal_Int32 SAL_CALL endOfCharBlock( const OUString& Text, sal_Int32 nStartPos, + const css::lang::Locale& nLocale, sal_Int16 CharType ) override; + virtual sal_Int32 SAL_CALL previousCharBlock( const OUString& Text, sal_Int32 nStartPos, + const css::lang::Locale& nLocale, sal_Int16 CharType ) override; + virtual sal_Int32 SAL_CALL nextCharBlock( const OUString& Text, sal_Int32 nStartPos, + const css::lang::Locale& nLocale, sal_Int16 CharType ) override; + + //XServiceInfo + virtual OUString SAL_CALL getImplementationName() override; + virtual sal_Bool SAL_CALL supportsService(const OUString& ServiceName) override; + virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override; + + static sal_Int16 getScriptClass(sal_uInt32 currentChar); +protected: + css::i18n::Boundary result; // for word break iterator + +private: + + struct lookupTableItem { + lookupTableItem(css::lang::Locale _aLocale, css::uno::Reference < XBreakIterator > _xBI) : aLocale(std::move(_aLocale)), xBI(std::move(_xBI)) {}; + css::lang::Locale aLocale; + css::uno::Reference < XBreakIterator > xBI; + }; + std::vector<lookupTableItem> lookupTable; + css::lang::Locale aLocale; + css::uno::Reference < XBreakIterator > xBI; + css::uno::Reference < css::uno::XComponentContext > m_xContext; + + /// @throws css::uno::RuntimeException + bool createLocaleSpecificBreakIterator( const OUString& aLocaleName ); + /// @throws css::uno::RuntimeException + const css::uno::Reference < XBreakIterator > & getLocaleSpecificBreakIterator( const css::lang::Locale& rLocale ); + +}; + +} // i18npool + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/i18npool/inc/breakiterator_cjk.hxx b/i18npool/inc/breakiterator_cjk.hxx new file mode 100644 index 0000000000..0f8b0c6c0a --- /dev/null +++ b/i18npool/inc/breakiterator_cjk.hxx @@ -0,0 +1,69 @@ +/* -*- 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/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#pragma once + +#include "breakiterator_unicode.hxx" +#include "xdictionary.hxx" +#include <optional> +#include <memory> + +namespace i18npool { + + +class BreakIterator_CJK : public BreakIterator_Unicode +{ +public: + BreakIterator_CJK(); + + css::i18n::Boundary SAL_CALL nextWord( const OUString& Text, sal_Int32 nStartPos, + const css::lang::Locale& nLocale, sal_Int16 WordType) override; + css::i18n::Boundary SAL_CALL previousWord( const OUString& Text, sal_Int32 nStartPos, + const css::lang::Locale& nLocale, sal_Int16 WordType) override; + css::i18n::Boundary SAL_CALL getWordBoundary( const OUString& Text, sal_Int32 nPos, + const css::lang::Locale& nLocale, sal_Int16 WordType, sal_Bool bDirection ) override; + css::i18n::LineBreakResults SAL_CALL getLineBreak( const OUString& Text, sal_Int32 nStartPos, + const css::lang::Locale& nLocale, sal_Int32 nMinBreakPos, + const css::i18n::LineBreakHyphenationOptions& hOptions, + const css::i18n::LineBreakUserOptions& bOptions ) override; + +protected: + std::optional<xdictionary> m_oDict; + OUString hangingCharacters; +}; + +class BreakIterator_zh final : public BreakIterator_CJK { +public: + BreakIterator_zh(); +}; +class BreakIterator_zh_TW final : public BreakIterator_CJK { +public: + BreakIterator_zh_TW(); +}; +class BreakIterator_ja final : public BreakIterator_CJK { +public: + BreakIterator_ja(); +}; +class BreakIterator_ko final : public BreakIterator_CJK { +public: + BreakIterator_ko(); +}; + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/i18npool/inc/breakiterator_th.hxx b/i18npool/inc/breakiterator_th.hxx new file mode 100644 index 0000000000..cc6a717493 --- /dev/null +++ b/i18npool/inc/breakiterator_th.hxx @@ -0,0 +1,53 @@ +/* -*- 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/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#pragma once + +#include "breakiterator_unicode.hxx" + +namespace i18npool { + + + +class BreakIterator_th final : public BreakIterator_Unicode +{ +public: + BreakIterator_th(); + virtual ~BreakIterator_th() override; + virtual sal_Int32 SAL_CALL previousCharacters(const OUString& text, sal_Int32 start, + const css::lang::Locale& nLocale, sal_Int16 nCharacterIteratorMode, sal_Int32 count, + sal_Int32& nDone) override; + virtual sal_Int32 SAL_CALL nextCharacters(const OUString& text, sal_Int32 start, + const css::lang::Locale& rLocale, sal_Int16 nCharacterIteratorMode, sal_Int32 count, + sal_Int32& nDone) override; + virtual css::i18n::LineBreakResults SAL_CALL getLineBreak( const OUString& Text, sal_Int32 nStartPos, + const css::lang::Locale& nLocale, sal_Int32 nMinBreakPos, + const css::i18n::LineBreakHyphenationOptions& hOptions, + const css::i18n::LineBreakUserOptions& bOptions ) override; + +private: + OUString cachedText; // for cell index + std::vector<sal_Int32> m_aNextCellIndex; + std::vector<sal_Int32> m_aPreviousCellIndex; + + void makeIndex(const OUString& text, sal_Int32 pos); +}; + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/i18npool/inc/breakiterator_unicode.hxx b/i18npool/inc/breakiterator_unicode.hxx new file mode 100644 index 0000000000..d468a2ebf9 --- /dev/null +++ b/i18npool/inc/breakiterator_unicode.hxx @@ -0,0 +1,108 @@ +/* -*- 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/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#pragma once + +#include "breakiteratorImpl.hxx" + +#include <unicode/brkiter.h> +#include <unicode/utext.h> +#include <memory> +#include <unordered_map> + +namespace i18npool { + +#define LOAD_CHARACTER_BREAKITERATOR 0 +#define LOAD_WORD_BREAKITERATOR 1 +#define LOAD_SENTENCE_BREAKITERATOR 2 +#define LOAD_LINE_BREAKITERATOR 3 + + + +class BreakIterator_Unicode : public BreakIteratorImpl +{ +public: + BreakIterator_Unicode(); + virtual ~BreakIterator_Unicode() override; + + virtual sal_Int32 SAL_CALL previousCharacters( const OUString& Text, sal_Int32 nStartPos, + const css::lang::Locale& nLocale, sal_Int16 nCharacterIteratorMode, sal_Int32 nCount, + sal_Int32& nDone ) override; + virtual sal_Int32 SAL_CALL nextCharacters( const OUString& Text, sal_Int32 nStartPos, + const css::lang::Locale& rLocale, sal_Int16 nCharacterIteratorMode, sal_Int32 nCount, + sal_Int32& nDone ) override; + + virtual css::i18n::Boundary SAL_CALL previousWord( const OUString& Text, sal_Int32 nStartPos, + const css::lang::Locale& nLocale, sal_Int16 WordType) override; + virtual css::i18n::Boundary SAL_CALL nextWord( const OUString& Text, sal_Int32 nStartPos, + const css::lang::Locale& nLocale, sal_Int16 WordType) override; + virtual css::i18n::Boundary SAL_CALL getWordBoundary( const OUString& Text, sal_Int32 nPos, + const css::lang::Locale& nLocale, sal_Int16 WordType, sal_Bool bDirection ) override; + + virtual sal_Int32 SAL_CALL beginOfSentence( const OUString& Text, sal_Int32 nStartPos, + const css::lang::Locale& nLocale ) override; + virtual sal_Int32 SAL_CALL endOfSentence( const OUString& Text, sal_Int32 nStartPos, + const css::lang::Locale& nLocale ) override; + + virtual css::i18n::LineBreakResults SAL_CALL getLineBreak( const OUString& Text, sal_Int32 nStartPos, + const css::lang::Locale& nLocale, sal_Int32 nMinBreakPos, + const css::i18n::LineBreakHyphenationOptions& hOptions, + const css::i18n::LineBreakUserOptions& bOptions ) override; + + //XServiceInfo + virtual OUString SAL_CALL getImplementationName() override; + virtual sal_Bool SAL_CALL supportsService(const OUString& ServiceName) override; + virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override; + +protected: + const char *cBreakIterator, *lineRule; + + /** Used as map value. */ + struct BI_ValueData + { + OUString maICUText; + UText* mpUt; + std::shared_ptr< icu::BreakIterator > mpBreakIterator; + + BI_ValueData() : mpUt(nullptr) + { + } + ~BI_ValueData() + { + utext_close(mpUt); + } + }; + + struct BI_Data + { + std::shared_ptr< BI_ValueData > mpValue; + OString maBIMapKey; + } character, sentence, line, *icuBI; + BI_Data words[4]; // 4 is css::i18n::WordType enumeration size + + /// @throws css::uno::RuntimeException + void loadICUBreakIterator(const css::lang::Locale& rLocale, + sal_Int16 rBreakType, sal_Int16 rWordType, const char* name, const OUString& rText); + +public: + typedef std::unordered_map< OString, std::shared_ptr< BI_ValueData > > BIMap; +}; + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/i18npool/inc/bullet.h b/i18npool/inc/bullet.h new file mode 100644 index 0000000000..6f2fd5f702 --- /dev/null +++ b/i18npool/inc/bullet.h @@ -0,0 +1,359 @@ +/* -*- 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/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include <sal/types.h> + +namespace i18npool { + +const sal_Unicode table_AIUFullWidth_ja_JP[] = { + 0x30A2, // KATAKANA LETTER A + 0x30A4, // KATAKANA LETTER I + 0x30A6, // KATAKANA LETTER U + 0x30A8, // KATAKANA LETTER E + 0x30AA, // KATAKANA LETTER O + 0x30AB, // KATAKANA LETTER KA + 0x30AD, // KATAKANA LETTER KI + 0x30AF, // KATAKANA LETTER KU + 0x30B1, // KATAKANA LETTER KE + 0x30B3, // KATAKANA LETTER KO + 0x30B5, // KATAKANA LETTER SA + 0x30B7, // KATAKANA LETTER SI + 0x30B9, // KATAKANA LETTER SU + 0x30BB, // KATAKANA LETTER SE + 0x30BD, // KATAKANA LETTER SO + 0x30BF, // KATAKANA LETTER TA + 0x30C1, // KATAKANA LETTER TI + 0x30C4, // KATAKANA LETTER TU + 0x30C6, // KATAKANA LETTER TE + 0x30C8, // KATAKANA LETTER TO + 0x30CA, // KATAKANA LETTER NA + 0x30CB, // KATAKANA LETTER NI + 0x30CC, // KATAKANA LETTER NU + 0x30CD, // KATAKANA LETTER NE + 0x30CE, // KATAKANA LETTER NO + 0x30CF, // KATAKANA LETTER HA + 0x30D2, // KATAKANA LETTER HI + 0x30D5, // KATAKANA LETTER HU + 0x30D8, // KATAKANA LETTER HE + 0x30DB, // KATAKANA LETTER HO + 0x30DE, // KATAKANA LETTER MA + 0x30DF, // KATAKANA LETTER MI + 0x30E0, // KATAKANA LETTER MU + 0x30E1, // KATAKANA LETTER ME + 0x30E2, // KATAKANA LETTER MO + 0x30E4, // KATAKANA LETTER YA + 0x30E6, // KATAKANA LETTER YU + 0x30E8, // KATAKANA LETTER YO + 0x30E9, // KATAKANA LETTER RA + 0x30EA, // KATAKANA LETTER RI + 0x30EB, // KATAKANA LETTER RU + 0x30EC, // KATAKANA LETTER RE + 0x30ED, // KATAKANA LETTER RO + 0x30EF, // KATAKANA LETTER WA + 0x30F2, // KATAKANA LETTER WO + 0x30F3 // KATAKANA LETTER N +}; + +const sal_Unicode table_AIUHalfWidth_ja_JP[] = { + 0xFF71, // HALFWIDTH KATAKANA LETTER A + 0xFF72, // HALFWIDTH KATAKANA LETTER I + 0xFF73, // HALFWIDTH KATAKANA LETTER U + 0xFF74, // HALFWIDTH KATAKANA LETTER E + 0xFF75, // HALFWIDTH KATAKANA LETTER O + 0xFF76, // HALFWIDTH KATAKANA LETTER KA + 0xFF77, // HALFWIDTH KATAKANA LETTER KI + 0xFF78, // HALFWIDTH KATAKANA LETTER KU + 0xFF79, // HALFWIDTH KATAKANA LETTER KE + 0xFF7A, // HALFWIDTH KATAKANA LETTER KO + 0xFF7B, // HALFWIDTH KATAKANA LETTER SA + 0xFF7C, // HALFWIDTH KATAKANA LETTER SI + 0xFF7D, // HALFWIDTH KATAKANA LETTER SU + 0xFF7E, // HALFWIDTH KATAKANA LETTER SE + 0xFF7F, // HALFWIDTH KATAKANA LETTER SO + 0xFF80, // HALFWIDTH KATAKANA LETTER TA + 0xFF81, // HALFWIDTH KATAKANA LETTER TI + 0xFF82, // HALFWIDTH KATAKANA LETTER TU + 0xFF83, // HALFWIDTH KATAKANA LETTER TE + 0xFF84, // HALFWIDTH KATAKANA LETTER TO + 0xFF85, // HALFWIDTH KATAKANA LETTER NA + 0xFF86, // HALFWIDTH KATAKANA LETTER NI + 0xFF87, // HALFWIDTH KATAKANA LETTER NU + 0xFF88, // HALFWIDTH KATAKANA LETTER NE + 0xFF89, // HALFWIDTH KATAKANA LETTER NO + 0xFF8A, // HALFWIDTH KATAKANA LETTER HA + 0xFF8B, // HALFWIDTH KATAKANA LETTER HI + 0xFF8C, // HALFWIDTH KATAKANA LETTER HU + 0xFF8D, // HALFWIDTH KATAKANA LETTER HE + 0xFF8E, // HALFWIDTH KATAKANA LETTER HO + 0xFF8F, // HALFWIDTH KATAKANA LETTER MA + 0xFF90, // HALFWIDTH KATAKANA LETTER MI + 0xFF91, // HALFWIDTH KATAKANA LETTER MU + 0xFF92, // HALFWIDTH KATAKANA LETTER ME + 0xFF93, // HALFWIDTH KATAKANA LETTER MO + 0xFF94, // HALFWIDTH KATAKANA LETTER YA + 0xFF95, // HALFWIDTH KATAKANA LETTER YU + 0xFF96, // HALFWIDTH KATAKANA LETTER YO + 0xFF97, // HALFWIDTH KATAKANA LETTER RA + 0xFF98, // HALFWIDTH KATAKANA LETTER RI + 0xFF99, // HALFWIDTH KATAKANA LETTER RU + 0xFF9A, // HALFWIDTH KATAKANA LETTER RE + 0xFF9B, // HALFWIDTH KATAKANA LETTER RO + 0xFF9C, // HALFWIDTH KATAKANA LETTER WA + 0xFF66, // HALFWIDTH KATAKANA LETTER WO + 0xFF9D // HALFWIDTH KATAKANA LETTER N +}; + +const sal_Unicode table_IROHAFullWidth_ja_JP[] = { + 0x30A4, // KATAKANA LETTER I + 0x30ED, // KATAKANA LETTER RO + 0x30CF, // KATAKANA LETTER HA + 0x30CB, // KATAKANA LETTER NI + 0x30DB, // KATAKANA LETTER HO + 0x30D8, // KATAKANA LETTER HE + 0x30C8, // KATAKANA LETTER TO + 0x30C1, // KATAKANA LETTER TI + 0x30EA, // KATAKANA LETTER RI + 0x30CC, // KATAKANA LETTER NU + 0x30EB, // KATAKANA LETTER RU + 0x30F2, // KATAKANA LETTER WO + 0x30EF, // KATAKANA LETTER WA + 0x30AB, // KATAKANA LETTER KA + 0x30E8, // KATAKANA LETTER YO + 0x30BF, // KATAKANA LETTER TA + 0x30EC, // KATAKANA LETTER RE + 0x30BD, // KATAKANA LETTER SO + 0x30C4, // KATAKANA LETTER TU + 0x30CD, // KATAKANA LETTER NE + 0x30CA, // KATAKANA LETTER NA + 0x30E9, // KATAKANA LETTER RA + 0x30E0, // KATAKANA LETTER MU + 0x30A6, // KATAKANA LETTER U + 0x30F0, // KATAKANA LETTER WI + 0x30CE, // KATAKANA LETTER NO + 0x30AA, // KATAKANA LETTER O + 0x30AF, // KATAKANA LETTER KU + 0x30E4, // KATAKANA LETTER YA + 0x30DE, // KATAKANA LETTER MA + 0x30B1, // KATAKANA LETTER KE + 0x30D5, // KATAKANA LETTER HU + 0x30B3, // KATAKANA LETTER KO + 0x30A8, // KATAKANA LETTER E + 0x30C6, // KATAKANA LETTER TE + 0x30A2, // KATAKANA LETTER A + 0x30B5, // KATAKANA LETTER SA + 0x30AD, // KATAKANA LETTER KI + 0x30E6, // KATAKANA LETTER YU + 0x30E1, // KATAKANA LETTER ME + 0x30DF, // KATAKANA LETTER MI + 0x30B7, // KATAKANA LETTER SI + 0x30F1, // KATAKANA LETTER WE + 0x30D2, // KATAKANA LETTER HI + 0x30E2, // KATAKANA LETTER MO + 0x30BB, // KATAKANA LETTER SE + 0x30B9, // KATAKANA LETTER SU + 0x30F3 // KATAKANA LETTER N +}; + +const sal_Unicode table_IROHAHalfWidth_ja_JP[] = { + 0xFF72, // HALFWIDTH KATAKANA LETTER I + 0xFF9B, // HALFWIDTH KATAKANA LETTER RO + 0xFF8A, // HALFWIDTH KATAKANA LETTER HA + 0xFF86, // HALFWIDTH KATAKANA LETTER NI + 0xFF8E, // HALFWIDTH KATAKANA LETTER HO + 0xFF8D, // HALFWIDTH KATAKANA LETTER HE + 0xFF84, // HALFWIDTH KATAKANA LETTER TO + 0xFF81, // HALFWIDTH KATAKANA LETTER TI + 0xFF98, // HALFWIDTH KATAKANA LETTER RI + 0xFF87, // HALFWIDTH KATAKANA LETTER NU + 0xFF99, // HALFWIDTH KATAKANA LETTER RU + 0xFF66, // HALFWIDTH KATAKANA LETTER WO + 0xFF9C, // HALFWIDTH KATAKANA LETTER WA + 0xFF76, // HALFWIDTH KATAKANA LETTER KA + 0xFF96, // HALFWIDTH KATAKANA LETTER YO + 0xFF80, // HALFWIDTH KATAKANA LETTER TA + 0xFF9A, // HALFWIDTH KATAKANA LETTER RE + 0xFF7F, // HALFWIDTH KATAKANA LETTER SO + 0xFF82, // HALFWIDTH KATAKANA LETTER TU + 0xFF88, // HALFWIDTH KATAKANA LETTER NE + 0xFF85, // HALFWIDTH KATAKANA LETTER NA + 0xFF97, // HALFWIDTH KATAKANA LETTER RA + 0xFF91, // HALFWIDTH KATAKANA LETTER MU + 0xFF73, // HALFWIDTH KATAKANA LETTER U + 0x30F0, // KATAKANA LETTER WI + 0xFF89, // HALFWIDTH KATAKANA LETTER NO + 0xFF75, // HALFWIDTH KATAKANA LETTER O + 0xFF78, // HALFWIDTH KATAKANA LETTER KU + 0xFF94, // HALFWIDTH KATAKANA LETTER YA + 0xFF8F, // HALFWIDTH KATAKANA LETTER MA + 0xFF79, // HALFWIDTH KATAKANA LETTER KE + 0xFF8C, // HALFWIDTH KATAKANA LETTER HU + 0xFF7A, // HALFWIDTH KATAKANA LETTER KO + 0xFF74, // HALFWIDTH KATAKANA LETTER E + 0xFF83, // HALFWIDTH KATAKANA LETTER TE + 0xFF71, // HALFWIDTH KATAKANA LETTER A + 0xFF7B, // HALFWIDTH KATAKANA LETTER SA + 0xFF77, // HALFWIDTH KATAKANA LETTER KI + 0xFF95, // HALFWIDTH KATAKANA LETTER YU + 0xFF92, // HALFWIDTH KATAKANA LETTER ME + 0xFF90, // HALFWIDTH KATAKANA LETTER MI + 0xFF7C, // HALFWIDTH KATAKANA LETTER SI + 0x30F1, // KATAKANA LETTER WE + 0xFF8B, // HALFWIDTH KATAKANA LETTER HI + 0xFF93, // HALFWIDTH KATAKANA LETTER MO + 0xFF7E, // HALFWIDTH KATAKANA LETTER SE + 0xFF7D, // HALFWIDTH KATAKANA LETTER SU + 0xFF9D // HALFWIDTH KATAKANA LETTER N +}; + +const sal_Unicode table_CircledNumber[] = { + 0x2460, // CIRCLED DIGIT ONE + 0x2461, // CIRCLED DIGIT TWO + 0x2462, // CIRCLED DIGIT THREE + 0x2463, // CIRCLED DIGIT FOUR + 0x2464, // CIRCLED DIGIT FIVE + 0x2465, // CIRCLED DIGIT SIX + 0x2466, // CIRCLED DIGIT SEVEN + 0x2467, // CIRCLED DIGIT EIGHT + 0x2468, // CIRCLED DIGIT NINE + 0x2469, // CIRCLED NUMBER TEN + 0x246A, // CIRCLED NUMBER ELEVEN + 0x246B, // CIRCLED NUMBER TWELVE + 0x246C, // CIRCLED NUMBER THIRTEEN + 0x246D, // CIRCLED NUMBER FOURTEEN + 0x246E, // CIRCLED NUMBER FIFTEEN + 0x246F, // CIRCLED NUMBER SIXTEEN + 0x2470, // CIRCLED NUMBER SEVENTEEN + 0x2471, // CIRCLED NUMBER EIGHTEEN + 0x2472, // CIRCLED NUMBER NINETEEN + 0x2473, // CIRCLED NUMBER TWENTY + 0x3251, // CIRCLED NUMBER TWENTY ONE + 0x3252, // CIRCLED NUMBER TWENTY TWO + 0x3253, // CIRCLED NUMBER TWENTY THREE + 0x3254, // CIRCLED NUMBER TWENTY FOUR + 0x3255, // CIRCLED NUMBER TWENTY FIVE + 0x3256, // CIRCLED NUMBER TWENTY SIX + 0x3257, // CIRCLED NUMBER TWENTY SEVEN + 0x3258, // CIRCLED NUMBER TWENTY EIGHT + 0x3259, // CIRCLED NUMBER TWENTY NINE + 0x325A, // CIRCLED NUMBER THIRTY + 0x325B, // CIRCLED NUMBER THIRTY ONE + 0x325C, // CIRCLED NUMBER THIRTY TWO + 0x325D, // CIRCLED NUMBER THIRTY THREE + 0x325E, // CIRCLED NUMBER THIRTY FOUR + 0x325F, // CIRCLED NUMBER THIRTY FIVE + 0x32B1, // CIRCLED NUMBER THIRTY SIX + 0x32B2, // CIRCLED NUMBER THIRTY SEVEN + 0x32B3, // CIRCLED NUMBER THIRTY EIGHT + 0x32B4, // CIRCLED NUMBER THIRTY NINE + 0x32B5, // CIRCLED NUMBER FORTY + 0x32B6, // CIRCLED NUMBER FORTY ONE + 0x32B7, // CIRCLED NUMBER FORTY TWO + 0x32B8, // CIRCLED NUMBER FORTY THREE + 0x32B9, // CIRCLED NUMBER FORTY FOUR + 0x32BA, // CIRCLED NUMBER FORTY FIVE + 0x32BB, // CIRCLED NUMBER FORTY SIX + 0x32BC, // CIRCLED NUMBER FORTY SEVEN + 0x32BD, // CIRCLED NUMBER FORTY EIGHT + 0x32BE, // CIRCLED NUMBER FORTY NINE + 0x32BF // CIRCLED NUMBER FIFTY +}; + +const sal_Unicode table_HangulJamo_ko[] = { + 0x3131, // HANGUL LETTER KIYEOK + 0x3134, // HANGUL LETTER NIEUN + 0x3137, // HANGUL LETTER TIKEUT + 0x3139, // HANGUL LETTER RIEUL + 0x3141, // HANGUL LETTER MIEUM + 0x3142, // HANGUL LETTER PIEUP + 0x3145, // HANGUL LETTER SIOS + 0x3147, // HANGUL LETTER IEUNG + 0x3148, // HANGUL LETTER CIEUC + 0x314A, // HANGUL LETTER CHIEUCH + 0x314B, // HANGUL LETTER KHIEUKH + 0x314C, // HANGUL LETTER THIEUTH + 0x314D, // HANGUL LETTER PHIEUPH + 0x314E // HANGUL LETTER HIEUH +}; + +const sal_Unicode table_HangulSyllable_ko[] = { + 0xAC00, // HANGUL SYLLABLE GA + 0xB098, // HANGUL SYLLABLE NA + 0xB2E4, // HANGUL SYLLABLE DA + 0xB77C, // HANGUL SYLLABLE LA + 0xB9C8, // HANGUL SYLLABLE MA + 0xBC14, // HANGUL SYLLABLE BA + 0xC0AC, // HANGUL SYLLABLE SA + 0xC544, // HANGUL SYLLABLE A + 0xC790, // HANGUL SYLLABLE JA + 0xCC28, // HANGUL SYLLABLE CA + 0xCE74, // HANGUL SYLLABLE KA + 0xD0C0, // HANGUL SYLLABLE TA + 0xD30C, // HANGUL SYLLABLE PA + 0xD558 // HANGUL SYLLABLE HA + +}; + +const sal_Unicode table_HangulCircledJamo_ko[] = { + 0x3260, // CIRCLED HANGUL LETTER KIYEOK + 0x3261, // CIRCLED HANGUL LETTER NIEUN + 0x3262, // CIRCLED HANGUL LETTER TIKEUT + 0x3263, // CIRCLED HANGUL LETTER RIEUL + 0x3264, // CIRCLED HANGUL LETTER MIEUM + 0x3265, // CIRCLED HANGUL LETTER PIEUP + 0x3266, // CIRCLED HANGUL LETTER SIOS + 0x3267, // CIRCLED HANGUL LETTER IEUNG + 0x3268, // CIRCLED HANGUL LETTER CIEUC + 0x3269, // CIRCLED HANGUL LETTER CHIEUCH + 0x326A, // CIRCLED HANGUL LETTER KHIEUKH + 0x326B, // CIRCLED HANGUL LETTER THIEUTH + 0x326C, // CIRCLED HANGUL LETTER PHIEUPH + 0x326D // CIRCLED HANGUL LETTER HIEUH +}; + + +const sal_Unicode table_HangulCircledSyllable_ko[] = { + 0x326E, // CIRCLED HANGUL SYLLABLE GA + 0x326F, // CIRCLED HANGUL SYLLABLE NA + 0x3270, // CIRCLED HANGUL SYLLABLE DA + 0x3271, // CIRCLED HANGUL SYLLABLE LA + 0x3272, // CIRCLED HANGUL SYLLABLE MA + 0x3273, // CIRCLED HANGUL SYLLABLE BA + 0x3274, // CIRCLED HANGUL SYLLABLE SA + 0x3275, // CIRCLED HANGUL SYLLABLE A + 0x3276, // CIRCLED HANGUL SYLLABLE JA + 0x3277, // CIRCLED HANGUL SYLLABLE CA + 0x3278, // CIRCLED HANGUL SYLLABLE KA + 0x3279, // CIRCLED HANGUL SYLLABLE TA + 0x327A, // CIRCLED HANGUL SYLLABLE PA + 0x327B // CIRCLED HANGUL SYLLABLE HA +}; + +const sal_Unicode table_TianGan_zh[] = { + 0x7532,0x4e59,0x4e19,0x4e01,0x620a,0x5df1,0x5e9a,0x8f9b,0x58ec,0x7678 +}; + +const sal_Unicode table_DiZi_zh[] = { + 0x5b50,0x4e11,0x5bc5,0x536f,0x8fb0,0x5df3,0x5348,0x672a,0x7533,0x9149,0x620c,0x4ea5 +}; + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/i18npool/inc/calendarImpl.hxx b/i18npool/inc/calendarImpl.hxx new file mode 100644 index 0000000000..0580a87853 --- /dev/null +++ b/i18npool/inc/calendarImpl.hxx @@ -0,0 +1,108 @@ +/* -*- 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/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#pragma once + +#include <com/sun/star/i18n/XCalendar4.hpp> +#include <cppuhelper/implbase.hxx> +#include <com/sun/star/lang/XServiceInfo.hpp> +#include <utility> +#include <vector> + +namespace com::sun::star::uno { class XComponentContext; } + + + +namespace i18npool { + +class CalendarImpl : public cppu::WeakImplHelper +< + css::i18n::XCalendar4, + css::lang::XServiceInfo +> +{ +public: + + // Constructors + CalendarImpl(); + CalendarImpl(const css::uno::Reference < css::uno::XComponentContext >& rxContext); + + /** + * Destructor + */ + virtual ~CalendarImpl() override; + + + // Methods + virtual void SAL_CALL loadDefaultCalendar(const css::lang::Locale& rLocale) override; + virtual void SAL_CALL loadCalendar(const OUString& uniqueID, const css::lang::Locale& rLocale) override; + virtual css::i18n::Calendar SAL_CALL getLoadedCalendar() override; + virtual css::uno::Sequence < OUString > SAL_CALL getAllCalendars(const css::lang::Locale& rLocale) override; + virtual OUString SAL_CALL getUniqueID() override; + virtual void SAL_CALL setDateTime(double fTimeInDays) override; + virtual double SAL_CALL getDateTime() override; + virtual void SAL_CALL setValue( sal_Int16 nFieldIndex, sal_Int16 nValue ) override; + virtual sal_Int16 SAL_CALL getValue(sal_Int16 nFieldIndex) override; + virtual sal_Bool SAL_CALL isValid() override; + virtual void SAL_CALL addValue(sal_Int16 nFieldIndex, sal_Int32 nAmount) override; + virtual sal_Int16 SAL_CALL getFirstDayOfWeek() override; + virtual void SAL_CALL setFirstDayOfWeek(sal_Int16 nDay) override; + virtual void SAL_CALL setMinimumNumberOfDaysForFirstWeek(sal_Int16 nDays) override; + virtual sal_Int16 SAL_CALL getMinimumNumberOfDaysForFirstWeek() override; + virtual sal_Int16 SAL_CALL getNumberOfMonthsInYear() override; + virtual sal_Int16 SAL_CALL getNumberOfDaysInWeek() override; + virtual css::uno::Sequence < css::i18n::CalendarItem > SAL_CALL getMonths() override; + virtual css::uno::Sequence < css::i18n::CalendarItem > SAL_CALL getDays() override; + virtual OUString SAL_CALL getDisplayName(sal_Int16 nCalendarDisplayIndex, sal_Int16 nIdx, sal_Int16 nNameType) override; + + // Methods in XExtendedCalendar + virtual OUString SAL_CALL getDisplayString( sal_Int32 nCalendarDisplayCode, sal_Int16 nNativeNumberMode ) override; + + // XCalendar3 + virtual css::i18n::Calendar2 SAL_CALL getLoadedCalendar2() override; + virtual css::uno::Sequence < css::i18n::CalendarItem2 > SAL_CALL getDays2() override; + virtual css::uno::Sequence < css::i18n::CalendarItem2 > SAL_CALL getMonths2() override; + virtual css::uno::Sequence < css::i18n::CalendarItem2 > SAL_CALL getGenitiveMonths2() override; + virtual css::uno::Sequence < css::i18n::CalendarItem2 > SAL_CALL getPartitiveMonths2() override; + + // XCalendar4 + virtual void SAL_CALL setLocalDateTime(double TimeInDays) override; + virtual double SAL_CALL getLocalDateTime() override; + virtual void SAL_CALL loadDefaultCalendarTZ(const css::lang::Locale& rLocale, const OUString& rTimeZone) override; + virtual void SAL_CALL loadCalendarTZ(const OUString& uniqueID, const css::lang::Locale& rLocale, const OUString& rTimeZone) override; + + //XServiceInfo + virtual OUString SAL_CALL getImplementationName() override; + virtual sal_Bool SAL_CALL supportsService(const OUString& ServiceName) override; + virtual css::uno::Sequence < OUString > SAL_CALL getSupportedServiceNames() override; + +private: + struct lookupTableItem { + lookupTableItem(OUString aCacheID, css::uno::Reference < css::i18n::XCalendar4 > _xCalendar) + : m_aCacheID(std::move(aCacheID)), xCalendar(std::move(_xCalendar)) {} + OUString m_aCacheID; + css::uno::Reference < css::i18n::XCalendar4 > xCalendar; + }; + std::vector<lookupTableItem> lookupTable; + css::uno::Reference < css::uno::XComponentContext > m_xContext; + css::uno::Reference < css::i18n::XCalendar4 > xCalendar; +}; + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/i18npool/inc/calendar_gregorian.hxx b/i18npool/inc/calendar_gregorian.hxx new file mode 100644 index 0000000000..1ee7cabaab --- /dev/null +++ b/i18npool/inc/calendar_gregorian.hxx @@ -0,0 +1,204 @@ +/* -*- 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/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#pragma once + +#include "calendarImpl.hxx" + +#include <com/sun/star/i18n/CalendarFieldIndex.hpp> + +#include <unicode/calendar.h> +#include <rtl/ref.hxx> + +#include <memory> + +namespace i18npool { class NativeNumberSupplierService; } + + + +namespace i18npool { + +const sal_uInt8 kDisplayEraForcedLongYear = 0x01; + +struct Era { + sal_Int32 year; + sal_Int32 month; + sal_Int32 day; + sal_uInt8 flags; +}; + +const sal_Int16 FIELD_INDEX_COUNT = css::i18n::CalendarFieldIndex::FIELD_COUNT2; + +class Calendar_gregorian : public CalendarImpl +{ +public: + + // Constructors + Calendar_gregorian(); + Calendar_gregorian(const Era *_eraArray); + void init(const Era *_eraArray); + bool setTimeZone( const OUString& rTimeZone ); + + /** + * Destructor + */ + virtual ~Calendar_gregorian() override; + + // Methods in XCalendar + virtual void SAL_CALL loadCalendar(const OUString& uniqueID, const css::lang::Locale& rLocale) override; + virtual void SAL_CALL setDateTime(double fTimeInDays) override; + virtual double SAL_CALL getDateTime() override; + virtual void SAL_CALL setValue( sal_Int16 nFieldIndex, sal_Int16 nValue ) override; + virtual sal_Int16 SAL_CALL getValue(sal_Int16 nFieldIndex) override; + virtual void SAL_CALL addValue(sal_Int16 nFieldIndex, sal_Int32 nAmount) override; + virtual sal_Bool SAL_CALL isValid() override; + virtual css::i18n:: Calendar SAL_CALL getLoadedCalendar() override; + virtual OUString SAL_CALL getUniqueID() override; + virtual sal_Int16 SAL_CALL getFirstDayOfWeek() override; + virtual void SAL_CALL setFirstDayOfWeek(sal_Int16 nDay) override; + virtual void SAL_CALL setMinimumNumberOfDaysForFirstWeek(sal_Int16 nDays) override; + virtual sal_Int16 SAL_CALL getMinimumNumberOfDaysForFirstWeek() override; + virtual sal_Int16 SAL_CALL getNumberOfMonthsInYear() override; + virtual sal_Int16 SAL_CALL getNumberOfDaysInWeek() override; + virtual css::uno::Sequence < css::i18n::CalendarItem > SAL_CALL getMonths() override; + virtual css::uno::Sequence < css::i18n::CalendarItem > SAL_CALL getDays() override; + virtual OUString SAL_CALL getDisplayName(sal_Int16 nCalendarDisplayIndex, sal_Int16 nIdx, sal_Int16 nNameType) override; + + // Methods in XExtendedCalendar + virtual OUString SAL_CALL getDisplayString( sal_Int32 nCalendarDisplayCode, sal_Int16 nNativeNumberMode ) override; + + // XCalendar3 + virtual css::i18n::Calendar2 SAL_CALL getLoadedCalendar2() override; + virtual css::uno::Sequence < css::i18n::CalendarItem2 > SAL_CALL getDays2() override; + virtual css::uno::Sequence < css::i18n::CalendarItem2 > SAL_CALL getMonths2() override; + virtual css::uno::Sequence < css::i18n::CalendarItem2 > SAL_CALL getGenitiveMonths2() override; + virtual css::uno::Sequence < css::i18n::CalendarItem2 > SAL_CALL getPartitiveMonths2() override; + + // XCalendar4 + virtual void SAL_CALL setLocalDateTime(double TimeInDays) override; + virtual double SAL_CALL getLocalDateTime() override; + + //XServiceInfo + virtual OUString SAL_CALL getImplementationName() override; + virtual sal_Bool SAL_CALL supportsService(const OUString& ServiceName) override; + virtual css::uno::Sequence < OUString > SAL_CALL getSupportedServiceNames() override; + +protected: + const Era *eraArray; + std::unique_ptr<icu::Calendar> body; + rtl::Reference<NativeNumberSupplierService> mxNatNum; + const char* cCalendar; + css::lang::Locale aLocale; + sal_uInt32 fieldSet; + sal_Int16 fieldValue[FIELD_INDEX_COUNT]; + sal_Int16 fieldSetValue[FIELD_INDEX_COUNT]; + + /// @throws css::uno::RuntimeException + virtual void mapToGregorian(); + /// @throws css::uno::RuntimeException + virtual void mapFromGregorian(); + /// @throws css::uno::RuntimeException + void getValue(); + + /// @throws css::uno::RuntimeException + OUString getDisplayStringImpl( sal_Int32 nCalendarDisplayCode, sal_Int16 nNativeNumberMode, bool bEraMode ); + +private: + css::i18n::Calendar2 aCalendar; + + /** Submit fieldSetValue array according to fieldSet. + + @throws css::uno::RuntimeException + */ + void submitFields(); + /** Set fields internally. + + @throws css::uno::RuntimeException + */ + void setValue(); + /** Obtain combined field values for timezone offset (minutes+secondmillis) + in milliseconds and whether fields were set. */ + bool getZoneOffset( sal_Int32 & o_nOffset ) const; + /** Obtain combined field values for DST offset (minutes+secondmillis) in + milliseconds and whether fields were set. */ + bool getDSTOffset( sal_Int32 & o_nOffset ) const; + /** Used by getZoneOffset() and getDSTOffset(). Parent is + CalendarFieldIndex for offset in minutes, child is CalendarFieldIndex + for offset in milliseconds. */ + bool getCombinedOffset( sal_Int32 & o_nOffset, sal_Int16 nParentFieldIndex, sal_Int16 nChildFieldIndex ) const; +}; + + + +class Calendar_hanja final : public Calendar_gregorian +{ +public: + // Constructors + Calendar_hanja(); + virtual OUString SAL_CALL getDisplayName(sal_Int16 nCalendarDisplayIndex, sal_Int16 nIdx, sal_Int16 nNameType) override; +}; + +class Calendar_hanja_yoil final : public Calendar_gregorian +{ +public: + // Constructors + Calendar_hanja_yoil(); + virtual OUString SAL_CALL getDisplayName(sal_Int16 nCalendarDisplayIndex, sal_Int16 nIdx, sal_Int16 nNameType) override; +}; + + +class Calendar_gengou final : public Calendar_gregorian +{ +public: + // Constructors + Calendar_gengou(); +}; + + + +class Calendar_ROC final : public Calendar_gregorian +{ +public: + // Constructors + Calendar_ROC(); +}; + + + +class Calendar_dangi final : public Calendar_gregorian +{ +public: + // Constructors + Calendar_dangi(); +}; + + + +class Calendar_buddhist final : public Calendar_gregorian +{ +public: + // Constructors + Calendar_buddhist(); + + // Methods in XExtendedCalendar + virtual OUString SAL_CALL getDisplayString( sal_Int32 nCalendarDisplayCode, sal_Int16 nNativeNumberMode ) override; +}; + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/i18npool/inc/calendar_hijri.hxx b/i18npool/inc/calendar_hijri.hxx new file mode 100644 index 0000000000..c02fa31e5d --- /dev/null +++ b/i18npool/inc/calendar_hijri.hxx @@ -0,0 +1,49 @@ +/* -*- 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/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#pragma once + +#include "calendar_gregorian.hxx" + + + + +namespace i18npool { + +class Calendar_hijri final : public Calendar_gregorian +{ +public: + + // Constructors + Calendar_hijri(); + +private: + void mapToGregorian() override; + void mapFromGregorian() override; + +public: + static double SAL_DLLPUBLIC_EXPORT NewMoon(sal_Int32 n); + static void SAL_DLLPUBLIC_EXPORT getHijri(sal_Int32 *day, sal_Int32 *month, sal_Int32 *year); + static void SAL_DLLPUBLIC_EXPORT ToGregorian(sal_Int32 *day, sal_Int32 *month, sal_Int32 *year); + static void SAL_DLLPUBLIC_EXPORT getGregorianDay(sal_Int32 jd, sal_Int32 *pnDay, sal_Int32 *pnMonth, sal_Int32 *pnYear); + static sal_Int32 SAL_DLLPUBLIC_EXPORT getJulianDay(sal_Int32 day, sal_Int32 month, sal_Int32 year); +}; + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/i18npool/inc/calendar_jewish.hxx b/i18npool/inc/calendar_jewish.hxx new file mode 100644 index 0000000000..0f43cf87e8 --- /dev/null +++ b/i18npool/inc/calendar_jewish.hxx @@ -0,0 +1,44 @@ +/* -*- 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/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#pragma once + +#include "calendar_gregorian.hxx" + + + + +namespace i18npool { + +class Calendar_jewish final : public Calendar_gregorian +{ +public: + // Constructors + Calendar_jewish(); + + // Methods in XExtendedCalendar + virtual OUString SAL_CALL getDisplayString( sal_Int32 nCalendarDisplayCode, sal_Int16 nNativeNumberMode ) override; + +private: + void mapToGregorian() override; + void mapFromGregorian() override; +}; + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/i18npool/inc/cclass_unicode.hxx b/i18npool/inc/cclass_unicode.hxx new file mode 100644 index 0000000000..3a5f28f124 --- /dev/null +++ b/i18npool/inc/cclass_unicode.hxx @@ -0,0 +1,187 @@ +/* -*- 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/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#pragma once + +#include <com/sun/star/i18n/XCharacterClassification.hpp> +#include <cppuhelper/implbase.hxx> +#include <com/sun/star/lang/XServiceInfo.hpp> +#include <rtl/ref.hxx> + +#include <o3tl/typed_flags_set.hxx> +#include <memory> + +namespace com::sun::star::uno { class XComponentContext; } +namespace com::sun::star::i18n { class XNativeNumberSupplier; } +namespace com::sun::star::i18n { class XLocaleData5; } +namespace i18npool { class Transliteration_casemapping; } + + +/// Flag values of table. +enum class ParserFlags : sal_uInt32 { + ILLEGAL = 0x00000000, + CHAR = 0x00000001, + CHAR_BOOL = 0x00000002, + CHAR_WORD = 0x00000004, + CHAR_VALUE = 0x00000008, + CHAR_STRING = 0x00000010, + CHAR_DONTCARE = 0x00000020, + BOOL = 0x00000040, + WORD = 0x00000080, + WORD_SEP = 0x00000100, + VALUE = 0x00000200, + VALUE_SEP = 0x00000400, + VALUE_EXP = 0x00000800, + VALUE_SIGN = 0x00001000, + VALUE_EXP_VALUE = 0x00002000, + VALUE_DIGIT = 0x00004000, + NAME_SEP = 0x20000000, + STRING_SEP = 0x40000000, + EXCLUDED = 0x80000000, +}; +namespace o3tl { + template<> struct typed_flags<ParserFlags> : is_typed_flags<ParserFlags, 0xe0007fff> {}; +} + + +namespace i18npool { + +class cclass_Unicode final : public cppu::WeakImplHelper < css::i18n::XCharacterClassification, css::lang::XServiceInfo > +{ +public: + cclass_Unicode(css::uno::Reference < css::uno::XComponentContext > xContext ); + virtual ~cclass_Unicode() override; + + virtual OUString SAL_CALL toUpper( const OUString& Text, sal_Int32 nPos, sal_Int32 nCount, + const css::lang::Locale& rLocale ) override; + virtual OUString SAL_CALL toLower( const OUString& Text, sal_Int32 nPos, sal_Int32 nCount, + const css::lang::Locale& rLocale ) override; + virtual OUString SAL_CALL toTitle( const OUString& Text, sal_Int32 nPos, sal_Int32 nCount, + const css::lang::Locale& rLocale ) override; + virtual sal_Int16 SAL_CALL getType( const OUString& Text, sal_Int32 nPos ) override; + virtual sal_Int16 SAL_CALL getCharacterDirection( const OUString& Text, sal_Int32 nPos ) override; + virtual sal_Int16 SAL_CALL getScript( const OUString& Text, sal_Int32 nPos ) override; + virtual sal_Int32 SAL_CALL getCharacterType( const OUString& text, sal_Int32 nPos, + const css::lang::Locale& rLocale ) override; + virtual sal_Int32 SAL_CALL getStringType( const OUString& text, sal_Int32 nPos, sal_Int32 nCount, + const css::lang::Locale& rLocale ) override; + virtual css::i18n::ParseResult SAL_CALL parseAnyToken( const OUString& Text, sal_Int32 nPos, + const css::lang::Locale& rLocale, sal_Int32 nStartCharFlags, const OUString& userDefinedCharactersStart, + sal_Int32 nContCharFlags, const OUString& userDefinedCharactersCont ) override; + virtual css::i18n::ParseResult SAL_CALL parsePredefinedToken( sal_Int32 nTokenType, const OUString& Text, + sal_Int32 nPos, const css::lang::Locale& rLocale, sal_Int32 nStartCharFlags, + const OUString& userDefinedCharactersStart, sal_Int32 nContCharFlags, + const OUString& userDefinedCharactersCont ) override; + + //XServiceInfo + virtual OUString SAL_CALL getImplementationName() override; + virtual sal_Bool SAL_CALL supportsService(const OUString& ServiceName) override; + virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override; + +private: + // These are performance sensitive, so we don't want to use locking and switch their state, so just + // have multiple copies. + rtl::Reference<Transliteration_casemapping> transToUpper; + rtl::Reference<Transliteration_casemapping> transToLower; + rtl::Reference<Transliteration_casemapping> transToTitle; + +// --- parser specific (implemented in cclass_unicode_parser.cxx) --- + + enum ScanState + { + ssGetChar, // initial state; -> ssBounce, ssGetValue, ssRewindFromValue, ssGetWord, ssGetWordFirstChar, ssGetString, ssGetBool, ssStop + ssGetValue, // -> ssBounce, ssRewindFromValue, ssStopBack, ssGetWord + ssGetWord, // -> ssBounce, ssStop, ssStopBack + ssGetWordFirstChar, // -> ssBounce, ssGetWord, ssStop, ssStopBack + ssGetString, // -> ssBounce, ssStop + ssGetBool, // -> ssBounce, ssStop, ssStopBack + ssRewindFromValue, // -> ssBounce, ssGetValue, ssGetWord, ssGetWordFirstChar, ssGetString, ssGetBool, ssStop, ssIgnoreLeadingInRewind + ssIgnoreLeadingInRewind, // -> ssBounce, ssGetValue, ssRewindFromValue, ssGetWord, ssGetWordFirstChar, ssGetString, ssGetBool, ssStop + ssStopBack, // -> ssStop + ssBounce, // -> ssStopBack + ssStop + }; + + static const sal_uInt8 nDefCnt; + static const ParserFlags pDefaultParserTable[]; + static const sal_Int32 pParseTokensType[]; + + /// If and where c occurs in pStr + static const sal_Unicode* StrChr( const sal_Unicode* pStr, sal_uInt32 c ); + + + css::uno::Reference < css::uno::XComponentContext > m_xContext; + + /// used for parser only + css::lang::Locale aParserLocale; + css::uno::Reference < css::i18n::XLocaleData5 > mxLocaleData; + css::uno::Reference < css::i18n::XNativeNumberSupplier > xNatNumSup; + OUString aStartChars; + OUString aContChars; + std::unique_ptr<ParserFlags[]> pTable; + std::unique_ptr<ParserFlags[]> pStart; + std::unique_ptr<ParserFlags[]> pCont; + sal_Int32 nStartTypes; + sal_Int32 nContTypes; + sal_Unicode cGroupSep; + sal_Unicode cDecimalSep; + sal_Unicode cDecimalSepAlt; + + /// Get corresponding KParseTokens flag for a character + static sal_Int32 getParseTokensType(sal_uInt32 c, bool isFirst); + + /// Access parser table flags. + ParserFlags getFlags(sal_uInt32 c, ScanState eState); + + /// Access parser flags via International and special definitions. + ParserFlags getFlagsExtended(sal_uInt32 c, ScanState eState) const; + + /// Access parser table flags for user defined start characters. + ParserFlags getStartCharsFlags( sal_uInt32 c ); + + /// Access parser table flags for user defined continuation characters. + ParserFlags getContCharsFlags( sal_Unicode c ); + + /// Setup parser table. Calls initParserTable() only if needed. + void setupParserTable( const css::lang::Locale& rLocale, sal_Int32 startCharTokenType, + const OUString& userDefinedCharactersStart, sal_Int32 contCharTokenType, + const OUString& userDefinedCharactersCont ); + + /// Init parser table. + void initParserTable( const css::lang::Locale& rLocale, sal_Int32 startCharTokenType, + const OUString& userDefinedCharactersStart, sal_Int32 contCharTokenType, + const OUString& userDefinedCharactersCont ); + + /// Destroy parser table. + void destroyParserTable(); + + /// Parse a text. + void parseText( css::i18n::ParseResult& r, const OUString& rText, sal_Int32 nPos, + sal_Int32 nTokenType = 0xffffffff ); + + /// Setup International class, new'ed only if different from existing. + void setupInternational( const css::lang::Locale& rLocale ); + + /// Implementation of getCharacterType() for one single character + static sal_Int32 getCharType( std::u16string_view Text, sal_Int32 *nPos, sal_Int32 increment); + +}; + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/i18npool/inc/chaptercollator.hxx b/i18npool/inc/chaptercollator.hxx new file mode 100644 index 0000000000..267c11b287 --- /dev/null +++ b/i18npool/inc/chaptercollator.hxx @@ -0,0 +1,54 @@ +/* -*- 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/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#pragma once + +#include "collatorImpl.hxx" + +namespace com::sun::star::i18n { class XCharacterClassification; } + +namespace i18npool { + +// ---------------------------------------------------- +// class ChapterCollator +// ---------------------------------------------------- +class ChapterCollator final : public CollatorImpl +{ +public: + // Constructors + ChapterCollator( const css::uno::Reference < css::uno::XComponentContext >& rxContext ); + // Destructor + virtual ~ChapterCollator() override; + + sal_Int32 SAL_CALL compareSubstring( const OUString& s1, sal_Int32 off1, sal_Int32 len1, + const OUString& s2, sal_Int32 off2, sal_Int32 len2) override; + sal_Int32 SAL_CALL compareString( const OUString& s1, const OUString& s2) override; + + //XServiceInfo + virtual OUString SAL_CALL getImplementationName() override; + virtual sal_Bool SAL_CALL supportsService(const OUString& ServiceName) override; + virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override; + +private: + // CharacterClassification Implementation + css::uno::Reference< css::i18n::XCharacterClassification > cclass; +}; + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/i18npool/inc/characterclassificationImpl.hxx b/i18npool/inc/characterclassificationImpl.hxx new file mode 100644 index 0000000000..bcfc7836a9 --- /dev/null +++ b/i18npool/inc/characterclassificationImpl.hxx @@ -0,0 +1,98 @@ +/* -*- 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/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#pragma once + +#include <com/sun/star/i18n/XCharacterClassification.hpp> +#include <cppuhelper/implbase.hxx> +#include <utility> +#include <vector> +#include <optional> +#include <com/sun/star/lang/XServiceInfo.hpp> + +namespace com::sun::star::uno { class XComponentContext; } + +namespace i18npool { + +class CharacterClassificationImpl final : public cppu::WeakImplHelper +< + css::i18n::XCharacterClassification, + css::lang::XServiceInfo +> +{ +public: + + CharacterClassificationImpl( const css::uno::Reference < css::uno::XComponentContext >& rxContext ); + virtual ~CharacterClassificationImpl() override; + + virtual OUString SAL_CALL toUpper( const OUString& Text, + sal_Int32 nPos, sal_Int32 nCount, const css::lang::Locale& rLocale ) override; + virtual OUString SAL_CALL toLower( const OUString& Text, + sal_Int32 nPos, sal_Int32 nCount, const css::lang::Locale& rLocale ) override; + virtual OUString SAL_CALL toTitle( const OUString& Text, sal_Int32 nPos, + sal_Int32 nCount, const css::lang::Locale& rLocale ) override; + virtual sal_Int16 SAL_CALL getType( const OUString& Text, sal_Int32 nPos ) override; + virtual sal_Int16 SAL_CALL getCharacterDirection( const OUString& Text, sal_Int32 nPos ) override; + virtual sal_Int16 SAL_CALL getScript( const OUString& Text, sal_Int32 nPos ) override; + virtual sal_Int32 SAL_CALL getCharacterType( const OUString& text, sal_Int32 nPos, + const css::lang::Locale& rLocale ) override; + virtual sal_Int32 SAL_CALL getStringType( const OUString& text, sal_Int32 nPos, + sal_Int32 nCount, const css::lang::Locale& rLocale ) override; + virtual css::i18n::ParseResult SAL_CALL parseAnyToken( const OUString& Text, sal_Int32 nPos, + const css::lang::Locale& rLocale, sal_Int32 nStartCharFlags, + const OUString& userDefinedCharactersStart, sal_Int32 nContCharFlags, + const OUString& userDefinedCharactersCont ) override; + virtual css::i18n::ParseResult SAL_CALL parsePredefinedToken( sal_Int32 nTokenType, + const OUString& Text, sal_Int32 nPos, const css::lang::Locale& rLocale, + sal_Int32 nStartCharFlags, const OUString& userDefinedCharactersStart, + sal_Int32 nContCharFlags, const OUString& userDefinedCharactersCont ) override; + + //XServiceInfo + virtual OUString SAL_CALL getImplementationName() override; + virtual sal_Bool SAL_CALL supportsService(const OUString& ServiceName) override; + virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override; + +private: + struct lookupTableItem { + lookupTableItem(css::lang::Locale _aLocale, OUString _aName, + css::uno::Reference < XCharacterClassification > _xCI) : + aLocale(std::move(_aLocale)), aName(std::move(_aName)), xCI(std::move(_xCI)) {}; + css::lang::Locale aLocale; + OUString aName; + css::uno::Reference < XCharacterClassification > xCI; + bool equals(const css::lang::Locale& rLocale) const { + return aLocale.Language == rLocale.Language && + aLocale.Country == rLocale.Country && + aLocale.Variant == rLocale.Variant; + }; + }; + std::vector<lookupTableItem> lookupTable; + std::optional<lookupTableItem> cachedItem; + + css::uno::Reference < css::uno::XComponentContext > m_xContext; + css::uno::Reference < XCharacterClassification > xUCI; + + /// @throws css::uno::RuntimeException + css::uno::Reference < XCharacterClassification > const & getLocaleSpecificCharacterClassification(const css::lang::Locale& rLocale); + bool createLocaleSpecificCharacterClassification(const OUString& serviceName, const css::lang::Locale& rLocale); + +}; + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/i18npool/inc/chartonum.hxx b/i18npool/inc/chartonum.hxx new file mode 100644 index 0000000000..b9dd97d103 --- /dev/null +++ b/i18npool/inc/chartonum.hxx @@ -0,0 +1,52 @@ +/* -*- 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/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include "transliteration_Numeric.hxx" + +namespace i18npool { + +#define TRANSLITERATION_CHARTONUM( name ) \ +class CharToNum##name final : public transliteration_Numeric \ +{ \ +public: \ + CharToNum##name (); \ +}; + +TRANSLITERATION_CHARTONUM(Lower_zh_CN) +TRANSLITERATION_CHARTONUM(Upper_zh_CN) +TRANSLITERATION_CHARTONUM(Lower_zh_TW) +TRANSLITERATION_CHARTONUM(Upper_zh_TW) +TRANSLITERATION_CHARTONUM(Upper_ko) +TRANSLITERATION_CHARTONUM(Hangul_ko) +TRANSLITERATION_CHARTONUM(Lower_ko) +TRANSLITERATION_CHARTONUM(KanjiShort_ja_JP) +TRANSLITERATION_CHARTONUM(KanjiTraditional_ja_JP) +TRANSLITERATION_CHARTONUM(Fullwidth) +TRANSLITERATION_CHARTONUM(Indic_ar) +TRANSLITERATION_CHARTONUM(EastIndic_ar) +TRANSLITERATION_CHARTONUM(Indic_hi) +TRANSLITERATION_CHARTONUM(_th) + +#undef TRANSLITERATION_CHARTONUM + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/i18npool/inc/collatorImpl.hxx b/i18npool/inc/collatorImpl.hxx new file mode 100644 index 0000000000..4d2eee6b7f --- /dev/null +++ b/i18npool/inc/collatorImpl.hxx @@ -0,0 +1,109 @@ +/* -*- 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/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#pragma once + +#include <com/sun/star/uno/Reference.h> +#include <com/sun/star/i18n/XCollator.hpp> +#include <com/sun/star/lang/Locale.hpp> +#include <cppuhelper/implbase.hxx> +#include <com/sun/star/lang/XServiceInfo.hpp> + +#include <utility> +#include <vector> +#include <optional> + +namespace com::sun::star::i18n { class XLocaleData5; } +namespace com::sun::star::uno { class XComponentContext; } + +namespace i18npool { + +// ---------------------------------------------------- +// class CollatorImpl +// ---------------------------------------------------- +class CollatorImpl : public cppu::WeakImplHelper +< + css::i18n::XCollator, + css::lang::XServiceInfo +> +{ +public: + + // Constructors + CollatorImpl( const css::uno::Reference < css::uno::XComponentContext >& rxContext ); + // Destructor + virtual ~CollatorImpl() override; + + virtual sal_Int32 SAL_CALL compareSubstring(const OUString& s1, sal_Int32 off1, sal_Int32 len1, + const OUString& s2, sal_Int32 off2, sal_Int32 len2) override; + + virtual sal_Int32 SAL_CALL compareString( const OUString& s1, + const OUString& s2) override; + + virtual sal_Int32 SAL_CALL loadDefaultCollator( const css::lang::Locale& rLocale, sal_Int32 collatorOptions) override; + + virtual sal_Int32 SAL_CALL loadCollatorAlgorithm( const OUString& impl, const css::lang::Locale& rLocale, + sal_Int32 collatorOptions) override; + + virtual void SAL_CALL loadCollatorAlgorithmWithEndUserOption( const OUString& impl, const css::lang::Locale& rLocale, + const css::uno::Sequence< sal_Int32 >& collatorOptions) override; + + virtual css::uno::Sequence< OUString > SAL_CALL listCollatorAlgorithms( const css::lang::Locale& rLocale ) override; + + virtual css::uno::Sequence< sal_Int32 > SAL_CALL listCollatorOptions( const OUString& collatorAlgorithmName ) override; + + //XServiceInfo + virtual OUString SAL_CALL getImplementationName() override; + virtual sal_Bool SAL_CALL supportsService(const OUString& ServiceName) override; + virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override; + +protected: + css::lang::Locale nLocale; +private: + struct lookupTableItem { + css::lang::Locale aLocale; + OUString algorithm; + OUString service; + css::uno::Reference < XCollator > xC; + lookupTableItem(css::lang::Locale _aLocale, OUString _algorithm, OUString _service, + css::uno::Reference < XCollator > _xC) : aLocale(std::move(_aLocale)), algorithm(std::move(_algorithm)), service(std::move(_service)), xC(std::move(_xC)) {} + bool equals(const css::lang::Locale& rLocale, std::u16string_view _algorithm) { + return aLocale.Language == rLocale.Language && + aLocale.Country == rLocale.Country && + aLocale.Variant == rLocale.Variant && + algorithm == _algorithm; + } + }; + std::vector<lookupTableItem> lookupTable; + std::optional<lookupTableItem> cachedItem; + + // Service Factory + css::uno::Reference < css::uno::XComponentContext > m_xContext; + // lang::Locale Data + css::uno::Reference < css::i18n::XLocaleData5 > mxLocaleData; + + /// @throws css::uno::RuntimeException + bool createCollator(const css::lang::Locale& rLocale, const OUString& serviceName, + const OUString& rSortAlgorithm); + /// @throws css::uno::RuntimeException + void loadCachedCollator(const css::lang::Locale& rLocale, const OUString& rSortAlgorithm); +}; + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/i18npool/inc/collator_unicode.hxx b/i18npool/inc/collator_unicode.hxx new file mode 100644 index 0000000000..f0173799a0 --- /dev/null +++ b/i18npool/inc/collator_unicode.hxx @@ -0,0 +1,72 @@ +/* -*- 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/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#pragma once + +#include <com/sun/star/i18n/XCollator.hpp> +#include <com/sun/star/lang/XServiceInfo.hpp> +#include <cppuhelper/implbase.hxx> +#include <osl/module.h> + +#include <unicode/tblcoll.h> + +// ---------------------------------------------------- +// class Collator_Unicode +// ---------------------------------------------------- + +namespace i18npool { + +class Collator_Unicode final : public cppu::WeakImplHelper < css::i18n::XCollator, css::lang::XServiceInfo > +{ +public: + // Constructors + Collator_Unicode(); + // Destructor + virtual ~Collator_Unicode() override; + + sal_Int32 SAL_CALL compareSubstring( const OUString& s1, sal_Int32 off1, sal_Int32 len1, + const OUString& s2, sal_Int32 off2, sal_Int32 len2) override; + + sal_Int32 SAL_CALL compareString( const OUString& s1, const OUString& s2) override; + + sal_Int32 SAL_CALL loadCollatorAlgorithm( const OUString& impl, const css::lang::Locale& rLocale, + sal_Int32 collatorOptions) override; + + + // following 4 methods are implemented in collatorImpl. + sal_Int32 SAL_CALL loadDefaultCollator( const css::lang::Locale&, sal_Int32) override {throw css::uno::RuntimeException();} + void SAL_CALL loadCollatorAlgorithmWithEndUserOption( const OUString&, const css::lang::Locale&, + const css::uno::Sequence< sal_Int32 >&) override {throw css::uno::RuntimeException();} + css::uno::Sequence< OUString > SAL_CALL listCollatorAlgorithms( const css::lang::Locale&) override {throw css::uno::RuntimeException();} + css::uno::Sequence< sal_Int32 > SAL_CALL listCollatorOptions( const OUString& ) override {throw css::uno::RuntimeException();} + + //XServiceInfo + virtual OUString SAL_CALL getImplementationName() override; + virtual sal_Bool SAL_CALL supportsService(const OUString& ServiceName) override; + virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override; + +private: + std::unique_ptr<icu::RuleBasedCollator> uca_base, collator; +#ifndef DISABLE_DYNLOADING + oslModule hModule; +#endif +}; + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/i18npool/inc/defaultnumberingprovider.hxx b/i18npool/inc/defaultnumberingprovider.hxx new file mode 100644 index 0000000000..74f03b7e95 --- /dev/null +++ b/i18npool/inc/defaultnumberingprovider.hxx @@ -0,0 +1,92 @@ +/* -*- 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/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#pragma once + +#include <com/sun/star/text/XDefaultNumberingProvider.hpp> +#include <com/sun/star/text/XNumberingFormatter.hpp> +#include <com/sun/star/text/XNumberingTypeInfo.hpp> +#include <com/sun/star/lang/XServiceInfo.hpp> +#include <cppuhelper/implbase.hxx> +#include <rtl/ref.hxx> +#include <map> + +namespace com::sun::star::container { class XHierarchicalNameAccess; } +namespace com::sun::star::uno { class XComponentContext; } +namespace i18npool { + class TransliterationImpl; + class NativeNumberSupplierService; + struct Supported_NumberingType; +} + +namespace i18npool { + +class DefaultNumberingProvider final : public cppu::WeakImplHelper +< + css::text::XDefaultNumberingProvider, + css::text::XNumberingFormatter, + css::text::XNumberingTypeInfo, + css::lang::XServiceInfo +> +{ +public: + DefaultNumberingProvider( + const css::uno::Reference < css::uno::XComponentContext >& rxContext ); + virtual ~DefaultNumberingProvider() override; + + //XDefaultNumberingProvider + virtual css::uno::Sequence< css::uno::Reference< + css::container::XIndexAccess > > SAL_CALL + getDefaultOutlineNumberings( const css::lang::Locale& aLocale ) override; + + virtual css::uno::Sequence< css::uno::Sequence< + css::beans::PropertyValue > > SAL_CALL + getDefaultContinuousNumberingLevels( const css::lang::Locale& aLocale ) override; + + //XNumberingFormatter + virtual OUString SAL_CALL makeNumberingString( + const css::uno::Sequence< + css::beans::PropertyValue >& aProperties, + const css::lang::Locale& aLocale ) override; + + //XNumberingTypeInfo + virtual css::uno::Sequence< sal_Int16 > SAL_CALL getSupportedNumberingTypes( ) override; + virtual sal_Int16 SAL_CALL getNumberingType( const OUString& NumberingIdentifier ) override; + virtual sal_Bool SAL_CALL hasNumberingType( const OUString& NumberingIdentifier ) override; + virtual OUString SAL_CALL getNumberingIdentifier( sal_Int16 NumberingType ) override; + + //XServiceInfo + virtual OUString SAL_CALL getImplementationName() override; + virtual sal_Bool SAL_CALL supportsService(const OUString& ServiceName) override; + virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override; +private: + css::uno::Reference < css::uno::XComponentContext > m_xContext; + css::uno::Reference < css::container::XHierarchicalNameAccess > xHierarchicalNameAccess; + rtl::Reference<TransliterationImpl> translit; + rtl::Reference<NativeNumberSupplierService> mxNatNum; + std::map<OUString, const Supported_NumberingType*> maSupportedTypesCache; + + /// @throws css::uno::RuntimeException + OUString makeNumberingIdentifier( sal_Int16 index ); + /// @throws css::uno::RuntimeException + bool isScriptFlagEnabled(const OUString& aName ); +}; + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/i18npool/inc/indexentrysupplier.hxx b/i18npool/inc/indexentrysupplier.hxx new file mode 100644 index 0000000000..bbfe58b763 --- /dev/null +++ b/i18npool/inc/indexentrysupplier.hxx @@ -0,0 +1,94 @@ +/* -*- 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/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#pragma once + +#include <sal/config.h> + +#include <string_view> + +#include <com/sun/star/i18n/XExtendedIndexEntrySupplier.hpp> +#include <cppuhelper/implbase.hxx> +#include <com/sun/star/lang/XServiceInfo.hpp> + +namespace com::sun::star::uno { class XComponentContext; } + +namespace i18npool { + + + +class IndexEntrySupplier final : public cppu::WeakImplHelper +< + css::i18n::XExtendedIndexEntrySupplier, + css::lang::XServiceInfo +> +{ +public: + IndexEntrySupplier( const css::uno::Reference < css::uno::XComponentContext >& rxContext ); + + // Methods + virtual css::uno::Sequence < css::lang::Locale > SAL_CALL getLocaleList() override; + + virtual css::uno::Sequence < OUString > SAL_CALL getAlgorithmList( + const css::lang::Locale& rLocale ) override; + + virtual sal_Bool SAL_CALL loadAlgorithm( + const css::lang::Locale& rLocale, + const OUString& SortAlgorithm, sal_Int32 collatorOptions ) override; + + virtual sal_Bool SAL_CALL usePhoneticEntry( + const css::lang::Locale& rLocale ) override; + + virtual OUString SAL_CALL getPhoneticCandidate( const OUString& IndexEntry, + const css::lang::Locale& rLocale ) override; + + virtual OUString SAL_CALL getIndexKey( const OUString& IndexEntry, + const OUString& PhoneticEntry, const css::lang::Locale& rLocale ) override; + + virtual sal_Int16 SAL_CALL compareIndexEntry( const OUString& IndexEntry1, + const OUString& PhoneticEntry1, const css::lang::Locale& rLocale1, + const OUString& IndexEntry2, const OUString& PhoneticEntry2, + const css::lang::Locale& rLocale2 ) override; + + virtual OUString SAL_CALL getIndexCharacter( const OUString& IndexEntry, + const css::lang::Locale& rLocale, const OUString& SortAlgorithm ) override; + + virtual OUString SAL_CALL getIndexFollowPageWord( sal_Bool MorePages, + const css::lang::Locale& rLocale ) override; + + //XServiceInfo + virtual OUString SAL_CALL getImplementationName() override; + virtual sal_Bool SAL_CALL supportsService(const OUString& ServiceName) override; + virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override; + +private: + css::uno::Reference < css::i18n::XExtendedIndexEntrySupplier > xIES; + css::uno::Reference < css::uno::XComponentContext > m_xContext; + /// @throws css::uno::RuntimeException + bool createLocaleSpecificIndexEntrySupplier(std::u16string_view name); + /// @throws css::uno::RuntimeException + css::uno::Reference < css::i18n::XExtendedIndexEntrySupplier > const & getLocaleSpecificIndexEntrySupplier( + const css::lang::Locale& rLocale, const OUString& rSortAlgorithm); + + css::lang::Locale aLocale; + OUString aSortAlgorithm; +}; + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/i18npool/inc/indexentrysupplier_asian.hxx b/i18npool/inc/indexentrysupplier_asian.hxx new file mode 100644 index 0000000000..52e452b17b --- /dev/null +++ b/i18npool/inc/indexentrysupplier_asian.hxx @@ -0,0 +1,55 @@ +/* -*- 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/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + + +#include "indexentrysupplier_common.hxx" +#include <osl/module.h> + +namespace i18npool { + + + + +class IndexEntrySupplier_asian final : public IndexEntrySupplier_Common { +public: + IndexEntrySupplier_asian( const css::uno::Reference < css::uno::XComponentContext >& rxContext ); + virtual ~IndexEntrySupplier_asian() override; + + OUString SAL_CALL getIndexCharacter( const OUString& rIndexEntry, + const css::lang::Locale& rLocale, const OUString& rAlgorithm ) override; + OUString SAL_CALL getIndexKey( const OUString& rIndexEntry, + const OUString& rPhoneticEntry, const css::lang::Locale& rLocale) override; + sal_Int16 SAL_CALL compareIndexEntry( + const OUString& rIndexEntry1, const OUString& rPhoneticEntry1, + const css::lang::Locale& rLocale1, + const OUString& rIndexEntry2, const OUString& rPhoneticEntry2, + const css::lang::Locale& rLocale2 ) override; + OUString SAL_CALL getPhoneticCandidate( const OUString& rIndexEntry, + const css::lang::Locale& rLocale ) override; +#ifndef DISABLE_DYNLOADING +private: + oslModule hModule; +#endif +}; + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/i18npool/inc/indexentrysupplier_common.hxx b/i18npool/inc/indexentrysupplier_common.hxx new file mode 100644 index 0000000000..eaa752d4ff --- /dev/null +++ b/i18npool/inc/indexentrysupplier_common.hxx @@ -0,0 +1,94 @@ +/* -*- 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/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include <com/sun/star/i18n/XExtendedIndexEntrySupplier.hpp> +#include <cppuhelper/implbase.hxx> +#include <com/sun/star/lang/XServiceInfo.hpp> +#include <rtl/ref.hxx> + +namespace com::sun::star::uno { class XComponentContext; } +namespace i18npool { class CollatorImpl; } + +namespace i18npool { + + + + +class IndexEntrySupplier_Common : public cppu::WeakImplHelper +< + css::i18n::XExtendedIndexEntrySupplier, + css::lang::XServiceInfo +> +{ +public: + IndexEntrySupplier_Common( const css::uno::Reference < css::uno::XComponentContext >& rxContext ); + virtual ~IndexEntrySupplier_Common() override; + + virtual css::uno::Sequence < css::lang::Locale > SAL_CALL getLocaleList() override; + + virtual css::uno::Sequence < OUString > SAL_CALL getAlgorithmList( + const css::lang::Locale& rLocale ) override; + + virtual sal_Bool SAL_CALL usePhoneticEntry( + const css::lang::Locale& rLocale ) override; + + virtual OUString SAL_CALL getPhoneticCandidate( const OUString& IndexEntry, + const css::lang::Locale& rLocale ) override; + + virtual sal_Bool SAL_CALL loadAlgorithm( + const css::lang::Locale& rLocale, + const OUString& SortAlgorithm, sal_Int32 collatorOptions ) override; + + virtual OUString SAL_CALL getIndexKey( const OUString& IndexEntry, + const OUString& PhoneticEntry, const css::lang::Locale& rLocale ) override; + + virtual sal_Int16 SAL_CALL compareIndexEntry( const OUString& IndexEntry1, + const OUString& PhoneticEntry1, const css::lang::Locale& rLocale1, + const OUString& IndexEntry2, const OUString& PhoneticEntry2, + const css::lang::Locale& rLocale2 ) override; + + virtual OUString SAL_CALL getIndexCharacter( const OUString& rIndexEntry, + const css::lang::Locale& rLocale, const OUString& rSortAlgorithm ) override; + + virtual OUString SAL_CALL getIndexFollowPageWord( sal_Bool MorePages, + const css::lang::Locale& rLocale ) override; + + //XServiceInfo + virtual OUString SAL_CALL getImplementationName() override; + virtual sal_Bool SAL_CALL supportsService(const OUString& ServiceName) override; + virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override; + +protected: + const char * implementationName; + bool usePhonetic; + rtl::Reference<CollatorImpl> + collator; + css::lang::Locale aLocale; + OUString aAlgorithm; + + /// @throws css::uno::RuntimeException + const OUString& getEntry( const OUString& IndexEntry, + const OUString& PhoneticEntry, const css::lang::Locale& rLocale ) const; +}; + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/i18npool/inc/indexentrysupplier_default.hxx b/i18npool/inc/indexentrysupplier_default.hxx new file mode 100644 index 0000000000..e9c43583b6 --- /dev/null +++ b/i18npool/inc/indexentrysupplier_default.hxx @@ -0,0 +1,106 @@ +/* -*- 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/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#pragma once + +#include "indexentrysupplier_common.hxx" + +#include <memory> +#include <string_view> + +namespace i18npool { + +class Index; + + + +class IndexEntrySupplier_Unicode final : public IndexEntrySupplier_Common { +public: + IndexEntrySupplier_Unicode( const css::uno::Reference < css::uno::XComponentContext >& rxContext ); + virtual ~IndexEntrySupplier_Unicode() override; + + virtual sal_Bool SAL_CALL loadAlgorithm( + const css::lang::Locale& rLocale, + const OUString& SortAlgorithm, sal_Int32 collatorOptions ) override; + + virtual OUString SAL_CALL getIndexKey( const OUString& IndexEntry, + const OUString& PhoneticEntry, const css::lang::Locale& rLocale ) override; + + virtual sal_Int16 SAL_CALL compareIndexEntry( const OUString& IndexEntry1, + const OUString& PhoneticEntry1, const css::lang::Locale& rLocale1, + const OUString& IndexEntry2, const OUString& PhoneticEntry2, + const css::lang::Locale& rLocale2 ) override; + + virtual OUString SAL_CALL getIndexCharacter( const OUString& rIndexEntry, + const css::lang::Locale& rLocale, const OUString& rSortAlgorithm ) override; + +private: + std::unique_ptr<Index> index; +}; + +struct IndexKey { + sal_Unicode key; + OUString mkey; + OUString desc; +}; + +class IndexTable +{ +public: + IndexTable(); + ~IndexTable(); + + void init(sal_Unicode start_, sal_Unicode end_, IndexKey const * keys, sal_Int16 key_count, Index *index); + + sal_Unicode start; + sal_Unicode end; + sal_uInt8 *table; +}; + +#define MAX_KEYS 0xff +#define MAX_TABLES 20 + +class Index +{ +public: + Index(const css::uno::Reference < css::uno::XComponentContext >& rxContext); + ~Index(); + + /// @throws css::uno::RuntimeException + void init(const css::lang::Locale& rLocale, const OUString& algorithm); + + /// @throws css::uno::RuntimeException + void makeIndexKeys(const css::lang::Locale &rLocale, std::u16string_view algorithm); + sal_Int16 getIndexWeight(const OUString& rIndexEntry); + OUString getIndexDescription(const OUString& rIndexEntry); + sal_Int16 compare(sal_Unicode c1, sal_Unicode c2); + +private: + IndexTable tables[MAX_TABLES]; + sal_Int16 table_count; + IndexKey keys[MAX_KEYS]; + sal_Int16 key_count; + sal_Int16 mkeys[MAX_KEYS]; + sal_Int16 mkey_count; + OUString skipping_chars; + rtl::Reference<CollatorImpl> collator; +}; + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/i18npool/inc/indexentrysupplier_ja_phonetic.hxx b/i18npool/inc/indexentrysupplier_ja_phonetic.hxx new file mode 100644 index 0000000000..ea19dcb12a --- /dev/null +++ b/i18npool/inc/indexentrysupplier_ja_phonetic.hxx @@ -0,0 +1,63 @@ +/* -*- 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/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include "indexentrysupplier_common.hxx" + +namespace i18npool { + + + + +class IndexEntrySupplier_ja_phonetic : public IndexEntrySupplier_Common { +public: + IndexEntrySupplier_ja_phonetic( const css::uno::Reference < css::uno::XComponentContext >& rxContext ) : IndexEntrySupplier_Common(rxContext) { + implementationName = "com.sun.star.i18n.IndexEntrySupplier_ja_phonetic"; + }; + virtual OUString SAL_CALL getIndexCharacter( const OUString& rIndexEntry, + const css::lang::Locale& rLocale, const OUString& rSortAlgorithm ) override; + virtual OUString SAL_CALL getIndexKey( const OUString& IndexEntry, + const OUString& PhoneticEntry, const css::lang::Locale& rLocale ) override; + virtual sal_Int16 SAL_CALL compareIndexEntry( const OUString& IndexEntry1, + const OUString& PhoneticEntry1, const css::lang::Locale& rLocale1, + const OUString& IndexEntry2, const OUString& PhoneticEntry2, + const css::lang::Locale& rLocale2 ) override; +}; + +#define INDEXENTRYSUPPLIER_JA_PHONETIC( algorithm, algo_descr ) \ +class IndexEntrySupplier_##algorithm final : public IndexEntrySupplier_ja_phonetic {\ +public:\ + IndexEntrySupplier_##algorithm (const css::uno::Reference < css::uno::XComponentContext >& rxContext) : IndexEntrySupplier_ja_phonetic (rxContext) {\ + implementationName = "com.sun.star.i18n.IndexEntrySupplier_ja_phonetic" algo_descr;\ + };\ + virtual sal_Bool SAL_CALL loadAlgorithm(\ + const css::lang::Locale& rLocale,\ + const OUString& SortAlgorithm, sal_Int32 collatorOptions ) override;\ +}; + +/** descriptions formed by concatenating strings here must match names in .component file */ +INDEXENTRYSUPPLIER_JA_PHONETIC( ja_phonetic_alphanumeric_first_by_syllable, " (alphanumeric first) (grouped by syllable)" ) +INDEXENTRYSUPPLIER_JA_PHONETIC( ja_phonetic_alphanumeric_first_by_consonant, " (alphanumeric first) (grouped by consonant)" ) +INDEXENTRYSUPPLIER_JA_PHONETIC( ja_phonetic_alphanumeric_last_by_syllable, " (alphanumeric last) (grouped by syllable)" ) +INDEXENTRYSUPPLIER_JA_PHONETIC( ja_phonetic_alphanumeric_last_by_consonant, " (alphanumeric last) (grouped by consonant)" ) + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/i18npool/inc/inputsequencechecker.hxx b/i18npool/inc/inputsequencechecker.hxx new file mode 100644 index 0000000000..4f93ada082 --- /dev/null +++ b/i18npool/inc/inputsequencechecker.hxx @@ -0,0 +1,78 @@ +/* -*- 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/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#pragma once + +#include <cppuhelper/implbase.hxx> +#include <com/sun/star/lang/XServiceInfo.hpp> +#include <com/sun/star/i18n/XExtendedInputSequenceChecker.hpp> + +#include <utility> +#include <vector> +#include <optional> + +namespace com::sun::star::uno { class XComponentContext; } + +namespace i18npool { + + + +class InputSequenceCheckerImpl : public cppu::WeakImplHelper +< + css::i18n::XExtendedInputSequenceChecker, + css::lang::XServiceInfo +> +{ +public: + InputSequenceCheckerImpl( const css::uno::Reference < css::uno::XComponentContext >& rxContext ); + InputSequenceCheckerImpl(const char *pServiceName); + virtual ~InputSequenceCheckerImpl() override; + + virtual sal_Bool SAL_CALL checkInputSequence(const OUString& Text, sal_Int32 nStartPos, + sal_Unicode inputChar, sal_Int16 inputCheckMode) override; + + virtual sal_Int32 SAL_CALL correctInputSequence(OUString& Text, sal_Int32 nStartPos, + sal_Unicode inputChar, sal_Int16 inputCheckMode) override; + + //XServiceInfo + virtual OUString SAL_CALL getImplementationName() override; + virtual sal_Bool SAL_CALL supportsService(const OUString& ServiceName) override; + virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override; + +private: + const char *serviceName; + + struct lookupTableItem { + lookupTableItem(const char* rLanguage, css::uno::Reference < css::i18n::XExtendedInputSequenceChecker > _xISC) : + aLanguage(rLanguage), xISC(std::move(_xISC)) {} + const char* aLanguage; + css::uno::Reference < css::i18n::XExtendedInputSequenceChecker > xISC; + }; + std::vector<lookupTableItem> lookupTable; + std::optional<lookupTableItem> cachedItem; + + css::uno::Reference < css::uno::XComponentContext > m_xContext; + + /// @throws css::uno::RuntimeException + css::uno::Reference< css::i18n::XExtendedInputSequenceChecker >& getInputSequenceChecker(char const * rLanguage); + static char* getLanguageByScripType(sal_Unicode cChar, sal_Unicode nChar); +}; + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/i18npool/inc/inputsequencechecker_hi.hxx b/i18npool/inc/inputsequencechecker_hi.hxx new file mode 100644 index 0000000000..a190edbc72 --- /dev/null +++ b/i18npool/inc/inputsequencechecker_hi.hxx @@ -0,0 +1,42 @@ +/* -*- 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/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#pragma once + +#include "inputsequencechecker.hxx" + +namespace i18npool { + + + +class InputSequenceChecker_hi final : public InputSequenceCheckerImpl +{ +public: + InputSequenceChecker_hi(); + virtual ~InputSequenceChecker_hi() override; + + sal_Bool SAL_CALL checkInputSequence(const OUString& Text, sal_Int32 nStartPos, + sal_Unicode inputChar, sal_Int16 inputCheckMode) override; + + sal_Int32 SAL_CALL correctInputSequence(OUString& Text, sal_Int32 nStartPos, + sal_Unicode inputChar, sal_Int16 inputCheckMode) override; +}; + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/i18npool/inc/inputsequencechecker_th.hxx b/i18npool/inc/inputsequencechecker_th.hxx new file mode 100644 index 0000000000..062aea1f88 --- /dev/null +++ b/i18npool/inc/inputsequencechecker_th.hxx @@ -0,0 +1,42 @@ +/* -*- 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/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#pragma once + +#include "inputsequencechecker.hxx" + +namespace i18npool { + + + +class InputSequenceChecker_th final : public InputSequenceCheckerImpl +{ +public: + InputSequenceChecker_th(); + virtual ~InputSequenceChecker_th() override; + + sal_Bool SAL_CALL checkInputSequence(const OUString& Text, sal_Int32 nStartPos, + sal_Unicode inputChar, sal_Int16 inputCheckMode) override; + + sal_Int32 SAL_CALL correctInputSequence(OUString& Text, sal_Int32 nStartPos, + sal_Unicode inputChar, sal_Int16 inputCheckMode) override; +}; + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/i18npool/inc/localedata.hxx b/i18npool/inc/localedata.hxx new file mode 100644 index 0000000000..f4cd15a302 --- /dev/null +++ b/i18npool/inc/localedata.hxx @@ -0,0 +1,176 @@ +/* -*- 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/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#pragma once + +#include <com/sun/star/i18n/XLocaleData5.hpp> + + +#include <cppuhelper/implbase.hxx> + +#include <com/sun/star/uno/Sequence.h> +#include <com/sun/star/i18n/Calendar.hpp> +#include <com/sun/star/i18n/LocaleDataItem2.hpp> +#include <com/sun/star/i18n/UnicodeScript.hpp> +#include <rtl/ref.hxx> +#include <rtl/ustring.hxx> +#include <vector> +#include <string_view> +#include <optional> +#include <osl/module.hxx> + + +#include <com/sun/star/lang/XServiceInfo.hpp> + +namespace com::sun::star::beans { struct PropertyValue; } +namespace com::sun::star::container { class XIndexAccess; } +namespace com::sun::star::i18n { struct Currency; } +namespace com::sun::star::i18n { struct Currency2; } +namespace com::sun::star::i18n { struct FormatElement; } +namespace com::sun::star::lang { struct Locale; } + +struct LocaleDataLookupTableItem; + +namespace i18npool { + +struct LocaleDataLookupTableItem +{ + const char* dllName; + osl::Module *module; + const char* localeName; + css::lang::Locale aLocale; + + LocaleDataLookupTableItem(const char *name, osl::Module* m, const char* lname) : dllName(name), module(m), localeName(lname) + { + } + bool equals(const css::lang::Locale& rLocale) const + { + return (rLocale == aLocale); + } +}; + +class LocaleDataImpl final : public cppu::WeakImplHelper +< + css::i18n::XLocaleData5, + css::lang::XServiceInfo +> +{ +public: + LocaleDataImpl(); + virtual ~LocaleDataImpl() override; + + static rtl::Reference<LocaleDataImpl> get() { return new LocaleDataImpl; } + + static css::uno::Sequence< css::i18n::CalendarItem > downcastCalendarItems( const css::uno::Sequence< css::i18n::CalendarItem2 > & rCi ); + static css::i18n::Calendar downcastCalendar( const css::i18n::Calendar2 & rC ); + + /** Generates a <Language>_<Country> or <Variant> (if Language=="qlt") + string suitable as part of service name with all '-' replaced by '_' */ + static OUString getFirstLocaleServiceName( const css::lang::Locale & rLocale ); + /** Generates fallback strings suitable as parts of service names, + excluding the one obtained via getFirstLocaleServiceName() */ + static ::std::vector< OUString > getFallbackLocaleServiceNames( const css::lang::Locale & rLocale ); + + virtual css::i18n::LanguageCountryInfo SAL_CALL getLanguageCountryInfo( const css::lang::Locale& rLocale ) override; + virtual css::i18n::LocaleDataItem SAL_CALL getLocaleItem( const css::lang::Locale& rLocale ) override; + virtual css::uno::Sequence< css::i18n::Calendar2 > SAL_CALL getAllCalendars2( const css::lang::Locale& rLocale ) override; + virtual css::uno::Sequence< css::i18n::Calendar > SAL_CALL getAllCalendars( const css::lang::Locale& rLocale ) override; + virtual css::uno::Sequence< css::i18n::Currency > SAL_CALL getAllCurrencies( const css::lang::Locale& rLocale ) override; + virtual css::uno::Sequence< css::i18n::Currency2 > SAL_CALL getAllCurrencies2( const css::lang::Locale& rLocale ) override; + virtual css::uno::Sequence< css::i18n::FormatElement > SAL_CALL getAllFormats( const css::lang::Locale& rLocale ) override; + virtual css::uno::Sequence< css::i18n::Implementation > SAL_CALL getCollatorImplementations( const css::lang::Locale& rLocale ) override; + /// @throws css::uno::RuntimeException + OUString getCollatorRuleByAlgorithm( const css::lang::Locale& rLocale, std::u16string_view algorithm ); + virtual css::uno::Sequence< OUString > SAL_CALL getTransliterations( const css::lang::Locale& rLocale ) override; + virtual css::i18n::ForbiddenCharacters SAL_CALL getForbiddenCharacters( const css::lang::Locale& rLocale ) override; + virtual css::uno::Sequence< OUString > SAL_CALL getReservedWord( const css::lang::Locale& rLocale ) override ; + /// @throws css::uno::RuntimeException + css::uno::Sequence< OUString > getBreakIteratorRules( const css::lang::Locale& rLocale ) ; + virtual css::uno::Sequence< css::lang::Locale > SAL_CALL getAllInstalledLocaleNames() override; + + virtual css::uno::Sequence< OUString > SAL_CALL getSearchOptions( const css::lang::Locale& rLocale ) override; + virtual css::uno::Sequence< OUString > SAL_CALL getCollationOptions( const css::lang::Locale& rLocale ) override; + /// @throws css::uno::RuntimeException + css::uno::Sequence< css::uno::Sequence< css::beans::PropertyValue > > getContinuousNumberingLevels( const css::lang::Locale& rLocale ); + /// @throws css::uno::RuntimeException + css::uno::Sequence< css::uno::Reference< css::container::XIndexAccess > > getOutlineNumberingLevels( const css::lang::Locale& rLocale ); + + // XLocaleData4 + virtual css::uno::Sequence< OUString > SAL_CALL getDateAcceptancePatterns( const css::lang::Locale& rLocale ) override; + + // XLocaleData5 + virtual css::i18n::LocaleDataItem2 SAL_CALL getLocaleItem2( const css::lang::Locale& rLocale ) override; + + // following methods are used by indexentry service + /// @throws css::uno::RuntimeException + css::uno::Sequence< OUString > getIndexAlgorithm( const css::lang::Locale& rLocale ); + /// @throws css::uno::RuntimeException + OUString getDefaultIndexAlgorithm( const css::lang::Locale& rLocale ); + /// @throws css::uno::RuntimeException + OUString getIndexKeysByAlgorithm( + const css::lang::Locale& rLocale, std::u16string_view algorithm ); + /// @throws css::uno::RuntimeException + OUString getIndexModuleByAlgorithm( const css::lang::Locale& rLocale, std::u16string_view algorithm ); + /// @throws css::uno::RuntimeException + css::uno::Sequence< css::i18n::UnicodeScript > getUnicodeScripts( const css::lang::Locale& rLocale ); + /// @throws css::uno::RuntimeException + css::uno::Sequence< OUString > getFollowPageWords( const css::lang::Locale& rLocale ); + /// @throws css::uno::RuntimeException + bool hasPhonetic( const css::lang::Locale& rLocale ); + /// @throws css::uno::RuntimeException + bool isPhonetic( const css::lang::Locale& rLocale, std::u16string_view algorithm ); + /// @throws css::uno::RuntimeException + OUString getHangingCharacters( const css::lang::Locale& rLocale ); + + //XServiceInfo + virtual OUString SAL_CALL getImplementationName() override; + virtual sal_Bool SAL_CALL supportsService(const OUString& ServiceName) override; + virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override; + +private: + ::std::optional< LocaleDataLookupTableItem > moCachedItem; + css::i18n::Calendar2 ref_cal; + OUString ref_name; + + /// @throws css::uno::RuntimeException + oslGenericFunction getFunctionSymbol( const css::lang::Locale& rLocale, const char* pFunction ); + OUString const * getIndexArray(const css::lang::Locale& rLocale, sal_Int16& indexCount); + OUString const * getIndexArrayForAlgorithm(const css::lang::Locale& rLocale, std::u16string_view rAlgorithm); + /// @throws css::uno::RuntimeException + css::uno::Sequence< css::i18n::CalendarItem2 > & + getCalendarItemByName(const OUString& name, + const css::lang::Locale& rLocale, + const css::uno::Sequence< css::i18n::Calendar2 >& calendarsSeq, + sal_Int16 item); + + /// Helper to obtain a sequence of days, months, gmonths or eras. + /// + /// @throws css::uno::RuntimeException + css::uno::Sequence< css::i18n::CalendarItem2 > getCalendarItems( + OUString const * allCalendars, + sal_Int16 & rnOffset, + const sal_Int16 nWhichItem, + const sal_Int16 nCalendar, + const css::lang::Locale & rLocale, + const css::uno::Sequence< css::i18n::Calendar2 > & calendarsSeq ); + +}; + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/i18npool/inc/nativenumbersupplier.hxx b/i18npool/inc/nativenumbersupplier.hxx new file mode 100644 index 0000000000..61e336024d --- /dev/null +++ b/i18npool/inc/nativenumbersupplier.hxx @@ -0,0 +1,85 @@ +/* -*- 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/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#pragma once + +#include <com/sun/star/i18n/XNativeNumberSupplier2.hpp> +#include <com/sun/star/i18n/NativeNumberXmlAttributes.hpp> +#include <cppuhelper/implbase.hxx> +#include <com/sun/star/lang/XServiceInfo.hpp> + +namespace com::sun::star::i18n { class XCharacterClassification; } + +namespace i18npool { + +// ---------------------------------------------------- +// class NativeNumberSupplierService +// ---------------------------------------------------- +class NativeNumberSupplierService final : public cppu::WeakImplHelper +< + css::i18n::XNativeNumberSupplier2, + css::lang::XServiceInfo +> +{ +public: + NativeNumberSupplierService() {} + + // Methods + virtual OUString SAL_CALL getNativeNumberString( const OUString& aNumberString, + const css::lang::Locale& aLocale, sal_Int16 nNativeNumberMode ) override; + + virtual sal_Bool SAL_CALL isValidNatNum( const css::lang::Locale& rLocale, + sal_Int16 nNativeNumberMode ) override { return isValidNatNumImpl(rLocale, nNativeNumberMode); } + + virtual css::i18n::NativeNumberXmlAttributes SAL_CALL convertToXmlAttributes( + const css::lang::Locale& aLocale, sal_Int16 nNativeNumberMode ) override; + + virtual sal_Int16 SAL_CALL convertFromXmlAttributes( + const css::i18n::NativeNumberXmlAttributes& aAttr ) override; + + // XNativeNumberSupplier2 + virtual OUString SAL_CALL getNativeNumberStringParams( + const OUString& rNumberString, const css::lang::Locale& rLocale, + sal_Int16 nNativeNumberMode, const OUString& rNativeNumberParams) override; + + //XServiceInfo + virtual OUString SAL_CALL getImplementationName() override; + virtual sal_Bool SAL_CALL supportsService(const OUString& ServiceName) override; + virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override; + + // following methods are not for XNativeNumberSupplier, they are for calling from transliterations + /// @throws css::uno::RuntimeException + OUString getNativeNumberString(const OUString& rNumberString, + const css::lang::Locale& rLocale, + sal_Int16 nNativeNumberMode, + css::uno::Sequence<sal_Int32>* pOffset, + std::u16string_view rNativeNumberParams = std::u16string_view()); + /// @throws css::uno::RuntimeException + static sal_Unicode getNativeNumberChar( const sal_Unicode inChar, + const css::lang::Locale& aLocale, sal_Int16 nNativeNumberMode ) ; + +private: + static bool isValidNatNumImpl( const css::lang::Locale& aLocale, + sal_Int16 nNativeNumberMode ); + css::lang::Locale aLocale; + mutable css::uno::Reference< css::i18n::XCharacterClassification > xCharClass; +}; + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/i18npool/inc/numberformatcode.hxx b/i18npool/inc/numberformatcode.hxx new file mode 100644 index 0000000000..fba19db55f --- /dev/null +++ b/i18npool/inc/numberformatcode.hxx @@ -0,0 +1,70 @@ +/* -*- 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/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include <cppuhelper/implbase.hxx> + +#include <com/sun/star/i18n/XNumberFormatCode.hpp> +#include <com/sun/star/uno/Sequence.hxx> +#include <com/sun/star/lang/XServiceInfo.hpp> + +#include <deque> +#include <mutex> +#include <utility> + +namespace com::sun::star::i18n { class XLocaleData5; } +namespace com::sun::star::i18n { struct FormatElement; } +namespace com::sun::star::uno { class XComponentContext; } + +class NumberFormatCodeMapper final : public cppu::WeakImplHelper +< + css::i18n::XNumberFormatCode, + css::lang::XServiceInfo +> +{ +public: + NumberFormatCodeMapper( const css::uno::Reference < + css::uno::XComponentContext >& rxContext ); + virtual ~NumberFormatCodeMapper() override; + + virtual css::i18n::NumberFormatCode SAL_CALL getDefault( sal_Int16 nFormatType, sal_Int16 nFormatUsage, const css::lang::Locale& rLocale ) override; + virtual css::i18n::NumberFormatCode SAL_CALL getFormatCode( sal_Int16 nFormatIndex, const css::lang::Locale& rLocale ) override; + virtual css::uno::Sequence< css::i18n::NumberFormatCode > SAL_CALL getAllFormatCode( sal_Int16 nFormatUsage, const css::lang::Locale& rLocale ) override; + virtual css::uno::Sequence< css::i18n::NumberFormatCode > SAL_CALL getAllFormatCodes( const css::lang::Locale& rLocale ) override; + + //XServiceInfo + virtual OUString SAL_CALL getImplementationName() override; + virtual sal_Bool SAL_CALL supportsService(const OUString& ServiceName) override; + virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override; + +private: + std::mutex maMutex; + css::uno::Reference < css::i18n::XLocaleData5 > m_xLocaleData; + typedef std::pair< css::lang::Locale, css::uno::Sequence< css::i18n::FormatElement > > FormatElementCacheItem; + std::deque < FormatElementCacheItem > m_aFormatElementCache; + + const css::uno::Sequence< css::i18n::FormatElement >& getFormats( const css::lang::Locale& rLocale ); + static OUString mapElementTypeShortToString(sal_Int16 formatType); + static sal_Int16 mapElementTypeStringToShort(std::u16string_view formatType); + static OUString mapElementUsageShortToString(sal_Int16 formatUsage); + static sal_Int16 mapElementUsageStringToShort(std::u16string_view formatUsage); +}; + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/i18npool/inc/numtochar.hxx b/i18npool/inc/numtochar.hxx new file mode 100644 index 0000000000..f571a496c8 --- /dev/null +++ b/i18npool/inc/numtochar.hxx @@ -0,0 +1,53 @@ +/* -*- 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/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include "transliteration_Numeric.hxx" + +namespace i18npool { + +#define TRANSLITERATION_NUMTOCHAR( name ) \ +class NumToChar##name final : public transliteration_Numeric \ +{ \ +public: \ + NumToChar##name (); \ +}; + +TRANSLITERATION_NUMTOCHAR(Lower_zh_CN) +TRANSLITERATION_NUMTOCHAR(Upper_zh_CN) +TRANSLITERATION_NUMTOCHAR(Lower_zh_TW) +TRANSLITERATION_NUMTOCHAR(Upper_zh_TW) +TRANSLITERATION_NUMTOCHAR(Upper_ko) +TRANSLITERATION_NUMTOCHAR(Hangul_ko) +TRANSLITERATION_NUMTOCHAR(Lower_ko) +TRANSLITERATION_NUMTOCHAR(KanjiShort_ja_JP) +TRANSLITERATION_NUMTOCHAR(KanjiTraditional_ja_JP) +TRANSLITERATION_NUMTOCHAR(Fullwidth) +TRANSLITERATION_NUMTOCHAR(Indic_ar) +TRANSLITERATION_NUMTOCHAR(EastIndic_ar) +TRANSLITERATION_NUMTOCHAR(Indic_hi) +TRANSLITERATION_NUMTOCHAR(_th) +TRANSLITERATION_NUMTOCHAR(Halfwidth) + +#undef TRANSLITERATION_NUMTOCHAR + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/i18npool/inc/numtotext_cjk.hxx b/i18npool/inc/numtotext_cjk.hxx new file mode 100644 index 0000000000..68518e3cc5 --- /dev/null +++ b/i18npool/inc/numtotext_cjk.hxx @@ -0,0 +1,68 @@ +/* -*- 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/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include "transliteration_Numeric.hxx" + +namespace i18npool { + +#define TRANSLITERATION_NUMTOTEXT_CJK( name ) \ +class NumToText##name final : public transliteration_Numeric \ +{ \ +public: \ + NumToText##name (); \ +}; + +TRANSLITERATION_NUMTOTEXT_CJK ( Lower_zh_CN ) +TRANSLITERATION_NUMTOTEXT_CJK ( Upper_zh_CN ) +TRANSLITERATION_NUMTOTEXT_CJK ( Lower_zh_TW ) +TRANSLITERATION_NUMTOTEXT_CJK ( Upper_zh_TW ) +TRANSLITERATION_NUMTOTEXT_CJK ( Fullwidth_zh_CN ) +TRANSLITERATION_NUMTOTEXT_CJK ( Fullwidth_zh_TW ) +TRANSLITERATION_NUMTOTEXT_CJK ( Fullwidth_ja_JP ) +TRANSLITERATION_NUMTOTEXT_CJK ( Fullwidth_ko ) +TRANSLITERATION_NUMTOTEXT_CJK ( Date_zh ) +TRANSLITERATION_NUMTOTEXT_CJK ( InformalLower_ko ) +TRANSLITERATION_NUMTOTEXT_CJK ( InformalUpper_ko ) +TRANSLITERATION_NUMTOTEXT_CJK ( InformalHangul_ko ) +TRANSLITERATION_NUMTOTEXT_CJK ( FormalLower_ko ) +TRANSLITERATION_NUMTOTEXT_CJK ( FormalUpper_ko ) +TRANSLITERATION_NUMTOTEXT_CJK ( FormalHangul_ko ) +TRANSLITERATION_NUMTOTEXT_CJK ( KanjiLongModern_ja_JP ) +TRANSLITERATION_NUMTOTEXT_CJK ( KanjiLongTraditional_ja_JP ) +TRANSLITERATION_NUMTOTEXT_CJK ( KanjiShortModern_ja_JP ) +TRANSLITERATION_NUMTOTEXT_CJK ( KanjiShortTraditional_ja_JP ) +TRANSLITERATION_NUMTOTEXT_CJK ( AIUFullWidth_ja_JP ) +TRANSLITERATION_NUMTOTEXT_CJK ( AIUHalfWidth_ja_JP ) +TRANSLITERATION_NUMTOTEXT_CJK ( IROHAFullWidth_ja_JP ) +TRANSLITERATION_NUMTOTEXT_CJK ( IROHAHalfWidth_ja_JP ) +TRANSLITERATION_NUMTOTEXT_CJK ( CircledNumber ) +TRANSLITERATION_NUMTOTEXT_CJK ( TianGan_zh ) +TRANSLITERATION_NUMTOTEXT_CJK ( DiZi_zh ) +TRANSLITERATION_NUMTOTEXT_CJK ( HangulJamo_ko ) +TRANSLITERATION_NUMTOTEXT_CJK ( HangulSyllable_ko ) +TRANSLITERATION_NUMTOTEXT_CJK ( HangulCircledJamo_ko ) +TRANSLITERATION_NUMTOTEXT_CJK ( HangulCircledSyllable_ko ) + +#undef TRANSLITERATION_NUMTOTEXT + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/i18npool/inc/ordinalsuffix.hxx b/i18npool/inc/ordinalsuffix.hxx new file mode 100644 index 0000000000..39342359fc --- /dev/null +++ b/i18npool/inc/ordinalsuffix.hxx @@ -0,0 +1,52 @@ +/* -*- 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/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include <com/sun/star/i18n/XOrdinalSuffix.hpp> +#include <cppuhelper/implbase.hxx> +#include <com/sun/star/lang/XServiceInfo.hpp> + +namespace com::sun::star::lang { struct Locale; } + +namespace i18npool { + +class OrdinalSuffixService final : public cppu::WeakImplHelper +< + css::i18n::XOrdinalSuffix, + css::lang::XServiceInfo +> +{ + public: + OrdinalSuffixService(); + virtual ~OrdinalSuffixService() override; + + // XOrdinalSuffix + virtual css::uno::Sequence< OUString > SAL_CALL getOrdinalSuffix( sal_Int32 nNumber, const css::lang::Locale &rLocale ) override; + + // XServiceInfo + virtual OUString SAL_CALL getImplementationName() override; + virtual sal_Bool SAL_CALL supportsService(const OUString& ServiceName) override; + virtual css::uno::Sequence < OUString > SAL_CALL getSupportedServiceNames() override; + +}; + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/i18npool/inc/servicename.hxx b/i18npool/inc/servicename.hxx new file mode 100644 index 0000000000..37c79e548c --- /dev/null +++ b/i18npool/inc/servicename.hxx @@ -0,0 +1,64 @@ +/* -*- 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/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +/* +Service Name + com.sun.star.i18n.Transliteration ... dispatching UNO object and generic methods + com.sun.star.i18n.Transliteration.u2l ... upper to lower + com.sun.star.i18n.Transliteration.l2u ... lower to upper + com.sun.star.i18n.Transliteration.caseignore ... case ignore + com.sun.star.i18n.Transliteration.l10n ... other + + We have to adopt different service name for internal UNO objects. + Case related functionality vary depending on Locale. + + +Implementation Name + For generic service: com.sun.star.i18n.Transliteration, + com.sun.star.i18n.Transliteration + + com.sun.star.i18n.Transliteration.u2l + com.sun.star.i18n.Transliteration.l2u + com.sun.star.i18n.Transliteration.caseignore + For these there services above, + + com.sun.star.i18n.Transliteration.ja_JP + ^^^^^ + Locale name + + For com.sun.star.i18n.l10n.Transliteration service, + com.sun.star.i18n.Transliteration.HALFWIDTH_FULLWIDTH, + com.sun.star.i18n.Transliteration.FULLWIDTH_HALFWIDTH, + com.sun.star.i18n.Transliteration.IGNORE_WIDTH, + com.sun.star.i18n.Transliteration.KATAKANA_HIRAGANA, + com.sun.star.i18n.Transliteration.HIRAGANA_KATAKANA, + com.sun.star.i18n.Transliteration.IGNORE_KANA, + + ... These objects above can be used in every Locale context. + +*/ + +#pragma once + +#define TRLT_SERVICELNAME "com.sun.star.i18n.Transliteration" +#define TRLT_SERVICELNAME_L10N TRLT_SERVICELNAME ".l10n" + +#define TRLT_IMPLNAME_PREFIX "com.sun.star.i18n.Transliteration." +// 1...5...901...5...901...5...901..4 --> 34 + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/i18npool/inc/textToPronounce_zh.hxx b/i18npool/inc/textToPronounce_zh.hxx new file mode 100644 index 0000000000..b34398e608 --- /dev/null +++ b/i18npool/inc/textToPronounce_zh.hxx @@ -0,0 +1,73 @@ +/* -*- 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/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include "transliteration_Ignore.hxx" +#include <osl/module.hxx> + +namespace i18npool { + +class TextToPronounce_zh : public transliteration_Ignore +{ +protected: +#ifndef DISABLE_DYNLOADING + oslModule hModule; +#endif + sal_uInt16 const **idx; + const sal_Unicode* getPronounce(const sal_Unicode ch); + +public: +#ifndef DISABLE_DYNLOADING + TextToPronounce_zh(const char* func_name); +#else + TextToPronounce_zh(sal_uInt16 const ** (*function)(sal_Int16 &)); +#endif + virtual ~TextToPronounce_zh() override; + + OUString + foldingImpl(const OUString & inStr, sal_Int32 startPos, sal_Int32 nCount, css::uno::Sequence< sal_Int32 >* pOffset) override; + + sal_Int16 SAL_CALL getType() override; + + sal_Bool SAL_CALL + equals( const OUString & str1, sal_Int32 pos1, sal_Int32 nCount1, sal_Int32 & nMatch1, const OUString & str2, sal_Int32 pos2, sal_Int32 nCount2, sal_Int32 & nMatch2) override; + + OUString SAL_CALL + transliterateChar2String( sal_Unicode inChar) override; + + sal_Unicode SAL_CALL + transliterateChar2Char( sal_Unicode inChar) override; +}; + +#define TRANSLITERATION_TextToPronounce_zh( name ) \ +class name final : public TextToPronounce_zh \ +{ \ +public: \ + name (); \ +}; + +TRANSLITERATION_TextToPronounce_zh( TextToPinyin_zh_CN) +TRANSLITERATION_TextToPronounce_zh( TextToChuyin_zh_TW) + +#undef TRANSLITERATION_TextToPronounce_zh + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/i18npool/inc/textconversion.hxx b/i18npool/inc/textconversion.hxx new file mode 100644 index 0000000000..ebb973de0b --- /dev/null +++ b/i18npool/inc/textconversion.hxx @@ -0,0 +1,155 @@ +/* -*- 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/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#pragma once + +#include <com/sun/star/lang/XServiceInfo.hpp> +#include <com/sun/star/i18n/XExtendedTextConversion.hpp> +#include <cppuhelper/implbase.hxx> +#include <osl/module.h> + +namespace com::sun::star::linguistic2 { class XConversionDictionary; } +namespace com::sun::star::linguistic2 { class XConversionDictionaryList; } +namespace com::sun::star::uno { class XComponentContext; } + +namespace i18npool { + + + +class TextConversionService: public cppu::WeakImplHelper +< + css::i18n::XExtendedTextConversion, + css::lang::XServiceInfo +> +{ +public: + TextConversionService(const char* pImplName); + virtual ~TextConversionService() override; + // Methods + virtual css::i18n::TextConversionResult SAL_CALL + getConversions( const OUString& aText, sal_Int32 nStartPos, sal_Int32 nLength, + const css::lang::Locale& aLocale, sal_Int16 nTextConversionType, + sal_Int32 nTextConversionOptions ) override = 0; + virtual OUString SAL_CALL + getConversion( const OUString& aText, sal_Int32 nStartPos, sal_Int32 nLength, + const css::lang::Locale& aLocale, sal_Int16 nTextConversionType, + sal_Int32 nTextConversionOptions ) override = 0; + virtual OUString SAL_CALL + getConversionWithOffset( const OUString& aText, sal_Int32 nStartPos, sal_Int32 nLength, + const css::lang::Locale& aLocale, sal_Int16 nTextConversionType, + sal_Int32 nTextConversionOptions, css::uno::Sequence< sal_Int32 >& offset ) override = 0; + virtual sal_Bool SAL_CALL + interactiveConversion(const css::lang::Locale& aLocale, + sal_Int16 nTextConversionType, sal_Int32 nTextConversionOptions ) override = 0; + + //XServiceInfo + OUString SAL_CALL + getImplementationName() override; + sal_Bool SAL_CALL + supportsService(const OUString& ServiceName) override; + css::uno::Sequence< OUString > SAL_CALL + getSupportedServiceNames() override; +private: + const char* implementationName; +protected: +#ifndef DISABLE_DYNLOADING + oslModule hModule; + oslGenericFunction getFunctionBySymbol(const char* func); +#endif +}; + +// for Hangul2Hanja conversion +typedef struct { + sal_Unicode code; + sal_Int16 address; + sal_Int16 count; +} Hangul_Index; + + + +class TextConversion_ko final : public TextConversionService +{ +public: + TextConversion_ko( const css::uno::Reference < css::uno::XComponentContext >& rxContext ); + + // Methods + css::i18n::TextConversionResult SAL_CALL + getConversions( const OUString& aText, sal_Int32 nStartPos, sal_Int32 nLength, + const css::lang::Locale& aLocale, sal_Int16 nTextConversionType, + sal_Int32 nTextConversionOptions ) override; + OUString SAL_CALL + getConversion( const OUString& aText, sal_Int32 nStartPos, sal_Int32 nLength, + const css::lang::Locale& aLocale, sal_Int16 nTextConversionType, + sal_Int32 nTextConversionOptions ) override; + OUString SAL_CALL + getConversionWithOffset( const OUString& aText, sal_Int32 nStartPos, sal_Int32 nLength, + const css::lang::Locale& aLocale, sal_Int16 nTextConversionType, + sal_Int32 nTextConversionOptions, css::uno::Sequence< sal_Int32 >& offset ) override; + sal_Bool SAL_CALL + interactiveConversion(const css::lang::Locale& aLocale, + sal_Int16 nTextConversionType, + sal_Int32 nTextConversionOptions ) override; + +private: + // Hangul/Hanja system dictionary + css::uno::Reference < css::linguistic2::XConversionDictionary > xCD; + // Hangul/Hanja user defined dictionary list + css::uno::Reference < css::linguistic2::XConversionDictionaryList > xCDL; + sal_Int32 maxLeftLength; + sal_Int32 maxRightLength; + css::uno::Sequence< OUString > + getCharConversions(const OUString& aText, sal_Int32 nStartPos, sal_Int32 nLength, bool toHanja); +}; + + + + +class TextConversion_zh final : public TextConversionService +{ +public: + TextConversion_zh( const css::uno::Reference < css::uno::XComponentContext >& rxContext ); + + // Methods + css::i18n::TextConversionResult SAL_CALL + getConversions( const OUString& aText, sal_Int32 nStartPos, sal_Int32 nLength, + const css::lang::Locale& aLocale, sal_Int16 nTextConversionType, + sal_Int32 nTextConversionOptions ) override; + OUString SAL_CALL + getConversion( const OUString& aText, sal_Int32 nStartPos, sal_Int32 nLength, + const css::lang::Locale& aLocale, sal_Int16 nTextConversionType, + sal_Int32 nTextConversionOptions ) override; + OUString SAL_CALL + getConversionWithOffset( const OUString& aText, sal_Int32 nStartPos, sal_Int32 nLength, + const css::lang::Locale& aLocale, sal_Int16 nTextConversionType, + sal_Int32 nTextConversionOptions, css::uno::Sequence< sal_Int32 >& offset ) override; + sal_Bool SAL_CALL + interactiveConversion(const css::lang::Locale& aLocale, + sal_Int16 nTextConversionType, + sal_Int32 nTextConversionOptions ) override; +private: + // user defined dictionary list + css::uno::Reference < css::linguistic2::XConversionDictionaryList > xCDL; + OUString getWordConversion(const OUString& aText, + sal_Int32 nStartPos, sal_Int32 nLength, bool toSChinese, sal_Int32 nConversionOptions, css::uno::Sequence <sal_Int32>& offset); + rtl:: OUString getCharConversion(const rtl:: OUString& aText, sal_Int32 nStartPos, sal_Int32 nLength, bool toSChinese, sal_Int32 nConversionOptions); + css::lang::Locale aLocale; +}; + +} // i18npool + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/i18npool/inc/textconversionImpl.hxx b/i18npool/inc/textconversionImpl.hxx new file mode 100644 index 0000000000..f1502b619b --- /dev/null +++ b/i18npool/inc/textconversionImpl.hxx @@ -0,0 +1,76 @@ +/* -*- 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/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#pragma once + +#include <com/sun/star/lang/XServiceInfo.hpp> +#include <com/sun/star/i18n/XExtendedTextConversion.hpp> +#include <cppuhelper/implbase.hxx> +#include <utility> + +namespace com::sun::star::uno { class XComponentContext; } + +namespace i18npool { + + + +class TextConversionImpl final : public cppu::WeakImplHelper +< + css::i18n::XExtendedTextConversion, + css::lang::XServiceInfo +> +{ +public: + TextConversionImpl( css::uno::Reference < css::uno::XComponentContext > xContext ) : m_xContext(std::move(xContext)) {}; + + // Methods + css::i18n::TextConversionResult SAL_CALL + getConversions( const OUString& aText, sal_Int32 nStartPos, sal_Int32 nLength, + const css::lang::Locale& aLocale, sal_Int16 nTextConversionType, + sal_Int32 nTextConversionOptions ) override; + OUString SAL_CALL + getConversion( const OUString& aText, sal_Int32 nStartPos, sal_Int32 nLength, + const css::lang::Locale& aLocale, sal_Int16 nTextConversionType, + sal_Int32 nTextConversionOptions ) override; + OUString SAL_CALL + getConversionWithOffset( const OUString& aText, sal_Int32 nStartPos, sal_Int32 nLength, + const css::lang::Locale& aLocale, sal_Int16 nTextConversionType, + sal_Int32 nTextConversionOptions, css::uno::Sequence< sal_Int32 >& offset ) override; + sal_Bool SAL_CALL + interactiveConversion( const css::lang::Locale& aLocale, + sal_Int16 nTextConversionType, sal_Int32 nTextConversionOptions ) override; + + //XServiceInfo + OUString SAL_CALL + getImplementationName() override; + sal_Bool SAL_CALL + supportsService(const OUString& ServiceName) override; + css::uno::Sequence< OUString > SAL_CALL + getSupportedServiceNames() override; +private: + css::lang::Locale aLocale; + css::uno::Reference < css::i18n::XExtendedTextConversion > xTC; + css::uno::Reference < css::uno::XComponentContext > m_xContext; + + /// @throws css::lang::NoSupportException + void getLocaleSpecificTextConversion( const css::lang::Locale& rLocale ); +}; + +} // i18npool + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/i18npool/inc/texttonum.hxx b/i18npool/inc/texttonum.hxx new file mode 100644 index 0000000000..ad095fff9c --- /dev/null +++ b/i18npool/inc/texttonum.hxx @@ -0,0 +1,50 @@ +/* -*- 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/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include "transliteration_Numeric.hxx" + +namespace i18npool { + +#define TRANSLITERATION_TEXTTONUM( name ) \ +class TextToNum##name final : public transliteration_Numeric \ +{ \ +public: \ + TextToNum##name (); \ +}; + +TRANSLITERATION_TEXTTONUM(Lower_zh_CN) +TRANSLITERATION_TEXTTONUM(Upper_zh_CN) +TRANSLITERATION_TEXTTONUM(Lower_zh_TW) +TRANSLITERATION_TEXTTONUM(Upper_zh_TW) +TRANSLITERATION_TEXTTONUM(InformalLower_ko) +TRANSLITERATION_TEXTTONUM(InformalUpper_ko) +TRANSLITERATION_TEXTTONUM(InformalHangul_ko) +TRANSLITERATION_TEXTTONUM(FormalLower_ko) +TRANSLITERATION_TEXTTONUM(FormalUpper_ko) +TRANSLITERATION_TEXTTONUM(FormalHangul_ko) +TRANSLITERATION_TEXTTONUM(KanjiLongModern_ja_JP) +TRANSLITERATION_TEXTTONUM(KanjiLongTraditional_ja_JP) + +#undef TRANSLITERATION_TEXTTONUM + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/i18npool/inc/transliterationImpl.hxx b/i18npool/inc/transliterationImpl.hxx new file mode 100644 index 0000000000..5744106734 --- /dev/null +++ b/i18npool/inc/transliterationImpl.hxx @@ -0,0 +1,111 @@ +/* -*- 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/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#pragma once + +#include <com/sun/star/i18n/XExtendedTransliteration.hpp> +#include <cppuhelper/implbase.hxx> +#include <com/sun/star/lang/XServiceInfo.hpp> +#include <sal/types.h> + +namespace com::sun::star::i18n { class XLocaleData5; } +namespace com::sun::star::uno { class XComponentContext; } + +namespace i18npool { + +class TransliterationImpl final : public cppu::WeakImplHelper +< + css::i18n::XExtendedTransliteration, + css::lang::XServiceInfo +> +{ +public: + // Constructors + TransliterationImpl(const css::uno::Reference < css::uno::XComponentContext >& xContext); + // Destructor + virtual ~TransliterationImpl() override; + + // Methods + virtual OUString SAL_CALL getName( ) override ; + virtual sal_Int16 SAL_CALL getType( ) override ; + + virtual void SAL_CALL loadModule( css::i18n::TransliterationModules modName, const css::lang::Locale& rLocale ) override ; + virtual void SAL_CALL loadModuleNew( const css::uno::Sequence< css::i18n::TransliterationModulesNew >& modName, + const css::lang::Locale& rLocale ) override ; + virtual void SAL_CALL loadModuleByImplName( const OUString& implName, + const css::lang::Locale& rLocale ) override; + virtual void SAL_CALL loadModulesByImplNames(const css::uno::Sequence< OUString >& modNamelist, + const css::lang::Locale& rLocale) override; + + virtual css::uno::Sequence< OUString > SAL_CALL getAvailableModules( + const css::lang::Locale& rLocale, sal_Int16 sType ) override; + + virtual OUString SAL_CALL transliterate( const OUString& inStr, sal_Int32 startPos, sal_Int32 nCount, + css::uno::Sequence< sal_Int32 >& offset ) override ; + + virtual OUString SAL_CALL folding( const OUString& inStr, sal_Int32 startPos, sal_Int32 nCount, + css::uno::Sequence< sal_Int32 >& offset ) override; + + // Methods in XExtendedTransliteration + virtual OUString SAL_CALL transliterateString2String( const OUString& inStr, sal_Int32 startPos, sal_Int32 nCount ) override ; + virtual OUString SAL_CALL transliterateChar2String( sal_Unicode inChar ) override ; + virtual sal_Unicode SAL_CALL transliterateChar2Char( sal_Unicode inChar ) override ; + + virtual sal_Bool SAL_CALL equals( const OUString& str1, sal_Int32 pos1, sal_Int32 nCount1, + sal_Int32& nMatch1, const OUString& str2, sal_Int32 pos2, sal_Int32 nCount2, sal_Int32& nMatch2 ) override; + virtual css::uno::Sequence< OUString > SAL_CALL transliterateRange( const OUString& str1, + const OUString& str2 ) override ; + + virtual sal_Int32 SAL_CALL compareSubstring( const OUString& s1, sal_Int32 off1, sal_Int32 len1, + const OUString& s2, sal_Int32 off2, sal_Int32 len2) override; + + virtual sal_Int32 SAL_CALL compareString( const OUString& s1, const OUString& s2) override; + + //XServiceInfo + virtual OUString SAL_CALL getImplementationName() override; + virtual sal_Bool SAL_CALL supportsService(const OUString& ServiceName) override; + virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override; + +private: +#define maxCascade 27 + css::uno::Reference< css::i18n::XExtendedTransliteration > bodyCascade[maxCascade]; + sal_Int16 numCascade; + bool caseignoreOnly; + css::uno::Reference< css::uno::XComponentContext > mxContext; + css::uno::Reference< css::i18n::XLocaleData5 > mxLocaledata; + css::uno::Reference< css::i18n::XExtendedTransliteration > caseignore; + + /// @throws css::uno::RuntimeException + bool loadModuleByName( std::u16string_view implName, + css::uno::Reference<css::i18n::XExtendedTransliteration> & body, const css::lang::Locale& rLocale); + + void clear(); + + /// @throws css::uno::RuntimeException + void loadBody( OUString const &implName, + css::uno::Reference< css::i18n::XExtendedTransliteration >& body ); + + /// @throws css::uno::RuntimeException + css::uno::Sequence< OUString > getRange( + const css::uno::Sequence< OUString > &inStrs, + sal_Int32 length, const sal_Int16 _nCascade); +}; + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/i18npool/inc/transliteration_Ignore.hxx b/i18npool/inc/transliteration_Ignore.hxx new file mode 100644 index 0000000000..ba685c8e45 --- /dev/null +++ b/i18npool/inc/transliteration_Ignore.hxx @@ -0,0 +1,157 @@ +/* -*- 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/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#pragma once + +#include "transliteration_commonclass.hxx" +#include <unicode/translit.h> +#include <memory> + +namespace i18nutil { class oneToOneMapping; } + +typedef sal_Unicode (*TransFunc)(const sal_Unicode); + +namespace i18npool { + +class transliteration_Ignore : public transliteration_commonclass +{ +public: + virtual OUString + foldingImpl( const OUString& inStr, sal_Int32 startPos, sal_Int32 nCount, css::uno::Sequence< sal_Int32 >* pOffset ) override; + + // This method is shared. + sal_Bool SAL_CALL + equals( const OUString& str1, sal_Int32 pos1, sal_Int32 nCount1, sal_Int32& nMatch1, + const OUString& str2, sal_Int32 pos2, sal_Int32 nCount2, sal_Int32& nMatch2 ) override; + + // This method is implemented in sub class if needed. Otherwise, the method implemented in this class will be used. + css::uno::Sequence< OUString > SAL_CALL + transliterateRange( const OUString& str1, const OUString& str2 ) override; + + + // Methods which are shared. + sal_Int16 SAL_CALL getType( ) override; + + OUString + transliterateImpl( const OUString& inStr, sal_Int32 startPos, sal_Int32 nCount, css::uno::Sequence< sal_Int32 >* pOffset ) override; + + virtual sal_Unicode SAL_CALL + transliterateChar2Char( sal_Unicode inChar) override; + + /// @throws css::uno::RuntimeException + static css::uno::Sequence< OUString > + transliterateRange( const OUString& str1, const OUString& str2, XTransliteration& t1, XTransliteration& t2 ); + + struct Mapping { + sal_Unicode previousChar; + sal_Unicode currentChar; + sal_Unicode replaceChar; + bool two2one; + }; + +protected: + TransFunc func; + i18nutil::oneToOneMapping *table; + const Mapping *map; +}; + +#define TRANSLITERATION_IGNORE( name ) \ +class ignore##name final : public transliteration_Ignore {\ +public:\ + ignore##name ();\ +}; + +TRANSLITERATION_IGNORE(BaFa_ja_JP) +TRANSLITERATION_IGNORE(HyuByu_ja_JP) +TRANSLITERATION_IGNORE(SeZe_ja_JP) +TRANSLITERATION_IGNORE(TiJi_ja_JP) +TRANSLITERATION_IGNORE(MiddleDot_ja_JP) +TRANSLITERATION_IGNORE(MinusSign_ja_JP) +TRANSLITERATION_IGNORE(Separator_ja_JP) +TRANSLITERATION_IGNORE(Space_ja_JP) +TRANSLITERATION_IGNORE(TraditionalKana_ja_JP) +TRANSLITERATION_IGNORE(TraditionalKanji_ja_JP) +TRANSLITERATION_IGNORE(ZiZu_ja_JP) +TRANSLITERATION_IGNORE(Kashida_CTL) + +class ignoreDiacritics_CTL final : public transliteration_Ignore +{ + std::unique_ptr<icu::Transliterator> m_transliterator; + +public: + ignoreDiacritics_CTL(); + + OUString + foldingImpl(const OUString& rInStr, sal_Int32 nStartPos, sal_Int32 nCount, css::uno::Sequence<sal_Int32>* pOffset) override; + + sal_Unicode SAL_CALL + transliterateChar2Char(sal_Unicode nInChar) override; +}; + +#undef TRANSLITERATION_IGNORE + +#define TRANSLITERATION_IGNORE( name ) \ +class ignore##name final : public transliteration_Ignore {\ +public:\ + ignore##name () {\ + func = nullptr;\ + table = nullptr;\ + map = nullptr;\ + transliterationName = "ignore"#name;\ + implementationName = "com.sun.star.i18n.Transliteration.ignore"#name;\ + };\ + OUString foldingImpl( const OUString& inStr, sal_Int32 startPos, sal_Int32 nCount, \ + css::uno::Sequence< sal_Int32 >* pOffset) override; \ +}; + +TRANSLITERATION_IGNORE(KiKuFollowedBySa_ja_JP) +TRANSLITERATION_IGNORE(IandEfollowedByYa_ja_JP) +TRANSLITERATION_IGNORE(IterationMark_ja_JP) +TRANSLITERATION_IGNORE(ProlongedSoundMark_ja_JP) + +#undef TRANSLITERATION_IGNORE + +#define TRANSLITERATION_IGNORE( name, implname ) \ +class ignore##name final : public transliteration_Ignore {\ +public:\ + ignore##name () {\ + func = nullptr;\ + table = nullptr;\ + map = nullptr;\ + transliterationName = "ignore"#name;\ + implementationName = "com.sun.star.i18n.Transliteration." implname;\ + };\ + OUString foldingImpl( const OUString& inStr, sal_Int32 startPos, sal_Int32 nCount, \ + css::uno::Sequence< sal_Int32 >* pOffset) override; \ + using transliteration_Ignore::transliterateRange;\ + css::uno::Sequence< OUString > SAL_CALL transliterateRange( const OUString& str1, \ + const OUString& str2 ) override; \ + sal_Unicode SAL_CALL \ + transliterateChar2Char( sal_Unicode inChar) \ + override;\ +}; + +TRANSLITERATION_IGNORE(Kana, "IGNORE_KANA") +TRANSLITERATION_IGNORE(Width, "IGNORE_WIDTH") +TRANSLITERATION_IGNORE(Size_ja_JP, "ignoreSize_ja_JP") + +#undef TRANSLITERATION_IGNORE + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/i18npool/inc/transliteration_Numeric.hxx b/i18npool/inc/transliteration_Numeric.hxx new file mode 100644 index 0000000000..7c0d7ec95d --- /dev/null +++ b/i18npool/inc/transliteration_Numeric.hxx @@ -0,0 +1,58 @@ +/* -*- 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/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#pragma once + +#include "transliteration_commonclass.hxx" + +namespace i18npool { + +class transliteration_Numeric : public transliteration_commonclass { +public: + virtual OUString + transliterateImpl( const OUString& inStr, sal_Int32 startPos, sal_Int32 nCount, css::uno::Sequence< sal_Int32 >* pOffset ) override; + + virtual sal_Unicode SAL_CALL + transliterateChar2Char( sal_Unicode inChar) override; + + // Methods which are shared. + virtual sal_Int16 SAL_CALL getType( ) override; + + virtual OUString + foldingImpl( const OUString& inStr, sal_Int32 startPos, sal_Int32 nCount, css::uno::Sequence< sal_Int32 >* pOffset ) override; + + virtual sal_Bool SAL_CALL + equals( const OUString& str1, sal_Int32 pos1, sal_Int32 nCount1, sal_Int32& nMatch1, const OUString& str2, sal_Int32 pos2, sal_Int32 nCount2, sal_Int32& nMatch2 ) override; + + virtual css::uno::Sequence< OUString > SAL_CALL + transliterateRange( const OUString& str1, const OUString& str2 ) override; +protected: + sal_Int16 nNativeNumberMode; + sal_Int16 tableSize; + const sal_Unicode* table; + bool recycleSymbol; +private: + /// @throws css::uno::RuntimeException + OUString + transliterateBullet( std::u16string_view inStr, sal_Int32 startPos, sal_Int32 nCount, + css::uno::Sequence< sal_Int32 >* pOffset ) const; +}; + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/i18npool/inc/transliteration_OneToOne.hxx b/i18npool/inc/transliteration_OneToOne.hxx new file mode 100644 index 0000000000..c8e885f024 --- /dev/null +++ b/i18npool/inc/transliteration_OneToOne.hxx @@ -0,0 +1,113 @@ +/* -*- 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/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#pragma once + +#include "transliteration_commonclass.hxx" + +namespace i18nutil { class oneToOneMapping; } + +namespace i18npool { + +typedef sal_Unicode (*TransFunc)(const sal_Unicode); + +class transliteration_OneToOne : public transliteration_commonclass +{ +public: + OUString + transliterateImpl( const OUString& inStr, sal_Int32 startPos, sal_Int32 nCount, css::uno::Sequence< sal_Int32 >* pOffset ) override; + + sal_Unicode SAL_CALL + transliterateChar2Char( sal_Unicode inChar) override; + + // Methods which are shared. + sal_Int16 SAL_CALL getType() override; + + OUString + foldingImpl( const OUString& inStr, sal_Int32 startPos, sal_Int32 nCount, css::uno::Sequence< sal_Int32 >* pOffset ) override; + + sal_Bool SAL_CALL + equals( const OUString& str1, sal_Int32 pos1, sal_Int32 nCount1, sal_Int32& nMatch1, + const OUString& str2, sal_Int32 pos2, sal_Int32 nCount2, sal_Int32& nMatch2 ) override; + + css::uno::Sequence< OUString > SAL_CALL + transliterateRange( const OUString& str1, const OUString& str2 ) override; + +protected: + TransFunc func; + i18nutil::oneToOneMapping *table; +}; + +#define TRANSLITERATION_ONETOONE( name ) \ +class name final : public transliteration_OneToOne \ +{ \ +public: \ + name (); \ + OUString \ + transliterateImpl( const OUString& inStr, sal_Int32 startPos, sal_Int32 nCount, css::uno::Sequence< sal_Int32 >* pOffset ) \ + override; \ + sal_Unicode SAL_CALL \ + transliterateChar2Char( sal_Unicode inChar) \ + override; \ +}; + +TRANSLITERATION_ONETOONE( fullwidthToHalfwidth ) +TRANSLITERATION_ONETOONE( FULLWIDTHKATAKANA_HALFWIDTHKATAKANA ) +TRANSLITERATION_ONETOONE( FULLWIDTH_HALFWIDTH_LIKE_ASC ) + +class halfwidthToFullwidth final : public transliteration_OneToOne +{ +public: + halfwidthToFullwidth(); + OUString + transliterateImpl( const OUString& inStr, sal_Int32 startPos, sal_Int32 nCount, css::uno::Sequence< sal_Int32 >* pOffset ) override; +}; +class HALFWIDTHKATAKANA_FULLWIDTHKATAKANA final : public transliteration_OneToOne +{ +public: + HALFWIDTHKATAKANA_FULLWIDTHKATAKANA(); + OUString + transliterateImpl( const OUString& inStr, sal_Int32 startPos, sal_Int32 nCount, css::uno::Sequence< sal_Int32 >* pOffset ) override; +}; +class HALFWIDTH_FULLWIDTH_LIKE_JIS final : public transliteration_OneToOne +{ +public: + HALFWIDTH_FULLWIDTH_LIKE_JIS(); + OUString + transliterateImpl( const OUString& inStr, sal_Int32 startPos, sal_Int32 nCount, css::uno::Sequence< sal_Int32 >* pOffset ) override; +}; + +#undef TRANSLITERATION_ONETOONE + +#define TRANSLITERATION_ONETOONE( name ) \ +class name final : public transliteration_OneToOne \ +{ \ +public: \ + name (); \ +}; + +TRANSLITERATION_ONETOONE(hiraganaToKatakana) +TRANSLITERATION_ONETOONE(katakanaToHiragana) +TRANSLITERATION_ONETOONE(largeToSmall_ja_JP) +TRANSLITERATION_ONETOONE(smallToLarge_ja_JP) + +#undef TRANSLITERATION_ONETOONE + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/i18npool/inc/transliteration_body.hxx b/i18npool/inc/transliteration_body.hxx new file mode 100644 index 0000000000..6c3418fd79 --- /dev/null +++ b/i18npool/inc/transliteration_body.hxx @@ -0,0 +1,111 @@ +/* -*- 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/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#pragma once + +#include "transliteration_commonclass.hxx" +#include <i18nutil/casefolding.hxx> + +namespace i18npool { + +class Transliteration_body : public transliteration_commonclass +{ +public: + Transliteration_body(); + + // Methods which are shared. + sal_Int16 SAL_CALL getType() override; + + OUString transliterateImpl(const OUString& inStr, sal_Int32 startPos, sal_Int32 nCount, + css::uno::Sequence< sal_Int32 >* pOffset) override; + + OUString SAL_CALL + transliterateChar2String( sal_Unicode inChar) override; + + virtual sal_Unicode SAL_CALL + transliterateChar2Char( sal_Unicode inChar) override; + + OUString foldingImpl(const OUString& inStr, sal_Int32 startPos, sal_Int32 nCount, + css::uno::Sequence< sal_Int32 >* pOffset) override; + + sal_Bool SAL_CALL equals( + const OUString& str1, sal_Int32 pos1, sal_Int32 nCount1, sal_Int32& nMatch1, + const OUString& str2, sal_Int32 pos2, sal_Int32 nCount2, sal_Int32& nMatch2 ) override; + + css::uno::Sequence< OUString > SAL_CALL transliterateRange( const OUString& str1, + const OUString& str2 ) override; + +protected: + MappingType nMappingType; +}; + +class Transliteration_u2l final : public Transliteration_body +{ +public: + Transliteration_u2l(); +}; + +class Transliteration_l2u final : public Transliteration_body +{ +public: + Transliteration_l2u(); +}; + +class Transliteration_casemapping final : public Transliteration_body +{ +public: + Transliteration_casemapping(); + void setMappingType( const MappingType rMappingType ) + { + if (nMappingType != rMappingType) + nMappingType = rMappingType; + } + void setLocale( const css::lang::Locale& rLocale ) + { + if (aLocale != rLocale) + aLocale = rLocale; + } +}; + +class Transliteration_togglecase final : public Transliteration_body +{ +public: + Transliteration_togglecase(); +}; + +class Transliteration_titlecase final : public Transliteration_body +{ +public: + Transliteration_titlecase(); + + virtual OUString transliterateImpl( const OUString& inStr, sal_Int32 startPos, sal_Int32 nCount, + css::uno::Sequence< sal_Int32 >* pOffset ) override; +}; + +class Transliteration_sentencecase final : public Transliteration_body +{ +public: + Transliteration_sentencecase(); + + virtual OUString transliterateImpl( const OUString& inStr, sal_Int32 startPos, sal_Int32 nCount, + css::uno::Sequence< sal_Int32 >* pOffset ) override; +}; + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/i18npool/inc/transliteration_caseignore.hxx b/i18npool/inc/transliteration_caseignore.hxx new file mode 100644 index 0000000000..919cec3796 --- /dev/null +++ b/i18npool/inc/transliteration_caseignore.hxx @@ -0,0 +1,61 @@ +/* -*- 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/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#pragma once + +#include "transliteration_body.hxx" + +namespace i18npool { + +class Transliteration_caseignore final : public Transliteration_body +{ +public: + Transliteration_caseignore(); + + // Methods which are shared. + sal_Int16 SAL_CALL getType() override; + + void SAL_CALL loadModule( css::i18n::TransliterationModules modName, const css::lang::Locale& rLocale ) override; + + css::uno::Sequence< OUString > SAL_CALL transliterateRange( + const OUString& str1, const OUString& str2 ) override; + + sal_Bool SAL_CALL equals( + const OUString& str1, sal_Int32 pos1, sal_Int32 nCount1, sal_Int32& nMatch1, + const OUString& src2, sal_Int32 pos2, sal_Int32 nCount2, sal_Int32& nMatch2) override; + + sal_Int32 SAL_CALL compareSubstring( + const OUString& s1, sal_Int32 off1, sal_Int32 len1, + const OUString& s2, sal_Int32 off2, sal_Int32 len2) override; + + sal_Int32 SAL_CALL compareString( + const OUString& s1, + const OUString& s2) override; + +private: + /// @throws css::uno::RuntimeException + sal_Int32 compare( + const OUString& str1, sal_Int32 pos1, sal_Int32 nCount1, sal_Int32& nMatch1, + const OUString& str2, sal_Int32 pos2, sal_Int32 nCount2, sal_Int32& nMatch2); + + TransliterationFlags moduleLoaded; +}; + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/i18npool/inc/transliteration_commonclass.hxx b/i18npool/inc/transliteration_commonclass.hxx new file mode 100644 index 0000000000..4dc1b31fcc --- /dev/null +++ b/i18npool/inc/transliteration_commonclass.hxx @@ -0,0 +1,103 @@ +/* -*- 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/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#pragma once + +#include <com/sun/star/i18n/XExtendedTransliteration.hpp> +#include <com/sun/star/lang/XServiceInfo.hpp> +#include <cppuhelper/implbase.hxx> +#include <rtl/ustring.hxx> + +namespace i18npool { + +class transliteration_commonclass : public cppu::WeakImplHelper< + css::i18n::XExtendedTransliteration, + css::lang::XServiceInfo + > +{ +public: + transliteration_commonclass(); + + // Methods which are shared. + void SAL_CALL + loadModule( css::i18n::TransliterationModules modName, const css::lang::Locale& rLocale ) override; + + void SAL_CALL + loadModuleNew( const css::uno::Sequence< css::i18n::TransliterationModulesNew >& modName, const css::lang::Locale& rLocale ) override; + + void SAL_CALL + loadModuleByImplName( const OUString& implName, const css::lang::Locale& rLocale ) override; + + void SAL_CALL + loadModulesByImplNames(const css::uno::Sequence< OUString >& modNamelist, const css::lang::Locale& rLocale) override; + + css::uno::Sequence< OUString > SAL_CALL + getAvailableModules( const css::lang::Locale& rLocale, sal_Int16 sType ) override; + + // Methods which should be implemented in each transliteration module. + virtual OUString SAL_CALL getName() override; + + virtual sal_Int16 SAL_CALL getType( ) override = 0; + + virtual OUString SAL_CALL + transliterate( const OUString& inStr, sal_Int32 startPos, sal_Int32 nCount, css::uno::Sequence< sal_Int32 >& offset ) override final + { return transliterateImpl( inStr, startPos, nCount, &offset ); } + + virtual OUString SAL_CALL + folding( const OUString& inStr, sal_Int32 startPos, sal_Int32 nCount, css::uno::Sequence< sal_Int32 >& offset) override final + { return foldingImpl( inStr, startPos, nCount, &offset ); } + + // Methods in XExtendedTransliteration + virtual OUString SAL_CALL + transliterateString2String( const OUString& inStr, sal_Int32 startPos, sal_Int32 nCount ) override; + virtual OUString SAL_CALL + transliterateChar2String( sal_Unicode inChar) override; + virtual sal_Unicode SAL_CALL + transliterateChar2Char( sal_Unicode inChar ) override = 0; + + virtual sal_Bool SAL_CALL + equals( const OUString& str1, sal_Int32 pos1, sal_Int32 nCount1, sal_Int32& nMatch1, const OUString& str2, sal_Int32 pos2, sal_Int32 nCount2, sal_Int32& nMatch2 ) override = 0; + + virtual css::uno::Sequence< OUString > SAL_CALL + transliterateRange( const OUString& str1, const OUString& str2 ) override = 0; + + virtual sal_Int32 SAL_CALL + compareSubstring( const OUString& s1, sal_Int32 off1, sal_Int32 len1, const OUString& s2, sal_Int32 off2, sal_Int32 len2) override; + + virtual sal_Int32 SAL_CALL + compareString( const OUString& s1, const OUString& s2) override; + + //XServiceInfo + virtual OUString SAL_CALL getImplementationName() override; + virtual sal_Bool SAL_CALL supportsService(const OUString& ServiceName) override; + virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override; +protected: + virtual OUString + transliterateImpl( const OUString& inStr, sal_Int32 startPos, sal_Int32 nCount, css::uno::Sequence< sal_Int32 >* pOffset ) = 0; + + virtual OUString + foldingImpl( const OUString& inStr, sal_Int32 startPos, sal_Int32 nCount, css::uno::Sequence< sal_Int32 >* pOffset ) = 0; + + css::lang::Locale aLocale; + const char* transliterationName; + const char* implementationName; +}; + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/i18npool/inc/unoscripttypedetector.hxx b/i18npool/inc/unoscripttypedetector.hxx new file mode 100644 index 0000000000..255828b517 --- /dev/null +++ b/i18npool/inc/unoscripttypedetector.hxx @@ -0,0 +1,50 @@ +/* -*- 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/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#pragma once + +#include <com/sun/star/lang/XServiceInfo.hpp> + +#include <com/sun/star/i18n/XScriptTypeDetector.hpp> +#include <cppuhelper/implbase.hxx> + + + +class UnoScriptTypeDetector final : public cppu::WeakImplHelper +< + css::i18n::XScriptTypeDetector, + css::lang::XServiceInfo +> +{ +public: + // Methods + virtual sal_Int32 SAL_CALL beginOfScriptDirection( const OUString& Text, sal_Int32 nPos, sal_Int16 scriptDirection ) override; + virtual sal_Int32 SAL_CALL endOfScriptDirection( const OUString& Text, sal_Int32 nPos, sal_Int16 scriptDirection ) override; + virtual sal_Int16 SAL_CALL getScriptDirection( const OUString& Text, sal_Int32 nPos, sal_Int16 defaultScriptDirection ) override; + virtual sal_Int32 SAL_CALL beginOfCTLScriptType( const OUString& Text, sal_Int32 nPos ) override; + virtual sal_Int32 SAL_CALL endOfCTLScriptType( const OUString& Text, sal_Int32 nPos ) override; + virtual sal_Int16 SAL_CALL getCTLScriptType( const OUString& Text, sal_Int32 nPos ) override; + + + //XServiceInfo + virtual OUString SAL_CALL getImplementationName() override; + virtual sal_Bool SAL_CALL supportsService(const OUString& ServiceName) override; + virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override; +}; + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/i18npool/inc/wtt.h b/i18npool/inc/wtt.h new file mode 100644 index 0000000000..c81afe0e1f --- /dev/null +++ b/i18npool/inc/wtt.h @@ -0,0 +1,67 @@ +/* -*- 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/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#pragma once + +#include <sal/types.h> + +namespace i18npool { + +/* + * Thai character type definition. + */ + +#define CT_CTRL 0 // Control character +#define CT_NON 1 // Non-composible +#define CT_CONS 2 // Consonant +#define CT_LV 3 // Leading vowel +#define CT_FV1 4 // Following vowel +#define CT_FV2 5 // Following vowel +#define CT_FV3 6 +#define CT_BV1 7 // Below vowel +#define CT_BV2 8 +#define CT_BD 9 // Below diacritic +#define CT_TONE 10 // Tone +#define CT_AD1 11 // Above diacritic +#define CT_AD2 12 +#define CT_AD3 13 +#define CT_AV1 14 // Above vowel +#define CT_AV2 15 +#define CT_AV3 16 + +#define MAX_CT 17 + +const sal_uInt16 thaiCT[128] = { // Thai character type + CT_NON, CT_CONS, CT_CONS, CT_CONS, CT_CONS,CT_CONS, CT_CONS, CT_CONS, //0E00 + CT_CONS, CT_CONS, CT_CONS, CT_CONS, CT_CONS, CT_CONS, CT_CONS, CT_CONS, + CT_CONS, CT_CONS, CT_CONS, CT_CONS, CT_CONS, CT_CONS, CT_CONS, CT_CONS, //0E10 + CT_CONS, CT_CONS, CT_CONS, CT_CONS, CT_CONS, CT_CONS, CT_CONS, CT_CONS, + CT_CONS, CT_CONS, CT_CONS, CT_CONS, CT_FV3, CT_CONS, CT_FV3, CT_CONS, //0E20 + CT_CONS, CT_CONS, CT_CONS, CT_CONS, CT_CONS, CT_CONS, CT_CONS, CT_NON, + CT_FV1, CT_AV2, CT_FV1, CT_FV1, CT_AV1, CT_AV3, CT_AV2, CT_AV3, //0E30 + CT_BV1, CT_BV2, CT_BD, CT_NON, CT_NON, CT_NON, CT_NON, CT_NON, + CT_LV, CT_LV, CT_LV, CT_LV, CT_LV, CT_FV2, CT_NON, CT_AD2, //0E40 + CT_TONE, CT_TONE, CT_TONE, CT_TONE, CT_AD1, CT_AD1, CT_AD3, CT_NON, + CT_NON, CT_NON, CT_NON, CT_NON, CT_NON, CT_NON, CT_NON, CT_NON, //0E50 + CT_NON, CT_NON, CT_NON, CT_NON, CT_NON, CT_NON, CT_NON, CT_CTRL }; + +#define getCharType(x) ((x >= 0x0E00 && x < 0x0E60) ? thaiCT[x - 0x0E00] : CT_NON) + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/i18npool/inc/xdictionary.hxx b/i18npool/inc/xdictionary.hxx new file mode 100644 index 0000000000..f0861408bb --- /dev/null +++ b/i18npool/inc/xdictionary.hxx @@ -0,0 +1,94 @@ +/* -*- 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/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#pragma once + +#include <osl/file.h> +#include <sal/types.h> + +#include <com/sun/star/i18n/Boundary.hpp> + +namespace i18npool { + +#define CACHE_MAX 32 // max cache structure number +#define DEFAULT_SIZE 256 // for boundary size, to avoid alloc and release memory + +// cache structure. +struct WordBreakCache { + sal_Unicode *contents; // separated segment contents. + sal_Int32* wordboundary; // word boundaries in segments. + sal_Int32 length; // contents length saved here. + sal_Int32 size; // size of wordboundary + + WordBreakCache(); + bool equals(const sal_Unicode *str, css::i18n::Boundary const & boundary) const; // checking cached string +}; + +struct xdictionarydata +{ + const sal_uInt8 * existMark; + const sal_Int16 * index1; + const sal_Int32 * index2; + const sal_Int32 * lenArray; + const sal_Unicode* dataArea; + xdictionarydata() : + existMark( nullptr ), + index1( nullptr ), + index2( nullptr ), + lenArray( nullptr ), + dataArea( nullptr ) + { + } +}; + +class xdictionary +{ +private: + xdictionarydata data; + void initDictionaryData(const char *lang); + + css::i18n::Boundary boundary; + bool japaneseWordBreak; +#ifdef DICT_JA_ZH_IN_DATAFILE + oslFileHandle m_aFileHandle; + sal_uInt64 m_nFileSize; + char* m_pMapping; +#endif + +public: + xdictionary(const char *lang); + ~xdictionary(); + css::i18n::Boundary nextWord( const OUString& rText, sal_Int32 nPos, sal_Int16 wordType); + css::i18n::Boundary previousWord( const OUString& rText, sal_Int32 nPos, sal_Int16 wordType); + css::i18n::Boundary const & getWordBoundary( const OUString& rText, sal_Int32 nPos, sal_Int16 wordType, bool bDirection ); + void setJapaneseWordBreak(); + +private: + WordBreakCache cache[CACHE_MAX]; + OUString segmentCachedString; + css::i18n::Boundary segmentCachedBoundary; + + bool seekSegment(const OUString& rText, sal_Int32 pos, css::i18n::Boundary& boundary); + WordBreakCache& getCache(const sal_Unicode *text, css::i18n::Boundary const & boundary); + bool exists(const sal_uInt32 u) const; + sal_Int32 getLongestMatch(const sal_Unicode *text, sal_Int32 len) const; +}; + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |