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