22#include <com/sun/star/i18n/TextConversionType.hpp>
23#include <com/sun/star/i18n/TextConversionOption.hpp>
24#include <com/sun/star/lang/NoSupportException.hpp>
25#include <com/sun/star/linguistic2/ConversionDirection.hpp>
26#include <com/sun/star/linguistic2/ConversionDictionaryType.hpp>
27#include <com/sun/star/linguistic2/ConversionDictionaryList.hpp>
41 xCDL = ConversionDictionaryList::create(xContext);
48 if (address != 0xFFFF)
49 address =
Data[address + (
ch & 0xFF)];
50 return (address != 0xFFFF) ? address :
ch;
56#ifdef DISABLE_DYNLOADING
61const sal_uInt16* getSTC_CharIndex_T2S();
63const sal_uInt16* getSTC_CharIndex_S2V();
65const sal_uInt16* getSTC_CharIndex_S2T();
69const sal_uInt16 *getSTC_WordIndex_T2S(sal_Int32&);
70const sal_uInt16 *getSTC_WordEntry_T2S();
71const sal_uInt16 *getSTC_WordIndex_S2T(sal_Int32&);
72const sal_uInt16 *getSTC_WordEntry_S2T();
82 const sal_uInt16 *
Index;
84#ifndef DISABLE_DYNLOADING
88 }
else if (nConversionOptions & TextConversionOption::USE_CHARACTER_VARIANTS) {
97 Data = getSTC_CharData_T2S();
98 Index = getSTC_CharIndex_T2S();
99 }
else if (nConversionOptions & TextConversionOption::USE_CHARACTER_VARIANTS) {
100 Data = getSTC_CharData_S2V();
101 Index = getSTC_CharIndex_S2V();
103 Data = getSTC_CharData_S2T();
104 Index = getSTC_CharIndex_S2T();
108 rtl_uString * newStr = rtl_uString_alloc(
nLength);
112 return OUString(newStr, SAL_NO_ACQUIRE);
118 sal_Int32 dictLen = 0;
119 sal_Int32 maxLen = 0;
120 const sal_uInt16 *
index;
121 const sal_uInt16 *entry;
123 const sal_uInt16 *charIndex;
126#ifndef DISABLE_DYNLOADING
130 entry =
reinterpret_cast<const sal_uInt16* (*)()
>(
getFunctionBySymbol(
"getSTC_WordEntry_T2S"))();
132 charIndex =
reinterpret_cast<const sal_uInt16* (*)()
>(
getFunctionBySymbol(
"getSTC_CharIndex_T2S"))();
135 entry =
reinterpret_cast<const sal_uInt16* (*)()
>(
getFunctionBySymbol(
"getSTC_WordEntry_S2T"))();
136 if (nConversionOptions & TextConversionOption::USE_CHARACTER_VARIANTS) {
138 charIndex =
reinterpret_cast<const sal_uInt16* (*)()
>(
getFunctionBySymbol(
"getSTC_CharIndex_S2V"))();
141 charIndex =
reinterpret_cast<const sal_uInt16* (*)()
>(
getFunctionBySymbol(
"getSTC_CharIndex_S2T"))();
145 const sal_Unicode *wordData = getSTC_WordData(dictLen);
147 index = getSTC_WordIndex_T2S(maxLen);
148 entry = getSTC_WordEntry_T2S();
149 charData = getSTC_CharData_T2S();
150 charIndex = getSTC_CharIndex_T2S();
152 index = getSTC_WordIndex_S2T(maxLen);
153 entry = getSTC_WordEntry_S2T();
154 if (nConversionOptions & TextConversionOption::USE_CHARACTER_VARIANTS) {
155 charData = getSTC_CharData_S2V();
156 charIndex = getSTC_CharIndex_S2V();
158 charData = getSTC_CharData_S2T();
159 charIndex = getSTC_CharIndex_S2T();
164 if ((!wordData || !
index || !entry) && !
xCDL.is())
168 sal_Int32 currPos = 0,
count = 0;
169 auto offsetRange = asNonConstRange(offset);
171 sal_Int32 len =
nLength - currPos;
175 for (; len > 0 && ! found; len--) {
176 OUString word = aText.copy(nStartPos + currPos, len);
177 sal_Int32 current = 0;
182 conversions =
xCDL->queryConversions(word, 0, len,
183 aLocale, ConversionDictionaryType::SCHINESE_TCHINESE,
184 ConversionDirection_FROM_LEFT ,
187 catch ( NoSupportException & ) {
197 if (conversions.hasElements()) {
198 if (offset.hasElements()) {
199 if (word.getLength() != conversions[0].getLength())
201 while (current < conversions[0].
getLength()) {
202 offsetRange[
count] = nStartPos + currPos + (current *
203 word.getLength() / conversions[0].getLength());
204 newStr[
count++] = conversions[0][current++];
208 while (current < conversions[0].
getLength())
209 newStr[
count++] = conversions[0][current++];
211 currPos += word.getLength();
216 if (wordData && !found &&
index[len+1] -
index[len] > 0) {
217 sal_Int32
bottom =
static_cast<sal_Int32
>(
index[len]);
218 sal_Int32
top =
static_cast<sal_Int32
>(
index[len+1]) - 1;
222 const sal_Int32
result = rtl_ustr_compare(
223 word.getStr(), wordData + entry[current]);
230 for (current = entry[current]-1; current > 0 && wordData[current-1]; current--) ;
232 current = entry[current] + word.getLength() + 1;
233 sal_Int32
start=current;
234 if (offset.hasElements()) {
235 if (word.getLength() !=
static_cast<sal_Int32
>(std::u16string_view(&wordData[current]).size()))
237 sal_Int32 convertedLength=std::u16string_view(&wordData[current]).size();
238 while (wordData[current]) {
239 offsetRange[
count]=nStartPos + currPos + ((current-
start) *
240 word.getLength() / convertedLength);
241 newStr[
count++] = wordData[current++];
245 while (wordData[current])
246 newStr[
count++] = wordData[current++];
248 currPos += word.getLength();
255 if (offset.hasElements())
256 offsetRange[
count]=nStartPos+currPos;
262 if (offset.hasElements())
263 offset.realloc(one2one ? 0 :
count);
264 OUString aRet(newStr.get(),
count);
268TextConversionResult SAL_CALL
270 const Locale& rLocale, sal_Int16 nConversionType, sal_Int32 nConversionOptions)
272 TextConversionResult
result;
276 result.Boundary.startPos = nStartPos;
284 const Locale& rLocale, sal_Int16 nConversionType, sal_Int32 nConversionOptions)
286 if (rLocale.Language !=
"zh" || ( nConversionType != TextConversionType::TO_SCHINESE && nConversionType != TextConversionType::TO_TCHINESE) )
287 throw NoSupportException();
290 bool toSChinese = nConversionType == TextConversionType::TO_SCHINESE;
292 if (nConversionOptions & TextConversionOption::CHARACTER_BY_CHARACTER)
304 const Locale& rLocale, sal_Int16 nConversionType, sal_Int32 nConversionOptions,
Sequence<sal_Int32>& offset)
306 if (rLocale.Language !=
"zh" || ( nConversionType != TextConversionType::TO_SCHINESE && nConversionType != TextConversionType::TO_TCHINESE) )
307 throw NoSupportException();
310 bool toSChinese = nConversionType == TextConversionType::TO_SCHINESE;
312 if (nConversionOptions & TextConversionOption::CHARACTER_BY_CHARACTER) {
317 if (offset.getLength() < 2*
nLength)
oslGenericFunction getFunctionBySymbol(const char *func)
TextConversion_zh(const css::uno::Reference< css::uno::XComponentContext > &rxContext)
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
css::lang::Locale aLocale
OUString getWordConversion(const OUString &aText, sal_Int32 nStartPos, sal_Int32 nLength, bool toSChinese, sal_Int32 nConversionOptions, css::uno::Sequence< sal_Int32 > &offset)
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
css::uno::Reference< css::linguistic2::XConversionDictionaryList > xCDL
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
rtl::OUString getCharConversion(const rtl::OUString &aText, sal_Int32 nStartPos, sal_Int32 nLength, bool toSChinese, sal_Int32 nConversionOptions)
sal_Bool SAL_CALL interactiveConversion(const css::lang::Locale &aLocale, sal_Int16 nTextConversionType, sal_Int32 nTextConversionOptions) override
double getLength(const B2DPolygon &rCandidate)
Constant values shared between i18npool and, for example, the number formatter.
static sal_Unicode getOneCharConversion(sal_Unicode ch, const sal_Unicode *Data, const sal_uInt16 *Index)