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_polyline_ffi.h"
17
18 #include "bridge/cj_frontend/interfaces/cj_ffi/cj_shape_ffi.h"
19 #include "bridge/cj_frontend/interfaces/cj_ffi/cj_view_abstract_ffi.h"
20 #include "core/components_ng/pattern/shape/polygon_model.h"
21 #include "core/components_ng/pattern/shape/polygon_model_ng.h"
22
23 using namespace OHOS::Ace;
24 using namespace OHOS::Ace::Framework;
25
26 namespace {
27 const int SIZE_CHECK = 2;
28 }
29
30 extern "C" {
FfiOHOSAceFrameworkPolylineCreate(double width,int32_t widthUnit,double height,int32_t heightUnit)31 void FfiOHOSAceFrameworkPolylineCreate(double width, int32_t widthUnit, double height, int32_t heightUnit)
32 {
33 PolygonModel::GetInstance()->Create(false);
34 if (width > 0.0) {
35 FfiOHOSAceFrameworkShapeSetWidth(width, widthUnit);
36 }
37 if (height > 0.0) {
38 FfiOHOSAceFrameworkShapeSetHeight(height, heightUnit);
39 }
40 }
41
FfiOHOSAceFrameworkPolylineSetPoints(VectorFloat64Ptr xPointVec,VectorFloat64Ptr yPointVec)42 void FfiOHOSAceFrameworkPolylineSetPoints(VectorFloat64Ptr xPointVec, VectorFloat64Ptr yPointVec)
43 {
44 ShapePoint point;
45 ShapePoints points;
46 const auto& xPointVector = *reinterpret_cast<std::vector<double>*>(xPointVec);
47 const auto& yPointVector = *reinterpret_cast<std::vector<double>*>(yPointVec);
48 if (xPointVector.size() < SIZE_CHECK || xPointVector.size() != yPointVector.size()) {
49 LOGE("Polyline set points error: params requires at least 2 points or point data loss");
50 return;
51 }
52 for (size_t i = 0; i < xPointVector.size(); ++i) {
53 point.first = Dimension(xPointVector[i], DimensionUnit::VP);
54 point.second = Dimension(yPointVector[i], DimensionUnit::VP);
55 points.push_back(point);
56 }
57 PolygonModel::GetInstance()->SetPoints(points);
58 }
59 }
60