• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 #include "bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_text_bridge.h"
16 
17 #include "base/utils/string_utils.h"
18 #include "base/utils/utils.h"
19 #include "bridge/declarative_frontend/engine/js_ref_ptr.h"
20 #include "bridge/declarative_frontend/engine/jsi/jsi_types.h"
21 #include "bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_frame_node_bridge.h"
22 #include "bridge/declarative_frontend/style_string/js_span_string.h"
23 #include "core/components/common/properties/shadow.h"
24 #include "core/components_ng/pattern/text/text_model_ng.h"
25 #include "frameworks/bridge/declarative_frontend/engine/jsi/nativeModule/arkts_utils.h"
26 #include "frameworks/bridge/declarative_frontend/jsview/js_text.h"
27 
28 namespace OHOS::Ace::NG {
29 namespace {
30 constexpr int PARAM_ARR_LENGTH_1 = 1;
31 constexpr int PARAM_ARR_LENGTH_2 = 2;
32 constexpr int SIZE_OF_TEXT_CASES = 2;
33 constexpr int16_t DEFAULT_ALPHA = 255;
34 constexpr double DEFAULT_OPACITY = 0.2;
35 constexpr double DEFAULT_SPAN_FONT_SIZE = 16;
36 constexpr DimensionUnit DEFAULT_SPAN_FONT_UNIT = DimensionUnit::FP;
37 constexpr TextDecorationStyle DEFAULT_DECORATION_STYLE = TextDecorationStyle::SOLID;
38 constexpr Ace::FontStyle DEFAULT_FONT_STYLE = Ace::FontStyle::NORMAL;
39 const Color DEFAULT_DECORATION_COLOR = Color::BLACK;
40 const std::string DEFAULT_FONT_WEIGHT = "400";
41 constexpr int DEFAULT_VARIABLE_FONT_WEIGHT = 400;
42 constexpr Dimension DEFAULT_MARQUEE_STEP_VALUE = 4.0_vp;
43 constexpr int NUM_0 = 0;
44 constexpr int NUM_1 = 1;
45 constexpr int NUM_2 = 2;
46 constexpr int NUM_3 = 3;
47 constexpr int NUM_4 = 4;
48 constexpr int NUM_5 = 5;
49 constexpr int NUM_6 = 6;
50 constexpr int NUM_7 = 7;
51 const std::vector<TextOverflow> TEXT_OVERFLOWS = { TextOverflow::NONE, TextOverflow::CLIP, TextOverflow::ELLIPSIS,
52     TextOverflow::MARQUEE };
53 const std::vector<std::string> TEXT_DETECT_TYPES = { "phoneNum", "url", "email", "location", "datetime" };
54 } // namespace
55 
SetFontWeight(ArkUIRuntimeCallInfo * runtimeCallInfo)56 ArkUINativeModuleValue TextBridge::SetFontWeight(ArkUIRuntimeCallInfo* runtimeCallInfo)
57 {
58     EcmaVM* vm = runtimeCallInfo->GetVM();
59     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
60     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
61     Local<JSValueRef> weightArg = runtimeCallInfo->GetCallArgRef(NUM_1);
62     Local<JSValueRef> optionsArg = runtimeCallInfo->GetCallArgRef(NUM_2);
63     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
64 
65     ArkUIFontWeightWithOptionsStruct weightInfo;
66     int32_t variableFontWeight = DEFAULT_VARIABLE_FONT_WEIGHT;
67     std::string weight = DEFAULT_FONT_WEIGHT;
68     if (!weightArg->IsNull()) {
69         if (weightArg->IsNumber()) {
70             weight = std::to_string(weightArg->Int32Value(vm));
71             variableFontWeight = weightArg->Int32Value(vm);
72         } else if (weightArg->IsString(vm)) {
73             weight = weightArg->ToString(vm)->ToString(vm);
74             variableFontWeight = StringUtils::StringToInt(weight);
75         }
76     }
77     weightInfo.weight = weight.c_str();
78     weightInfo.variableFontWeight = variableFontWeight;
79 
80     if (optionsArg->IsBoolean()) {
81         weightInfo.enableVariableFontWeight = static_cast<int32_t>(optionsArg->BooleaValue(vm));
82     }
83     GetArkUINodeModifiers()->getTextModifier()->setFontWeightWithOption(nativeNode, &weightInfo);
84     return panda::JSValueRef::Undefined(vm);
85 }
86 
ResetFontWeight(ArkUIRuntimeCallInfo * runtimeCallInfo)87 ArkUINativeModuleValue TextBridge::ResetFontWeight(ArkUIRuntimeCallInfo* runtimeCallInfo)
88 {
89     EcmaVM* vm = runtimeCallInfo->GetVM();
90     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
91     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
92     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
93     GetArkUINodeModifiers()->getTextModifier()->resetFontWeight(nativeNode);
94     return panda::JSValueRef::Undefined(vm);
95 }
96 
SetFontStyle(ArkUIRuntimeCallInfo * runtimeCallInfo)97 ArkUINativeModuleValue TextBridge::SetFontStyle(ArkUIRuntimeCallInfo* runtimeCallInfo)
98 {
99     EcmaVM* vm = runtimeCallInfo->GetVM();
100     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
101     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
102     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
103     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
104     if (secondArg->IsNumber()) {
105         uint32_t fontStyle = secondArg->Uint32Value(vm);
106         if (fontStyle < static_cast<uint32_t>(OHOS::Ace::FontStyle::NORMAL) ||
107             fontStyle > static_cast<uint32_t>(OHOS::Ace::FontStyle::ITALIC)) {
108             fontStyle = static_cast<uint32_t>(OHOS::Ace::FontStyle::NORMAL);
109         }
110         GetArkUINodeModifiers()->getTextModifier()->setFontStyle(nativeNode, fontStyle);
111     } else {
112         GetArkUINodeModifiers()->getTextModifier()->resetFontStyle(nativeNode);
113     }
114     return panda::JSValueRef::Undefined(vm);
115 }
116 
ResetFontStyle(ArkUIRuntimeCallInfo * runtimeCallInfo)117 ArkUINativeModuleValue TextBridge::ResetFontStyle(ArkUIRuntimeCallInfo* runtimeCallInfo)
118 {
119     EcmaVM* vm = runtimeCallInfo->GetVM();
120     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
121     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
122     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
123     GetArkUINodeModifiers()->getTextModifier()->resetFontStyle(nativeNode);
124     return panda::JSValueRef::Undefined(vm);
125 }
126 
SetTextAlign(ArkUIRuntimeCallInfo * runtimeCallInfo)127 ArkUINativeModuleValue TextBridge::SetTextAlign(ArkUIRuntimeCallInfo* runtimeCallInfo)
128 {
129     EcmaVM* vm = runtimeCallInfo->GetVM();
130     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
131     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
132     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
133     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
134     if (secondArg->IsNumber()) {
135         GetArkUINodeModifiers()->getTextModifier()->setTextAlign(nativeNode, secondArg->ToNumber(vm)->Value());
136     } else {
137         GetArkUINodeModifiers()->getTextModifier()->resetTextAlign(nativeNode);
138     }
139     return panda::JSValueRef::Undefined(vm);
140 }
141 
ResetTextAlign(ArkUIRuntimeCallInfo * runtimeCallInfo)142 ArkUINativeModuleValue TextBridge::ResetTextAlign(ArkUIRuntimeCallInfo* runtimeCallInfo)
143 {
144     EcmaVM* vm = runtimeCallInfo->GetVM();
145     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
146     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
147     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
148     GetArkUINodeModifiers()->getTextModifier()->resetTextAlign(nativeNode);
149     return panda::JSValueRef::Undefined(vm);
150 }
151 
SetFontColor(ArkUIRuntimeCallInfo * runtimeCallInfo)152 ArkUINativeModuleValue TextBridge::SetFontColor(ArkUIRuntimeCallInfo* runtimeCallInfo)
153 {
154     EcmaVM* vm = runtimeCallInfo->GetVM();
155     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
156     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
157     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
158     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
159     Color color;
160     if (!ArkTSUtils::ParseJsColorAlpha(vm, secondArg, color)) {
161         GetArkUINodeModifiers()->getTextModifier()->resetFontColor(nativeNode);
162     } else {
163         GetArkUINodeModifiers()->getTextModifier()->setFontColor(nativeNode, color.GetValue());
164     }
165     return panda::JSValueRef::Undefined(vm);
166 }
ResetFontColor(ArkUIRuntimeCallInfo * runtimeCallInfo)167 ArkUINativeModuleValue TextBridge::ResetFontColor(ArkUIRuntimeCallInfo* runtimeCallInfo)
168 {
169     EcmaVM* vm = runtimeCallInfo->GetVM();
170     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
171     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
172     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
173     GetArkUINodeModifiers()->getTextModifier()->resetFontColor(nativeNode);
174     return panda::JSValueRef::Undefined(vm);
175 }
176 
SetForegroundColor(ArkUIRuntimeCallInfo * runtimeCallInfo)177 ArkUINativeModuleValue TextBridge::SetForegroundColor(ArkUIRuntimeCallInfo* runtimeCallInfo)
178 {
179     EcmaVM *vm = runtimeCallInfo->GetVM();
180     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
181     Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(0);
182     auto colorArg = runtimeCallInfo->GetCallArgRef(1);
183     auto nativeNode = nodePtr(nodeArg->ToNativePointer(vm)->Value());
184 
185     ForegroundColorStrategy strategy;
186     if (ArkTSUtils::ParseJsColorStrategy(vm, colorArg, strategy)) {
187         auto strategyInt = static_cast<uint32_t>(ForegroundColorStrategy::INVERT);
188         GetArkUINodeModifiers()->getTextModifier()->setTextForegroundColor(nativeNode, false, strategyInt);
189         return panda::JSValueRef::Undefined(vm);
190     }
191     Color foregroundColor;
192     if (!ArkTSUtils::ParseJsColorAlpha(vm, colorArg, foregroundColor)) {
193         GetArkUINodeModifiers()->getTextModifier()->resetTextForegroundColor(nativeNode);
194     } else {
195         GetArkUINodeModifiers()->getTextModifier()->setTextForegroundColor(
196             nativeNode, true, foregroundColor.GetValue());
197     }
198     return panda::JSValueRef::Undefined(vm);
199 }
200 
ResetForegroundColor(ArkUIRuntimeCallInfo * runtimeCallInfo)201 ArkUINativeModuleValue TextBridge::ResetForegroundColor(ArkUIRuntimeCallInfo* runtimeCallInfo)
202 {
203     EcmaVM* vm = runtimeCallInfo->GetVM();
204     Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(0);
205     auto nativeNode = nodePtr(nodeArg->ToNativePointer(vm)->Value());
206     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
207     GetArkUINodeModifiers()->getTextModifier()->resetTextForegroundColor(nativeNode);
208     return panda::JSValueRef::Undefined(vm);
209 }
210 
SetFontSize(ArkUIRuntimeCallInfo * runtimeCallInfo)211 ArkUINativeModuleValue TextBridge::SetFontSize(ArkUIRuntimeCallInfo* runtimeCallInfo)
212 {
213     EcmaVM* vm = runtimeCallInfo->GetVM();
214     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
215     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
216     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
217     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
218     CalcDimension fontSize;
219     if (!ArkTSUtils::ParseJsDimensionFpNG(vm, secondArg, fontSize, false)) {
220         GetArkUINodeModifiers()->getTextModifier()->resetFontSize(nativeNode);
221     } else {
222         GetArkUINodeModifiers()->getTextModifier()->setFontSize(
223             nativeNode, fontSize.Value(), static_cast<int>(fontSize.Unit()));
224     }
225     return panda::JSValueRef::Undefined(vm);
226 }
ResetFontSize(ArkUIRuntimeCallInfo * runtimeCallInfo)227 ArkUINativeModuleValue TextBridge::ResetFontSize(ArkUIRuntimeCallInfo* runtimeCallInfo)
228 {
229     EcmaVM* vm = runtimeCallInfo->GetVM();
230     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
231     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
232     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
233     GetArkUINodeModifiers()->getTextModifier()->resetFontSize(nativeNode);
234     return panda::JSValueRef::Undefined(vm);
235 }
236 
SetLineHeight(ArkUIRuntimeCallInfo * runtimeCallInfo)237 ArkUINativeModuleValue TextBridge::SetLineHeight(ArkUIRuntimeCallInfo* runtimeCallInfo)
238 {
239     EcmaVM* vm = runtimeCallInfo->GetVM();
240     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
241     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
242     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
243     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
244     CalcDimension lineHeight(0.0, DEFAULT_SPAN_FONT_UNIT);
245     if (!ArkTSUtils::ParseJsDimensionFpNG(vm, secondArg, lineHeight)) {
246         lineHeight.Reset();
247     }
248     if (lineHeight.IsNegative()) {
249         lineHeight.Reset();
250     }
251     GetArkUINodeModifiers()->getTextModifier()->setTextLineHeight(
252         nativeNode, lineHeight.Value(), static_cast<int8_t>(lineHeight.Unit()));
253     return panda::JSValueRef::Undefined(vm);
254 }
255 
ResetLineHeight(ArkUIRuntimeCallInfo * runtimeCallInfo)256 ArkUINativeModuleValue TextBridge::ResetLineHeight(ArkUIRuntimeCallInfo* runtimeCallInfo)
257 {
258     EcmaVM* vm = runtimeCallInfo->GetVM();
259     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
260     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
261     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
262     GetArkUINodeModifiers()->getTextModifier()->resetTextLineHeight(nativeNode);
263     return panda::JSValueRef::Undefined(vm);
264 }
265 
SetTextOverflow(ArkUIRuntimeCallInfo * runtimeCallInfo)266 ArkUINativeModuleValue TextBridge::SetTextOverflow(ArkUIRuntimeCallInfo* runtimeCallInfo)
267 {
268     EcmaVM* vm = runtimeCallInfo->GetVM();
269     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
270     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
271     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
272     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
273     int32_t value;
274     if (secondArg->IsUndefined()) {
275         value = 0;
276     } else if (secondArg->IsNumber()) {
277         value = secondArg->Int32Value(vm);
278     } else {
279         return panda::JSValueRef::Undefined(vm);
280     }
281     if (value < 0 || value >= static_cast<int32_t>(TEXT_OVERFLOWS.size())) {
282         return panda::JSValueRef::Undefined(vm);
283     }
284     GetArkUINodeModifiers()->getTextModifier()->setTextOverflow(nativeNode, value);
285     return panda::JSValueRef::Undefined(vm);
286 }
287 
ResetTextOverflow(ArkUIRuntimeCallInfo * runtimeCallInfo)288 ArkUINativeModuleValue TextBridge::ResetTextOverflow(ArkUIRuntimeCallInfo* runtimeCallInfo)
289 {
290     EcmaVM* vm = runtimeCallInfo->GetVM();
291     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
292     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
293     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
294     GetArkUINodeModifiers()->getTextModifier()->resetTextOverflow(nativeNode);
295     return panda::JSValueRef::Undefined(vm);
296 }
297 
SetDecoration(ArkUIRuntimeCallInfo * runtimeCallInfo)298 ArkUINativeModuleValue TextBridge::SetDecoration(ArkUIRuntimeCallInfo* runtimeCallInfo)
299 {
300     EcmaVM* vm = runtimeCallInfo->GetVM();
301     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
302     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
303     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
304     Local<JSValueRef> thirdArg = runtimeCallInfo->GetCallArgRef(NUM_2);
305     Local<JSValueRef> fourthArg = runtimeCallInfo->GetCallArgRef(NUM_3);
306     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
307     int32_t textDecoration = static_cast<int32_t>(TextDecoration::NONE);
308     Color color = DEFAULT_DECORATION_COLOR;
309     int32_t style = static_cast<int32_t>(DEFAULT_DECORATION_STYLE);
310     if (secondArg->IsInt()) {
311         textDecoration = secondArg->Int32Value(vm);
312     }
313     if (!ArkTSUtils::ParseJsColorAlpha(vm, thirdArg, color)) {
314         color = DEFAULT_DECORATION_COLOR;
315     }
316     if (fourthArg->IsInt()) {
317         style = fourthArg->Int32Value(vm);
318     }
319     GetArkUINodeModifiers()->getTextModifier()->setTextDecoration(nativeNode, textDecoration, color.GetValue(), style);
320     return panda::JSValueRef::Undefined(vm);
321 }
322 
ResetDecoration(ArkUIRuntimeCallInfo * runtimeCallInfo)323 ArkUINativeModuleValue TextBridge::ResetDecoration(ArkUIRuntimeCallInfo* runtimeCallInfo)
324 {
325     EcmaVM* vm = runtimeCallInfo->GetVM();
326     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
327     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
328     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
329     GetArkUINodeModifiers()->getTextModifier()->resetTextDecoration(nativeNode);
330     return panda::JSValueRef::Undefined(vm);
331 }
332 
SetTextCase(ArkUIRuntimeCallInfo * runtimeCallInfo)333 ArkUINativeModuleValue TextBridge::SetTextCase(ArkUIRuntimeCallInfo* runtimeCallInfo)
334 {
335     EcmaVM* vm = runtimeCallInfo->GetVM();
336     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
337     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
338     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
339     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
340     if (secondArg->IsNumber() && secondArg->Int32Value(vm) >= NUM_0 &&
341         secondArg->Int32Value(vm) <= SIZE_OF_TEXT_CASES) {
342         GetArkUINodeModifiers()->getTextModifier()->setTextCase(nativeNode, secondArg->Int32Value(vm));
343     } else {
344         GetArkUINodeModifiers()->getTextModifier()->resetTextCase(nativeNode);
345     }
346     return panda::JSValueRef::Undefined(vm);
347 }
348 
ResetTextCase(ArkUIRuntimeCallInfo * runtimeCallInfo)349 ArkUINativeModuleValue TextBridge::ResetTextCase(ArkUIRuntimeCallInfo* runtimeCallInfo)
350 {
351     EcmaVM* vm = runtimeCallInfo->GetVM();
352     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
353     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
354     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
355     GetArkUINodeModifiers()->getTextModifier()->resetTextCase(nativeNode);
356     return panda::JSValueRef::Undefined(vm);
357 }
358 
SetMaxLines(ArkUIRuntimeCallInfo * runtimeCallInfo)359 ArkUINativeModuleValue TextBridge::SetMaxLines(ArkUIRuntimeCallInfo* runtimeCallInfo)
360 {
361     EcmaVM* vm = runtimeCallInfo->GetVM();
362     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
363     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
364     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
365     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
366     if (secondArg->IsNumber()) {
367         uint32_t maxLine = secondArg->Uint32Value(vm);
368         GetArkUINodeModifiers()->getTextModifier()->setTextMaxLines(nativeNode, maxLine);
369     } else {
370         GetArkUINodeModifiers()->getTextModifier()->resetTextMaxLines(nativeNode);
371     }
372     return panda::JSValueRef::Undefined(vm);
373 }
374 
ResetMaxLines(ArkUIRuntimeCallInfo * runtimeCallInfo)375 ArkUINativeModuleValue TextBridge::ResetMaxLines(ArkUIRuntimeCallInfo* runtimeCallInfo)
376 {
377     EcmaVM* vm = runtimeCallInfo->GetVM();
378     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
379     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
380     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
381     GetArkUINodeModifiers()->getTextModifier()->resetTextMaxLines(nativeNode);
382     return panda::JSValueRef::Undefined(vm);
383 }
384 
SetMinFontSize(ArkUIRuntimeCallInfo * runtimeCallInfo)385 ArkUINativeModuleValue TextBridge::SetMinFontSize(ArkUIRuntimeCallInfo* runtimeCallInfo)
386 {
387     EcmaVM* vm = runtimeCallInfo->GetVM();
388     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
389     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
390     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
391     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
392 
393     CalcDimension fontSize;
394     if (ArkTSUtils::ParseJsDimensionFpNG(vm, secondArg, fontSize, false)) {
395         GetArkUINodeModifiers()->getTextModifier()->setTextMinFontSize(
396             nativeNode, fontSize.Value(), static_cast<int8_t>(fontSize.Unit()));
397     } else {
398         GetArkUINodeModifiers()->getTextModifier()->resetTextMinFontSize(nativeNode);
399     }
400     return panda::JSValueRef::Undefined(vm);
401 }
402 
ReSetMinFontSize(ArkUIRuntimeCallInfo * runtimeCallInfo)403 ArkUINativeModuleValue TextBridge::ReSetMinFontSize(ArkUIRuntimeCallInfo* runtimeCallInfo)
404 {
405     EcmaVM* vm = runtimeCallInfo->GetVM();
406     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
407     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
408     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
409     GetArkUINodeModifiers()->getTextModifier()->resetTextMinFontSize(nativeNode);
410     return panda::JSValueRef::Undefined(vm);
411 }
412 
SetDraggable(ArkUIRuntimeCallInfo * runtimeCallInfo)413 ArkUINativeModuleValue TextBridge::SetDraggable(ArkUIRuntimeCallInfo* runtimeCallInfo)
414 {
415     EcmaVM* vm = runtimeCallInfo->GetVM();
416     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
417     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
418     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
419     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
420     uint32_t draggable = false;
421     if (secondArg->IsBoolean()) {
422         draggable = static_cast<uint32_t>(secondArg->ToBoolean(vm)->Value());
423     }
424     GetArkUINodeModifiers()->getTextModifier()->setTextDraggable(nativeNode, draggable);
425     return panda::JSValueRef::Undefined(vm);
426 }
427 
ResetDraggable(ArkUIRuntimeCallInfo * runtimeCallInfo)428 ArkUINativeModuleValue TextBridge::ResetDraggable(ArkUIRuntimeCallInfo* runtimeCallInfo)
429 {
430     EcmaVM* vm = runtimeCallInfo->GetVM();
431     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
432     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
433     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
434     GetArkUINodeModifiers()->getTextModifier()->resetTextDraggable(nativeNode);
435     return panda::JSValueRef::Undefined(vm);
436 }
437 
SetPrivacySensitive(ArkUIRuntimeCallInfo * runtimeCallInfo)438 ArkUINativeModuleValue TextBridge::SetPrivacySensitive(ArkUIRuntimeCallInfo* runtimeCallInfo)
439 {
440     EcmaVM* vm = runtimeCallInfo->GetVM();
441     CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
442     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
443     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
444     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
445     uint32_t sensitive = false;
446     if (secondArg->IsBoolean()) {
447         sensitive = static_cast<uint32_t>(secondArg->ToBoolean(vm)->Value());
448     }
449     GetArkUINodeModifiers()->getTextModifier()->setTextPrivacySensitive(nativeNode, sensitive);
450     return panda::JSValueRef::Undefined(vm);
451 }
452 
ResetPrivacySensitive(ArkUIRuntimeCallInfo * runtimeCallInfo)453 ArkUINativeModuleValue TextBridge::ResetPrivacySensitive(ArkUIRuntimeCallInfo* runtimeCallInfo)
454 {
455     EcmaVM* vm = runtimeCallInfo->GetVM();
456     CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
457     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
458     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
459     GetArkUINodeModifiers()->getTextModifier()->resetTextPrivacySensitive(nativeNode);
460     return panda::JSValueRef::Undefined(vm);
461 }
462 
SetMaxFontSize(ArkUIRuntimeCallInfo * runtimeCallInfo)463 ArkUINativeModuleValue TextBridge::SetMaxFontSize(ArkUIRuntimeCallInfo* runtimeCallInfo)
464 {
465     EcmaVM* vm = runtimeCallInfo->GetVM();
466     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
467     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
468     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
469     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
470     CalcDimension fontSize;
471     if (ArkTSUtils::ParseJsDimensionFpNG(vm, secondArg, fontSize, false)) {
472         GetArkUINodeModifiers()->getTextModifier()->setTextMaxFontSize(
473             nativeNode, fontSize.Value(), static_cast<int8_t>(fontSize.Unit()));
474     } else {
475         GetArkUINodeModifiers()->getTextModifier()->resetTextMaxFontSize(nativeNode);
476     }
477 
478     return panda::JSValueRef::Undefined(vm);
479 }
480 
ResetMaxFontSize(ArkUIRuntimeCallInfo * runtimeCallInfo)481 ArkUINativeModuleValue TextBridge::ResetMaxFontSize(ArkUIRuntimeCallInfo* runtimeCallInfo)
482 {
483     EcmaVM* vm = runtimeCallInfo->GetVM();
484     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
485     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
486     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
487     GetArkUINodeModifiers()->getTextModifier()->resetTextMaxFontSize(nativeNode);
488     return panda::JSValueRef::Undefined(vm);
489 }
490 
SetMinFontScale(ArkUIRuntimeCallInfo * runtimeCallInfo)491 ArkUINativeModuleValue TextBridge::SetMinFontScale(ArkUIRuntimeCallInfo* runtimeCallInfo)
492 {
493     EcmaVM* vm = runtimeCallInfo->GetVM();
494     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
495     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
496     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
497     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
498     double minFontScale;
499     if (!ArkTSUtils::ParseJsDouble(vm, secondArg, minFontScale)) {
500         return panda::JSValueRef::Undefined(vm);
501     }
502     if (LessOrEqual(minFontScale, 0.0f)) {
503         GetArkUINodeModifiers()->getTextModifier()->setTextMinFontScale(nativeNode, static_cast<float>(minFontScale));
504         minFontScale = 0.0f;
505     } else if (GreatOrEqual(minFontScale, 1.0f)) {
506         minFontScale = 1.0f;
507     }
508     GetArkUINodeModifiers()->getTextModifier()->setTextMinFontScale(nativeNode, static_cast<float>(minFontScale));
509     return panda::JSValueRef::Undefined(vm);
510 }
511 
ResetMinFontScale(ArkUIRuntimeCallInfo * runtimeCallInfo)512 ArkUINativeModuleValue TextBridge::ResetMinFontScale(ArkUIRuntimeCallInfo* runtimeCallInfo)
513 {
514     EcmaVM* vm = runtimeCallInfo->GetVM();
515     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
516     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
517     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
518     GetArkUINodeModifiers()->getTextModifier()->resetTextMinFontScale(nativeNode);
519     return panda::JSValueRef::Undefined(vm);
520 }
521 
SetMaxFontScale(ArkUIRuntimeCallInfo * runtimeCallInfo)522 ArkUINativeModuleValue TextBridge::SetMaxFontScale(ArkUIRuntimeCallInfo* runtimeCallInfo)
523 {
524     EcmaVM* vm = runtimeCallInfo->GetVM();
525     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
526     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
527     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
528     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
529     double maxFontScale;
530     if (!ArkTSUtils::ParseJsDouble(vm, secondArg, maxFontScale)) {
531         return panda::JSValueRef::Undefined(vm);
532     }
533     if (LessOrEqual(maxFontScale, 1.0f)) {
534         maxFontScale = 1.0f;
535     }
536     GetArkUINodeModifiers()->getTextModifier()->setTextMaxFontScale(nativeNode, static_cast<float>(maxFontScale));
537     return panda::JSValueRef::Undefined(vm);
538 }
539 
ResetMaxFontScale(ArkUIRuntimeCallInfo * runtimeCallInfo)540 ArkUINativeModuleValue TextBridge::ResetMaxFontScale(ArkUIRuntimeCallInfo* runtimeCallInfo)
541 {
542     EcmaVM* vm = runtimeCallInfo->GetVM();
543     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
544     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
545     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
546     GetArkUINodeModifiers()->getTextModifier()->resetTextMaxFontScale(nativeNode);
547     return panda::JSValueRef::Undefined(vm);
548 }
549 
SetFontFamily(ArkUIRuntimeCallInfo * runtimeCallInfo)550 ArkUINativeModuleValue TextBridge::SetFontFamily(ArkUIRuntimeCallInfo* runtimeCallInfo)
551 {
552     EcmaVM* vm = runtimeCallInfo->GetVM();
553     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
554     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
555     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
556     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
557 
558     std::vector<std::string> fontFamilies;
559     if (!ArkTSUtils::ParseJsFontFamilies(vm, secondArg, fontFamilies)) {
560         GetArkUINodeModifiers()->getTextModifier()->resetTextFontFamily(nativeNode);
561         return panda::JSValueRef::Undefined(vm);
562     }
563     auto families = std::make_unique<char* []>(fontFamilies.size());
564     for (uint32_t i = 0; i < fontFamilies.size(); i++) {
565         families[i] = const_cast<char*>(fontFamilies.at(i).c_str());
566     }
567     GetArkUINodeModifiers()->getTextModifier()->setTextFontFamily(
568         nativeNode, const_cast<const char**>(families.get()), fontFamilies.size());
569     return panda::JSValueRef::Undefined(vm);
570 }
571 
ResetFontFamily(ArkUIRuntimeCallInfo * runtimeCallInfo)572 ArkUINativeModuleValue TextBridge::ResetFontFamily(ArkUIRuntimeCallInfo* runtimeCallInfo)
573 {
574     EcmaVM* vm = runtimeCallInfo->GetVM();
575     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
576     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
577     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
578 
579     GetArkUINodeModifiers()->getTextModifier()->resetTextFontFamily(nativeNode);
580     return panda::JSValueRef::Undefined(vm);
581 }
582 
SetCopyOption(ArkUIRuntimeCallInfo * runtimeCallInfo)583 ArkUINativeModuleValue TextBridge::SetCopyOption(ArkUIRuntimeCallInfo* runtimeCallInfo)
584 {
585     EcmaVM* vm = runtimeCallInfo->GetVM();
586     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
587     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
588     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
589     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
590     int32_t copyOption = static_cast<int32_t>(CopyOptions::None);
591     if (secondArg->IsInt()) {
592         copyOption = secondArg->Int32Value(vm);
593     }
594     GetArkUINodeModifiers()->getTextModifier()->setTextCopyOption(nativeNode, copyOption);
595     return panda::JSValueRef::Undefined(vm);
596 }
597 
ResetCopyOption(ArkUIRuntimeCallInfo * runtimeCallInfo)598 ArkUINativeModuleValue TextBridge::ResetCopyOption(ArkUIRuntimeCallInfo* runtimeCallInfo)
599 {
600     EcmaVM* vm = runtimeCallInfo->GetVM();
601     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
602     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
603     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
604     GetArkUINodeModifiers()->getTextModifier()->resetTextCopyOption(nativeNode);
605     return panda::JSValueRef::Undefined(vm);
606 }
607 
SetTextShadow(ArkUIRuntimeCallInfo * runtimeCallInfo)608 ArkUINativeModuleValue TextBridge::SetTextShadow(ArkUIRuntimeCallInfo* runtimeCallInfo)
609 {
610     EcmaVM* vm = runtimeCallInfo->GetVM();
611     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
612     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
613     Local<JSValueRef> radiusArg = runtimeCallInfo->GetCallArgRef(NUM_1);
614     Local<JSValueRef> typeArg = runtimeCallInfo->GetCallArgRef(NUM_2);
615     Local<JSValueRef> colorArg = runtimeCallInfo->GetCallArgRef(NUM_3);
616     Local<JSValueRef> offsetXArg = runtimeCallInfo->GetCallArgRef(NUM_4);
617     Local<JSValueRef> offsetYArg = runtimeCallInfo->GetCallArgRef(NUM_5);
618     Local<JSValueRef> fillArg = runtimeCallInfo->GetCallArgRef(NUM_6);
619     Local<JSValueRef> lengthArg = runtimeCallInfo->GetCallArgRef(NUM_7);
620     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
621     uint32_t length;
622     if (!lengthArg->IsNumber() || lengthArg->Uint32Value(vm) == 0) {
623         return panda::JSValueRef::Undefined(vm);
624     }
625     length = lengthArg->Uint32Value(vm);
626     auto radiusArray = std::make_unique<double[]>(length);
627     auto typeArray = std::make_unique<uint32_t[]>(length);
628     auto colorArray = std::make_unique<uint32_t[]>(length);
629     auto offsetXArray = std::make_unique<double[]>(length);
630     auto offsetYArray = std::make_unique<double[]>(length);
631     auto fillArray = std::make_unique<uint32_t[]>(length);
632     bool radiusParseResult = ArkTSUtils::ParseArray<double>(
633         vm, radiusArg, radiusArray.get(), length, ArkTSUtils::parseShadowRadius);
634     bool typeParseResult = ArkTSUtils::ParseArray<uint32_t>(
635         vm, typeArg, typeArray.get(), length, ArkTSUtils::parseShadowType);
636     bool colorParseResult = ArkTSUtils::ParseArray<uint32_t>(
637         vm, colorArg, colorArray.get(), length, ArkTSUtils::parseShadowColor);
638     bool offsetXParseResult = ArkTSUtils::ParseArray<double>(
639         vm, offsetXArg, offsetXArray.get(), length, ArkTSUtils::parseShadowOffset);
640     bool offsetYParseResult = ArkTSUtils::ParseArray<double>(
641         vm, offsetYArg, offsetYArray.get(), length, ArkTSUtils::parseShadowOffset);
642     bool fillParseResult = ArkTSUtils::ParseArray<uint32_t>(
643         vm, fillArg, fillArray.get(), length, ArkTSUtils::parseShadowFill);
644     if (!radiusParseResult || !colorParseResult || !offsetXParseResult ||
645         !offsetYParseResult || !fillParseResult || !typeParseResult) {
646         return panda::JSValueRef::Undefined(vm);
647     }
648     auto textShadowArray = std::make_unique<ArkUITextShadowStruct[]>(length);
649     CHECK_NULL_RETURN(textShadowArray.get(), panda::JSValueRef::Undefined(vm));
650     for (uint32_t i = 0; i < length; i++) {
651         textShadowArray[i].radius = radiusArray[i];
652         textShadowArray[i].type = typeArray[i];
653         textShadowArray[i].color = colorArray[i];
654         textShadowArray[i].offsetX = offsetXArray[i];
655         textShadowArray[i].offsetY = offsetYArray[i];
656         textShadowArray[i].fill = fillArray[i];
657     }
658     GetArkUINodeModifiers()->getTextModifier()->setTextShadow(nativeNode, textShadowArray.get(), length);
659     return panda::JSValueRef::Undefined(vm);
660 }
661 
ResetTextShadow(ArkUIRuntimeCallInfo * runtimeCallInfo)662 ArkUINativeModuleValue TextBridge::ResetTextShadow(ArkUIRuntimeCallInfo* runtimeCallInfo)
663 {
664     EcmaVM* vm = runtimeCallInfo->GetVM();
665     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
666     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
667     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
668     GetArkUINodeModifiers()->getTextModifier()->resetTextShadow(nativeNode);
669     return panda::JSValueRef::Undefined(vm);
670 }
671 
SetContent(ArkUIRuntimeCallInfo * runtimeCallInfo)672 ArkUINativeModuleValue TextBridge::SetContent(ArkUIRuntimeCallInfo* runtimeCallInfo)
673 {
674     EcmaVM* vm = runtimeCallInfo->GetVM();
675     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
676     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
677     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
678     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
679     Framework::JsiCallbackInfo info = Framework::JsiCallbackInfo(runtimeCallInfo);
680 
681     Framework::JSRef<Framework::JSVal> args = info[1];
682     if (args->IsObject() && Framework::JSRef<Framework::JSObject>::Cast(args)->Unwrap<Framework::JSSpanString>()) {
683         auto* spanString = Framework::JSRef<Framework::JSObject>::Cast(args)->Unwrap<Framework::JSSpanString>();
684         CHECK_NULL_RETURN(spanString, panda::JSValueRef::Undefined(vm));
685         auto spanStringController = spanString->GetController();
686         if (spanStringController) {
687             TextModelNG::InitSpanStringController(reinterpret_cast<FrameNode*>(nativeNode), spanStringController);
688         }
689         return panda::JSValueRef::Undefined(vm);
690     }
691     std::string content;
692     if (ArkTSUtils::ParseJsString(vm, secondArg, content)) {
693         GetArkUINodeModifiers()->getTextModifier()->setContent(nativeNode, content.c_str());
694     }
695     return panda::JSValueRef::Undefined(vm);
696 }
697 
SetTextController(ArkUIRuntimeCallInfo * runtimeCallInfo)698 ArkUINativeModuleValue TextBridge::SetTextController(ArkUIRuntimeCallInfo* runtimeCallInfo)
699 {
700     EcmaVM* vm = runtimeCallInfo->GetVM();
701     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
702     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
703     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
704     Framework::JsiCallbackInfo info = Framework::JsiCallbackInfo(runtimeCallInfo);
705     Framework::JSRef<Framework::JSVal> args = info[1];
706     if (args->IsObject()) {
707         auto paramObject = Framework::JSRef<Framework::JSObject>::Cast(args);
708         auto controllerObj = paramObject->GetProperty("controller");
709         Framework::JSTextController* jsController = nullptr;
710         if (controllerObj->IsObject()) {
711             jsController =
712                 Framework::JSRef<Framework::JSObject>::Cast(controllerObj)->Unwrap<Framework::JSTextController>();
713         }
714         RefPtr<TextControllerBase> controller =
715             TextModelNG::InitTextController(reinterpret_cast<FrameNode*>(nativeNode));
716         if (jsController) {
717             jsController->SetController(controller);
718         }
719     }
720     return panda::JSValueRef::Undefined(vm);
721 }
722 
SetHeightAdaptivePolicy(ArkUIRuntimeCallInfo * runtimeCallInfo)723 ArkUINativeModuleValue TextBridge::SetHeightAdaptivePolicy(ArkUIRuntimeCallInfo* runtimeCallInfo)
724 {
725     EcmaVM* vm = runtimeCallInfo->GetVM();
726     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
727     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
728     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
729     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
730     if (secondArg->IsNumber()
731         && secondArg->Int32Value(vm) >= static_cast<int32_t>(TextHeightAdaptivePolicy::MAX_LINES_FIRST)
732         && secondArg->Int32Value(vm) <= static_cast<int32_t>(TextHeightAdaptivePolicy::LAYOUT_CONSTRAINT_FIRST)) {
733         auto value = secondArg->Int32Value(vm);
734         GetArkUINodeModifiers()->getTextModifier()->setTextHeightAdaptivePolicy(nativeNode, value);
735     } else {
736         GetArkUINodeModifiers()->getTextModifier()->resetTextHeightAdaptivePolicy(nativeNode);
737     }
738     return panda::JSValueRef::Undefined(vm);
739 }
740 
ResetHeightAdaptivePolicy(ArkUIRuntimeCallInfo * runtimeCallInfo)741 ArkUINativeModuleValue TextBridge::ResetHeightAdaptivePolicy(ArkUIRuntimeCallInfo* runtimeCallInfo)
742 {
743     EcmaVM* vm = runtimeCallInfo->GetVM();
744     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
745     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
746     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
747     GetArkUINodeModifiers()->getTextModifier()->resetTextHeightAdaptivePolicy(nativeNode);
748     return panda::JSValueRef::Undefined(vm);
749 }
750 
SetTextIndent(ArkUIRuntimeCallInfo * runtimeCallInfo)751 ArkUINativeModuleValue TextBridge::SetTextIndent(ArkUIRuntimeCallInfo* runtimeCallInfo)
752 {
753     EcmaVM* vm = runtimeCallInfo->GetVM();
754     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
755     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
756     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
757     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
758     CalcDimension indent;
759     if (!ArkTSUtils::ParseJsDimensionFpNG(vm, secondArg, indent) || indent.IsNegative()) {
760         indent.Reset();
761     }
762 
763     GetArkUINodeModifiers()->getTextModifier()->setTextIndent(
764         nativeNode, indent.Value(), static_cast<int8_t>(indent.Unit()));
765     return panda::JSValueRef::Undefined(vm);
766 }
767 
ResetTextIndent(ArkUIRuntimeCallInfo * runtimeCallInfo)768 ArkUINativeModuleValue TextBridge::ResetTextIndent(ArkUIRuntimeCallInfo* runtimeCallInfo)
769 {
770     EcmaVM* vm = runtimeCallInfo->GetVM();
771     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
772     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
773     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
774     GetArkUINodeModifiers()->getTextModifier()->resetTextIndent(nativeNode);
775     return panda::JSValueRef::Undefined(vm);
776 }
777 
SetBaselineOffset(ArkUIRuntimeCallInfo * runtimeCallInfo)778 ArkUINativeModuleValue TextBridge::SetBaselineOffset(ArkUIRuntimeCallInfo* runtimeCallInfo)
779 {
780     EcmaVM* vm = runtimeCallInfo->GetVM();
781     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
782     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
783     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
784     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
785     CalcDimension baselineOffset;
786     if (!ArkTSUtils::ParseJsDimensionNG(vm, secondArg, baselineOffset, DimensionUnit::FP, false)) {
787         baselineOffset.Reset();
788     }
789 
790     GetArkUINodeModifiers()->getTextModifier()->setTextBaselineOffset(
791         nativeNode, baselineOffset.Value(), static_cast<int8_t>(baselineOffset.Unit()));
792     return panda::JSValueRef::Undefined(vm);
793 }
794 
ResetBaselineOffset(ArkUIRuntimeCallInfo * runtimeCallInfo)795 ArkUINativeModuleValue TextBridge::ResetBaselineOffset(ArkUIRuntimeCallInfo* runtimeCallInfo)
796 {
797     EcmaVM* vm = runtimeCallInfo->GetVM();
798     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
799     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
800     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
801     GetArkUINodeModifiers()->getTextModifier()->resetTextBaselineOffset(nativeNode);
802     return panda::JSValueRef::Undefined(vm);
803 }
804 
SetLetterSpacing(ArkUIRuntimeCallInfo * runtimeCallInfo)805 ArkUINativeModuleValue TextBridge::SetLetterSpacing(ArkUIRuntimeCallInfo* runtimeCallInfo)
806 {
807     EcmaVM* vm = runtimeCallInfo->GetVM();
808     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
809     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
810     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
811     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
812     CalcDimension letterSpacing;
813     if (!ArkTSUtils::ParseJsDimensionNG(vm, secondArg, letterSpacing, DimensionUnit::FP, false)) {
814         letterSpacing.Reset();
815     }
816 
817     GetArkUINodeModifiers()->getTextModifier()->setTextLetterSpacing(
818         nativeNode, letterSpacing.Value(), static_cast<int8_t>(letterSpacing.Unit()));
819     return panda::JSValueRef::Undefined(vm);
820 }
821 
ResetLetterSpacing(ArkUIRuntimeCallInfo * runtimeCallInfo)822 ArkUINativeModuleValue TextBridge::ResetLetterSpacing(ArkUIRuntimeCallInfo* runtimeCallInfo)
823 {
824     EcmaVM* vm = runtimeCallInfo->GetVM();
825     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
826     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
827     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
828     GetArkUINodeModifiers()->getTextModifier()->resetTextLetterSpacing(nativeNode);
829     return panda::JSValueRef::Undefined(vm);
830 }
831 
SetFont(ArkUIRuntimeCallInfo * runtimeCallInfo)832 ArkUINativeModuleValue TextBridge::SetFont(ArkUIRuntimeCallInfo* runtimeCallInfo)
833 {
834     EcmaVM* vm = runtimeCallInfo->GetVM();
835     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
836     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
837     Local<JSValueRef> sizeArg = runtimeCallInfo->GetCallArgRef(NUM_1);
838     Local<JSValueRef> weightArg = runtimeCallInfo->GetCallArgRef(NUM_2);
839     Local<JSValueRef> familyArg = runtimeCallInfo->GetCallArgRef(NUM_3);
840     Local<JSValueRef> styleArg = runtimeCallInfo->GetCallArgRef(NUM_4);
841     Local<JSValueRef> optionsArg = runtimeCallInfo->GetCallArgRef(NUM_5);
842 
843     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
844     ArkUIFontWithOptionsStruct fontInfo;
845     CalcDimension fontSize;
846     if (!ArkTSUtils::ParseJsDimensionFpNG(vm, sizeArg, fontSize, false) || sizeArg->IsNull()) {
847         fontSize.SetValue(DEFAULT_SPAN_FONT_SIZE);
848         fontSize.SetUnit(DEFAULT_SPAN_FONT_UNIT);
849     }
850     if (sizeArg->IsUndefined() || fontSize.IsNegative() || fontSize.Unit() == DimensionUnit::PERCENT) {
851         auto theme = ArkTSUtils::GetTheme<TextTheme>();
852         CHECK_NULL_RETURN(theme, panda::JSValueRef::Undefined(vm));
853         auto size = theme->GetTextStyle().GetFontSize();
854         fontInfo.fontSizeNumber = size.Value();
855         fontInfo.fontSizeUnit = static_cast<int8_t>(size.Unit());
856     } else {
857         fontInfo.fontSizeNumber = fontSize.Value();
858         fontInfo.fontSizeUnit = static_cast<int8_t>(fontSize.Unit());
859     }
860 
861     int32_t variableFontWeight = DEFAULT_VARIABLE_FONT_WEIGHT;
862     std::string weight = DEFAULT_FONT_WEIGHT;
863     if (!weightArg->IsNull()) {
864         if (weightArg->IsNumber()) {
865             weight = std::to_string(weightArg->Int32Value(vm));
866             variableFontWeight = weightArg->Int32Value(vm);
867         } else if (weightArg->IsString(vm)) {
868             weight = weightArg->ToString(vm)->ToString(vm);
869             variableFontWeight = StringUtils::StringToInt(weight);
870         }
871     }
872     fontInfo.fontWeight = static_cast<uint8_t>(Framework::ConvertStrToFontWeight(weight));
873     fontInfo.variableFontWeight = variableFontWeight;
874 
875     if (optionsArg->IsBoolean()) {
876         fontInfo.enableVariableFontWeight = static_cast<int32_t>(optionsArg->BooleaValue(vm));
877     }
878 
879     int32_t style = static_cast<int32_t>(DEFAULT_FONT_STYLE);
880     if (styleArg->IsInt()) {
881         style = styleArg->Int32Value(vm);
882     }
883     fontInfo.fontStyle = static_cast<uint8_t>(style);
884 
885     std::vector<std::string> fontFamilies;
886     fontInfo.fontFamilies = nullptr;
887     if (!familyArg->IsNull() && ArkTSUtils::ParseJsFontFamilies(vm, familyArg, fontFamilies)) {
888         fontInfo.familyLength = fontFamilies.size();
889         auto families = std::make_unique<const char* []>(fontInfo.familyLength);
890         for (uint32_t i = 0; i < fontFamilies.size(); i++) {
891             families[i] = fontFamilies[i].c_str();
892         }
893         fontInfo.fontFamilies = families.get();
894         GetArkUINodeModifiers()->getTextModifier()->setTextFont(nativeNode, &fontInfo);
895     } else {
896         GetArkUINodeModifiers()->getTextModifier()->setTextFont(nativeNode, &fontInfo);
897     }
898     return panda::JSValueRef::Undefined(vm);
899 }
900 
ResetFont(ArkUIRuntimeCallInfo * runtimeCallInfo)901 ArkUINativeModuleValue TextBridge::ResetFont(ArkUIRuntimeCallInfo* runtimeCallInfo)
902 {
903     EcmaVM* vm = runtimeCallInfo->GetVM();
904     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
905     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
906     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
907     GetArkUINodeModifiers()->getTextModifier()->resetTextFont(nativeNode);
908     return panda::JSValueRef::Undefined(vm);
909 }
910 
SetWordBreak(ArkUIRuntimeCallInfo * runtimeCallInfo)911 ArkUINativeModuleValue TextBridge::SetWordBreak(ArkUIRuntimeCallInfo* runtimeCallInfo)
912 {
913     EcmaVM* vm = runtimeCallInfo->GetVM();
914     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
915     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
916     Local<JSValueRef> workBreakArg = runtimeCallInfo->GetCallArgRef(NUM_1);
917     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
918     if (workBreakArg->IsNull() || workBreakArg->IsUndefined() || !workBreakArg->IsNumber()) {
919         GetArkUINodeModifiers()->getTextModifier()->resetWordBreak(nativeNode);
920         return panda::JSValueRef::Undefined(vm);
921     }
922     uint32_t wordBreak = workBreakArg->Uint32Value(vm);
923     GetArkUINodeModifiers()->getTextModifier()->setWordBreak(nativeNode, wordBreak);
924     return panda::JSValueRef::Undefined(vm);
925 }
926 
ResetWordBreak(ArkUIRuntimeCallInfo * runtimeCallInfo)927 ArkUINativeModuleValue TextBridge::ResetWordBreak(ArkUIRuntimeCallInfo* runtimeCallInfo)
928 {
929     EcmaVM* vm = runtimeCallInfo->GetVM();
930     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
931     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
932     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
933     GetArkUINodeModifiers()->getTextModifier()->resetWordBreak(nativeNode);
934     return panda::JSValueRef::Undefined(vm);
935 }
936 
SetLineBreakStrategy(ArkUIRuntimeCallInfo * runtimeCallInfo)937 ArkUINativeModuleValue TextBridge::SetLineBreakStrategy(ArkUIRuntimeCallInfo* runtimeCallInfo)
938 {
939     EcmaVM* vm = runtimeCallInfo->GetVM();
940     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
941     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
942     Local<JSValueRef> lineBreakStrategyArg = runtimeCallInfo->GetCallArgRef(NUM_1);
943     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
944     if (lineBreakStrategyArg->IsNull() || lineBreakStrategyArg->IsUndefined() || !lineBreakStrategyArg->IsNumber()) {
945         GetArkUINodeModifiers()->getTextModifier()->resetLineBreakStrategy(nativeNode);
946         return panda::JSValueRef::Undefined(vm);
947     }
948     uint32_t lineBreakStrategy = lineBreakStrategyArg->Uint32Value(vm);
949     GetArkUINodeModifiers()->getTextModifier()->setLineBreakStrategy(nativeNode, lineBreakStrategy);
950     return panda::JSValueRef::Undefined(vm);
951 }
952 
ResetLineBreakStrategy(ArkUIRuntimeCallInfo * runtimeCallInfo)953 ArkUINativeModuleValue TextBridge::ResetLineBreakStrategy(ArkUIRuntimeCallInfo* runtimeCallInfo)
954 {
955     EcmaVM* vm = runtimeCallInfo->GetVM();
956     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
957     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
958     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
959     GetArkUINodeModifiers()->getTextModifier()->resetLineBreakStrategy(nativeNode);
960     return panda::JSValueRef::Undefined(vm);
961 }
962 
SetEllipsisMode(ArkUIRuntimeCallInfo * runtimeCallInfo)963 ArkUINativeModuleValue TextBridge::SetEllipsisMode(ArkUIRuntimeCallInfo* runtimeCallInfo)
964 {
965     EcmaVM* vm = runtimeCallInfo->GetVM();
966     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
967     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
968     Local<JSValueRef> ellipsisModeArg = runtimeCallInfo->GetCallArgRef(NUM_1);
969     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
970     if (ellipsisModeArg->IsNull() || ellipsisModeArg->IsUndefined() || !ellipsisModeArg->IsNumber()) {
971         GetArkUINodeModifiers()->getTextModifier()->resetEllipsisMode(nativeNode);
972         return panda::JSValueRef::Undefined(vm);
973     }
974     uint32_t ellipsisMode = ellipsisModeArg->Uint32Value(vm);
975     GetArkUINodeModifiers()->getTextModifier()->setEllipsisMode(nativeNode, ellipsisMode);
976     return panda::JSValueRef::Undefined(vm);
977 }
978 
ResetEllipsisMode(ArkUIRuntimeCallInfo * runtimeCallInfo)979 ArkUINativeModuleValue TextBridge::ResetEllipsisMode(ArkUIRuntimeCallInfo* runtimeCallInfo)
980 {
981     EcmaVM* vm = runtimeCallInfo->GetVM();
982     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
983     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
984     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
985     GetArkUINodeModifiers()->getTextModifier()->resetEllipsisMode(nativeNode);
986     return panda::JSValueRef::Undefined(vm);
987 }
988 
SetEnableDataDetector(ArkUIRuntimeCallInfo * runtimeCallInfo)989 ArkUINativeModuleValue TextBridge::SetEnableDataDetector(ArkUIRuntimeCallInfo* runtimeCallInfo)
990 {
991     EcmaVM* vm = runtimeCallInfo->GetVM();
992     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
993     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
994     Local<JSValueRef> enableDataDetectorArg = runtimeCallInfo->GetCallArgRef(NUM_1);
995     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
996     if (enableDataDetectorArg->IsNull() || enableDataDetectorArg->IsUndefined() ||
997         !enableDataDetectorArg->IsBoolean()) {
998         GetArkUINodeModifiers()->getTextModifier()->resetEnableDataDetector(nativeNode);
999         return panda::JSValueRef::Undefined(vm);
1000     }
1001     uint32_t enableDataDetector = enableDataDetectorArg->Uint32Value(vm);
1002     GetArkUINodeModifiers()->getTextModifier()->setEnableDataDetector(nativeNode, enableDataDetector);
1003     return panda::JSValueRef::Undefined(vm);
1004 }
1005 
ResetEnableDataDetector(ArkUIRuntimeCallInfo * runtimeCallInfo)1006 ArkUINativeModuleValue TextBridge::ResetEnableDataDetector(ArkUIRuntimeCallInfo* runtimeCallInfo)
1007 {
1008     EcmaVM* vm = runtimeCallInfo->GetVM();
1009     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
1010     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
1011     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
1012     GetArkUINodeModifiers()->getTextModifier()->resetEnableDataDetector(nativeNode);
1013     return panda::JSValueRef::Undefined(vm);
1014 }
1015 
SetFontFeature(ArkUIRuntimeCallInfo * runtimeCallInfo)1016 ArkUINativeModuleValue TextBridge::SetFontFeature(ArkUIRuntimeCallInfo* runtimeCallInfo)
1017 {
1018     EcmaVM* vm = runtimeCallInfo->GetVM();
1019     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
1020     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
1021     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
1022     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
1023     if (secondArg->IsString(vm)) {
1024         auto value = secondArg->ToString(vm)->ToString(vm);
1025         GetArkUINodeModifiers()->getTextModifier()->setTextFontFeature(nativeNode, value.c_str());
1026     } else {
1027         GetArkUINodeModifiers()->getTextModifier()->resetTextFontFeature(nativeNode);
1028     }
1029     return panda::JSValueRef::Undefined(vm);
1030 }
1031 
ResetFontFeature(ArkUIRuntimeCallInfo * runtimeCallInfo)1032 ArkUINativeModuleValue TextBridge::ResetFontFeature(ArkUIRuntimeCallInfo* runtimeCallInfo)
1033 {
1034     EcmaVM* vm = runtimeCallInfo->GetVM();
1035     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
1036     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
1037     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
1038     GetArkUINodeModifiers()->getTextModifier()->resetTextFontFeature(nativeNode);
1039     return panda::JSValueRef::Undefined(vm);
1040 }
1041 
SetLineSpacing(ArkUIRuntimeCallInfo * runtimeCallInfo)1042 ArkUINativeModuleValue TextBridge::SetLineSpacing(ArkUIRuntimeCallInfo* runtimeCallInfo)
1043 {
1044     EcmaVM* vm = runtimeCallInfo->GetVM();
1045     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
1046     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
1047     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
1048     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
1049     CalcDimension value;
1050     if (!ArkTSUtils::ParseJsLengthMetrics(vm, secondArg, value)) {
1051         GetArkUINodeModifiers()->getTextModifier()->resetTextLineSpacing(nativeNode);
1052     } else {
1053         if (value.IsNegative()) {
1054             value.Reset();
1055         }
1056         GetArkUINodeModifiers()->getTextModifier()->setTextLineSpacing(
1057             nativeNode, value.Value(), static_cast<int>(value.Unit()));
1058     }
1059     return panda::JSValueRef::Undefined(vm);
1060 }
1061 
ResetLineSpacing(ArkUIRuntimeCallInfo * runtimeCallInfo)1062 ArkUINativeModuleValue TextBridge::ResetLineSpacing(ArkUIRuntimeCallInfo* runtimeCallInfo)
1063 {
1064     EcmaVM* vm = runtimeCallInfo->GetVM();
1065     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
1066     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
1067     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
1068     GetArkUINodeModifiers()->getTextModifier()->resetTextLineSpacing(nativeNode);
1069     return panda::JSValueRef::Undefined(vm);
1070 }
1071 
SetSelection(ArkUIRuntimeCallInfo * runtimeCallInfo)1072 ArkUINativeModuleValue TextBridge::SetSelection(ArkUIRuntimeCallInfo* runtimeCallInfo)
1073 {
1074     EcmaVM* vm = runtimeCallInfo->GetVM();
1075     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
1076     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
1077     Local<JSValueRef> startArg = runtimeCallInfo->GetCallArgRef(NUM_1);
1078     Local<JSValueRef> endArg = runtimeCallInfo->GetCallArgRef(NUM_2);
1079     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
1080     if (!startArg->IsNumber() || !endArg->IsNumber()) {
1081         GetArkUINodeModifiers()->getTextModifier()->resetTextSelection(nativeNode);
1082         return panda::JSValueRef::Undefined(vm);
1083     }
1084     int32_t startIndex = startArg->Int32Value(vm);
1085     int32_t endIndex = endArg->Int32Value(vm);
1086     if (startIndex >= endIndex) {
1087         GetArkUINodeModifiers()->getTextModifier()->resetTextSelection(nativeNode);
1088         return panda::JSValueRef::Undefined(vm);
1089     }
1090     GetArkUINodeModifiers()->getTextModifier()->setTextSelection(nativeNode, startIndex, endIndex);
1091     return panda::JSValueRef::Undefined(vm);
1092 }
1093 
ResetSelection(ArkUIRuntimeCallInfo * runtimeCallInfo)1094 ArkUINativeModuleValue TextBridge::ResetSelection(ArkUIRuntimeCallInfo* runtimeCallInfo)
1095 {
1096     EcmaVM* vm = runtimeCallInfo->GetVM();
1097     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
1098     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
1099     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
1100     GetArkUINodeModifiers()->getTextModifier()->resetTextSelection(nativeNode);
1101     return panda::JSValueRef::Undefined(vm);
1102 }
1103 
SetTextSelectableMode(ArkUIRuntimeCallInfo * runtimeCallInfo)1104 ArkUINativeModuleValue TextBridge::SetTextSelectableMode(ArkUIRuntimeCallInfo* runtimeCallInfo)
1105 {
1106     EcmaVM* vm = runtimeCallInfo->GetVM();
1107     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
1108     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
1109     Local<JSValueRef> textSelectableModeArg = runtimeCallInfo->GetCallArgRef(NUM_1);
1110     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
1111     if (textSelectableModeArg->IsNull() || textSelectableModeArg->IsUndefined() || !textSelectableModeArg->IsNumber()) {
1112         GetArkUINodeModifiers()->getTextModifier()->resetTextSelectableMode(nativeNode);
1113         return panda::JSValueRef::Undefined(vm);
1114     }
1115     uint32_t textSelectableMode = textSelectableModeArg->Uint32Value(vm);
1116     GetArkUINodeModifiers()->getTextModifier()->setTextSelectableMode(nativeNode, textSelectableMode);
1117     return panda::JSValueRef::Undefined(vm);
1118 }
1119 
ResetTextSelectableMode(ArkUIRuntimeCallInfo * runtimeCallInfo)1120 ArkUINativeModuleValue TextBridge::ResetTextSelectableMode(ArkUIRuntimeCallInfo* runtimeCallInfo)
1121 {
1122     EcmaVM* vm = runtimeCallInfo->GetVM();
1123     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
1124     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
1125     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
1126     GetArkUINodeModifiers()->getTextModifier()->resetTextSelectableMode(nativeNode);
1127     return panda::JSValueRef::Undefined(vm);
1128 }
1129 
SetCaretColor(ArkUIRuntimeCallInfo * runtimeCallInfo)1130 ArkUINativeModuleValue TextBridge::SetCaretColor(ArkUIRuntimeCallInfo *runtimeCallInfo)
1131 {
1132     EcmaVM *vm = runtimeCallInfo->GetVM();
1133     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
1134     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
1135     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
1136     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
1137     Color color;
1138     if (!ArkTSUtils::ParseJsColorAlpha(vm, secondArg, color)) {
1139         GetArkUINodeModifiers()->getTextModifier()->resetTextCaretColor(nativeNode);
1140     } else {
1141         GetArkUINodeModifiers()->getTextModifier()->setTextCaretColor(nativeNode, color.GetValue());
1142     }
1143     return panda::JSValueRef::Undefined(vm);
1144 }
1145 
ResetCaretColor(ArkUIRuntimeCallInfo * runtimeCallInfo)1146 ArkUINativeModuleValue TextBridge::ResetCaretColor(ArkUIRuntimeCallInfo *runtimeCallInfo)
1147 {
1148     EcmaVM *vm = runtimeCallInfo->GetVM();
1149     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
1150     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
1151     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
1152     GetArkUINodeModifiers()->getTextModifier()->resetTextCaretColor(nativeNode);
1153     return panda::JSValueRef::Undefined(vm);
1154 }
1155 
SetSelectedBackgroundColor(ArkUIRuntimeCallInfo * runtimeCallInfo)1156 ArkUINativeModuleValue TextBridge::SetSelectedBackgroundColor(ArkUIRuntimeCallInfo *runtimeCallInfo)
1157 {
1158     EcmaVM *vm = runtimeCallInfo->GetVM();
1159     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
1160     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
1161     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
1162     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
1163     Color color;
1164     if (!ArkTSUtils::ParseJsColorAlpha(vm, secondArg, color)) {
1165         GetArkUINodeModifiers()->getTextModifier()->resetTextSelectedBackgroundColor(nativeNode);
1166     } else {
1167         if (color.GetAlpha() == DEFAULT_ALPHA) {
1168             color = color.ChangeOpacity(DEFAULT_OPACITY);
1169         }
1170         GetArkUINodeModifiers()->getTextModifier()->setTextSelectedBackgroundColor(
1171             nativeNode, color.GetValue());
1172     }
1173     return panda::JSValueRef::Undefined(vm);
1174 }
1175 
ResetSelectedBackgroundColor(ArkUIRuntimeCallInfo * runtimeCallInfo)1176 ArkUINativeModuleValue TextBridge::ResetSelectedBackgroundColor(ArkUIRuntimeCallInfo *runtimeCallInfo)
1177 {
1178     EcmaVM *vm = runtimeCallInfo->GetVM();
1179     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
1180     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
1181     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
1182     GetArkUINodeModifiers()->getTextModifier()->resetTextSelectedBackgroundColor(nativeNode);
1183     return panda::JSValueRef::Undefined(vm);
1184 }
1185 
SetDataDetectorConfig(ArkUIRuntimeCallInfo * runtimeCallInfo)1186 ArkUINativeModuleValue TextBridge::SetDataDetectorConfig(ArkUIRuntimeCallInfo* runtimeCallInfo)
1187 {
1188     EcmaVM* vm = runtimeCallInfo->GetVM();
1189     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
1190     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
1191     Local<JSValueRef> typesArg = runtimeCallInfo->GetCallArgRef(NUM_1);
1192     Local<JSValueRef> callbackArg = runtimeCallInfo->GetCallArgRef(NUM_2);
1193     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
1194     auto frameNode = reinterpret_cast<FrameNode*>(nativeNode);
1195     CHECK_NULL_RETURN(frameNode, panda::NativePointerRef::New(vm, nullptr));
1196     if (!typesArg->IsArray(vm)) {
1197         GetArkUINodeModifiers()->getTextModifier()->
1198             resetTextDataDetectorConfigWithEvent(nativeNode);
1199         return panda::JSValueRef::Undefined(vm);
1200     }
1201 
1202     struct ArkUITextDetectConfigStruct arkUITextDetectConfig;
1203     std::string types;
1204     auto array = panda::Local<panda::ArrayRef>(typesArg);
1205     for (size_t i = 0; i < array->Length(vm); i++) {
1206         auto value = panda::ArrayRef::GetValueAt(vm, array, i);
1207         auto index = value->Int32Value(vm);
1208         if (index < 0 || index >= static_cast<int32_t>(TEXT_DETECT_TYPES.size())) {
1209             return panda::NativePointerRef::New(vm, nullptr);
1210         }
1211         if (i != 0) {
1212             types.append(",");
1213         }
1214         types.append(TEXT_DETECT_TYPES[index]);
1215     }
1216     arkUITextDetectConfig.types = types.c_str();
1217     std::function<void(const std::string&)> callback;
1218     if (callbackArg->IsFunction(vm)) {
1219         panda::Local<panda::FunctionRef> func = callbackArg->ToObject(vm);
1220         callback = [vm, frameNode, func = panda::CopyableGlobal(vm, func)](const std::string& info) {
1221             panda::LocalScope pandaScope(vm);
1222             panda::TryCatch trycatch(vm);
1223             PipelineContext::SetCallBackNode(AceType::WeakClaim(frameNode));
1224             panda::Local<panda::JSValueRef> params[PARAM_ARR_LENGTH_1] = {
1225                 panda::StringRef::NewFromUtf8(vm, info.c_str()) };
1226             func->Call(vm, func.ToLocal(), params, PARAM_ARR_LENGTH_1);
1227         };
1228         arkUITextDetectConfig.onResult = reinterpret_cast<void*>(&callback);
1229     }
1230     ParseAIEntityColor(runtimeCallInfo, arkUITextDetectConfig);
1231     GetArkUINodeModifiers()->getTextModifier()->
1232         setTextDataDetectorConfigWithEvent(nativeNode, &arkUITextDetectConfig);
1233     return panda::JSValueRef::Undefined(vm);
1234 }
1235 
ParseAIEntityColor(ArkUIRuntimeCallInfo * runtimeCallInfo,struct ArkUITextDetectConfigStruct & arkUITextDetectConfig)1236 void TextBridge::ParseAIEntityColor(
1237     ArkUIRuntimeCallInfo* runtimeCallInfo, struct ArkUITextDetectConfigStruct& arkUITextDetectConfig)
1238 {
1239     EcmaVM* vm = runtimeCallInfo->GetVM();
1240     CHECK_NULL_VOID(vm);
1241     TextDetectConfig textDetectConfig;
1242     Local<JSValueRef> entityColorArg = runtimeCallInfo->GetCallArgRef(NUM_3);
1243     ArkTSUtils::ParseJsColorAlpha(vm, entityColorArg, textDetectConfig.entityColor);
1244     arkUITextDetectConfig.entityColor = textDetectConfig.entityColor.GetValue();
1245 
1246     Local<JSValueRef> entityDecorationTypeArg = runtimeCallInfo->GetCallArgRef(NUM_4);
1247     Local<JSValueRef> entityDecorationColorArg = runtimeCallInfo->GetCallArgRef(NUM_5);
1248     Local<JSValueRef> entityDecorationStyleArg = runtimeCallInfo->GetCallArgRef(NUM_6);
1249     arkUITextDetectConfig.entityDecorationType = static_cast<int32_t>(textDetectConfig.entityDecorationType);
1250     arkUITextDetectConfig.entityDecorationColor = arkUITextDetectConfig.entityColor;
1251     arkUITextDetectConfig.entityDecorationStyle = static_cast<int32_t>(textDetectConfig.entityDecorationStyle);
1252 
1253     if (entityDecorationTypeArg->IsInt()) {
1254         arkUITextDetectConfig.entityDecorationType = entityDecorationTypeArg->Int32Value(vm);
1255     }
1256     if (ArkTSUtils::ParseJsColorAlpha(vm, entityDecorationColorArg, textDetectConfig.entityDecorationColor)) {
1257         arkUITextDetectConfig.entityDecorationColor = textDetectConfig.entityDecorationColor.GetValue();
1258     }
1259     if (entityDecorationStyleArg->IsInt()) {
1260         arkUITextDetectConfig.entityDecorationStyle = entityDecorationStyleArg->Int32Value(vm);
1261     }
1262 }
1263 
ResetDataDetectorConfig(ArkUIRuntimeCallInfo * runtimeCallInfo)1264 ArkUINativeModuleValue TextBridge::ResetDataDetectorConfig(ArkUIRuntimeCallInfo* runtimeCallInfo)
1265 {
1266     EcmaVM* vm = runtimeCallInfo->GetVM();
1267     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
1268     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
1269     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
1270     GetArkUINodeModifiers()->getTextModifier()->
1271         resetTextDataDetectorConfigWithEvent(nativeNode);
1272     return panda::JSValueRef::Undefined(vm);
1273 }
1274 
SetOnCopy(ArkUIRuntimeCallInfo * runtimeCallInfo)1275 ArkUINativeModuleValue TextBridge::SetOnCopy(ArkUIRuntimeCallInfo* runtimeCallInfo)
1276 {
1277     EcmaVM *vm = runtimeCallInfo->GetVM();
1278     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
1279     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
1280     Local<JSValueRef> callbackArg = runtimeCallInfo->GetCallArgRef(1);
1281     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
1282     auto frameNode = reinterpret_cast<FrameNode*>(nativeNode);
1283     CHECK_NULL_RETURN(frameNode, panda::NativePointerRef::New(vm, nullptr));
1284     if (callbackArg->IsUndefined() || callbackArg->IsNull() || !callbackArg->IsFunction(vm)) {
1285         GetArkUINodeModifiers()->getTextModifier()->resetTextOnCopy(nativeNode);
1286         return panda::JSValueRef::Undefined(vm);
1287     }
1288     panda::Local<panda::FunctionRef> func = callbackArg->ToObject(vm);
1289     std::function<void(const std::u16string&)> callback = [vm, frameNode,
1290         func = panda::CopyableGlobal(vm, func)](const std::u16string& copyStr) {
1291         panda::LocalScope pandaScope(vm);
1292         panda::TryCatch trycatch(vm);
1293         PipelineContext::SetCallBackNode(AceType::WeakClaim(frameNode));
1294         panda::Local<panda::JSValueRef> params[PARAM_ARR_LENGTH_1] = {
1295             panda::StringRef::NewFromUtf16(vm, copyStr.c_str()) };
1296         func->Call(vm, func.ToLocal(), params, PARAM_ARR_LENGTH_1);
1297     };
1298     GetArkUINodeModifiers()->getTextModifier()->setTextOnCopy(nativeNode, reinterpret_cast<void*>(&callback));
1299     return panda::JSValueRef::Undefined(vm);
1300 }
1301 
ResetOnCopy(ArkUIRuntimeCallInfo * runtimeCallInfo)1302 ArkUINativeModuleValue TextBridge::ResetOnCopy(ArkUIRuntimeCallInfo* runtimeCallInfo)
1303 {
1304     EcmaVM* vm = runtimeCallInfo->GetVM();
1305     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
1306     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
1307     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
1308     GetArkUINodeModifiers()->getTextModifier()->resetTextOnCopy(nativeNode);
1309     return panda::JSValueRef::Undefined(vm);
1310 }
1311 
SetOnTextSelectionChange(ArkUIRuntimeCallInfo * runtimeCallInfo)1312 ArkUINativeModuleValue TextBridge::SetOnTextSelectionChange(ArkUIRuntimeCallInfo* runtimeCallInfo)
1313 {
1314     EcmaVM *vm = runtimeCallInfo->GetVM();
1315     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
1316     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
1317     Local<JSValueRef> callbackArg = runtimeCallInfo->GetCallArgRef(1);
1318     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
1319     auto frameNode = reinterpret_cast<FrameNode*>(nativeNode);
1320     CHECK_NULL_RETURN(frameNode, panda::NativePointerRef::New(vm, nullptr));
1321     if (callbackArg->IsUndefined() || callbackArg->IsNull() || !callbackArg->IsFunction(vm)) {
1322         GetArkUINodeModifiers()->getTextModifier()->resetTextOnTextSelectionChange(nativeNode);
1323         return panda::JSValueRef::Undefined(vm);
1324     }
1325     panda::Local<panda::FunctionRef> func = callbackArg->ToObject(vm);
1326     std::function<void(int32_t, int32_t)> callback = [vm, frameNode,
1327         func = panda::CopyableGlobal(vm, func)](int32_t selectionStart, int32_t selectionEnd) {
1328         panda::LocalScope pandaScope(vm);
1329         panda::TryCatch trycatch(vm);
1330         PipelineContext::SetCallBackNode(AceType::WeakClaim(frameNode));
1331         panda::Local<panda::NumberRef> startParam = panda::NumberRef::New(vm, selectionStart);
1332         panda::Local<panda::NumberRef> endParam = panda::NumberRef::New(vm, selectionEnd);
1333         panda::Local<panda::JSValueRef> params[PARAM_ARR_LENGTH_2] = { startParam, endParam };
1334         func->Call(vm, func.ToLocal(), params, PARAM_ARR_LENGTH_2);
1335     };
1336     GetArkUINodeModifiers()->getTextModifier()->setTextOnTextSelectionChange(
1337         nativeNode, reinterpret_cast<void*>(&callback));
1338     return panda::JSValueRef::Undefined(vm);
1339 }
1340 
ResetOnTextSelectionChange(ArkUIRuntimeCallInfo * runtimeCallInfo)1341 ArkUINativeModuleValue TextBridge::ResetOnTextSelectionChange(ArkUIRuntimeCallInfo* runtimeCallInfo)
1342 {
1343     EcmaVM* vm = runtimeCallInfo->GetVM();
1344     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
1345     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
1346     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
1347     GetArkUINodeModifiers()->getTextModifier()->resetTextOnTextSelectionChange(nativeNode);
1348     return panda::JSValueRef::Undefined(vm);
1349 }
1350 
SetSelectionMenuOptions(ArkUIRuntimeCallInfo * runtimeCallInfo)1351 ArkUINativeModuleValue TextBridge::SetSelectionMenuOptions(ArkUIRuntimeCallInfo* runtimeCallInfo)
1352 {
1353     EcmaVM* vm = runtimeCallInfo->GetVM();
1354     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
1355     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
1356     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
1357     NG::OnCreateMenuCallback onCreateMenuCallback;
1358     NG::OnMenuItemClickCallback onMenuItemClickCallback;
1359     if (!ArkTSUtils::ParseSelectionMenuOptions(runtimeCallInfo, vm, onCreateMenuCallback, onMenuItemClickCallback)) {
1360         GetArkUINodeModifiers()->getTextModifier()->resetTextSelectionMenuOptions(nativeNode);
1361         return panda::JSValueRef::Undefined(vm);
1362     }
1363     GetArkUINodeModifiers()->getTextModifier()->setTextSelectionMenuOptions(
1364         nativeNode, reinterpret_cast<void*>(&onCreateMenuCallback), reinterpret_cast<void*>(&onMenuItemClickCallback));
1365     return panda::JSValueRef::Undefined(vm);
1366 }
1367 
ResetSelectionMenuOptions(ArkUIRuntimeCallInfo * runtimeCallInfo)1368 ArkUINativeModuleValue TextBridge::ResetSelectionMenuOptions(ArkUIRuntimeCallInfo* runtimeCallInfo)
1369 {
1370     EcmaVM* vm = runtimeCallInfo->GetVM();
1371     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
1372     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
1373     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
1374     GetArkUINodeModifiers()->getTextModifier()->resetTextSelectionMenuOptions(nativeNode);
1375     return panda::JSValueRef::Undefined(vm);
1376 }
1377 
SetHalfLeading(ArkUIRuntimeCallInfo * runtimeCallInfo)1378 ArkUINativeModuleValue TextBridge::SetHalfLeading(ArkUIRuntimeCallInfo* runtimeCallInfo)
1379 {
1380     EcmaVM* vm = runtimeCallInfo->GetVM();
1381     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
1382     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
1383     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
1384     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
1385     bool halfLeading = false;
1386     if (secondArg->IsBoolean()) {
1387         halfLeading = secondArg->ToBoolean(vm)->Value();
1388     }
1389     GetArkUINodeModifiers()->getTextModifier()->setTextHalfLeading(nativeNode, halfLeading);
1390     return panda::JSValueRef::Undefined(vm);
1391 }
1392 
ResetHalfLeading(ArkUIRuntimeCallInfo * runtimeCallInfo)1393 ArkUINativeModuleValue TextBridge::ResetHalfLeading(ArkUIRuntimeCallInfo* runtimeCallInfo)
1394 {
1395     EcmaVM* vm = runtimeCallInfo->GetVM();
1396     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
1397     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
1398     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
1399     GetArkUINodeModifiers()->getTextModifier()->resetTextHalfLeading(nativeNode);
1400     return panda::JSValueRef::Undefined(vm);
1401 }
1402 
SetOnClick(ArkUIRuntimeCallInfo * runtimeCallInfo)1403 ArkUINativeModuleValue TextBridge::SetOnClick(ArkUIRuntimeCallInfo* runtimeCallInfo)
1404 {
1405     EcmaVM *vm = runtimeCallInfo->GetVM();
1406     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
1407     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
1408     Local<JSValueRef> callbackArg = runtimeCallInfo->GetCallArgRef(1);
1409     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
1410     auto frameNode = reinterpret_cast<FrameNode*>(nativeNode);
1411     CHECK_NULL_RETURN(frameNode, panda::NativePointerRef::New(vm, nullptr));
1412     if (callbackArg->IsUndefined() || callbackArg->IsNull() || !callbackArg->IsFunction(vm)) {
1413         GetArkUINodeModifiers()->getTextModifier()->resetTextOnClick(nativeNode);
1414         return panda::JSValueRef::Undefined(vm);
1415     }
1416     panda::Local<panda::FunctionRef> func = callbackArg->ToObject(vm);
1417     auto containerId = Container::CurrentId();
1418     std::function<void(GestureEvent& info)> callback = [vm,
1419         func = panda::CopyableGlobal(vm, func), containerId, node = AceType::WeakClaim(frameNode)]
1420         (GestureEvent& info) {
1421         panda::LocalScope pandaScope(vm);
1422         panda::TryCatch trycatch(vm);
1423         ContainerScope scope(containerId);
1424         PipelineContext::SetCallBackNode(node);
1425         auto obj = FrameNodeBridge::CreateGestureEventInfo(vm, info);
1426         panda::Local<panda::JSValueRef> params[1] = { obj };
1427         func->Call(vm, func.ToLocal(), params, 1);
1428     };
1429     GetArkUINodeModifiers()->getTextModifier()->setTextOnClick(
1430         nativeNode, reinterpret_cast<void*>(&callback));
1431     return panda::JSValueRef::Undefined(vm);
1432 }
1433 
ResetOnClick(ArkUIRuntimeCallInfo * runtimeCallInfo)1434 ArkUINativeModuleValue TextBridge::ResetOnClick(ArkUIRuntimeCallInfo* runtimeCallInfo)
1435 {
1436     EcmaVM* vm = runtimeCallInfo->GetVM();
1437     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
1438     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
1439     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
1440     GetArkUINodeModifiers()->getTextModifier()->resetTextOnClick(nativeNode);
1441     return panda::JSValueRef::Undefined(vm);
1442 }
1443 
SetResponseRegion(ArkUIRuntimeCallInfo * runtimeCallInfo)1444 ArkUINativeModuleValue TextBridge::SetResponseRegion(ArkUIRuntimeCallInfo* runtimeCallInfo)
1445 {
1446     EcmaVM* vm = runtimeCallInfo->GetVM();
1447     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
1448     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
1449     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
1450     Local<JSValueRef> thirdArg = runtimeCallInfo->GetCallArgRef(NUM_2);
1451     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
1452     int32_t length = thirdArg->Int32Value(vm);
1453     ArkUI_Float32 regionArray[length];
1454     int32_t regionUnits[length];
1455     if (!ArkTSUtils::ParseResponseRegion(vm, secondArg, regionArray, regionUnits, length)) {
1456         GetArkUINodeModifiers()->getTextModifier()->resetTextResponseRegion(nativeNode);
1457         return panda::JSValueRef::Undefined(vm);
1458     }
1459     GetArkUINodeModifiers()->getTextModifier()->setTextResponseRegion(nativeNode, regionArray, regionUnits, length);
1460     return panda::JSValueRef::Undefined(vm);
1461 }
1462 
ResetResponseRegion(ArkUIRuntimeCallInfo * runtimeCallInfo)1463 ArkUINativeModuleValue TextBridge::ResetResponseRegion(ArkUIRuntimeCallInfo* runtimeCallInfo)
1464 {
1465     EcmaVM* vm = runtimeCallInfo->GetVM();
1466     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
1467     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
1468     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
1469     GetArkUINodeModifiers()->getTextModifier()->resetTextResponseRegion(nativeNode);
1470     return panda::JSValueRef::Undefined(vm);
1471 }
1472 
SetEnableHapticFeedback(ArkUIRuntimeCallInfo * runtimeCallInfo)1473 ArkUINativeModuleValue TextBridge::SetEnableHapticFeedback(ArkUIRuntimeCallInfo* runtimeCallInfo)
1474 {
1475     EcmaVM* vm = runtimeCallInfo->GetVM();
1476     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
1477     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
1478     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
1479     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
1480 
1481     if (secondArg->IsBoolean()) {
1482         uint32_t value = static_cast<uint32_t>(secondArg->ToBoolean(vm)->Value());
1483         GetArkUINodeModifiers()->getTextModifier()->setTextEnableHapticFeedback(nativeNode, value);
1484     } else {
1485         GetArkUINodeModifiers()->getTextModifier()->resetTextEnableHapticFeedback(nativeNode);
1486     }
1487     return panda::JSValueRef::Undefined(vm);
1488 }
1489 
ResetEnableHapticFeedback(ArkUIRuntimeCallInfo * runtimeCallInfo)1490 ArkUINativeModuleValue TextBridge::ResetEnableHapticFeedback(ArkUIRuntimeCallInfo* runtimeCallInfo)
1491 {
1492     EcmaVM* vm = runtimeCallInfo->GetVM();
1493     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
1494     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
1495     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
1496     GetArkUINodeModifiers()->getTextModifier()->resetTextEnableHapticFeedback(nativeNode);
1497     return panda::JSValueRef::Undefined(vm);
1498 }
1499 
SetMarqueeOptions(ArkUIRuntimeCallInfo * runtimeCallInfo)1500 ArkUINativeModuleValue TextBridge::SetMarqueeOptions(ArkUIRuntimeCallInfo* runtimeCallInfo)
1501 {
1502     EcmaVM* vm = runtimeCallInfo->GetVM();
1503     CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
1504     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
1505     Local<JSValueRef> startArg = runtimeCallInfo->GetCallArgRef(NUM_1);
1506     Local<JSValueRef> fromStartArg = runtimeCallInfo->GetCallArgRef(NUM_2);
1507     Local<JSValueRef> stepArg = runtimeCallInfo->GetCallArgRef(NUM_3);
1508     Local<JSValueRef> loopArg = runtimeCallInfo->GetCallArgRef(NUM_4);
1509     Local<JSValueRef> delayArg = runtimeCallInfo->GetCallArgRef(NUM_5);
1510     Local<JSValueRef> fadeoutArg = runtimeCallInfo->GetCallArgRef(NUM_6);
1511     Local<JSValueRef> marqueeStartPolicyArg = runtimeCallInfo->GetCallArgRef(NUM_7);
1512     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
1513 
1514     auto textMarqueeOptions = std::make_unique<ArkUITextMarqueeOptions>();
1515     textMarqueeOptions->start = startArg->IsBoolean() ? startArg->ToBoolean(vm)->Value() : true;
1516     textMarqueeOptions->fromStart = fromStartArg->IsBoolean() ? fromStartArg->ToBoolean(vm)->Value() : true;
1517     textMarqueeOptions->step = stepArg->IsNumber() ?
1518         Dimension(stepArg->ToNumber(vm)->Value(), DimensionUnit::VP).ConvertToPx() :
1519         DEFAULT_MARQUEE_STEP_VALUE.ConvertToPx();
1520     textMarqueeOptions->loop = loopArg->IsNumber() ? loopArg->Int32Value(vm) : -1;
1521     textMarqueeOptions->delay = delayArg->IsNumber() ? delayArg->Int32Value(vm) : 0;
1522     textMarqueeOptions->fadeout = fadeoutArg->IsBoolean() ? fadeoutArg->ToBoolean(vm)->Value() : false;
1523     textMarqueeOptions->marqueeStartPolicy = marqueeStartPolicyArg->IsNumber() ?
1524         marqueeStartPolicyArg->Int32Value(vm) : 0;
1525 
1526     bool isValid = startArg->IsBoolean() || fromStartArg->IsBoolean() || stepArg->IsNumber() || loopArg->IsNumber()
1527         || delayArg->IsNumber() || fadeoutArg->IsBoolean() || marqueeStartPolicyArg->IsNumber();
1528     if (isValid) {
1529         GetArkUINodeModifiers()->getTextModifier()->setTextMarqueeOptions(nativeNode, textMarqueeOptions.get());
1530     } else {
1531         GetArkUINodeModifiers()->getTextModifier()->resetTextMarqueeOptions(nativeNode);
1532     }
1533     return panda::JSValueRef::Undefined(vm);
1534 }
1535 
ResetMarqueeOptions(ArkUIRuntimeCallInfo * runtimeCallInfo)1536 ArkUINativeModuleValue TextBridge::ResetMarqueeOptions(ArkUIRuntimeCallInfo* runtimeCallInfo)
1537 {
1538     EcmaVM* vm = runtimeCallInfo->GetVM();
1539     CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
1540     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
1541     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
1542     GetArkUINodeModifiers()->getTextModifier()->resetTextMarqueeOptions(nativeNode);
1543     return panda::JSValueRef::Undefined(vm);
1544 }
1545 
SetOnMarqueeStateChange(ArkUIRuntimeCallInfo * runtimeCallInfo)1546 ArkUINativeModuleValue TextBridge::SetOnMarqueeStateChange(ArkUIRuntimeCallInfo* runtimeCallInfo)
1547 {
1548     EcmaVM *vm = runtimeCallInfo->GetVM();
1549     CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
1550     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
1551     Local<JSValueRef> callbackArg = runtimeCallInfo->GetCallArgRef(1);
1552     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
1553     auto frameNode = reinterpret_cast<FrameNode*>(nativeNode);
1554     CHECK_NULL_RETURN(frameNode, panda::NativePointerRef::New(vm, nullptr));
1555     if (callbackArg->IsUndefined() || callbackArg->IsNull() || !callbackArg->IsFunction(vm)) {
1556         GetArkUINodeModifiers()->getTextModifier()->resetOnMarqueeStateChange(nativeNode);
1557         return panda::JSValueRef::Undefined(vm);
1558     }
1559     panda::Local<panda::FunctionRef> func = callbackArg->ToObject(vm);
1560     std::function<void(int32_t)> callback = [vm, frameNode,
1561         func = panda::CopyableGlobal(vm, func)](int32_t state) {
1562         panda::LocalScope pandaScope(vm);
1563         panda::TryCatch trycatch(vm);
1564         PipelineContext::SetCallBackNode(AceType::WeakClaim(frameNode));
1565         panda::Local<panda::NumberRef> stateParam = panda::NumberRef::New(vm, state);
1566         panda::Local<panda::JSValueRef> params[PARAM_ARR_LENGTH_1] = { stateParam };
1567         func->Call(vm, func.ToLocal(), params, PARAM_ARR_LENGTH_1);
1568     };
1569     GetArkUINodeModifiers()->getTextModifier()->setOnMarqueeStateChange(nativeNode, reinterpret_cast<void*>(&callback));
1570     return panda::JSValueRef::Undefined(vm);
1571 }
1572 
ResetOnMarqueeStateChange(ArkUIRuntimeCallInfo * runtimeCallInfo)1573 ArkUINativeModuleValue TextBridge::ResetOnMarqueeStateChange(ArkUIRuntimeCallInfo* runtimeCallInfo)
1574 {
1575     EcmaVM* vm = runtimeCallInfo->GetVM();
1576     CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
1577     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
1578     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
1579     GetArkUINodeModifiers()->getTextModifier()->resetOnMarqueeStateChange(nativeNode);
1580     return panda::JSValueRef::Undefined(vm);
1581 }
1582 } // namespace OHOS::Ace::NG
1583