merge textconv_dict into i18npool

(*) it is a small library
(*) this avoids more dynamic symbol lookup
(*) this unblocks more --enable-mergedlibs optimisation

Change-Id: Icb708828e9d711981ec4273351cd73343aa206d7
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/163596
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
This commit is contained in:
Noel Grandin 2024-02-19 15:48:38 +02:00 committed by Noel Grandin
parent 9bd2012df7
commit 191e3f8d89
13 changed files with 42 additions and 156 deletions

View file

@ -705,7 +705,6 @@ $(eval $(call gb_Helper_register_plugins_for_install,PLAINLIBS_OOO,ooo, \
localedata_es \
localedata_euro \
localedata_others \
textconv_dict \
))
ifeq ($(OS),WNT)

View file

@ -20,9 +20,7 @@ $(call gb_CustomTarget_get_workdir,i18npool/textconversion)/%.cxx : \
$(call gb_Output_announce,$(subst $(WORKDIR)/,,$@),$(true),CDC,1)
$(call gb_Trace_StartRange,$(subst $(WORKDIR)/,,$@),CDC)
$(call gb_Helper_abbreviate_dirs, \
$(call gb_Helper_execute,genconv_dict) $* $< $@.tmp && \
sed 's/\(^.*get\)/SAL_DLLPUBLIC_EXPORT \1/' $@.tmp > $@ && \
rm $@.tmp)
$(call gb_Helper_execute,genconv_dict) $* $< $@ )
$(call gb_Trace_EndRange,$(subst $(WORKDIR)/,,$@),CDC)
# vim: set noet sw=4 ts=4:

View file

