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