• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 
16 #include "ani_path_iterator.h"
17 #include "draw/path.h"
18 #include "path_ani/ani_path.h"
19 
20 namespace OHOS::Rosen {
21 namespace Drawing {
22 const char* ANI_CLASS_PATH_ITERATOR_NAME = "L@ohos/graphics/drawing/drawing/PathIterator;";
23 
AniInit(ani_env * env)24 ani_status AniPathIterator::AniInit(ani_env *env)
25 {
26     ani_class cls = nullptr;
27     ani_status ret = env->FindClass(ANI_CLASS_PATH_ITERATOR_NAME, &cls);
28     if (ret != ANI_OK) {
29         ROSEN_LOGE("[ANI] can't find class: %{public}s", ANI_CLASS_PATH_ITERATOR_NAME);
30         return ANI_NOT_FOUND;
31     }
32 
33     std::array methods = {
34         ani_native_function { "constructorNative", "L@ohos/graphics/drawing/drawing/Path;:V",
35             reinterpret_cast<void*>(ConstructorWithPath) },
36     };
37 
38     ret = env->Class_BindNativeMethods(cls, methods.data(), methods.size());
39     if (ret != ANI_OK) {
40         ROSEN_LOGE("[ANI] bind methods fail: %{public}s", ANI_CLASS_PATH_ITERATOR_NAME);
41         return ANI_NOT_FOUND;
42     }
43 
44     return ANI_OK;
45 }
46 
ConstructorWithPath(ani_env * env,ani_object obj,ani_object aniPathObj)47 void AniPathIterator::ConstructorWithPath(ani_env* env, ani_object obj, ani_object aniPathObj)
48 {
49     auto aniPath = GetNativeFromObj<AniPath>(env, aniPathObj);
50     if (aniPath == nullptr) {
51         AniThrowError(env, "Invalid params. "); // message length must be a multiple of 4, for example 16, 20, etc
52         return;
53     }
54 
55     AniPathIterator* newAniPathIterator = new AniPathIterator(aniPath->GetPath());
56     if (ANI_OK != env->Object_SetFieldByName_Long(obj, NATIVE_OBJ, reinterpret_cast<ani_long>(newAniPathIterator))) {
57         ROSEN_LOGE("AniPathIterator::Constructor failed create AniPathIterator");
58         delete newAniPathIterator;
59         return;
60     }
61 }
62 
GetPathIterator()63 PathIterator& AniPathIterator::GetPathIterator()
64 {
65     return pathIterator_;
66 }
67 } // namespace Drawing
68 } // namespace OHOS::Rosen