@ -165,5 +165,10 @@ $(eval $(call gb_Library_add_generated_exception_objects,i18npool,\
CustomTarget/i18npool/indexentry/$(notdir $(basename $(txt)))) \
))
# textconv_dict
$(eval $(call gb_Library_add_generated_exception_objects,i18npool,\
$(foreach txt,$(wildcard $(SRCDIR)/i18npool/source/textconversion/data/*.dic),\
CustomTarget/i18npool/textconversion/$(notdir $(basename $(txt)))) \
))
# vim: set noet sw=4 ts=4:

View file

@ -1,32 +0,0 @@
# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
#
# 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/.
#
$(eval $(call gb_Library_Library,textconv_dict))
$(eval $(call gb_Library_set_plugin_for_nodep,textconv_dict,i18npool))
$(eval $(call gb_Library_set_include,textconv_dict,\
$$(INCLUDE) \
-I$(SRCDIR)/i18npool/inc \
))
$(eval $(call gb_Library_use_sdk_api,textconv_dict))
$(eval $(call gb_Library_use_libraries,textconv_dict,\
sal \
cppu \
cppuhelper \
))
$(eval $(call gb_Library_add_generated_exception_objects,textconv_dict,\
$(foreach txt,$(wildcard $(SRCDIR)/i18npool/source/textconversion/data/*.dic),\
CustomTarget/i18npool/textconversion/$(notdir $(basename $(txt)))) \
))
# vim: set noet sw=4 ts=4:

View file

@ -24,7 +24,6 @@ $(eval $(call gb_Module_add_targets,i18npool,\
Library_localedata_es \
Library_localedata_euro \
Library_localedata_others \
Library_textconv_dict \
))
$(eval $(call gb_Module_add_targets_for_build,i18npool,\

View file

@ -21,7 +21,6 @@
#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; }
@ -66,11 +65,6 @@ public:
getSupportedServiceNames() override;
private:
const char* implementationName;
protected:
#ifndef DISABLE_DYNLOADING
oslModule hModule;
oslGenericFunction getFunctionBySymbol(const char* func);
#endif
};
// for Hangul2Hanja conversion
@ -112,8 +106,8 @@ private:
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);
static css::uno::Sequence< OUString >
getCharConversions(std::u16string_view aText, sal_Int32 nStartPos, sal_Int32 nLength, bool toHanja);
};
@ -144,12 +138,36 @@ public:
private:
// user defined dictionary list
css::uno::Reference < css::linguistic2::XConversionDictionaryList > xCDL;
OUString getWordConversion(const OUString& aText,
OUString getWordConversion(std::u16string_view 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);
static OUString getCharConversion(std::u16string_view aText, sal_Int32 nStartPos, sal_Int32 nLength, bool toSChinese, sal_Int32 nConversionOptions);
css::lang::Locale aLocale;
};
} // i18npool
extern "C" {
const sal_Unicode* getHangul2HanjaData();
const i18npool::Hangul_Index* getHangul2HanjaIndex();
sal_Int16 getHangul2HanjaIndexCount();
const sal_uInt16* getHanja2HangulIndex();
const sal_Unicode* getHanja2HangulData();
const sal_Unicode* getSTC_CharData_T2S();
const sal_uInt16* getSTC_CharIndex_T2S();
const sal_Unicode* getSTC_CharData_S2V();
const sal_uInt16* getSTC_CharIndex_S2V();
const sal_Unicode* getSTC_CharData_S2T();
const sal_uInt16* getSTC_CharIndex_S2T();
const sal_Unicode *getSTC_WordData(sal_Int32&);
const sal_uInt16 *getSTC_WordIndex_T2S(sal_Int32&);
const sal_uInt16 *getSTC_WordEntry_T2S();
const sal_uInt16 *getSTC_WordIndex_S2T(sal_Int32&);
const sal_uInt16 *getSTC_WordEntry_S2T();
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */

View file

@ -24,47 +24,15 @@ using namespace com::sun::star::uno;
namespace i18npool {
#ifndef DISABLE_DYNLOADING
extern "C" { static void thisModule() {} }
#endif
TextConversionService::TextConversionService(const char *pImplName)
: implementationName(pImplName)
{
#ifndef DISABLE_DYNLOADING
constexpr OUString lib( u"" SAL_MODULENAME( "textconv_dict" ) ""_ustr );
hModule = osl_loadModuleRelative(
&thisModule, lib.pData, SAL_LOADMODULE_DEFAULT );
#endif
}
TextConversionService::~TextConversionService()
{
#ifndef DISABLE_DYNLOADING
if (hModule) osl_unloadModule(hModule);
#endif
}
#ifndef DISABLE_DYNLOADING
static void* nullFunc()
{
return nullptr;
}
oslGenericFunction
TextConversionService::getFunctionBySymbol(const char* func)
{
if (hModule)
return osl_getFunctionSymbol(hModule, OUString::createFromAscii(func).pData);
else
return reinterpret_cast< oslGenericFunction >(nullFunc);
}
#endif
OUString SAL_CALL
TextConversionService::getImplementationName()
{

View file

@ -105,33 +105,14 @@ static sal_Int16 checkScriptType(sal_Unicode c)
}
#ifdef DISABLE_DYNLOADING
extern "C" {
const sal_Unicode* getHangul2HanjaData();
const Hangul_Index* getHangul2HanjaIndex();
sal_Int16 getHangul2HanjaIndexCount();
const sal_uInt16* getHanja2HangulIndex();
const sal_Unicode* getHanja2HangulData();
}
#endif
Sequence< OUString >
TextConversion_ko::getCharConversions(const OUString& aText, sal_Int32 nStartPos, sal_Int32 nLength, bool toHanja)
TextConversion_ko::getCharConversions(std::u16string_view aText, sal_Int32 nStartPos, sal_Int32 nLength, bool toHanja)
{
sal_Unicode ch;
Sequence< OUString > output;
#ifndef DISABLE_DYNLOADING
const sal_Unicode* (*getHangul2HanjaData)() = reinterpret_cast<const sal_Unicode* (*)()>(getFunctionBySymbol("getHangul2HanjaData"));
const Hangul_Index* (*getHangul2HanjaIndex)() = reinterpret_cast<const Hangul_Index* (*)()>(getFunctionBySymbol("getHangul2HanjaIndex"));
sal_Int16 (*getHangul2HanjaIndexCount)() = reinterpret_cast<sal_Int16 (*)()>(getFunctionBySymbol("getHangul2HanjaIndexCount"));
const sal_uInt16* (*getHanja2HangulIndex)() = reinterpret_cast<const sal_uInt16* (*)()>(getFunctionBySymbol("getHanja2HangulIndex"));
const sal_Unicode* (*getHanja2HangulData)() = reinterpret_cast<const sal_Unicode* (*)()>(getFunctionBySymbol("getHanja2HangulData"));
if (toHanja && getHangul2HanjaIndex && getHangul2HanjaIndexCount && getHangul2HanjaData)
#else
if (toHanja)
#endif
{
ch = aText[nStartPos];
const Hangul_Index *Hangul_ko = getHangul2HanjaIndex();
@ -157,11 +138,7 @@ TextConversion_ko::getCharConversions(const OUString& aText, sal_Int32 nStartPos
}
}
}
#ifndef DISABLE_DYNLOADING
else if (!toHanja && getHanja2HangulIndex && getHanja2HangulData)
#else
else if (!toHanja)
#endif
{
std::unique_ptr<sal_Unicode[]> newStr(new sal_Unicode[nLength+1]);
sal_Int32 count = 0;

View file

@ -57,42 +57,17 @@ static sal_Unicode getOneCharConversion(sal_Unicode ch, const sal_Unicode* Data,
extern "C" {
const sal_Unicode* getSTC_CharData_T2S();
const sal_uInt16* getSTC_CharIndex_T2S();
const sal_Unicode* getSTC_CharData_S2V();
const sal_uInt16* getSTC_CharIndex_S2V();
const sal_Unicode* getSTC_CharData_S2T();
const sal_uInt16* getSTC_CharIndex_S2T();
const sal_Unicode *getSTC_WordData(sal_Int32&);
const sal_uInt16 *getSTC_WordIndex_T2S(sal_Int32&);
const sal_uInt16 *getSTC_WordEntry_T2S();
const sal_uInt16 *getSTC_WordIndex_S2T(sal_Int32&);
const sal_uInt16 *getSTC_WordEntry_S2T();
}
#endif
OUString
TextConversion_zh::getCharConversion(const OUString& aText, sal_Int32 nStartPos, sal_Int32 nLength, bool toSChinese, sal_Int32 nConversionOptions)
TextConversion_zh::getCharConversion(std::u16string_view aText, sal_Int32 nStartPos, sal_Int32 nLength, bool toSChinese, sal_Int32 nConversionOptions)
{
const sal_Unicode *Data;
const sal_uInt16 *Index;
#ifndef DISABLE_DYNLOADING
if (toSChinese) {
Data = reinterpret_cast<const sal_Unicode* (*)()>(getFunctionBySymbol("getSTC_CharData_T2S"))();
Index = reinterpret_cast<const sal_uInt16* (*)()>(getFunctionBySymbol("getSTC_CharIndex_T2S"))();
} else if (nConversionOptions & TextConversionOption::USE_CHARACTER_VARIANTS) {
Data = reinterpret_cast<const sal_Unicode* (*)()>(getFunctionBySymbol("getSTC_CharData_S2V"))();
Index = reinterpret_cast<const sal_uInt16* (*)()>(getFunctionBySymbol("getSTC_CharIndex_S2V"))();
} else {
Data = reinterpret_cast<const sal_Unicode* (*)()>(getFunctionBySymbol("getSTC_CharData_S2T"))();
Index = reinterpret_cast<const sal_uInt16* (*)()>(getFunctionBySymbol("getSTC_CharIndex_S2T"))();
}
#else
if (toSChinese) {
Data = getSTC_CharData_T2S();
Index = getSTC_CharIndex_T2S();
@ -103,7 +78,6 @@ TextConversion_zh::getCharConversion(const OUString& aText, sal_Int32 nStartPos,
Data = getSTC_CharData_S2T();
Index = getSTC_CharIndex_S2T();
}
#endif
rtl_uString * newStr = rtl_uString_alloc(nLength);
for (sal_Int32 i = 0; i < nLength; i++)
@ -113,7 +87,7 @@ TextConversion_zh::getCharConversion(const OUString& aText, sal_Int32 nStartPos,
}
OUString
TextConversion_zh::getWordConversion(const OUString& aText, sal_Int32 nStartPos, sal_Int32 nLength, bool toSChinese, sal_Int32 nConversionOptions, Sequence<sal_Int32>& offset)
TextConversion_zh::getWordConversion(std::u16string_view aText, sal_Int32 nStartPos, sal_Int32 nLength, bool toSChinese, sal_Int32 nConversionOptions, Sequence<sal_Int32>& offset)
{
sal_Int32 dictLen = 0;
sal_Int32 maxLen = 0;
@ -123,25 +97,6 @@ TextConversion_zh::getWordConversion(const OUString& aText, sal_Int32 nStartPos,
const sal_uInt16 *charIndex;
bool one2one=true;
#ifndef DISABLE_DYNLOADING
const sal_Unicode *wordData = reinterpret_cast<const sal_Unicode* (*)(sal_Int32&)>(getFunctionBySymbol("getSTC_WordData"))(dictLen);
if (toSChinese) {
index = reinterpret_cast<const sal_uInt16* (*)(sal_Int32&)>(getFunctionBySymbol("getSTC_WordIndex_T2S"))(maxLen);
entry = reinterpret_cast<const sal_uInt16* (*)()>(getFunctionBySymbol("getSTC_WordEntry_T2S"))();
charData = reinterpret_cast<const sal_Unicode* (*)()>(getFunctionBySymbol("getSTC_CharData_T2S"))();
charIndex = reinterpret_cast<const sal_uInt16* (*)()>(getFunctionBySymbol("getSTC_CharIndex_T2S"))();
} else {
index = reinterpret_cast<const sal_uInt16* (*)(sal_Int32&)>(getFunctionBySymbol("getSTC_WordIndex_S2T"))(maxLen);
entry = reinterpret_cast<const sal_uInt16* (*)()>(getFunctionBySymbol("getSTC_WordEntry_S2T"))();
if (nConversionOptions & TextConversionOption::USE_CHARACTER_VARIANTS) {
charData = reinterpret_cast<const sal_Unicode* (*)()>(getFunctionBySymbol("getSTC_CharData_S2V"))();
charIndex = reinterpret_cast<const sal_uInt16* (*)()>(getFunctionBySymbol("getSTC_CharIndex_S2V"))();
} else {
charData = reinterpret_cast<const sal_Unicode* (*)()>(getFunctionBySymbol("getSTC_CharData_S2T"))();
charIndex = reinterpret_cast<const sal_uInt16* (*)()>(getFunctionBySymbol("getSTC_CharIndex_S2T"))();
}
}
#else
const sal_Unicode *wordData = getSTC_WordData(dictLen);
if (toSChinese) {
index = getSTC_WordIndex_T2S(maxLen);
@ -159,7 +114,6 @@ TextConversion_zh::getWordConversion(const OUString& aText, sal_Int32 nStartPos,
charIndex = getSTC_CharIndex_S2T();
}
}
#endif
if ((!wordData || !index || !entry) && !xCDL.is()) // no word mapping defined, do char2char conversion.
return getCharConversion(aText, nStartPos, nLength, toSChinese, nConversionOptions);
@ -173,7 +127,7 @@ TextConversion_zh::getWordConversion(const OUString& aText, sal_Int32 nStartPos,
if (len > maxLen)
len = maxLen;
for (; len > 0 && ! found; len--) {
OUString word = aText.copy(nStartPos + currPos, len);
OUString word( aText.substr(nStartPos + currPos, len) );
sal_Int32 current = 0;
// user dictionary
if (xCDL.is()) {

View file

@ -72,7 +72,7 @@ $(eval $(call gb_CppunitTest_use_uiconfigs,sw_core_unocore, \
))
$(call gb_CppunitTest_get_target,sw_core_unocore): \
$(call gb_Library_get_target,textconv_dict)
$(call gb_Library_get_target,i18npool)
$(eval $(call gb_CppunitTest_use_more_fonts,sw_core_unocore))

View file

@ -72,7 +72,7 @@ $(eval $(call gb_CppunitTest_use_uiconfigs,sw_unowriter, \
))
$(call gb_CppunitTest_get_target,sw_unowriter): \
$(call gb_Library_get_target,textconv_dict)
$(call gb_Library_get_target,i18npool)
$(eval $(call gb_CppunitTest_use_more_fonts,sw_unowriter))

View file

@ -82,7 +82,7 @@ $(eval $(call gb_CppunitTest_use_uiconfigs,sw_layoutwriter$(1), \
))
$(call gb_CppunitTest_get_target,sw_layoutwriter$(1)): \
$(call gb_Library_get_target,textconv_dict)
$(call gb_Library_get_target,i18npool)
# assert if font/glyph fallback occurs
$(eval $(call gb_CppunitTest_set_non_application_font_use,sw_layoutwriter$(1),abort))

View file

@ -92,7 +92,7 @@ $(eval $(call gb_CppunitTest_use_packages,sw_uiwriter$(1),\
sfx2_classification \
))
$(call gb_CppunitTest_get_target,sw_uiwriter$(1)) : $(call gb_Library_get_target,textconv_dict)
$(call gb_CppunitTest_get_target,sw_uiwriter$(1)) : $(call gb_Library_get_target,i18npool)
$(eval $(call gb_CppunitTest_use_more_fonts,sw_uiwriter$(1)))