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_common_shape_bridge.h"
16 #include "frameworks/bridge/declarative_frontend/engine/jsi/nativeModule/arkts_utils.h"
17
18 namespace OHOS::Ace::NG {
19 constexpr int NUM_0 = 0;
20 constexpr int NUM_1 = 1;
21 constexpr double STROKE_MITERLIMIT_DEFAULT = 4.0f;
22 constexpr double DEFAULT_OPACITY = 1.0;
23 constexpr double MIN_OPACITY = 0.0;
24 constexpr uint32_t TRANSPARENT_COLOR = 0x00000000;
25
SetStrokeDashArray(ArkUIRuntimeCallInfo * runtimeCallInfo)26 ArkUINativeModuleValue CommonShapeBridge::SetStrokeDashArray(ArkUIRuntimeCallInfo* runtimeCallInfo)
27 {
28 EcmaVM* vm = runtimeCallInfo->GetVM();
29 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
30 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
31 Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
32
33 if (!secondArg->IsArray(vm)) {
34 return panda::JSValueRef::Undefined(vm);
35 }
36 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
37 auto array = Local<panda::ArrayRef>(secondArg);
38 auto length = array->Length(vm);
39
40 std::vector<ArkUI_Float32> dashArray;
41 std::vector<int32_t> dimUnits;
42 for (uint32_t index = 0; index < length; index++) {
43 Local<JSValueRef> value = panda::ArrayRef::GetValueAt(vm, array, index);
44 CalcDimension dimDash;
45 if (ArkTSUtils::ParseJsDimensionVpNG(vm, value, dimDash)) {
46 dashArray.emplace_back(dimDash.Value());
47 dimUnits.emplace_back(static_cast<int32_t>(dimDash.Unit()));
48 } else {
49 dashArray.clear();
50 dimUnits.clear();
51 break;
52 }
53 }
54 // if odd,add twice
55 if (static_cast<uint32_t>(length) == dashArray.size() && (static_cast<uint32_t>(length) & 1)) {
56 for (uint32_t i = 0; i < length; i++) {
57 dashArray.emplace_back(dashArray[i]);
58 dimUnits.emplace_back(dimUnits[i]);
59 }
60 }
61 GetArkUINodeModifiers()->getCommonShapeModifier()->setStrokeDashArray(nativeNode, dashArray.data(),
62 dimUnits.data(), dashArray.size());
63 return panda::JSValueRef::Undefined(vm);
64 }
65
ResetStrokeDashArray(ArkUIRuntimeCallInfo * runtimeCallInfo)66 ArkUINativeModuleValue CommonShapeBridge::ResetStrokeDashArray(ArkUIRuntimeCallInfo* runtimeCallInfo)
67 {
68 EcmaVM* vm = runtimeCallInfo->GetVM();
69 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
70 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
71 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
72 GetArkUINodeModifiers()->getCommonShapeModifier()->resetStrokeDashArray(nativeNode);
73 return panda::JSValueRef::Undefined(vm);
74 }
75
SetStroke(ArkUIRuntimeCallInfo * runtimeCallInfo)76 ArkUINativeModuleValue CommonShapeBridge::SetStroke(ArkUIRuntimeCallInfo* runtimeCallInfo)
77 {
78 EcmaVM* vm = runtimeCallInfo->GetVM();
79 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
80 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
81 Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
82 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
83 Color color;
84 if (!ArkTSUtils::ParseJsColorAlpha(vm, secondArg, color)) {
85 GetArkUINodeModifiers()->getCommonShapeModifier()->resetStroke(nativeNode);
86 } else {
87 GetArkUINodeModifiers()->getCommonShapeModifier()->setStroke(nativeNode, color.GetValue());
88 }
89 return panda::JSValueRef::Undefined(vm);
90 }
91
ResetStroke(ArkUIRuntimeCallInfo * runtimeCallInfo)92 ArkUINativeModuleValue CommonShapeBridge::ResetStroke(ArkUIRuntimeCallInfo* runtimeCallInfo)
93 {
94 EcmaVM* vm = runtimeCallInfo->GetVM();
95 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
96 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
97 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
98 GetArkUINodeModifiers()->getCommonShapeModifier()->resetStroke(nativeNode);
99 return panda::JSValueRef::Undefined(vm);
100 }
101
SetFill(ArkUIRuntimeCallInfo * runtimeCallInfo)102 ArkUINativeModuleValue CommonShapeBridge::SetFill(ArkUIRuntimeCallInfo* runtimeCallInfo)
103 {
104 EcmaVM* vm = runtimeCallInfo->GetVM();
105 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
106 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
107 Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
108 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
109 if (secondArg->IsString(vm) && secondArg->ToString(vm)->ToString(vm) == "none") {
110 GetArkUINodeModifiers()->getCommonShapeModifier()->setFill(nativeNode, TRANSPARENT_COLOR);
111 return panda::JSValueRef::Undefined(vm);
112 }
113 Color color;
114 if (!ArkTSUtils::ParseJsColorAlpha(vm, secondArg, color)) {
115 GetArkUINodeModifiers()->getCommonShapeModifier()->resetFill(nativeNode);
116 } else {
117 GetArkUINodeModifiers()->getCommonShapeModifier()->setFill(nativeNode, color.GetValue());
118 }
119 return panda::JSValueRef::Undefined(vm);
120 }
121
ResetFill(ArkUIRuntimeCallInfo * runtimeCallInfo)122 ArkUINativeModuleValue CommonShapeBridge::ResetFill(ArkUIRuntimeCallInfo* runtimeCallInfo)
123 {
124 EcmaVM* vm = runtimeCallInfo->GetVM();
125 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
126 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
127 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
128 GetArkUINodeModifiers()->getCommonShapeModifier()->resetFill(nativeNode);
129 return panda::JSValueRef::Undefined(vm);
130 }
131
SetStrokeDashOffset(ArkUIRuntimeCallInfo * runtimeCallInfo)132 ArkUINativeModuleValue CommonShapeBridge::SetStrokeDashOffset(ArkUIRuntimeCallInfo* runtimeCallInfo)
133 {
134 EcmaVM* vm = runtimeCallInfo->GetVM();
135 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
136 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
137 Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
138 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
139 CalcDimension strokeDashOffset;
140 std::string calcStr;
141 if (secondArg->IsUndefined() || !ArkTSUtils::ParseJsDimensionVpNG(vm, secondArg, strokeDashOffset)) {
142 GetArkUINodeModifiers()->getCommonShapeModifier()->resetStrokeDashOffset(nativeNode);
143 } else {
144 GetArkUINodeModifiers()->getCommonShapeModifier()->setStrokeDashOffset(
145 nativeNode, strokeDashOffset.Value(), static_cast<int>(strokeDashOffset.Unit()));
146 }
147 return panda::JSValueRef::Undefined(vm);
148 }
149
ResetStrokeDashOffset(ArkUIRuntimeCallInfo * runtimeCallInfo)150 ArkUINativeModuleValue CommonShapeBridge::ResetStrokeDashOffset(ArkUIRuntimeCallInfo* runtimeCallInfo)
151 {
152 EcmaVM* vm = runtimeCallInfo->GetVM();
153 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
154 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
155 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
156 GetArkUINodeModifiers()->getCommonShapeModifier()->resetStrokeDashOffset(nativeNode);
157 return panda::JSValueRef::Undefined(vm);
158 }
159
SetStrokeLineCap(ArkUIRuntimeCallInfo * runtimeCallInfo)160 ArkUINativeModuleValue CommonShapeBridge::SetStrokeLineCap(ArkUIRuntimeCallInfo* runtimeCallInfo)
161 {
162 EcmaVM* vm = runtimeCallInfo->GetVM();
163 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
164 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
165 Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
166 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
167 if (secondArg->IsUndefined()) {
168 GetArkUINodeModifiers()->getCommonShapeModifier()->resetStrokeLineCap(nativeNode);
169 } else {
170 int strokeLineCap = secondArg->ToNumber(vm)->Value();
171 GetArkUINodeModifiers()->getCommonShapeModifier()->setStrokeLineCap(nativeNode, strokeLineCap);
172 }
173 return panda::JSValueRef::Undefined(vm);
174 }
175
ResetStrokeLineCap(ArkUIRuntimeCallInfo * runtimeCallInfo)176 ArkUINativeModuleValue CommonShapeBridge::ResetStrokeLineCap(ArkUIRuntimeCallInfo* runtimeCallInfo)
177 {
178 EcmaVM* vm = runtimeCallInfo->GetVM();
179 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
180 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
181 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
182 GetArkUINodeModifiers()->getCommonShapeModifier()->resetStrokeLineCap(nativeNode);
183 return panda::JSValueRef::Undefined(vm);
184 }
185
SetStrokeLineJoin(ArkUIRuntimeCallInfo * runtimeCallInfo)186 ArkUINativeModuleValue CommonShapeBridge::SetStrokeLineJoin(ArkUIRuntimeCallInfo* runtimeCallInfo)
187 {
188 EcmaVM* vm = runtimeCallInfo->GetVM();
189 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
190 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
191 Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
192 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
193 if (secondArg->IsUndefined()) {
194 GetArkUINodeModifiers()->getCommonShapeModifier()->resetStrokeLineJoin(nativeNode);
195 } else {
196 int strokeLineJoin = secondArg->ToNumber(vm)->Value();
197 GetArkUINodeModifiers()->getCommonShapeModifier()->setStrokeLineJoin(nativeNode, strokeLineJoin);
198 }
199 return panda::JSValueRef::Undefined(vm);
200 }
201
ResetStrokeLineJoin(ArkUIRuntimeCallInfo * runtimeCallInfo)202 ArkUINativeModuleValue CommonShapeBridge::ResetStrokeLineJoin(ArkUIRuntimeCallInfo* runtimeCallInfo)
203 {
204 EcmaVM* vm = runtimeCallInfo->GetVM();
205 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
206 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
207 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
208 GetArkUINodeModifiers()->getCommonShapeModifier()->resetStrokeLineJoin(nativeNode);
209 return panda::JSValueRef::Undefined(vm);
210 }
211
SetStrokeMiterLimit(ArkUIRuntimeCallInfo * runtimeCallInfo)212 ArkUINativeModuleValue CommonShapeBridge::SetStrokeMiterLimit(ArkUIRuntimeCallInfo* runtimeCallInfo)
213 {
214 EcmaVM* vm = runtimeCallInfo->GetVM();
215 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
216 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
217 Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
218 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
219 double strokeMiterLimit = STROKE_MITERLIMIT_DEFAULT;
220 if (secondArg->IsUndefined() || !ArkTSUtils::ParseJsDouble(vm, secondArg, strokeMiterLimit)) {
221 GetArkUINodeModifiers()->getCommonShapeModifier()->resetStrokeMiterLimit(nativeNode);
222 } else {
223 GetArkUINodeModifiers()->getCommonShapeModifier()->setStrokeMiterLimit(nativeNode, strokeMiterLimit);
224 }
225 return panda::JSValueRef::Undefined(vm);
226 }
227
ResetStrokeMiterLimit(ArkUIRuntimeCallInfo * runtimeCallInfo)228 ArkUINativeModuleValue CommonShapeBridge::ResetStrokeMiterLimit(ArkUIRuntimeCallInfo* runtimeCallInfo)
229 {
230 EcmaVM* vm = runtimeCallInfo->GetVM();
231 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
232 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
233 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
234 GetArkUINodeModifiers()->getCommonShapeModifier()->resetStrokeMiterLimit(nativeNode);
235 return panda::JSValueRef::Undefined(vm);
236 }
237
SetFillOpacity(ArkUIRuntimeCallInfo * runtimeCallInfo)238 ArkUINativeModuleValue CommonShapeBridge::SetFillOpacity(ArkUIRuntimeCallInfo* runtimeCallInfo)
239 {
240 EcmaVM* vm = runtimeCallInfo->GetVM();
241 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
242 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
243 Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
244 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
245 if (secondArg->IsUndefined()) {
246 GetArkUINodeModifiers()->getCommonShapeModifier()->resetFillOpacity(nativeNode);
247 } else {
248 double opacity = DEFAULT_OPACITY;
249 if (!ArkTSUtils::ParseJsDouble(vm, secondArg, opacity)) {
250 GetArkUINodeModifiers()->getCommonShapeModifier()->resetFillOpacity(nativeNode);
251 } else {
252 if (opacity > DEFAULT_OPACITY) {
253 opacity = DEFAULT_OPACITY;
254 }
255 if (opacity < MIN_OPACITY) {
256 opacity = MIN_OPACITY;
257 }
258 GetArkUINodeModifiers()->getCommonShapeModifier()->setFillOpacity(nativeNode, opacity);
259 }
260 }
261 return panda::JSValueRef::Undefined(vm);
262 }
263
ResetFillOpacity(ArkUIRuntimeCallInfo * runtimeCallInfo)264 ArkUINativeModuleValue CommonShapeBridge::ResetFillOpacity(ArkUIRuntimeCallInfo* runtimeCallInfo)
265 {
266 EcmaVM* vm = runtimeCallInfo->GetVM();
267 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
268 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
269 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
270 GetArkUINodeModifiers()->getCommonShapeModifier()->resetFillOpacity(nativeNode);
271 return panda::JSValueRef::Undefined(vm);
272 }
273
SetStrokeOpacity(ArkUIRuntimeCallInfo * runtimeCallInfo)274 ArkUINativeModuleValue CommonShapeBridge::SetStrokeOpacity(ArkUIRuntimeCallInfo* runtimeCallInfo)
275 {
276 EcmaVM* vm = runtimeCallInfo->GetVM();
277 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
278 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
279 Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
280 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
281 if (secondArg->IsUndefined()) {
282 GetArkUINodeModifiers()->getCommonShapeModifier()->resetStrokeOpacity(nativeNode);
283 } else {
284 double opacity = DEFAULT_OPACITY;
285 if (!ArkTSUtils::ParseJsDouble(vm, secondArg, opacity)) {
286 GetArkUINodeModifiers()->getCommonShapeModifier()->resetStrokeOpacity(nativeNode);
287 } else {
288 if (opacity > DEFAULT_OPACITY) {
289 opacity = DEFAULT_OPACITY;
290 }
291 if (opacity < MIN_OPACITY) {
292 opacity = MIN_OPACITY;
293 }
294 GetArkUINodeModifiers()->getCommonShapeModifier()->setStrokeOpacity(nativeNode, opacity);
295 }
296 }
297 return panda::JSValueRef::Undefined(vm);
298 }
299
ResetStrokeOpacity(ArkUIRuntimeCallInfo * runtimeCallInfo)300 ArkUINativeModuleValue CommonShapeBridge::ResetStrokeOpacity(ArkUIRuntimeCallInfo* runtimeCallInfo)
301 {
302 EcmaVM* vm = runtimeCallInfo->GetVM();
303 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
304 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
305 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
306 GetArkUINodeModifiers()->getCommonShapeModifier()->resetStrokeOpacity(nativeNode);
307 return panda::JSValueRef::Undefined(vm);
308 }
309
SetStrokeWidth(ArkUIRuntimeCallInfo * runtimeCallInfo)310 ArkUINativeModuleValue CommonShapeBridge::SetStrokeWidth(ArkUIRuntimeCallInfo* runtimeCallInfo)
311 {
312 EcmaVM* vm = runtimeCallInfo->GetVM();
313 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
314 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
315 Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
316 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
317 CalcDimension strokeWidth = CalcDimension(1.0, DimensionUnit::VP);
318 if (secondArg->IsString(vm)) {
319 const std::string& value = secondArg->ToString(vm)->ToString(vm);
320 strokeWidth = StringUtils::StringToDimensionWithUnit(value, DimensionUnit::VP, 1.0);
321 } else {
322 ArkTSUtils::ParseJsDimension(vm, secondArg, strokeWidth, DimensionUnit::VP);
323 }
324 if (strokeWidth.IsNegative()) {
325 strokeWidth = CalcDimension(1.0, DimensionUnit::VP);
326 }
327 GetArkUINodeModifiers()->getCommonShapeModifier()->setStrokeWidth(
328 nativeNode, strokeWidth.Value(), static_cast<int>(strokeWidth.Unit()));
329 return panda::JSValueRef::Undefined(vm);
330 }
331
ResetStrokeWidth(ArkUIRuntimeCallInfo * runtimeCallInfo)332 ArkUINativeModuleValue CommonShapeBridge::ResetStrokeWidth(ArkUIRuntimeCallInfo* runtimeCallInfo)
333 {
334 EcmaVM* vm = runtimeCallInfo->GetVM();
335 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
336 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
337 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
338 GetArkUINodeModifiers()->getCommonShapeModifier()->resetStrokeWidth(nativeNode);
339 return panda::JSValueRef::Undefined(vm);
340 }
341
SetAntiAlias(ArkUIRuntimeCallInfo * runtimeCallInfo)342 ArkUINativeModuleValue CommonShapeBridge::SetAntiAlias(ArkUIRuntimeCallInfo* runtimeCallInfo)
343 {
344 EcmaVM* vm = runtimeCallInfo->GetVM();
345 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
346 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
347 Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
348 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
349 if (secondArg->IsUndefined()) {
350 GetArkUINodeModifiers()->getCommonShapeModifier()->resetAntiAlias(nativeNode);
351 } else {
352 bool antiAlias = secondArg->ToBoolean(vm)->Value();
353 GetArkUINodeModifiers()->getCommonShapeModifier()->setAntiAlias(nativeNode, antiAlias);
354 }
355 return panda::JSValueRef::Undefined(vm);
356 }
357
ResetAntiAlias(ArkUIRuntimeCallInfo * runtimeCallInfo)358 ArkUINativeModuleValue CommonShapeBridge::ResetAntiAlias(ArkUIRuntimeCallInfo* runtimeCallInfo)
359 {
360 EcmaVM* vm = runtimeCallInfo->GetVM();
361 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
362 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
363 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
364 GetArkUINodeModifiers()->getCommonShapeModifier()->resetAntiAlias(nativeNode);
365 return panda::JSValueRef::Undefined(vm);
366 }
367
SetWidth(ArkUIRuntimeCallInfo * runtimeCallInfo)368 ArkUINativeModuleValue CommonShapeBridge::SetWidth(ArkUIRuntimeCallInfo* runtimeCallInfo)
369 {
370 EcmaVM* vm = runtimeCallInfo->GetVM();
371 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
372 Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(NUM_0);
373 auto nativeNode = nodePtr(nodeArg->ToNativePointer(vm)->Value());
374 Local<JSValueRef> widthArg = runtimeCallInfo->GetCallArgRef(NUM_1);
375 CalcDimension width;
376 if (!ArkTSUtils::ParseJsDimensionVpNG(vm, widthArg, width)) {
377 GetArkUINodeModifiers()->getCommonShapeModifier()->resetShapeWidth(nativeNode);
378 return panda::JSValueRef::Undefined(vm);
379 }
380 if (LessNotEqual(width.Value(), 0.0)) {
381 width.SetValue(0.0);
382 }
383 GetArkUINodeModifiers()->getCommonShapeModifier()->setShapeWidth(
384 nativeNode, width.Value(), static_cast<int32_t>(width.Unit()));
385 return panda::JSValueRef::Undefined(vm);
386 }
387
ResetWidth(ArkUIRuntimeCallInfo * runtimeCallInfo)388 ArkUINativeModuleValue CommonShapeBridge::ResetWidth(ArkUIRuntimeCallInfo* runtimeCallInfo)
389 {
390 CommonBridge::ResetWidth(runtimeCallInfo);
391 EcmaVM* vm = runtimeCallInfo->GetVM();
392 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
393 Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(NUM_0);
394 auto nativeNode = nodePtr(nodeArg->ToNativePointer(vm)->Value());
395 GetArkUINodeModifiers()->getCommonShapeModifier()->resetShapeWidth(nativeNode);
396 return panda::JSValueRef::Undefined(vm);
397 }
398
SetHeight(ArkUIRuntimeCallInfo * runtimeCallInfo)399 ArkUINativeModuleValue CommonShapeBridge::SetHeight(ArkUIRuntimeCallInfo* runtimeCallInfo)
400 {
401 EcmaVM* vm = runtimeCallInfo->GetVM();
402 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
403 Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(NUM_0);
404 auto nativeNode = nodePtr(nodeArg->ToNativePointer(vm)->Value());
405 Local<JSValueRef> heightArg = runtimeCallInfo->GetCallArgRef(NUM_1);
406 CalcDimension height;
407 if (!ArkTSUtils::ParseJsDimensionVpNG(vm, heightArg, height)) {
408 GetArkUINodeModifiers()->getCommonShapeModifier()->resetShapeHeight(nativeNode);
409 return panda::JSValueRef::Undefined(vm);
410 }
411 if (LessNotEqual(height.Value(), 0.0)) {
412 height.SetValue(0.0);
413 }
414 GetArkUINodeModifiers()->getCommonShapeModifier()->setShapeHeight(
415 nativeNode, height.Value(), static_cast<int32_t>(height.Unit()));
416 return panda::JSValueRef::Undefined(vm);
417 }
418
ResetHeight(ArkUIRuntimeCallInfo * runtimeCallInfo)419 ArkUINativeModuleValue CommonShapeBridge::ResetHeight(ArkUIRuntimeCallInfo* runtimeCallInfo)
420 {
421 CommonBridge::ResetHeight(runtimeCallInfo);
422 EcmaVM* vm = runtimeCallInfo->GetVM();
423 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
424 Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(NUM_0);
425 auto nativeNode = nodePtr(nodeArg->ToNativePointer(vm)->Value());
426 GetArkUINodeModifiers()->getCommonShapeModifier()->resetShapeHeight(nativeNode);
427 return panda::JSValueRef::Undefined(vm);
428 }
429
SetForegroundColor(ArkUIRuntimeCallInfo * runtimeCallInfo)430 ArkUINativeModuleValue CommonShapeBridge::SetForegroundColor(ArkUIRuntimeCallInfo* runtimeCallInfo)
431 {
432 EcmaVM* vm = runtimeCallInfo->GetVM();
433 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
434 Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(NUM_0);
435 auto nativeNode = nodePtr(nodeArg->ToNativePointer(vm)->Value());
436 auto colorArg = runtimeCallInfo->GetCallArgRef(NUM_1);
437 ForegroundColorStrategy strategy;
438 if (ArkTSUtils::ParseJsColorStrategy(vm, colorArg, strategy)) {
439 auto castedStrategy = static_cast<uint32_t>(strategy);
440 GetArkUINodeModifiers()->getCommonShapeModifier()->setShapeForegroundColor(nativeNode, false, castedStrategy);
441 return panda::JSValueRef::Undefined(vm);
442 }
443 Color foregroundColor;
444 if (!ArkTSUtils::ParseJsColorAlpha(vm, colorArg, foregroundColor)) {
445 GetArkUINodeModifiers()->getCommonShapeModifier()->resetShapeForegroundColor(nativeNode);
446 } else {
447 GetArkUINodeModifiers()->getCommonShapeModifier()->setShapeForegroundColor(
448 nativeNode, true, foregroundColor.GetValue());
449 }
450 return panda::JSValueRef::Undefined(vm);
451 }
452
ResetForegroundColor(ArkUIRuntimeCallInfo * runtimeCallInfo)453 ArkUINativeModuleValue CommonShapeBridge::ResetForegroundColor(ArkUIRuntimeCallInfo* runtimeCallInfo)
454 {
455 EcmaVM* vm = runtimeCallInfo->GetVM();
456 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
457 Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(NUM_0);
458 auto nativeNode = nodePtr(nodeArg->ToNativePointer(vm)->Value());
459 GetArkUINodeModifiers()->getCommonShapeModifier()->resetShapeForegroundColor(nativeNode);
460 return panda::JSValueRef::Undefined(vm);
461 }
462 } // namespace OHOS::Ace::NG