1 /*
2  * Copyright (c) 2024 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 "bridge/cj_frontend/interfaces/cj_ffi/cj_path_ffi.h"
17 
18 #include "bridge/cj_frontend/cppview/shape_abstract.h"
19 #include "bridge/cj_frontend/interfaces/cj_ffi/cj_shape_ffi.h"
20 #include "core/common/container.h"
21 #include "core/components_ng/pattern/shape/path_model_ng.h"
22 
23 
24 using namespace OHOS::Ace;
25 
26 extern "C" {
FfiOHOSAceFrameworkPathCreate(const char * commands)27 void FfiOHOSAceFrameworkPathCreate(const char* commands)
28 {
29     PathModel::GetInstance()->Create();
30     PathModel::GetInstance()->SetCommands(commands);
31 }
32 
FfiOHOSAceFrameworkPathCreateWithSize(double width,int32_t widthUnit,double height,int32_t heightUnit,const char * commands)33 void FfiOHOSAceFrameworkPathCreateWithSize(
34     double width, int32_t widthUnit, double height, int32_t heightUnit, const char* commands)
35 {
36     PathModel::GetInstance()->Create();
37     if (width > 0.0) {
38         FfiOHOSAceFrameworkShapeSetWidth(width, widthUnit);
39     }
40     if (height > 0.0) {
41         FfiOHOSAceFrameworkShapeSetHeight(height, heightUnit);
42     }
43     PathModel::GetInstance()->SetCommands(commands);
44 }
45 
FfiOHOSAceFrameworkPathInsCreate(const char * commands)46 int64_t FfiOHOSAceFrameworkPathInsCreate(const char* commands)
47 {
48     auto nativePath = OHOS::FFI::FFIData::Create<OHOS::Ace::Framework::NativePath>(commands);
49     if (nativePath == nullptr) {
50         return FFI_ERROR_CODE;
51     }
52     return nativePath->GetID();
53 }
54 
FfiOHOSAceFrameworkPathInsCreateWithSize(double width,int32_t widthUnit,double height,int32_t heightUnit,const char * commands)55 int64_t FfiOHOSAceFrameworkPathInsCreateWithSize(
56     double width, int32_t widthUnit, double height, int32_t heightUnit, const char* commands)
57 {
58     OHOS::Ace::Dimension dWidth(width, static_cast<OHOS::Ace::DimensionUnit>(widthUnit));
59     OHOS::Ace::Dimension dHeight(height, static_cast<OHOS::Ace::DimensionUnit>(heightUnit));
60     auto nativePath = OHOS::FFI::FFIData::Create<OHOS::Ace::Framework::NativePath>(commands);
61     if (nativePath == nullptr) {
62         return FFI_ERROR_CODE;
63     }
64     nativePath->SetWidth(dWidth);
65     nativePath->SetHeight(dHeight);
66     return nativePath->GetID();
67 }
68 
FfiOHOSAceFrameworkPathSetCommands(const char * commands)69 void FfiOHOSAceFrameworkPathSetCommands(const char* commands)
70 {
71     PathModel::GetInstance()->SetCommands(commands);
72 }
73 }
74