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 "core/interfaces/native/node/api.h"
20 #include "core/components/common/properties/shadow.h"
21 #include "frameworks/base/geometry/calc_dimension.h"
22 #include "frameworks/base/geometry/dimension.h"
23 #include "frameworks/bridge/declarative_frontend/engine/js_types.h"
24 #include "frameworks/bridge/declarative_frontend/engine/jsi/jsi_value_conversions.h"
25 #include "frameworks/bridge/declarative_frontend/engine/jsi/nativeModule/arkts_utils.h"
26 #include "frameworks/bridge/declarative_frontend/jsview/js_shape_abstract.h"
27 #include "frameworks/bridge/declarative_frontend/jsview/js_view_abstract.h"
28
29 namespace OHOS::Ace::NG {
30 namespace {
31 constexpr int SIZE_OF_TEXT_CASES = 2;
32 constexpr double DEFAULT_SPAN_FONT_SIZE = 16;
33 constexpr DimensionUnit DEFAULT_SPAN_FONT_UNIT = DimensionUnit::FP;
34 constexpr bool DEFAULT_TEXT_SHADOW_FILL = false;
35 constexpr ShadowType DEFAULT_TEXT_SHADOW_TYPE = ShadowType::COLOR;
36 constexpr TextDecorationStyle DEFAULT_DECORATION_STYLE = TextDecorationStyle::SOLID;
37 constexpr Ace::FontStyle DEFAULT_FONT_STYLE = Ace::FontStyle::NORMAL;
38 const Color DEFAULT_DECORATION_COLOR = Color::BLACK;
39 const Color DEFAULT_TEXT_SHADOW_COLOR = Color::BLACK;
40 const std::string DEFAULT_FONT_WEIGHT = "400";
41 constexpr int NUM_0 = 0;
42 constexpr int NUM_1 = 1;
43 constexpr int NUM_2 = 2;
44 constexpr int NUM_3 = 3;
45 constexpr int NUM_4 = 4;
46 constexpr int NUM_5 = 5;
47 constexpr int NUM_6 = 6;
48 constexpr int NUM_7 = 7;
49 const std::vector<TextOverflow> TEXT_OVERFLOWS = { TextOverflow::NONE, TextOverflow::CLIP, TextOverflow::ELLIPSIS,
50 TextOverflow::MARQUEE };
51
parseShadowColor(const EcmaVM * vm,const Local<JSValueRef> & jsValue)52 uint32_t parseShadowColor(const EcmaVM* vm, const Local<JSValueRef>& jsValue)
53 {
54 Color color = DEFAULT_TEXT_SHADOW_COLOR;
55 if (!ArkTSUtils::ParseJsColorAlpha(vm, jsValue, color)) {
56 color = DEFAULT_TEXT_SHADOW_COLOR;
57 }
58 return color.GetValue();
59 };
60
parseShadowFill(const EcmaVM * vm,const Local<JSValueRef> & jsValue)61 uint32_t parseShadowFill(const EcmaVM* vm, const Local<JSValueRef>& jsValue)
62 {
63 if (jsValue->IsBoolean()) {
64 return static_cast<uint32_t>(jsValue->ToBoolean(vm)->Value());
65 }
66 return static_cast<uint32_t>(DEFAULT_TEXT_SHADOW_FILL);
67 };
68
parseShadowType(const EcmaVM * vm,const Local<JSValueRef> & jsValue)69 uint32_t parseShadowType(const EcmaVM* vm, const Local<JSValueRef>& jsValue)
70 {
71 if (jsValue->IsInt()) {
72 return jsValue->Uint32Value(vm);
73 }
74 return static_cast<uint32_t>(DEFAULT_TEXT_SHADOW_TYPE);
75 };
76
parseShadowRadius(const EcmaVM * vm,const Local<JSValueRef> & jsValue)77 double parseShadowRadius(const EcmaVM* vm, const Local<JSValueRef>& jsValue)
78 {
79 double radius = 0.0;
80 ArkTSUtils::ParseJsDouble(vm, jsValue, radius);
81 if (LessNotEqual(radius, 0.0)) {
82 radius = 0.0;
83 }
84 return radius;
85 };
86
parseShadowOffset(const EcmaVM * vm,const Local<JSValueRef> & jsValue)87 double parseShadowOffset(const EcmaVM* vm, const Local<JSValueRef>& jsValue)
88 {
89 CalcDimension offset;
90 if (ArkTSUtils::ParseJsResource(vm, jsValue, offset)) {
91 return offset.Value();
92 } else if (ArkTSUtils::ParseJsDimensionVp(vm, jsValue, offset)) {
93 return offset.Value();
94 }
95 return 0.0;
96 };
97 } // namespace
98
SetFontWeight(ArkUIRuntimeCallInfo * runtimeCallInfo)99 ArkUINativeModuleValue TextBridge::SetFontWeight(ArkUIRuntimeCallInfo* runtimeCallInfo)
100 {
101 EcmaVM* vm = runtimeCallInfo->GetVM();
102 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
103 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
104 Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
105 void* nativeNode = firstArg->ToNativePointer(vm)->Value();
106 if (secondArg->IsString()) {
107 std::string weight = secondArg->ToString(vm)->ToString();
108 GetArkUIInternalNodeAPI()->GetTextModifier().SetFontWeight(nativeNode, weight.c_str());
109 } else {
110 GetArkUIInternalNodeAPI()->GetTextModifier().ResetFontWeight(nativeNode);
111 }
112 return panda::JSValueRef::Undefined(vm);
113 }
114
ResetFontWeight(ArkUIRuntimeCallInfo * runtimeCallInfo)115 ArkUINativeModuleValue TextBridge::ResetFontWeight(ArkUIRuntimeCallInfo* runtimeCallInfo)
116 {
117 EcmaVM* vm = runtimeCallInfo->GetVM();
118 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
119 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
120 void* nativeNode = firstArg->ToNativePointer(vm)->Value();
121 GetArkUIInternalNodeAPI()->GetTextModifier().ResetFontWeight(nativeNode);
122 return panda::JSValueRef::Undefined(vm);
123 }
124
SetFontStyle(ArkUIRuntimeCallInfo * runtimeCallInfo)125 ArkUINativeModuleValue TextBridge::SetFontStyle(ArkUIRuntimeCallInfo* runtimeCallInfo)
126 {
127 EcmaVM* vm = runtimeCallInfo->GetVM();
128 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
129 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
130 Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
131 void* nativeNode = firstArg->ToNativePointer(vm)->Value();
132 if (secondArg->IsNumber()) {
133 uint32_t fontStyle = secondArg->Uint32Value(vm);
134 if (fontStyle < static_cast<uint32_t>(OHOS::Ace::FontStyle::NORMAL) ||
135 fontStyle > static_cast<uint32_t>(OHOS::Ace::FontStyle::ITALIC)) {
136 fontStyle = static_cast<uint32_t>(OHOS::Ace::FontStyle::NORMAL);
137 }
138 GetArkUIInternalNodeAPI()->GetTextModifier().SetFontStyle(nativeNode, fontStyle);
139 } else {
140 GetArkUIInternalNodeAPI()->GetTextModifier().ResetFontStyle(nativeNode);
141 }
142 return panda::JSValueRef::Undefined(vm);
143 }
144
ResetFontStyle(ArkUIRuntimeCallInfo * runtimeCallInfo)145 ArkUINativeModuleValue TextBridge::ResetFontStyle(ArkUIRuntimeCallInfo* runtimeCallInfo)
146 {
147 EcmaVM* vm = runtimeCallInfo->GetVM();
148 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
149 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
150 void* nativeNode = firstArg->ToNativePointer(vm)->Value();
151 GetArkUIInternalNodeAPI()->GetTextModifier().ResetFontStyle(nativeNode);
152 return panda::JSValueRef::Undefined(vm);
153 }
154
SetTextAlign(ArkUIRuntimeCallInfo * runtimeCallInfo)155 ArkUINativeModuleValue TextBridge::SetTextAlign(ArkUIRuntimeCallInfo* runtimeCallInfo)
156 {
157 EcmaVM* vm = runtimeCallInfo->GetVM();
158 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
159 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
160 Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
161 void* nativeNode = firstArg->ToNativePointer(vm)->Value();
162 if (secondArg->IsNumber()) {
163 GetArkUIInternalNodeAPI()->GetTextModifier().SetTextAlign(nativeNode, secondArg->ToNumber(vm)->Value());
164 } else {
165 GetArkUIInternalNodeAPI()->GetTextModifier().ResetTextAlign(nativeNode);
166 }
167 return panda::JSValueRef::Undefined(vm);
168 }
169
ResetTextAlign(ArkUIRuntimeCallInfo * runtimeCallInfo)170 ArkUINativeModuleValue TextBridge::ResetTextAlign(ArkUIRuntimeCallInfo* runtimeCallInfo)
171 {
172 EcmaVM* vm = runtimeCallInfo->GetVM();
173 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
174 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
175 void* nativeNode = firstArg->ToNativePointer(vm)->Value();
176 GetArkUIInternalNodeAPI()->GetTextModifier().ResetTextAlign(nativeNode);
177 return panda::JSValueRef::Undefined(vm);
178 }
179
SetFontColor(ArkUIRuntimeCallInfo * runtimeCallInfo)180 ArkUINativeModuleValue TextBridge::SetFontColor(ArkUIRuntimeCallInfo* runtimeCallInfo)
181 {
182 EcmaVM* vm = runtimeCallInfo->GetVM();
183 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
184 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
185 Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
186 void* nativeNode = firstArg->ToNativePointer(vm)->Value();
187 Color color;
188 if (!ArkTSUtils::ParseJsColorAlpha(vm, secondArg, color)) {
189 GetArkUIInternalNodeAPI()->GetTextModifier().ResetFontColor(nativeNode);
190 } else {
191 GetArkUIInternalNodeAPI()->GetTextModifier().SetFontColor(nativeNode, color.GetValue());
192 }
193 return panda::JSValueRef::Undefined(vm);
194 }
ResetFontColor(ArkUIRuntimeCallInfo * runtimeCallInfo)195 ArkUINativeModuleValue TextBridge::ResetFontColor(ArkUIRuntimeCallInfo* runtimeCallInfo)
196 {
197 EcmaVM* vm = runtimeCallInfo->GetVM();
198 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
199 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
200 void* nativeNode = firstArg->ToNativePointer(vm)->Value();
201 GetArkUIInternalNodeAPI()->GetTextModifier().ResetFontColor(nativeNode);
202 return panda::JSValueRef::Undefined(vm);
203 }
SetFontSize(ArkUIRuntimeCallInfo * runtimeCallInfo)204 ArkUINativeModuleValue TextBridge::SetFontSize(ArkUIRuntimeCallInfo* runtimeCallInfo)
205 {
206 EcmaVM* vm = runtimeCallInfo->GetVM();
207 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
208 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
209 Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
210 void* nativeNode = firstArg->ToNativePointer(vm)->Value();
211 CalcDimension fontSize;
212 if (!ArkTSUtils::ParseJsDimensionFp(vm, secondArg, fontSize)) {
213 GetArkUIInternalNodeAPI()->GetTextModifier().ResetFontSize(nativeNode);
214 } else {
215 GetArkUIInternalNodeAPI()->GetTextModifier().SetFontSize(
216 nativeNode, fontSize.Value(), static_cast<int>(fontSize.Unit()));
217 }
218 return panda::JSValueRef::Undefined(vm);
219 }
ResetFontSize(ArkUIRuntimeCallInfo * runtimeCallInfo)220 ArkUINativeModuleValue TextBridge::ResetFontSize(ArkUIRuntimeCallInfo* runtimeCallInfo)
221 {
222 EcmaVM* vm = runtimeCallInfo->GetVM();
223 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
224 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
225 void* nativeNode = firstArg->ToNativePointer(vm)->Value();
226 GetArkUIInternalNodeAPI()->GetTextModifier().ResetFontSize(nativeNode);
227 return panda::JSValueRef::Undefined(vm);
228 }
229
SetLineHeight(ArkUIRuntimeCallInfo * runtimeCallInfo)230 ArkUINativeModuleValue TextBridge::SetLineHeight(ArkUIRuntimeCallInfo* runtimeCallInfo)
231 {
232 EcmaVM* vm = runtimeCallInfo->GetVM();
233 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
234 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
235 Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
236 void* nativeNode = firstArg->ToNativePointer(vm)->Value();
237 CalcDimension lineHeight(0.0, DimensionUnit::PX);
238 if (!ArkTSUtils::ParseJsDimensionFp(vm, secondArg, lineHeight)) {
239 lineHeight.Reset();
240 }
241 if (lineHeight.IsNegative()) {
242 lineHeight.Reset();
243 }
244 GetArkUIInternalNodeAPI()->GetTextModifier().SetTextLineHeight(
245 nativeNode, lineHeight.Value(), static_cast<int8_t>(lineHeight.Unit()));
246 return panda::JSValueRef::Undefined(vm);
247 }
248
ResetLineHeight(ArkUIRuntimeCallInfo * runtimeCallInfo)249 ArkUINativeModuleValue TextBridge::ResetLineHeight(ArkUIRuntimeCallInfo* runtimeCallInfo)
250 {
251 EcmaVM* vm = runtimeCallInfo->GetVM();
252 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
253 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
254 void* nativeNode = firstArg->ToNativePointer(vm)->Value();
255 GetArkUIInternalNodeAPI()->GetTextModifier().ResetTextLineHeight(nativeNode);
256 return panda::JSValueRef::Undefined(vm);
257 }
258
SetTextOverflow(ArkUIRuntimeCallInfo * runtimeCallInfo)259 ArkUINativeModuleValue TextBridge::SetTextOverflow(ArkUIRuntimeCallInfo* runtimeCallInfo)
260 {
261 EcmaVM* vm = runtimeCallInfo->GetVM();
262 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
263 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
264 Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
265 void* nativeNode = firstArg->ToNativePointer(vm)->Value();
266 int32_t value;
267 if (secondArg->IsUndefined()) {
268 value = 0;
269 } else if (secondArg->IsNumber()) {
270 value = secondArg->Int32Value(vm);
271 } else {
272 return panda::JSValueRef::Undefined(vm);
273 }
274 if (value < 0 || value >= static_cast<int32_t>(TEXT_OVERFLOWS.size())) {
275 return panda::JSValueRef::Undefined(vm);
276 }
277 GetArkUIInternalNodeAPI()->GetTextModifier().SetTextTextOverflow(nativeNode, value);
278 return panda::JSValueRef::Undefined(vm);
279 }
280
ResetTextOverflow(ArkUIRuntimeCallInfo * runtimeCallInfo)281 ArkUINativeModuleValue TextBridge::ResetTextOverflow(ArkUIRuntimeCallInfo* runtimeCallInfo)
282 {
283 EcmaVM* vm = runtimeCallInfo->GetVM();
284 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
285 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
286 void* nativeNode = firstArg->ToNativePointer(vm)->Value();
287 GetArkUIInternalNodeAPI()->GetTextModifier().ResetTextTextOverflow(nativeNode);
288 return panda::JSValueRef::Undefined(vm);
289 }
290
SetDecoration(ArkUIRuntimeCallInfo * runtimeCallInfo)291 ArkUINativeModuleValue TextBridge::SetDecoration(ArkUIRuntimeCallInfo* runtimeCallInfo)
292 {
293 EcmaVM* vm = runtimeCallInfo->GetVM();
294 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
295 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
296 Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
297 Local<JSValueRef> thirdArg = runtimeCallInfo->GetCallArgRef(NUM_2);
298 void* nativeNode = firstArg->ToNativePointer(vm)->Value();
299 int32_t textDecoration = static_cast<int32_t>(TextDecoration::NONE);
300 Color color = DEFAULT_DECORATION_COLOR;
301 if (secondArg->IsInt()) {
302 textDecoration = secondArg->Int32Value(vm);
303 }
304 if (!ArkTSUtils::ParseJsColorAlpha(vm, thirdArg, color)) {
305 color = DEFAULT_DECORATION_COLOR;
306 }
307 GetArkUIInternalNodeAPI()->GetTextModifier().SetTextDecoration(
308 nativeNode, textDecoration, color.GetValue(), static_cast<int32_t>(DEFAULT_DECORATION_STYLE));
309 return panda::JSValueRef::Undefined(vm);
310 }
311
ResetDecoration(ArkUIRuntimeCallInfo * runtimeCallInfo)312 ArkUINativeModuleValue TextBridge::ResetDecoration(ArkUIRuntimeCallInfo* runtimeCallInfo)
313 {
314 EcmaVM* vm = runtimeCallInfo->GetVM();
315 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
316 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
317 void* nativeNode = firstArg->ToNativePointer(vm)->Value();
318 GetArkUIInternalNodeAPI()->GetTextModifier().ResetTextDecoration(nativeNode);
319 return panda::JSValueRef::Undefined(vm);
320 }
321
SetTextCase(ArkUIRuntimeCallInfo * runtimeCallInfo)322 ArkUINativeModuleValue TextBridge::SetTextCase(ArkUIRuntimeCallInfo* runtimeCallInfo)
323 {
324 EcmaVM* vm = runtimeCallInfo->GetVM();
325 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
326 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
327 Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
328 void* nativeNode = firstArg->ToNativePointer(vm)->Value();
329 if (secondArg->IsNumber() && secondArg->Int32Value(vm) >= NUM_0 &&
330 secondArg->Int32Value(vm) <= SIZE_OF_TEXT_CASES) {
331 GetArkUIInternalNodeAPI()->GetTextModifier().SetTextTextCase(nativeNode, secondArg->Int32Value(vm));
332 } else {
333 GetArkUIInternalNodeAPI()->GetTextModifier().ResetTextTextCase(nativeNode);
334 }
335 return panda::JSValueRef::Undefined(vm);
336 }
337
ResetTextCase(ArkUIRuntimeCallInfo * runtimeCallInfo)338 ArkUINativeModuleValue TextBridge::ResetTextCase(ArkUIRuntimeCallInfo* runtimeCallInfo)
339 {
340 EcmaVM* vm = runtimeCallInfo->GetVM();
341 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
342 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
343 void* nativeNode = firstArg->ToNativePointer(vm)->Value();
344 GetArkUIInternalNodeAPI()->GetTextModifier().ResetTextTextCase(nativeNode);
345 return panda::JSValueRef::Undefined(vm);
346 }
347
SetMaxLines(ArkUIRuntimeCallInfo * runtimeCallInfo)348 ArkUINativeModuleValue TextBridge::SetMaxLines(ArkUIRuntimeCallInfo* runtimeCallInfo)
349 {
350 EcmaVM* vm = runtimeCallInfo->GetVM();
351 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
352 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
353 Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
354 void* nativeNode = firstArg->ToNativePointer(vm)->Value();
355 if (secondArg->IsNumber() && secondArg->ToNumber(vm)->Value() >= NUM_0) {
356 uint32_t maxLine = secondArg->Uint32Value(vm);
357 GetArkUIInternalNodeAPI()->GetTextModifier().SetTextMaxLines(nativeNode, maxLine);
358 } else {
359 GetArkUIInternalNodeAPI()->GetTextModifier().ResetTextMaxLines(nativeNode);
360 }
361 return panda::JSValueRef::Undefined(vm);
362 }
363
ResetMaxLines(ArkUIRuntimeCallInfo * runtimeCallInfo)364 ArkUINativeModuleValue TextBridge::ResetMaxLines(ArkUIRuntimeCallInfo* runtimeCallInfo)
365 {
366 EcmaVM* vm = runtimeCallInfo->GetVM();
367 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
368 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
369 void* nativeNode = firstArg->ToNativePointer(vm)->Value();
370 GetArkUIInternalNodeAPI()->GetTextModifier().ResetTextMaxLines(nativeNode);
371 return panda::JSValueRef::Undefined(vm);
372 }
373
SetMinFontSize(ArkUIRuntimeCallInfo * runtimeCallInfo)374 ArkUINativeModuleValue TextBridge::SetMinFontSize(ArkUIRuntimeCallInfo* runtimeCallInfo)
375 {
376 EcmaVM* vm = runtimeCallInfo->GetVM();
377 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
378 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
379 Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
380 void* nativeNode = firstArg->ToNativePointer(vm)->Value();
381
382 CalcDimension fontSize;
383 if (ArkTSUtils::ParseJsDimensionFp(vm, secondArg, fontSize)) {
384 GetArkUIInternalNodeAPI()->GetTextModifier().SetTextMinFontSize(
385 nativeNode, fontSize.Value(), static_cast<int8_t>(fontSize.Unit()));
386 } else {
387 GetArkUIInternalNodeAPI()->GetTextModifier().ReSetTextMinFontSize(nativeNode);
388 }
389 return panda::JSValueRef::Undefined(vm);
390 }
391
ReSetMinFontSize(ArkUIRuntimeCallInfo * runtimeCallInfo)392 ArkUINativeModuleValue TextBridge::ReSetMinFontSize(ArkUIRuntimeCallInfo* runtimeCallInfo)
393 {
394 EcmaVM* vm = runtimeCallInfo->GetVM();
395 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
396 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
397 void* nativeNode = firstArg->ToNativePointer(vm)->Value();
398 GetArkUIInternalNodeAPI()->GetTextModifier().ReSetTextMinFontSize(nativeNode);
399 return panda::JSValueRef::Undefined(vm);
400 }
401
SetDraggable(ArkUIRuntimeCallInfo * runtimeCallInfo)402 ArkUINativeModuleValue TextBridge::SetDraggable(ArkUIRuntimeCallInfo* runtimeCallInfo)
403 {
404 EcmaVM* vm = runtimeCallInfo->GetVM();
405 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
406 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
407 Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
408 void* nativeNode = firstArg->ToNativePointer(vm)->Value();
409 uint32_t draggable = false;
410 if (secondArg->IsBoolean()) {
411 draggable = static_cast<uint32_t>(secondArg->ToBoolean(vm)->Value());
412 }
413 GetArkUIInternalNodeAPI()->GetTextModifier().SetTextDraggable(nativeNode, draggable);
414 return panda::JSValueRef::Undefined(vm);
415 }
416
ResetDraggable(ArkUIRuntimeCallInfo * runtimeCallInfo)417 ArkUINativeModuleValue TextBridge::ResetDraggable(ArkUIRuntimeCallInfo* runtimeCallInfo)
418 {
419 EcmaVM* vm = runtimeCallInfo->GetVM();
420 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
421 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
422 void* nativeNode = firstArg->ToNativePointer(vm)->Value();
423 GetArkUIInternalNodeAPI()->GetTextModifier().ResetTextDraggable(nativeNode);
424 return panda::JSValueRef::Undefined(vm);
425 }
426
SetMaxFontSize(ArkUIRuntimeCallInfo * runtimeCallInfo)427 ArkUINativeModuleValue TextBridge::SetMaxFontSize(ArkUIRuntimeCallInfo* runtimeCallInfo)
428 {
429 EcmaVM* vm = runtimeCallInfo->GetVM();
430 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
431 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
432 Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
433 void* nativeNode = firstArg->ToNativePointer(vm)->Value();
434 CalcDimension fontSize;
435 if (ArkTSUtils::ParseJsDimensionFp(vm, secondArg, fontSize)) {
436 GetArkUIInternalNodeAPI()->GetTextModifier().SetTextMaxFontSize(
437 nativeNode, fontSize.Value(), static_cast<int8_t>(fontSize.Unit()));
438 } else {
439 GetArkUIInternalNodeAPI()->GetTextModifier().ResetTextMaxFontSize(nativeNode);
440 }
441
442 return panda::JSValueRef::Undefined(vm);
443 }
444
ResetMaxFontSize(ArkUIRuntimeCallInfo * runtimeCallInfo)445 ArkUINativeModuleValue TextBridge::ResetMaxFontSize(ArkUIRuntimeCallInfo* runtimeCallInfo)
446 {
447 EcmaVM* vm = runtimeCallInfo->GetVM();
448 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
449 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
450 void* nativeNode = firstArg->ToNativePointer(vm)->Value();
451 GetArkUIInternalNodeAPI()->GetTextModifier().ResetTextMaxFontSize(nativeNode);
452 return panda::JSValueRef::Undefined(vm);
453 }
454
SetFontFamily(ArkUIRuntimeCallInfo * runtimeCallInfo)455 ArkUINativeModuleValue TextBridge::SetFontFamily(ArkUIRuntimeCallInfo* runtimeCallInfo)
456 {
457 EcmaVM* vm = runtimeCallInfo->GetVM();
458 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
459 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
460 Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
461 void* nativeNode = firstArg->ToNativePointer(vm)->Value();
462
463 std::vector<std::string> fontFamilies;
464 if (!ArkTSUtils::ParseJsFontFamilies(vm, secondArg, fontFamilies)) {
465 GetArkUIInternalNodeAPI()->GetTextModifier().ResetTextFontFamily(nativeNode);
466 return panda::JSValueRef::Undefined(vm);
467 }
468 auto families = std::make_unique<char* []>(fontFamilies.size());
469 for (uint32_t i = 0; i < fontFamilies.size(); i++) {
470 families[i] = const_cast<char*>(fontFamilies.at(i).c_str());
471 }
472 GetArkUIInternalNodeAPI()->GetTextModifier().SetTextFontFamily(
473 nativeNode, const_cast<const char**>(families.get()), fontFamilies.size());
474 return panda::JSValueRef::Undefined(vm);
475 }
476
ResetFontFamily(ArkUIRuntimeCallInfo * runtimeCallInfo)477 ArkUINativeModuleValue TextBridge::ResetFontFamily(ArkUIRuntimeCallInfo* runtimeCallInfo)
478 {
479 EcmaVM* vm = runtimeCallInfo->GetVM();
480 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
481 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
482 void* nativeNode = firstArg->ToNativePointer(vm)->Value();
483
484 GetArkUIInternalNodeAPI()->GetTextModifier().ResetTextFontFamily(nativeNode);
485 return panda::JSValueRef::Undefined(vm);
486 }
487
SetCopyOption(ArkUIRuntimeCallInfo * runtimeCallInfo)488 ArkUINativeModuleValue TextBridge::SetCopyOption(ArkUIRuntimeCallInfo* runtimeCallInfo)
489 {
490 EcmaVM* vm = runtimeCallInfo->GetVM();
491 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
492 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
493 Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
494 void* nativeNode = firstArg->ToNativePointer(vm)->Value();
495 int32_t copyOption = static_cast<int32_t>(CopyOptions::None);
496 if (secondArg->IsInt()) {
497 copyOption = secondArg->Int32Value(vm);
498 }
499 GetArkUIInternalNodeAPI()->GetTextModifier().SetTextCopyOption(nativeNode, copyOption);
500 return panda::JSValueRef::Undefined(vm);
501 }
502
ResetCopyOption(ArkUIRuntimeCallInfo * runtimeCallInfo)503 ArkUINativeModuleValue TextBridge::ResetCopyOption(ArkUIRuntimeCallInfo* runtimeCallInfo)
504 {
505 EcmaVM* vm = runtimeCallInfo->GetVM();
506 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
507 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
508 void* nativeNode = firstArg->ToNativePointer(vm)->Value();
509 GetArkUIInternalNodeAPI()->GetTextModifier().ResetTextCopyOption(nativeNode);
510 return panda::JSValueRef::Undefined(vm);
511 }
512
SetTextShadow(ArkUIRuntimeCallInfo * runtimeCallInfo)513 ArkUINativeModuleValue TextBridge::SetTextShadow(ArkUIRuntimeCallInfo* runtimeCallInfo)
514 {
515 EcmaVM* vm = runtimeCallInfo->GetVM();
516 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
517 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
518 Local<JSValueRef> radiusArg = runtimeCallInfo->GetCallArgRef(NUM_1);
519 Local<JSValueRef> typeArg = runtimeCallInfo->GetCallArgRef(NUM_2);
520 Local<JSValueRef> colorArg = runtimeCallInfo->GetCallArgRef(NUM_3);
521 Local<JSValueRef> offsetXArg = runtimeCallInfo->GetCallArgRef(NUM_4);
522 Local<JSValueRef> offsetYArg = runtimeCallInfo->GetCallArgRef(NUM_5);
523 Local<JSValueRef> fillArg = runtimeCallInfo->GetCallArgRef(NUM_6);
524 Local<JSValueRef> lengthArg = runtimeCallInfo->GetCallArgRef(NUM_7);
525 void* nativeNode = firstArg->ToNativePointer(vm)->Value();
526 uint32_t length;
527 if (!lengthArg->IsNumber() || lengthArg->Uint32Value(vm) == 0) {
528 return panda::JSValueRef::Undefined(vm);
529 }
530 length = lengthArg->Uint32Value(vm);
531 auto radiusArray = std::make_unique<double[]>(length);
532 auto typeArray = std::make_unique<uint32_t[]>(length);
533 auto colorArray = std::make_unique<uint32_t[]>(length);
534 auto offsetXArray = std::make_unique<double[]>(length);
535 auto offsetYArray = std::make_unique<double[]>(length);
536 auto fillArray = std::make_unique<uint32_t[]>(length);
537 bool radiusParseResult = ArkTSUtils::ParseArray<double>(
538 vm, radiusArg, radiusArray.get(), length, parseShadowRadius);
539 bool typeParseResult = ArkTSUtils::ParseArray<uint32_t>(
540 vm, typeArg, typeArray.get(), length, parseShadowType);
541 bool colorParseResult = ArkTSUtils::ParseArray<uint32_t>(
542 vm, colorArg, colorArray.get(), length, parseShadowColor);
543 bool offsetXParseResult = ArkTSUtils::ParseArray<double>(
544 vm, offsetXArg, offsetXArray.get(), length, parseShadowOffset);
545 bool offsetYParseResult = ArkTSUtils::ParseArray<double>(
546 vm, offsetYArg, offsetYArray.get(), length, parseShadowOffset);
547 bool fillParseResult = ArkTSUtils::ParseArray<uint32_t>(
548 vm, fillArg, fillArray.get(), length, parseShadowFill);
549 if (!radiusParseResult || !colorParseResult || !offsetXParseResult ||
550 !offsetYParseResult || !fillParseResult || !typeParseResult) {
551 return panda::JSValueRef::Undefined(vm);
552 }
553 auto textShadowArray = std::make_unique<ArkUITextShadowStruct[]>(length);
554 CHECK_NULL_RETURN(textShadowArray.get(), panda::JSValueRef::Undefined(vm));
555 for (uint32_t i = 0; i < length; i++) {
556 textShadowArray[i].radius = radiusArray[i];
557 textShadowArray[i].type = typeArray[i];
558 textShadowArray[i].color = colorArray[i];
559 textShadowArray[i].offsetX = offsetXArray[i];
560 textShadowArray[i].offsetY = offsetYArray[i];
561 textShadowArray[i].fill = fillArray[i];
562 }
563 GetArkUIInternalNodeAPI()->GetTextModifier().SetTextTextShadow(nativeNode, textShadowArray.get(), length);
564 return panda::JSValueRef::Undefined(vm);
565 }
566
ResetTextShadow(ArkUIRuntimeCallInfo * runtimeCallInfo)567 ArkUINativeModuleValue TextBridge::ResetTextShadow(ArkUIRuntimeCallInfo* runtimeCallInfo)
568 {
569 EcmaVM* vm = runtimeCallInfo->GetVM();
570 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
571 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
572 void* nativeNode = firstArg->ToNativePointer(vm)->Value();
573 GetArkUIInternalNodeAPI()->GetTextModifier().ResetTextTextShadow(nativeNode);
574 return panda::JSValueRef::Undefined(vm);
575 }
576
SetHeightAdaptivePolicy(ArkUIRuntimeCallInfo * runtimeCallInfo)577 ArkUINativeModuleValue TextBridge::SetHeightAdaptivePolicy(ArkUIRuntimeCallInfo* runtimeCallInfo)
578 {
579 EcmaVM* vm = runtimeCallInfo->GetVM();
580 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
581 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
582 Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
583 void* nativeNode = firstArg->ToNativePointer(vm)->Value();
584 if (secondArg->IsNumber()
585 && secondArg->Int32Value(vm) >= static_cast<int32_t>(TextHeightAdaptivePolicy::MAX_LINES_FIRST)
586 && secondArg->Int32Value(vm) <= static_cast<int32_t>(TextHeightAdaptivePolicy::LAYOUT_CONSTRAINT_FIRST)) {
587 auto value = secondArg->Int32Value(vm);
588 GetArkUIInternalNodeAPI()->GetTextModifier().SetTextHeightAdaptivePolicy(nativeNode, value);
589 } else {
590 GetArkUIInternalNodeAPI()->GetTextModifier().ResetTextHeightAdaptivePolicy(nativeNode);
591 }
592 return panda::JSValueRef::Undefined(vm);
593 }
594
ResetHeightAdaptivePolicy(ArkUIRuntimeCallInfo * runtimeCallInfo)595 ArkUINativeModuleValue TextBridge::ResetHeightAdaptivePolicy(ArkUIRuntimeCallInfo* runtimeCallInfo)
596 {
597 EcmaVM* vm = runtimeCallInfo->GetVM();
598 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
599 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
600 void* nativeNode = firstArg->ToNativePointer(vm)->Value();
601 GetArkUIInternalNodeAPI()->GetTextModifier().ResetTextHeightAdaptivePolicy(nativeNode);
602 return panda::JSValueRef::Undefined(vm);
603 }
604
SetTextIndent(ArkUIRuntimeCallInfo * runtimeCallInfo)605 ArkUINativeModuleValue TextBridge::SetTextIndent(ArkUIRuntimeCallInfo* runtimeCallInfo)
606 {
607 EcmaVM* vm = runtimeCallInfo->GetVM();
608 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
609 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
610 Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
611 void* nativeNode = firstArg->ToNativePointer(vm)->Value();
612 struct ArkUIStringAndFloat textIndentStruct = { 0.0, nullptr };
613 std::string str;
614 if (secondArg->IsNumber()) {
615 textIndentStruct.value = secondArg->ToNumber(vm)->Value();
616 GetArkUIInternalNodeAPI()->GetTextModifier().SetTextTextIndent(nativeNode, &textIndentStruct);
617 } else if (secondArg->IsString()) {
618 str = secondArg->ToString(vm)->ToString();
619 textIndentStruct.valueStr = str.c_str();
620 GetArkUIInternalNodeAPI()->GetTextModifier().SetTextTextIndent(nativeNode, &textIndentStruct);
621 } else {
622 GetArkUIInternalNodeAPI()->GetTextModifier().ResetTextTextIndent(nativeNode);
623 }
624 return panda::JSValueRef::Undefined(vm);
625 }
626
ResetTextIndent(ArkUIRuntimeCallInfo * runtimeCallInfo)627 ArkUINativeModuleValue TextBridge::ResetTextIndent(ArkUIRuntimeCallInfo* runtimeCallInfo)
628 {
629 EcmaVM* vm = runtimeCallInfo->GetVM();
630 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
631 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
632 void* nativeNode = firstArg->ToNativePointer(vm)->Value();
633 GetArkUIInternalNodeAPI()->GetTextModifier().ResetTextTextIndent(nativeNode);
634 return panda::JSValueRef::Undefined(vm);
635 }
636
SetBaselineOffset(ArkUIRuntimeCallInfo * runtimeCallInfo)637 ArkUINativeModuleValue TextBridge::SetBaselineOffset(ArkUIRuntimeCallInfo* runtimeCallInfo)
638 {
639 EcmaVM* vm = runtimeCallInfo->GetVM();
640 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
641 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
642 Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
643 void* nativeNode = firstArg->ToNativePointer(vm)->Value();
644 struct ArkUIStringAndFloat offset = { 0.0, nullptr };
645 std::string str;
646 if (secondArg->IsNumber()) {
647 offset.value = secondArg->ToNumber(vm)->Value();
648 GetArkUIInternalNodeAPI()->GetTextModifier().SetTextBaselineOffset(nativeNode, &offset);
649 } else if (secondArg->IsString()) {
650 str = secondArg->ToString(vm)->ToString();
651 offset.valueStr = str.c_str();
652 GetArkUIInternalNodeAPI()->GetTextModifier().SetTextBaselineOffset(nativeNode, &offset);
653 } else {
654 GetArkUIInternalNodeAPI()->GetTextModifier().ResetTextBaselineOffset(nativeNode);
655 }
656 return panda::JSValueRef::Undefined(vm);
657 }
658
ResetBaselineOffset(ArkUIRuntimeCallInfo * runtimeCallInfo)659 ArkUINativeModuleValue TextBridge::ResetBaselineOffset(ArkUIRuntimeCallInfo* runtimeCallInfo)
660 {
661 EcmaVM* vm = runtimeCallInfo->GetVM();
662 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
663 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
664 void* nativeNode = firstArg->ToNativePointer(vm)->Value();
665 GetArkUIInternalNodeAPI()->GetTextModifier().ResetTextBaselineOffset(nativeNode);
666 return panda::JSValueRef::Undefined(vm);
667 }
668
SetLetterSpacing(ArkUIRuntimeCallInfo * runtimeCallInfo)669 ArkUINativeModuleValue TextBridge::SetLetterSpacing(ArkUIRuntimeCallInfo* runtimeCallInfo)
670 {
671 EcmaVM* vm = runtimeCallInfo->GetVM();
672 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
673 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
674 Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
675 void* nativeNode = firstArg->ToNativePointer(vm)->Value();
676
677 struct ArkUIStringAndFloat letterSpacing = { 0.0, nullptr };
678 std::string str;
679 if (secondArg->IsNumber()) {
680 letterSpacing.value = secondArg->ToNumber(vm)->Value();
681 } else if (secondArg->IsString()) {
682 str = secondArg->ToString(vm)->ToString();
683 letterSpacing.valueStr = str.c_str();
684 } else {
685 return panda::JSValueRef::Undefined(vm);
686 }
687 GetArkUIInternalNodeAPI()->GetTextModifier().SetTextLetterSpacing(nativeNode, &letterSpacing);
688 return panda::JSValueRef::Undefined(vm);
689 }
690
ResetLetterSpacing(ArkUIRuntimeCallInfo * runtimeCallInfo)691 ArkUINativeModuleValue TextBridge::ResetLetterSpacing(ArkUIRuntimeCallInfo* runtimeCallInfo)
692 {
693 EcmaVM* vm = runtimeCallInfo->GetVM();
694 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
695 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
696 void* nativeNode = firstArg->ToNativePointer(vm)->Value();
697 GetArkUIInternalNodeAPI()->GetTextModifier().ResetTextLetterSpacing(nativeNode);
698 return panda::JSValueRef::Undefined(vm);
699 }
700
SetFont(ArkUIRuntimeCallInfo * runtimeCallInfo)701 ArkUINativeModuleValue TextBridge::SetFont(ArkUIRuntimeCallInfo* runtimeCallInfo)
702 {
703 EcmaVM* vm = runtimeCallInfo->GetVM();
704 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
705 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
706 Local<JSValueRef> sizeArg = runtimeCallInfo->GetCallArgRef(NUM_1);
707 Local<JSValueRef> weightArg = runtimeCallInfo->GetCallArgRef(NUM_2);
708 Local<JSValueRef> familyArg = runtimeCallInfo->GetCallArgRef(NUM_3);
709 Local<JSValueRef> styleArg = runtimeCallInfo->GetCallArgRef(NUM_4);
710 void *nativeNode = firstArg->ToNativePointer(vm)->Value();
711 ArkUIFontStruct fontInfo;
712 CalcDimension fontSize;
713 if (!ArkTSUtils::ParseJsDimensionFp(vm, sizeArg, fontSize) || sizeArg->IsNull()) {
714 fontSize.SetValue(DEFAULT_SPAN_FONT_SIZE);
715 fontSize.SetUnit(DEFAULT_SPAN_FONT_UNIT);
716 }
717 if (sizeArg->IsUndefined() || fontSize.IsNegative() || fontSize.Unit() == DimensionUnit::PERCENT) {
718 auto pipelineContext = PipelineContext::GetCurrentContext();
719 CHECK_NULL_RETURN(pipelineContext, panda::JSValueRef::Undefined(vm));
720 auto theme = pipelineContext->GetTheme<TextTheme>();
721 CHECK_NULL_RETURN(theme, panda::JSValueRef::Undefined(vm));
722 auto size = theme->GetTextStyle().GetFontSize();
723 fontInfo.fontSizeNumber = size.Value();
724 fontInfo.fontSizeUnit = static_cast<int8_t>(size.Unit());
725 } else {
726 fontInfo.fontSizeNumber = fontSize.Value();
727 fontInfo.fontSizeUnit = static_cast<int8_t>(fontSize.Unit());
728 }
729
730 std::string weight = DEFAULT_FONT_WEIGHT;
731 if (!weightArg->IsNull()) {
732 if (weightArg->IsNumber()) {
733 weight = std::to_string(weightArg->Int32Value(vm));
734 } else if (weightArg->IsString()) {
735 weight = weightArg->ToString(vm)->ToString();
736 }
737 }
738 fontInfo.fontWeight = static_cast<uint8_t>(Framework::ConvertStrToFontWeight(weight));
739
740 int32_t style = static_cast<int32_t>(DEFAULT_FONT_STYLE);
741 if (styleArg->IsInt()) {
742 style = styleArg->Int32Value(vm);
743 }
744 fontInfo.fontStyle = static_cast<uint8_t>(style);
745
746 std::vector<std::string> fontFamilies;
747 fontInfo.fontFamilies = nullptr;
748 if (!familyArg->IsNull() && ArkTSUtils::ParseJsFontFamilies(vm, familyArg, fontFamilies)) {
749 fontInfo.familyLength = fontFamilies.size();
750 auto families = std::make_unique<const char* []>(fontInfo.familyLength);
751 for (uint32_t i = 0; i < fontFamilies.size(); i++) {
752 families[i] = fontFamilies[i].c_str();
753 }
754 fontInfo.fontFamilies = families.get();
755 GetArkUIInternalNodeAPI()->GetTextModifier().SetTextFont(nativeNode, &fontInfo);
756 } else {
757 GetArkUIInternalNodeAPI()->GetTextModifier().SetTextFont(nativeNode, &fontInfo);
758 }
759 return panda::JSValueRef::Undefined(vm);
760 }
761
ResetFont(ArkUIRuntimeCallInfo * runtimeCallInfo)762 ArkUINativeModuleValue TextBridge::ResetFont(ArkUIRuntimeCallInfo* runtimeCallInfo)
763 {
764 EcmaVM* vm = runtimeCallInfo->GetVM();
765 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
766 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
767 void* nativeNode = firstArg->ToNativePointer(vm)->Value();
768 GetArkUIInternalNodeAPI()->GetTextModifier().ResetTextFont(nativeNode);
769 return panda::JSValueRef::Undefined(vm);
770 }
771
SetWordBreak(ArkUIRuntimeCallInfo * runtimeCallInfo)772 ArkUINativeModuleValue TextBridge::SetWordBreak(ArkUIRuntimeCallInfo* runtimeCallInfo)
773 {
774 EcmaVM* vm = runtimeCallInfo->GetVM();
775 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
776 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
777 Local<JSValueRef> workBreakArg = runtimeCallInfo->GetCallArgRef(NUM_1);
778 void* nativeNode = firstArg->ToNativePointer(vm)->Value();
779 if (workBreakArg->IsNull() || workBreakArg->IsUndefined() || !workBreakArg->IsNumber()) {
780 GetArkUIInternalNodeAPI()->GetTextModifier().ResetWordBreak(nativeNode);
781 return panda::JSValueRef::Undefined(vm);
782 }
783 uint32_t wordBreak = workBreakArg->Uint32Value(vm);
784 GetArkUIInternalNodeAPI()->GetTextModifier().SetWordBreak(nativeNode, wordBreak);
785 return panda::JSValueRef::Undefined(vm);
786 }
787
ResetWordBreak(ArkUIRuntimeCallInfo * runtimeCallInfo)788 ArkUINativeModuleValue TextBridge::ResetWordBreak(ArkUIRuntimeCallInfo* runtimeCallInfo)
789 {
790 EcmaVM* vm = runtimeCallInfo->GetVM();
791 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
792 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
793 void* nativeNode = firstArg->ToNativePointer(vm)->Value();
794 GetArkUIInternalNodeAPI()->GetTextModifier().ResetWordBreak(nativeNode);
795 return panda::JSValueRef::Undefined(vm);
796 }
797
SetEllipsisMode(ArkUIRuntimeCallInfo * runtimeCallInfo)798 ArkUINativeModuleValue TextBridge::SetEllipsisMode(ArkUIRuntimeCallInfo* runtimeCallInfo)
799 {
800 EcmaVM* vm = runtimeCallInfo->GetVM();
801 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
802 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
803 Local<JSValueRef> ellipsisModeArg = runtimeCallInfo->GetCallArgRef(NUM_1);
804 void* nativeNode = firstArg->ToNativePointer(vm)->Value();
805 if (ellipsisModeArg->IsNull() || ellipsisModeArg->IsUndefined() || !ellipsisModeArg->IsNumber()) {
806 GetArkUIInternalNodeAPI()->GetTextModifier().resetEllipsisMode(nativeNode);
807 return panda::JSValueRef::Undefined(vm);
808 }
809 uint32_t ellipsisMode = ellipsisModeArg->Uint32Value(vm);
810 GetArkUIInternalNodeAPI()->GetTextModifier().setEllipsisMode(nativeNode, ellipsisMode);
811 return panda::JSValueRef::Undefined(vm);
812 }
813
ResetEllipsisMode(ArkUIRuntimeCallInfo * runtimeCallInfo)814 ArkUINativeModuleValue TextBridge::ResetEllipsisMode(ArkUIRuntimeCallInfo* runtimeCallInfo)
815 {
816 EcmaVM* vm = runtimeCallInfo->GetVM();
817 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
818 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
819 void* nativeNode = firstArg->ToNativePointer(vm)->Value();
820 GetArkUIInternalNodeAPI()->GetTextModifier().resetEllipsisMode(nativeNode);
821 return panda::JSValueRef::Undefined(vm);
822 }
823 } // namespace OHOS::Ace::NG
824