• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 #include "bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_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     std::vector<RefPtr<ResourceObject>> resObjArray;
43     for (uint32_t index = 0; index < length; index++) {
44         Local<JSValueRef> value = panda::ArrayRef::GetValueAt(vm, array, index);
45         CalcDimension dimDash;
46         RefPtr<ResourceObject> resObj;
47         if (ArkTSUtils::ParseJsDimensionVpNG(vm, value, dimDash, resObj)) {
48             dashArray.emplace_back(dimDash.Value());
49             dimUnits.emplace_back(static_cast<int32_t>(dimDash.Unit()));
50             resObjArray.emplace_back(resObj);
51         } else {
52             dashArray.clear();
53             dimUnits.clear();
54             resObjArray.clear();
55             break;
56         }
57     }
58     // if odd,add twice
59     if (static_cast<uint32_t>(length) == dashArray.size() && (static_cast<uint32_t>(length) & 1)) {
60         for (uint32_t i = 0; i < length; i++) {
61             dashArray.emplace_back(dashArray[i]);
62             dimUnits.emplace_back(dimUnits[i]);
63             resObjArray.emplace_back(resObjArray[i]);
64         }
65     }
66     GetArkUINodeModifiers()->getCommonShapeModifier()->setStrokeDashArray(nativeNode, dashArray.data(),
67         dimUnits.data(), dashArray.size(), resObjArray.data());
68     return panda::JSValueRef::Undefined(vm);
69 }
70 
ResetStrokeDashArray(ArkUIRuntimeCallInfo * runtimeCallInfo)71 ArkUINativeModuleValue CommonShapeBridge::ResetStrokeDashArray(ArkUIRuntimeCallInfo* runtimeCallInfo)
72 {
73     EcmaVM* vm = runtimeCallInfo->GetVM();
74     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
75     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
76     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
77     GetArkUINodeModifiers()->getCommonShapeModifier()->resetStrokeDashArray(nativeNode);
78     return panda::JSValueRef::Undefined(vm);
79 }
80 
SetStroke(ArkUIRuntimeCallInfo * runtimeCallInfo)81 ArkUINativeModuleValue CommonShapeBridge::SetStroke(ArkUIRuntimeCallInfo* runtimeCallInfo)
82 {
83     EcmaVM* vm = runtimeCallInfo->GetVM();
84     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
85     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
86     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
87     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
88     Color color;
89     RefPtr<ResourceObject> resObj;
90     if (!ArkTSUtils::ParseJsColorAlpha(vm, secondArg, color, resObj, ArkTSUtils::MakeNativeNodeInfo(nativeNode))) {
91         GetArkUINodeModifiers()->getCommonShapeModifier()->resetStroke(nativeNode);
92     } else {
93         GetArkUINodeModifiers()->getCommonShapeModifier()->setStroke(
94             nativeNode, color.GetValue(), AceType::RawPtr(resObj));
95     }
96     return panda::JSValueRef::Undefined(vm);
97 }
98 
ResetStroke(ArkUIRuntimeCallInfo * runtimeCallInfo)99 ArkUINativeModuleValue CommonShapeBridge::ResetStroke(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     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
105     GetArkUINodeModifiers()->getCommonShapeModifier()->resetStroke(nativeNode);
106     return panda::JSValueRef::Undefined(vm);
107 }
108 
SetFill(ArkUIRuntimeCallInfo * runtimeCallInfo)109 ArkUINativeModuleValue CommonShapeBridge::SetFill(ArkUIRuntimeCallInfo* runtimeCallInfo)
110 {
111     EcmaVM* vm = runtimeCallInfo->GetVM();
112     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
113     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
114     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
115     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
116     if (secondArg->IsString(vm) && secondArg->ToString(vm)->ToString(vm) == "none") {
117         GetArkUINodeModifiers()->getCommonShapeModifier()->setFill(nativeNode, TRANSPARENT_COLOR, nullptr);
118         return panda::JSValueRef::Undefined(vm);
119     }
120     Color color;
121     RefPtr<ResourceObject> resObj;
122     if (!ArkTSUtils::ParseJsColorAlpha(vm, secondArg, color, resObj, ArkTSUtils::MakeNativeNodeInfo(nativeNode))) {
123         GetArkUINodeModifiers()->getCommonShapeModifier()->resetFill(nativeNode);
124     } else {
125         GetArkUINodeModifiers()->getCommonShapeModifier()->setFill(
126             nativeNode, color.GetValue(), AceType::RawPtr(resObj));
127     }
128     return panda::JSValueRef::Undefined(vm);
129 }
130 
ResetFill(ArkUIRuntimeCallInfo * runtimeCallInfo)131 ArkUINativeModuleValue CommonShapeBridge::ResetFill(ArkUIRuntimeCallInfo* runtimeCallInfo)
132 {
133     EcmaVM* vm = runtimeCallInfo->GetVM();
134     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
135     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
136     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
137     GetArkUINodeModifiers()->getCommonShapeModifier()->resetFill(nativeNode);
138     return panda::JSValueRef::Undefined(vm);
139 }
140 
SetStrokeDashOffset(ArkUIRuntimeCallInfo * runtimeCallInfo)141 ArkUINativeModuleValue CommonShapeBridge::SetStrokeDashOffset(ArkUIRuntimeCallInfo* runtimeCallInfo)
142 {
143     EcmaVM* vm = runtimeCallInfo->GetVM();
144     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
145     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
146     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
147     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
148     CalcDimension strokeDashOffset;
149     RefPtr<ResourceObject> resObj;
150     std::string calcStr;
151     if (secondArg->IsUndefined() || !ArkTSUtils::ParseJsDimensionVpNG(vm, secondArg, strokeDashOffset, resObj)) {
152         GetArkUINodeModifiers()->getCommonShapeModifier()->resetStrokeDashOffset(nativeNode);
153     } else {
154         GetArkUINodeModifiers()->getCommonShapeModifier()->setStrokeDashOffset(
155             nativeNode, strokeDashOffset.Value(), static_cast<int>(strokeDashOffset.Unit()), AceType::RawPtr(resObj));
156     }
157     return panda::JSValueRef::Undefined(vm);
158 }
159 
ResetStrokeDashOffset(ArkUIRuntimeCallInfo * runtimeCallInfo)160 ArkUINativeModuleValue CommonShapeBridge::ResetStrokeDashOffset(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     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
166     GetArkUINodeModifiers()->getCommonShapeModifier()->resetStrokeDashOffset(nativeNode);
167     return panda::JSValueRef::Undefined(vm);
168 }
169 
SetStrokeLineCap(ArkUIRuntimeCallInfo * runtimeCallInfo)170 ArkUINativeModuleValue CommonShapeBridge::SetStrokeLineCap(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     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
176     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
177     if (secondArg->IsUndefined()) {
178         GetArkUINodeModifiers()->getCommonShapeModifier()->resetStrokeLineCap(nativeNode);
179     } else {
180         int strokeLineCap = secondArg->ToNumber(vm)->Value();
181         GetArkUINodeModifiers()->getCommonShapeModifier()->setStrokeLineCap(nativeNode, strokeLineCap);
182     }
183     return panda::JSValueRef::Undefined(vm);
184 }
185 
ResetStrokeLineCap(ArkUIRuntimeCallInfo * runtimeCallInfo)186 ArkUINativeModuleValue CommonShapeBridge::ResetStrokeLineCap(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     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
192     GetArkUINodeModifiers()->getCommonShapeModifier()->resetStrokeLineCap(nativeNode);
193     return panda::JSValueRef::Undefined(vm);
194 }
195 
SetStrokeLineJoin(ArkUIRuntimeCallInfo * runtimeCallInfo)196 ArkUINativeModuleValue CommonShapeBridge::SetStrokeLineJoin(ArkUIRuntimeCallInfo* runtimeCallInfo)
197 {
198     EcmaVM* vm = runtimeCallInfo->GetVM();
199     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
200     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
201     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
202     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
203     if (secondArg->IsUndefined()) {
204         GetArkUINodeModifiers()->getCommonShapeModifier()->resetStrokeLineJoin(nativeNode);
205     } else {
206         int strokeLineJoin = secondArg->ToNumber(vm)->Value();
207         GetArkUINodeModifiers()->getCommonShapeModifier()->setStrokeLineJoin(nativeNode, strokeLineJoin);
208     }
209     return panda::JSValueRef::Undefined(vm);
210 }
211 
ResetStrokeLineJoin(ArkUIRuntimeCallInfo * runtimeCallInfo)212 ArkUINativeModuleValue CommonShapeBridge::ResetStrokeLineJoin(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     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
218     GetArkUINodeModifiers()->getCommonShapeModifier()->resetStrokeLineJoin(nativeNode);
219     return panda::JSValueRef::Undefined(vm);
220 }
221 
SetStrokeMiterLimit(ArkUIRuntimeCallInfo * runtimeCallInfo)222 ArkUINativeModuleValue CommonShapeBridge::SetStrokeMiterLimit(ArkUIRuntimeCallInfo* runtimeCallInfo)
223 {
224     EcmaVM* vm = runtimeCallInfo->GetVM();
225     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
226     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
227     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
228     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
229     double strokeMiterLimit = STROKE_MITERLIMIT_DEFAULT;
230     RefPtr<ResourceObject> resObj;
231     if (secondArg->IsUndefined() || !ArkTSUtils::ParseJsDouble(vm, secondArg, strokeMiterLimit, resObj)) {
232         GetArkUINodeModifiers()->getCommonShapeModifier()->resetStrokeMiterLimit(nativeNode);
233     } else {
234         GetArkUINodeModifiers()->getCommonShapeModifier()->setStrokeMiterLimit(
235             nativeNode, strokeMiterLimit, AceType::RawPtr(resObj));
236     }
237     return panda::JSValueRef::Undefined(vm);
238 }
239 
ResetStrokeMiterLimit(ArkUIRuntimeCallInfo * runtimeCallInfo)240 ArkUINativeModuleValue CommonShapeBridge::ResetStrokeMiterLimit(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     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
246     GetArkUINodeModifiers()->getCommonShapeModifier()->resetStrokeMiterLimit(nativeNode);
247     return panda::JSValueRef::Undefined(vm);
248 }
249 
SetFillOpacity(ArkUIRuntimeCallInfo * runtimeCallInfo)250 ArkUINativeModuleValue CommonShapeBridge::SetFillOpacity(ArkUIRuntimeCallInfo* runtimeCallInfo)
251 {
252     EcmaVM* vm = runtimeCallInfo->GetVM();
253     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
254     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
255     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
256     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
257     if (secondArg->IsUndefined()) {
258         GetArkUINodeModifiers()->getCommonShapeModifier()->resetFillOpacity(nativeNode);
259     } else {
260         double opacity = DEFAULT_OPACITY;
261         RefPtr<ResourceObject> resObj;
262         if (!ArkTSUtils::ParseJsDouble(vm, secondArg, opacity, resObj)) {
263             GetArkUINodeModifiers()->getCommonShapeModifier()->resetFillOpacity(nativeNode);
264         } else {
265             if (opacity > DEFAULT_OPACITY) {
266                 opacity = DEFAULT_OPACITY;
267             }
268             if (opacity < MIN_OPACITY) {
269                 opacity = MIN_OPACITY;
270             }
271             GetArkUINodeModifiers()->getCommonShapeModifier()->setFillOpacity(
272                 nativeNode, opacity, AceType::RawPtr(resObj));
273         }
274     }
275     return panda::JSValueRef::Undefined(vm);
276 }
277 
ResetFillOpacity(ArkUIRuntimeCallInfo * runtimeCallInfo)278 ArkUINativeModuleValue CommonShapeBridge::ResetFillOpacity(ArkUIRuntimeCallInfo* runtimeCallInfo)
279 {
280     EcmaVM* vm = runtimeCallInfo->GetVM();
281     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
282     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
283     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
284     GetArkUINodeModifiers()->getCommonShapeModifier()->resetFillOpacity(nativeNode);
285     return panda::JSValueRef::Undefined(vm);
286 }
287 
SetStrokeOpacity(ArkUIRuntimeCallInfo * runtimeCallInfo)288 ArkUINativeModuleValue CommonShapeBridge::SetStrokeOpacity(ArkUIRuntimeCallInfo* runtimeCallInfo)
289 {
290     EcmaVM* vm = runtimeCallInfo->GetVM();
291     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
292     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
293     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
294     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
295     if (secondArg->IsUndefined()) {
296         GetArkUINodeModifiers()->getCommonShapeModifier()->resetStrokeOpacity(nativeNode);
297     } else {
298         double opacity = DEFAULT_OPACITY;
299         RefPtr<ResourceObject> resObj;
300         if (!ArkTSUtils::ParseJsDouble(vm, secondArg, opacity, resObj)) {
301             GetArkUINodeModifiers()->getCommonShapeModifier()->resetStrokeOpacity(nativeNode);
302         } else {
303             if (opacity > DEFAULT_OPACITY) {
304                 opacity = DEFAULT_OPACITY;
305             }
306             if (opacity < MIN_OPACITY) {
307                 opacity = MIN_OPACITY;
308             }
309 
310             GetArkUINodeModifiers()->getCommonShapeModifier()->setStrokeOpacity(
311                 nativeNode, opacity, AceType::RawPtr(resObj));
312         }
313     }
314     return panda::JSValueRef::Undefined(vm);
315 }
316 
ResetStrokeOpacity(ArkUIRuntimeCallInfo * runtimeCallInfo)317 ArkUINativeModuleValue CommonShapeBridge::ResetStrokeOpacity(ArkUIRuntimeCallInfo* runtimeCallInfo)
318 {
319     EcmaVM* vm = runtimeCallInfo->GetVM();
320     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
321     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
322     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
323     GetArkUINodeModifiers()->getCommonShapeModifier()->resetStrokeOpacity(nativeNode);
324     return panda::JSValueRef::Undefined(vm);
325 }
326 
SetStrokeWidth(ArkUIRuntimeCallInfo * runtimeCallInfo)327 ArkUINativeModuleValue CommonShapeBridge::SetStrokeWidth(ArkUIRuntimeCallInfo* runtimeCallInfo)
328 {
329     EcmaVM* vm = runtimeCallInfo->GetVM();
330     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
331     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
332     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
333     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
334     CalcDimension strokeWidth = CalcDimension(1.0, DimensionUnit::VP);
335     RefPtr<ResourceObject> resObj;
336     if (secondArg->IsString(vm)) {
337         const std::string& value = secondArg->ToString(vm)->ToString(vm);
338         strokeWidth = StringUtils::StringToDimensionWithUnit(value, DimensionUnit::VP, 1.0);
339     } else {
340         ArkTSUtils::ParseJsDimension(vm, secondArg, strokeWidth, DimensionUnit::VP, resObj);
341     }
342     if (strokeWidth.IsNegative()) {
343         strokeWidth = CalcDimension(1.0, DimensionUnit::VP);
344     }
345     GetArkUINodeModifiers()->getCommonShapeModifier()->setStrokeWidth(
346         nativeNode, strokeWidth.Value(), static_cast<int>(strokeWidth.Unit()), AceType::RawPtr(resObj));
347     return panda::JSValueRef::Undefined(vm);
348 }
349 
ResetStrokeWidth(ArkUIRuntimeCallInfo * runtimeCallInfo)350 ArkUINativeModuleValue CommonShapeBridge::ResetStrokeWidth(ArkUIRuntimeCallInfo* runtimeCallInfo)
351 {
352     EcmaVM* vm = runtimeCallInfo->GetVM();
353     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
354     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
355     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
356     GetArkUINodeModifiers()->getCommonShapeModifier()->resetStrokeWidth(nativeNode);
357     return panda::JSValueRef::Undefined(vm);
358 }
359 
SetAntiAlias(ArkUIRuntimeCallInfo * runtimeCallInfo)360 ArkUINativeModuleValue CommonShapeBridge::SetAntiAlias(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     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
366     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
367     if (secondArg->IsUndefined()) {
368         GetArkUINodeModifiers()->getCommonShapeModifier()->resetAntiAlias(nativeNode);
369     } else {
370         bool antiAlias = secondArg->ToBoolean(vm)->Value();
371         GetArkUINodeModifiers()->getCommonShapeModifier()->setAntiAlias(nativeNode, antiAlias);
372     }
373     return panda::JSValueRef::Undefined(vm);
374 }
375 
ResetAntiAlias(ArkUIRuntimeCallInfo * runtimeCallInfo)376 ArkUINativeModuleValue CommonShapeBridge::ResetAntiAlias(ArkUIRuntimeCallInfo* runtimeCallInfo)
377 {
378     EcmaVM* vm = runtimeCallInfo->GetVM();
379     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
380     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
381     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
382     GetArkUINodeModifiers()->getCommonShapeModifier()->resetAntiAlias(nativeNode);
383     return panda::JSValueRef::Undefined(vm);
384 }
385 
SetWidth(ArkUIRuntimeCallInfo * runtimeCallInfo)386 ArkUINativeModuleValue CommonShapeBridge::SetWidth(ArkUIRuntimeCallInfo* runtimeCallInfo)
387 {
388     EcmaVM* vm = runtimeCallInfo->GetVM();
389     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
390     Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(NUM_0);
391     auto nativeNode = nodePtr(nodeArg->ToNativePointer(vm)->Value());
392     Local<JSValueRef> widthArg = runtimeCallInfo->GetCallArgRef(NUM_1);
393     CalcDimension width;
394     RefPtr<ResourceObject> resObj;
395     if (!ArkTSUtils::ParseJsDimensionVpNG(vm, widthArg, width, resObj)) {
396         GetArkUINodeModifiers()->getCommonShapeModifier()->resetShapeWidth(nativeNode);
397         return panda::JSValueRef::Undefined(vm);
398     }
399     if (LessNotEqual(width.Value(), 0.0)) {
400         width.SetValue(0.0);
401     }
402     GetArkUINodeModifiers()->getCommonShapeModifier()->setShapeWidth(
403         nativeNode, width.Value(), static_cast<int32_t>(width.Unit()), AceType::RawPtr(resObj));
404     return panda::JSValueRef::Undefined(vm);
405 }
406 
ResetWidth(ArkUIRuntimeCallInfo * runtimeCallInfo)407 ArkUINativeModuleValue CommonShapeBridge::ResetWidth(ArkUIRuntimeCallInfo* runtimeCallInfo)
408 {
409     CommonBridge::ResetWidth(runtimeCallInfo);
410     EcmaVM* vm = runtimeCallInfo->GetVM();
411     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
412     Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(NUM_0);
413     auto nativeNode = nodePtr(nodeArg->ToNativePointer(vm)->Value());
414     GetArkUINodeModifiers()->getCommonShapeModifier()->resetShapeWidth(nativeNode);
415     return panda::JSValueRef::Undefined(vm);
416 }
417 
SetHeight(ArkUIRuntimeCallInfo * runtimeCallInfo)418 ArkUINativeModuleValue CommonShapeBridge::SetHeight(ArkUIRuntimeCallInfo* runtimeCallInfo)
419 {
420     EcmaVM* vm = runtimeCallInfo->GetVM();
421     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
422     Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(NUM_0);
423     auto nativeNode = nodePtr(nodeArg->ToNativePointer(vm)->Value());
424     Local<JSValueRef> heightArg = runtimeCallInfo->GetCallArgRef(NUM_1);
425     CalcDimension height;
426     RefPtr<ResourceObject> resObj;
427     if (!ArkTSUtils::ParseJsDimensionVpNG(vm, heightArg, height, resObj)) {
428         GetArkUINodeModifiers()->getCommonShapeModifier()->resetShapeHeight(nativeNode);
429         return panda::JSValueRef::Undefined(vm);
430     }
431     if (LessNotEqual(height.Value(), 0.0)) {
432         height.SetValue(0.0);
433     }
434     GetArkUINodeModifiers()->getCommonShapeModifier()->setShapeHeight(
435         nativeNode, height.Value(), static_cast<int32_t>(height.Unit()), AceType::RawPtr(resObj));
436     return panda::JSValueRef::Undefined(vm);
437 }
438 
ResetHeight(ArkUIRuntimeCallInfo * runtimeCallInfo)439 ArkUINativeModuleValue CommonShapeBridge::ResetHeight(ArkUIRuntimeCallInfo* runtimeCallInfo)
440 {
441     CommonBridge::ResetHeight(runtimeCallInfo);
442     EcmaVM* vm = runtimeCallInfo->GetVM();
443     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
444     Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(NUM_0);
445     auto nativeNode = nodePtr(nodeArg->ToNativePointer(vm)->Value());
446     GetArkUINodeModifiers()->getCommonShapeModifier()->resetShapeHeight(nativeNode);
447     return panda::JSValueRef::Undefined(vm);
448 }
449 
SetForegroundColor(ArkUIRuntimeCallInfo * runtimeCallInfo)450 ArkUINativeModuleValue CommonShapeBridge::SetForegroundColor(ArkUIRuntimeCallInfo* runtimeCallInfo)
451 {
452     EcmaVM* vm = runtimeCallInfo->GetVM();
453     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
454     Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(NUM_0);
455     auto nativeNode = nodePtr(nodeArg->ToNativePointer(vm)->Value());
456     auto colorArg = runtimeCallInfo->GetCallArgRef(NUM_1);
457     ForegroundColorStrategy strategy;
458     if (ArkTSUtils::ParseJsColorStrategy(vm, colorArg, strategy)) {
459         auto castedStrategy = static_cast<uint32_t>(strategy);
460         GetArkUINodeModifiers()->getCommonShapeModifier()->setShapeForegroundColor(
461             nativeNode, false, castedStrategy, nullptr);
462         return panda::JSValueRef::Undefined(vm);
463     }
464     Color foregroundColor;
465     RefPtr<ResourceObject> resObj;
466     if (!ArkTSUtils::ParseJsColorAlpha(
467         vm, colorArg, foregroundColor, resObj, ArkTSUtils::MakeNativeNodeInfo(nativeNode))) {
468         GetArkUINodeModifiers()->getCommonShapeModifier()->resetShapeForegroundColor(nativeNode);
469     } else {
470         GetArkUINodeModifiers()->getCommonShapeModifier()->setShapeForegroundColor(
471             nativeNode, true, foregroundColor.GetValue(), AceType::RawPtr(resObj));
472     }
473     return panda::JSValueRef::Undefined(vm);
474 }
475 
ResetForegroundColor(ArkUIRuntimeCallInfo * runtimeCallInfo)476 ArkUINativeModuleValue CommonShapeBridge::ResetForegroundColor(ArkUIRuntimeCallInfo* runtimeCallInfo)
477 {
478     EcmaVM* vm = runtimeCallInfo->GetVM();
479     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
480     Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(NUM_0);
481     auto nativeNode = nodePtr(nodeArg->ToNativePointer(vm)->Value());
482     GetArkUINodeModifiers()->getCommonShapeModifier()->resetShapeForegroundColor(nativeNode);
483     return panda::JSValueRef::Undefined(vm);
484 }
485 } // namespace OHOS::Ace::NG