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_span_bridge.h"
16
17 #include <string>
18 #include "base/geometry/calc_dimension.h"
19 #include "base/geometry/dimension.h"
20 #include "bridge/declarative_frontend/engine/jsi/nativeModule/arkts_utils.h"
21 #include "core/components/common/layout/constants.h"
22 #include "bridge/declarative_frontend/engine/jsi/jsi_types.h"
23
24 namespace OHOS::Ace::NG {
25 namespace {
26 constexpr int SIZE_OF_TEXT_CASES = 2;
27 constexpr TextDecorationStyle DEFAULT_DECORATION_STYLE = TextDecorationStyle::SOLID;
28 constexpr Ace::FontStyle DEFAULT_FONT_STYLE = Ace::FontStyle::NORMAL;
29 constexpr Color DEFAULT_DECORATION_COLOR = Color(0xff000000);
30 const std::string DEFAULT_FONT_WEIGHT = "400";
31 constexpr int NUM_0 = 0;
32 constexpr int NUM_1 = 1;
33 constexpr int NUM_2 = 2;
34 constexpr int NUM_3 = 3;
35 constexpr int NUM_4 = 4;
36 constexpr int NUM_5 = 5;
37 constexpr int NUM_6 = 6;
38 constexpr int NUM_7 = 7;
39 const std::vector<OHOS::Ace::FontStyle> FONT_STYLES = { OHOS::Ace::FontStyle::NORMAL, OHOS::Ace::FontStyle::ITALIC };
40
ParseOuterBorderRadius(ArkUIRuntimeCallInfo * runtimeCallInfo,EcmaVM * vm,std::vector<ArkUI_Float32> & values,std::vector<ArkUI_Int32> & units,int32_t argsIndex)41 void ParseOuterBorderRadius(ArkUIRuntimeCallInfo* runtimeCallInfo, EcmaVM* vm, std::vector<ArkUI_Float32>& values,
42 std::vector<ArkUI_Int32>& units, int32_t argsIndex)
43 {
44 Local<JSValueRef> topLeftArgs = runtimeCallInfo->GetCallArgRef(argsIndex);
45 Local<JSValueRef> topRightArgs = runtimeCallInfo->GetCallArgRef(argsIndex + NUM_1);
46 Local<JSValueRef> bottomLeftArgs = runtimeCallInfo->GetCallArgRef(argsIndex + NUM_2);
47 Local<JSValueRef> bottomRightArgs = runtimeCallInfo->GetCallArgRef(argsIndex + NUM_3);
48
49 std::optional<CalcDimension> topLeftOptional;
50 std::optional<CalcDimension> topRightOptional;
51 std::optional<CalcDimension> bottomLeftOptional;
52 std::optional<CalcDimension> bottomRightOptional;
53
54 ArkTSUtils::ParseOuterBorder(vm, topLeftArgs, topLeftOptional);
55 ArkTSUtils::ParseOuterBorder(vm, topRightArgs, topRightOptional);
56 ArkTSUtils::ParseOuterBorder(vm, bottomLeftArgs, bottomLeftOptional);
57 ArkTSUtils::ParseOuterBorder(vm, bottomRightArgs, bottomRightOptional);
58
59 ArkTSUtils::PushOuterBorderDimensionVector(topLeftOptional, values, units);
60 ArkTSUtils::PushOuterBorderDimensionVector(topRightOptional, values, units);
61 ArkTSUtils::PushOuterBorderDimensionVector(bottomLeftOptional, values, units);
62 ArkTSUtils::PushOuterBorderDimensionVector(bottomRightOptional, values, units);
63 }
64
ParseTextShadow(ArkUIRuntimeCallInfo * runtimeCallInfo,uint32_t length,std::vector<ArkUITextShadowStruct> & textShadowArray)65 bool ParseTextShadow(ArkUIRuntimeCallInfo* runtimeCallInfo, uint32_t length,
66 std::vector<ArkUITextShadowStruct>& textShadowArray)
67 {
68 EcmaVM* vm = runtimeCallInfo->GetVM();
69 CHECK_NULL_RETURN(vm, false);
70 Local<JSValueRef> radiusArg = runtimeCallInfo->GetCallArgRef(NUM_1);
71 Local<JSValueRef> typeArg = runtimeCallInfo->GetCallArgRef(NUM_2);
72 Local<JSValueRef> colorArg = runtimeCallInfo->GetCallArgRef(NUM_3);
73 Local<JSValueRef> offsetXArg = runtimeCallInfo->GetCallArgRef(NUM_4);
74 Local<JSValueRef> offsetYArg = runtimeCallInfo->GetCallArgRef(NUM_5);
75 Local<JSValueRef> fillArg = runtimeCallInfo->GetCallArgRef(NUM_6);
76 auto radiusArray = std::make_unique<double[]>(length);
77 auto typeArray = std::make_unique<uint32_t[]>(length);
78 auto colorArray = std::make_unique<uint32_t[]>(length);
79 auto offsetXArray = std::make_unique<double[]>(length);
80 auto offsetYArray = std::make_unique<double[]>(length);
81 auto fillArray = std::make_unique<uint32_t[]>(length);
82 bool radiusParseResult =
83 ArkTSUtils::ParseArray<double>(vm, radiusArg, radiusArray.get(), length, ArkTSUtils::parseShadowRadius);
84 bool typeParseResult =
85 ArkTSUtils::ParseArray<uint32_t>(vm, typeArg, typeArray.get(), length, ArkTSUtils::parseShadowType);
86 bool colorParseResult =
87 ArkTSUtils::ParseArray<uint32_t>(vm, colorArg, colorArray.get(), length, ArkTSUtils::parseShadowColor);
88 bool offsetXParseResult =
89 ArkTSUtils::ParseArray<double>(vm, offsetXArg, offsetXArray.get(), length, ArkTSUtils::parseShadowOffset);
90 bool offsetYParseResult =
91 ArkTSUtils::ParseArray<double>(vm, offsetYArg, offsetYArray.get(), length, ArkTSUtils::parseShadowOffset);
92 bool fillParseResult =
93 ArkTSUtils::ParseArray<uint32_t>(vm, fillArg, fillArray.get(), length, ArkTSUtils::parseShadowFill);
94 if (!radiusParseResult || !colorParseResult || !offsetXParseResult || !offsetYParseResult || !fillParseResult ||
95 !typeParseResult) {
96 return false;
97 }
98 for (uint32_t i = 0; i < length; i++) {
99 ArkUITextShadowStruct textShadow;
100 textShadow.radius = radiusArray[i];
101 textShadow.type = typeArray[i];
102 textShadow.color = colorArray[i];
103 textShadow.offsetX = offsetXArray[i];
104 textShadow.offsetY = offsetYArray[i];
105 textShadow.fill = fillArray[i];
106 textShadowArray.emplace_back(textShadow);
107 }
108 return true;
109 }
110 } // namespace
111
SetSpanSrc(ArkUIRuntimeCallInfo * runtimeCallInfo)112 ArkUINativeModuleValue SpanBridge::SetSpanSrc(ArkUIRuntimeCallInfo *runtimeCallInfo)
113 {
114 EcmaVM *vm = runtimeCallInfo->GetVM();
115 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
116 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
117 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
118 Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
119 std::string src;
120 if (!ArkTSUtils::ParseJsString(vm, secondArg, src)) {
121 return panda::JSValueRef::Undefined(vm);
122 }
123 GetArkUINodeModifiers()->getSpanModifier()->setSpanSrc(nativeNode, src.c_str());
124 return panda::JSValueRef::Undefined(vm);
125 }
126
SetTextCase(ArkUIRuntimeCallInfo * runtimeCallInfo)127 ArkUINativeModuleValue SpanBridge::SetTextCase(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() && secondArg->Int32Value(vm) >= NUM_0 &&
135 secondArg->Int32Value(vm) <= SIZE_OF_TEXT_CASES) {
136 GetArkUINodeModifiers()->getSpanModifier()->setSpanTextCase(nativeNode, secondArg->Int32Value(vm));
137 } else {
138 GetArkUINodeModifiers()->getSpanModifier()->resetSpanTextCase(nativeNode);
139 }
140 return panda::JSValueRef::Undefined(vm);
141 }
142
ResetTextCase(ArkUIRuntimeCallInfo * runtimeCallInfo)143 ArkUINativeModuleValue SpanBridge::ResetTextCase(ArkUIRuntimeCallInfo *runtimeCallInfo)
144 {
145 EcmaVM *vm = runtimeCallInfo->GetVM();
146 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
147 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
148 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
149 GetArkUINodeModifiers()->getSpanModifier()->resetSpanTextCase(nativeNode);
150 return panda::JSValueRef::Undefined(vm);
151 }
152
SetFontWeight(ArkUIRuntimeCallInfo * runtimeCallInfo)153 ArkUINativeModuleValue SpanBridge::SetFontWeight(ArkUIRuntimeCallInfo *runtimeCallInfo)
154 {
155 EcmaVM *vm = runtimeCallInfo->GetVM();
156 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
157 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
158 Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
159 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
160
161 std::string weight = DEFAULT_FONT_WEIGHT;
162 if (!secondArg->IsNull()) {
163 if (secondArg->IsNumber()) {
164 weight = std::to_string(secondArg->Int32Value(vm));
165 } else if (secondArg->IsString(vm)) {
166 weight = secondArg->ToString(vm)->ToString(vm);
167 }
168 }
169
170 GetArkUINodeModifiers()->getSpanModifier()->setSpanFontWeight(nativeNode,
171 static_cast<ArkUI_Int32>(Framework::ConvertStrToFontWeight(weight)));
172 return panda::JSValueRef::Undefined(vm);
173 }
174
ResetFontWeight(ArkUIRuntimeCallInfo * runtimeCallInfo)175 ArkUINativeModuleValue SpanBridge::ResetFontWeight(ArkUIRuntimeCallInfo *runtimeCallInfo)
176 {
177 EcmaVM *vm = runtimeCallInfo->GetVM();
178 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
179 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
180 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
181 GetArkUINodeModifiers()->getSpanModifier()->resetSpanFontWeight(nativeNode);
182 return panda::JSValueRef::Undefined(vm);
183 }
184
SetLineHeight(ArkUIRuntimeCallInfo * runtimeCallInfo)185 ArkUINativeModuleValue SpanBridge::SetLineHeight(ArkUIRuntimeCallInfo *runtimeCallInfo)
186 {
187 EcmaVM *vm = runtimeCallInfo->GetVM();
188 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
189 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
190 Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
191 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
192 CalcDimension lineHeight(0.0, DimensionUnit::PX);
193 if (!ArkTSUtils::ParseJsDimensionFpNG(vm, secondArg, lineHeight) || lineHeight.IsNegative()) {
194 lineHeight.Reset();
195 }
196 GetArkUINodeModifiers()->getSpanModifier()->setSpanLineHeight(
197 nativeNode, lineHeight.Value(), static_cast<int8_t>(lineHeight.Unit()));
198 return panda::JSValueRef::Undefined(vm);
199 }
200
ResetLineHeight(ArkUIRuntimeCallInfo * runtimeCallInfo)201 ArkUINativeModuleValue SpanBridge::ResetLineHeight(ArkUIRuntimeCallInfo *runtimeCallInfo)
202 {
203 EcmaVM *vm = runtimeCallInfo->GetVM();
204 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
205 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
206 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
207 GetArkUINodeModifiers()->getSpanModifier()->resetSpanLineHeight(nativeNode);
208 return panda::JSValueRef::Undefined(vm);
209 }
210
SetFontStyle(ArkUIRuntimeCallInfo * runtimeCallInfo)211 ArkUINativeModuleValue SpanBridge::SetFontStyle(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 if (secondArg->IsNumber()) {
219 int32_t value = secondArg->Int32Value(vm);
220 if (value >= 0 && value < static_cast<int32_t>(FONT_STYLES.size())) {
221 GetArkUINodeModifiers()->getSpanModifier()->setSpanFontStyle(nativeNode, value);
222 } else {
223 GetArkUINodeModifiers()->getSpanModifier()->resetSpanFontStyle(nativeNode);
224 return panda::JSValueRef::Undefined(vm);
225 }
226 } else {
227 GetArkUINodeModifiers()->getSpanModifier()->resetSpanFontStyle(nativeNode);
228 }
229 return panda::JSValueRef::Undefined(vm);
230 }
231
ResetFontStyle(ArkUIRuntimeCallInfo * runtimeCallInfo)232 ArkUINativeModuleValue SpanBridge::ResetFontStyle(ArkUIRuntimeCallInfo *runtimeCallInfo)
233 {
234 EcmaVM *vm = runtimeCallInfo->GetVM();
235 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
236 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
237 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
238 GetArkUINodeModifiers()->getSpanModifier()->resetSpanFontStyle(nativeNode);
239 return panda::JSValueRef::Undefined(vm);
240 }
241
SetFontSize(ArkUIRuntimeCallInfo * runtimeCallInfo)242 ArkUINativeModuleValue SpanBridge::SetFontSize(ArkUIRuntimeCallInfo *runtimeCallInfo)
243 {
244 EcmaVM *vm = runtimeCallInfo->GetVM();
245 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
246 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
247 Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
248 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
249 auto theme = GetTheme<TextTheme>();
250 CHECK_NULL_RETURN(theme, panda::JSValueRef::Undefined(vm));
251
252 CalcDimension fontSize = theme->GetTextStyle().GetFontSize();
253 if (!ArkTSUtils::ParseJsDimensionFpNG(vm, secondArg, fontSize, false) || fontSize.IsNegative()) {
254 fontSize = theme->GetTextStyle().GetFontSize();
255 }
256 GetArkUINodeModifiers()->getSpanModifier()->setSpanFontSize(nativeNode, fontSize.Value(),
257 static_cast<int8_t>(fontSize.Unit()));
258 return panda::JSValueRef::Undefined(vm);
259 }
260
ResetFontSize(ArkUIRuntimeCallInfo * runtimeCallInfo)261 ArkUINativeModuleValue SpanBridge::ResetFontSize(ArkUIRuntimeCallInfo *runtimeCallInfo)
262 {
263 EcmaVM *vm = runtimeCallInfo->GetVM();
264 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
265 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
266 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
267 GetArkUINodeModifiers()->getSpanModifier()->resetSpanFontSize(nativeNode);
268 return panda::JSValueRef::Undefined(vm);
269 }
270
SetFontFamily(ArkUIRuntimeCallInfo * runtimeCallInfo)271 ArkUINativeModuleValue SpanBridge::SetFontFamily(ArkUIRuntimeCallInfo *runtimeCallInfo)
272 {
273 EcmaVM *vm = runtimeCallInfo->GetVM();
274 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
275 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
276 Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
277 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
278
279 std::vector<std::string> fontFamilies;
280 if (!ArkTSUtils::ParseJsFontFamilies(vm, secondArg, fontFamilies)) {
281 GetArkUINodeModifiers()->getSpanModifier()->resetSpanFontFamily(nativeNode);
282 return panda::JSValueRef::Undefined(vm);
283 }
284 auto families = std::make_unique<char *[]>(fontFamilies.size());
285 for (uint32_t i = 0; i < fontFamilies.size(); i++) {
286 families[i] = const_cast<char *>(fontFamilies.at(i).c_str());
287 }
288 GetArkUINodeModifiers()->getSpanModifier()->setSpanFontFamily(nativeNode,
289 const_cast<const char **>(families.get()), fontFamilies.size());
290 return panda::JSValueRef::Undefined(vm);
291 }
292
ResetFontFamily(ArkUIRuntimeCallInfo * runtimeCallInfo)293 ArkUINativeModuleValue SpanBridge::ResetFontFamily(ArkUIRuntimeCallInfo *runtimeCallInfo)
294 {
295 EcmaVM *vm = runtimeCallInfo->GetVM();
296 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
297 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
298 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
299
300 GetArkUINodeModifiers()->getSpanModifier()->resetSpanFontFamily(nativeNode);
301 return panda::JSValueRef::Undefined(vm);
302 }
303
SetDecoration(ArkUIRuntimeCallInfo * runtimeCallInfo)304 ArkUINativeModuleValue SpanBridge::SetDecoration(ArkUIRuntimeCallInfo *runtimeCallInfo)
305 {
306 EcmaVM *vm = runtimeCallInfo->GetVM();
307 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
308 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
309 Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
310 Local<JSValueRef> thirdArg = runtimeCallInfo->GetCallArgRef(NUM_2);
311 Local<JSValueRef> fourthArg = runtimeCallInfo->GetCallArgRef(NUM_3);
312 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
313 int32_t textDecoration = static_cast<int32_t>(TextDecoration::NONE);
314 Color color = DEFAULT_DECORATION_COLOR;
315 int32_t style = static_cast<int32_t>(DEFAULT_DECORATION_STYLE);
316 if (secondArg->IsInt()) {
317 textDecoration = secondArg->Int32Value(vm);
318 }
319 if (!ArkTSUtils::ParseJsColorAlpha(vm, thirdArg, color)) {
320 color = DEFAULT_DECORATION_COLOR;
321 }
322 if (fourthArg->IsInt()) {
323 style = fourthArg->Int32Value(vm);
324 }
325 GetArkUINodeModifiers()->getSpanModifier()->setSpanDecoration(nativeNode, textDecoration, color.GetValue(), style);
326 return panda::JSValueRef::Undefined(vm);
327 }
328
ResetDecoration(ArkUIRuntimeCallInfo * runtimeCallInfo)329 ArkUINativeModuleValue SpanBridge::ResetDecoration(ArkUIRuntimeCallInfo *runtimeCallInfo)
330 {
331 EcmaVM *vm = runtimeCallInfo->GetVM();
332 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
333 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
334 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
335 GetArkUINodeModifiers()->getSpanModifier()->resetSpanDecoration(nativeNode);
336 return panda::JSValueRef::Undefined(vm);
337 }
338
SetFontColor(ArkUIRuntimeCallInfo * runtimeCallInfo)339 ArkUINativeModuleValue SpanBridge::SetFontColor(ArkUIRuntimeCallInfo *runtimeCallInfo)
340 {
341 EcmaVM *vm = runtimeCallInfo->GetVM();
342 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
343 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
344 Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
345 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
346 auto theme = GetTheme<TextTheme>();
347 CHECK_NULL_RETURN(theme, panda::JSValueRef::Undefined(vm));
348
349 Color textColor = theme->GetTextStyle().GetTextColor();
350 if (!ArkTSUtils::ParseJsColorAlpha(vm, secondArg, textColor)) {
351 textColor = theme->GetTextStyle().GetTextColor();
352 }
353 GetArkUINodeModifiers()->getSpanModifier()->setSpanFontColor(nativeNode, textColor.GetValue());
354 return panda::JSValueRef::Undefined(vm);
355 }
356
ResetFontColor(ArkUIRuntimeCallInfo * runtimeCallInfo)357 ArkUINativeModuleValue SpanBridge::ResetFontColor(ArkUIRuntimeCallInfo *runtimeCallInfo)
358 {
359 EcmaVM *vm = runtimeCallInfo->GetVM();
360 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
361 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
362 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
363
364 GetArkUINodeModifiers()->getSpanModifier()->resetSpanFontColor(nativeNode);
365 return panda::JSValueRef::Undefined(vm);
366 }
367
SetLetterSpacing(ArkUIRuntimeCallInfo * runtimeCallInfo)368 ArkUINativeModuleValue SpanBridge::SetLetterSpacing(ArkUIRuntimeCallInfo *runtimeCallInfo)
369 {
370 EcmaVM *vm = runtimeCallInfo->GetVM();
371 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
372 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
373 Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
374 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
375 struct ArkUIStringAndFloat letterSpacingValue = { 0.0, nullptr };
376 if (secondArg->IsNumber()) {
377 letterSpacingValue.value = secondArg->ToNumber(vm)->Value();
378 GetArkUINodeModifiers()->getSpanModifier()->setSpanLetterSpacing(nativeNode, &letterSpacingValue);
379 } else if (secondArg->IsString(vm)) {
380 std::string tempValueStr = secondArg->ToString(vm)->ToString(vm);
381 letterSpacingValue.valueStr = tempValueStr.c_str();
382 GetArkUINodeModifiers()->getSpanModifier()->setSpanLetterSpacing(nativeNode, &letterSpacingValue);
383 } else {
384 GetArkUINodeModifiers()->getSpanModifier()->resetSpanLetterSpacing(nativeNode);
385 }
386 return panda::JSValueRef::Undefined(vm);
387 }
388
ResetLetterSpacing(ArkUIRuntimeCallInfo * runtimeCallInfo)389 ArkUINativeModuleValue SpanBridge::ResetLetterSpacing(ArkUIRuntimeCallInfo *runtimeCallInfo)
390 {
391 EcmaVM *vm = runtimeCallInfo->GetVM();
392 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
393 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
394 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
395 GetArkUINodeModifiers()->getSpanModifier()->resetSpanLetterSpacing(nativeNode);
396 return panda::JSValueRef::Undefined(vm);
397 }
398
SetBaselineOffset(ArkUIRuntimeCallInfo * runtimeCallInfo)399 ArkUINativeModuleValue SpanBridge::SetBaselineOffset(ArkUIRuntimeCallInfo *runtimeCallInfo)
400 {
401 EcmaVM *vm = runtimeCallInfo->GetVM();
402 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
403 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
404 Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
405 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
406 CalcDimension result;
407 if (secondArg->IsObject(vm) && ArkTSUtils::ParseJsLengthMetrics(vm, secondArg, result) &&
408 result.Unit() != DimensionUnit::PERCENT && !std::isnan(result.Value())) {
409 GetArkUINodeModifiers()->getSpanModifier()->setSpanBaselineOffset(
410 nativeNode, result.Value(), static_cast<int8_t>(result.Unit()));
411 } else {
412 GetArkUINodeModifiers()->getSpanModifier()->resetSpanBaselineOffset(nativeNode);
413 }
414 return panda::JSValueRef::Undefined(vm);
415 }
416
ResetBaselineOffset(ArkUIRuntimeCallInfo * runtimeCallInfo)417 ArkUINativeModuleValue SpanBridge::ResetBaselineOffset(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 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
423 GetArkUINodeModifiers()->getSpanModifier()->resetSpanBaselineOffset(nativeNode);
424 return panda::JSValueRef::Undefined(vm);
425 }
426
SetFont(ArkUIRuntimeCallInfo * runtimeCallInfo)427 ArkUINativeModuleValue SpanBridge::SetFont(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> sizeArg = runtimeCallInfo->GetCallArgRef(NUM_1);
433 Local<JSValueRef> weightArg = runtimeCallInfo->GetCallArgRef(NUM_2);
434 Local<JSValueRef> familyArg = runtimeCallInfo->GetCallArgRef(NUM_3);
435 Local<JSValueRef> styleArg = runtimeCallInfo->GetCallArgRef(NUM_4);
436 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
437 ArkUIFontStruct fontInfo;
438 auto theme = GetTheme<TextTheme>();
439 CHECK_NULL_RETURN(theme, panda::JSValueRef::Undefined(vm));
440
441 CalcDimension fontSize = theme->GetTextStyle().GetFontSize();
442 if (sizeArg->IsNull() || !ArkTSUtils::ParseJsDimensionFpNG(vm, sizeArg, fontSize, false) || fontSize.IsNegative()) {
443 fontSize = theme->GetTextStyle().GetFontSize();
444 }
445 fontInfo.fontSizeNumber = fontSize.Value();
446 fontInfo.fontSizeUnit = static_cast<int8_t>(fontSize.Unit());
447
448 std::string weight = DEFAULT_FONT_WEIGHT;
449 if (!weightArg->IsNull()) {
450 if (weightArg->IsNumber()) {
451 weight = std::to_string(weightArg->Int32Value(vm));
452 } else if (weightArg->IsString(vm)) {
453 weight = weightArg->ToString(vm)->ToString(vm);
454 }
455 }
456 fontInfo.fontWeight = static_cast<uint8_t>(Framework::ConvertStrToFontWeight(weight));
457 int32_t style = static_cast<int32_t>(DEFAULT_FONT_STYLE);
458 if (styleArg->IsInt()) {
459 style = styleArg->Int32Value(vm);
460 if (style <= 0 || style > static_cast<int32_t>(FONT_STYLES.size())) {
461 style = static_cast<int32_t>(DEFAULT_FONT_STYLE);
462 }
463 }
464 fontInfo.fontStyle = static_cast<uint8_t>(style);
465 std::vector<std::string> fontFamilies;
466 fontInfo.fontFamilies = nullptr;
467 if (!familyArg->IsNull() && ArkTSUtils::ParseJsFontFamilies(vm, familyArg, fontFamilies)) {
468 fontInfo.familyLength = fontFamilies.size();
469 auto families = std::make_unique<const char* []>(fontInfo.familyLength);
470 for (uint32_t i = 0; i < fontFamilies.size(); i++) {
471 families[i] = fontFamilies[i].c_str();
472 }
473 fontInfo.fontFamilies = families.get();
474 GetArkUINodeModifiers()->getSpanModifier()->setSpanFont(nativeNode, &fontInfo);
475 } else {
476 GetArkUINodeModifiers()->getSpanModifier()->setSpanFont(nativeNode, &fontInfo);
477 }
478 return panda::JSValueRef::Undefined(vm);
479 }
480
ResetFont(ArkUIRuntimeCallInfo * runtimeCallInfo)481 ArkUINativeModuleValue SpanBridge::ResetFont(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()->getSpanModifier()->resetSpanFont(nativeNode);
488 return panda::JSValueRef::Undefined(vm);
489 }
490
SetTextBackgroundStyle(ArkUIRuntimeCallInfo * runtimeCallInfo)491 ArkUINativeModuleValue SpanBridge::SetTextBackgroundStyle(ArkUIRuntimeCallInfo* runtimeCallInfo)
492 {
493 EcmaVM* vm = runtimeCallInfo->GetVM();
494 Color color;
495 std::vector<ArkUI_Float32> radiusArray;
496 std::vector<ArkUI_Int32> valueUnits;
497 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
498 Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
499 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
500 if (!(ArkTSUtils::ParseJsColorAlpha(vm, secondArg, color))) {
501 color = Color::TRANSPARENT;
502 }
503 ParseOuterBorderRadius(runtimeCallInfo, vm, radiusArray, valueUnits, NUM_2); // Border Radius args start index
504 GetArkUINodeModifiers()->getSpanModifier()->setSpanTextBackgroundStyle(
505 nativeNode, color.GetValue(), radiusArray.data(), valueUnits.data(), static_cast<int32_t>(radiusArray.size()));
506 return panda::JSValueRef::Undefined(vm);
507 }
508
ResetTextBackgroundStyle(ArkUIRuntimeCallInfo * runtimeCallInfo)509 ArkUINativeModuleValue SpanBridge::ResetTextBackgroundStyle(ArkUIRuntimeCallInfo* runtimeCallInfo)
510 {
511 EcmaVM* vm = runtimeCallInfo->GetVM();
512 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
513 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
514 GetArkUINodeModifiers()->getSpanModifier()->resetSpanTextBackgroundStyle(nativeNode);
515 return panda::JSValueRef::Undefined(vm);
516 }
517
SetTextShadow(ArkUIRuntimeCallInfo * runtimeCallInfo)518 ArkUINativeModuleValue SpanBridge::SetTextShadow(ArkUIRuntimeCallInfo* runtimeCallInfo)
519 {
520 EcmaVM* vm = runtimeCallInfo->GetVM();
521 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
522 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
523 Local<JSValueRef> lengthArg = runtimeCallInfo->GetCallArgRef(NUM_7);
524 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
525 uint32_t length;
526 if (!lengthArg->IsNumber() || lengthArg->Uint32Value(vm) == 0) {
527 return panda::JSValueRef::Undefined(vm);
528 }
529 length = lengthArg->Uint32Value(vm);
530 std::vector<ArkUITextShadowStruct> textShadowArray;
531 ParseTextShadow(runtimeCallInfo, length, textShadowArray);
532 GetArkUINodeModifiers()->getSpanModifier()->setTextShadow(nativeNode, textShadowArray.data(), length);
533 return panda::JSValueRef::Undefined(vm);
534 }
535
ResetTextShadow(ArkUIRuntimeCallInfo * runtimeCallInfo)536 ArkUINativeModuleValue SpanBridge::ResetTextShadow(ArkUIRuntimeCallInfo* runtimeCallInfo)
537 {
538 EcmaVM* vm = runtimeCallInfo->GetVM();
539 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
540 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
541 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
542 GetArkUINodeModifiers()->getSpanModifier()->resetTextShadow(nativeNode);
543 return panda::JSValueRef::Undefined(vm);
544 }
545
SetAccessibilityText(ArkUIRuntimeCallInfo * runtimeCallInfo)546 ArkUINativeModuleValue SpanBridge::SetAccessibilityText(ArkUIRuntimeCallInfo *runtimeCallInfo)
547 {
548 EcmaVM* vm = runtimeCallInfo->GetVM();
549 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
550 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
551 Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
552 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
553 if (secondArg->IsString(vm)) {
554 std::string stringValue = secondArg->ToString(vm)->ToString(vm);
555 GetArkUINodeModifiers()->getSpanModifier()->setAccessibilityText(nativeNode, stringValue.c_str());
556 } else {
557 GetArkUINodeModifiers()->getSpanModifier()->resetAccessibilityText(nativeNode);
558 }
559 return panda::JSValueRef::Undefined(vm);
560 }
561
ResetAccessibilityText(ArkUIRuntimeCallInfo * runtimeCallInfo)562 ArkUINativeModuleValue SpanBridge::ResetAccessibilityText(ArkUIRuntimeCallInfo *runtimeCallInfo)
563 {
564 EcmaVM* vm = runtimeCallInfo->GetVM();
565 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
566 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
567 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
568 GetArkUINodeModifiers()->getSpanModifier()->resetAccessibilityText(nativeNode);
569 return panda::JSValueRef::Undefined(vm);
570 }
571
SetAccessibilityDescription(ArkUIRuntimeCallInfo * runtimeCallInfo)572 ArkUINativeModuleValue SpanBridge::SetAccessibilityDescription(ArkUIRuntimeCallInfo *runtimeCallInfo)
573 {
574 EcmaVM* vm = runtimeCallInfo->GetVM();
575 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
576 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
577 Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
578 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
579 if (secondArg->IsString(vm)) {
580 std::string stringValue = secondArg->ToString(vm)->ToString(vm);
581 GetArkUINodeModifiers()->getSpanModifier()->setAccessibilityDescription(nativeNode, stringValue.c_str());
582 } else {
583 GetArkUINodeModifiers()->getSpanModifier()->resetAccessibilityDescription(nativeNode);
584 }
585 return panda::JSValueRef::Undefined(vm);
586 }
587
ResetAccessibilityDescription(ArkUIRuntimeCallInfo * runtimeCallInfo)588 ArkUINativeModuleValue SpanBridge::ResetAccessibilityDescription(ArkUIRuntimeCallInfo *runtimeCallInfo)
589 {
590 EcmaVM* vm = runtimeCallInfo->GetVM();
591 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
592 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
593 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
594 GetArkUINodeModifiers()->getSpanModifier()->resetAccessibilityDescription(nativeNode);
595 return panda::JSValueRef::Undefined(vm);
596 }
597
SetAccessibilityLevel(ArkUIRuntimeCallInfo * runtimeCallInfo)598 ArkUINativeModuleValue SpanBridge::SetAccessibilityLevel(ArkUIRuntimeCallInfo *runtimeCallInfo)
599 {
600 EcmaVM* vm = runtimeCallInfo->GetVM();
601 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
602 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
603 Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
604 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
605 if (secondArg->IsString(vm)) {
606 std::string stringValue = secondArg->ToString(vm)->ToString(vm);
607 GetArkUINodeModifiers()->getSpanModifier()->setAccessibilityLevel(nativeNode, stringValue.c_str());
608 } else {
609 GetArkUINodeModifiers()->getSpanModifier()->resetAccessibilityLevel(nativeNode);
610 }
611 return panda::JSValueRef::Undefined(vm);
612 }
613
ResetAccessibilityLevel(ArkUIRuntimeCallInfo * runtimeCallInfo)614 ArkUINativeModuleValue SpanBridge::ResetAccessibilityLevel(ArkUIRuntimeCallInfo *runtimeCallInfo)
615 {
616 EcmaVM* vm = runtimeCallInfo->GetVM();
617 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
618 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
619 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
620 GetArkUINodeModifiers()->getSpanModifier()->resetAccessibilityLevel(nativeNode);
621 return panda::JSValueRef::Undefined(vm);
622 }
623 } // namespace OHOS::Ace::NG
624