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/cppview/canvas_path.h"
17
18 #include <cinttypes>
19
20 #include "base/log/log_wrapper.h"
21
22 namespace OHOS::Ace::Framework {
23
NativeCanvasPath()24 NativeCanvasPath::NativeCanvasPath() : FFIData()
25 {
26 path2d_ = AceType::MakeRefPtr<CanvasPath2D>();
27 }
28
NativeCanvasPath(const std::string & capStr)29 NativeCanvasPath::NativeCanvasPath(const std::string& capStr) : FFIData()
30 {
31 path2d_ = AceType::MakeRefPtr<CanvasPath2D>(capStr);
32 }
33
~NativeCanvasPath()34 NativeCanvasPath::~NativeCanvasPath()
35 {
36 LOGI("Native CanvasPath Destroyed: %{public}" PRId64, GetID());
37 }
38
AddPath(const sptr<NativeCanvasPath> & path)39 void NativeCanvasPath::AddPath(const sptr<NativeCanvasPath>& path)
40 {
41 auto toBeAdd = path->GetCanvasPath2d();
42 path2d_->AddPath(toBeAdd);
43 }
44
SetTransform(double scaleX,double skewX,double skewY,double scaleY,double translateX,double translateY)45 void NativeCanvasPath::SetTransform(
46 double scaleX, double skewX, double skewY, double scaleY, double translateX, double translateY)
47 {
48 path2d_->SetTransform(scaleX, skewX, skewY, scaleY, translateX, translateY);
49 }
50
MoveTo(double x,double y)51 void NativeCanvasPath::MoveTo(double x, double y)
52 {
53 path2d_->MoveTo(x, y);
54 }
55
LineTo(double x,double y)56 void NativeCanvasPath::LineTo(double x, double y)
57 {
58 path2d_->LineTo(x, y);
59 }
60
Arc(double x,double y,double radius,double startAngle,double endAngle,bool anticlockwise)61 void NativeCanvasPath::Arc(double x, double y, double radius, double startAngle, double endAngle, bool anticlockwise)
62 {
63 path2d_->Arc(x, y, radius, startAngle, endAngle, anticlockwise);
64 }
65
ArcTo(double x1,double y1,double x2,double y2,double radius)66 void NativeCanvasPath::ArcTo(double x1, double y1, double x2, double y2, double radius)
67 {
68 path2d_->ArcTo(x1, y1, x2, y2, radius);
69 }
70
QuadraticCurveTo(double cpx,double cpy,double x,double y)71 void NativeCanvasPath::QuadraticCurveTo(double cpx, double cpy, double x, double y)
72 {
73 path2d_->QuadraticCurveTo(cpx, cpy, x, y);
74 }
75
BezierCurveTo(double cp1x,double cp1y,double cp2x,double cp2y,double x,double y)76 void NativeCanvasPath::BezierCurveTo(double cp1x, double cp1y, double cp2x, double cp2y, double x, double y)
77 {
78 path2d_->BezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y);
79 }
80
Ellipse(double x,double y,double radiusX,double radiusY,double rotation,double startAngle,double endAngle,bool anticlockwise)81 void NativeCanvasPath::Ellipse(double x, double y, double radiusX, double radiusY, double rotation, double startAngle,
82 double endAngle, bool anticlockwise)
83 {
84 path2d_->Ellipse(x, y, radiusX, radiusY, rotation, startAngle, endAngle, anticlockwise);
85 }
86
Rect(double x,double y,double width,double height)87 void NativeCanvasPath::Rect(double x, double y, double width, double height)
88 {
89 path2d_->Rect(x, y, width, height);
90 }
91
ClosePath()92 void NativeCanvasPath::ClosePath()
93 {
94 path2d_->ClosePath();
95 }
96 } // namespace OHOS::Ace::Framework