• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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/declarative_frontend/jsview/js_path2d.h"
17 #include "bridge/declarative_frontend/jsview/js_canvas_renderer.h"
18 #include "bridge/declarative_frontend/jsview/js_view_common_def.h"
19 
20 namespace OHOS::Ace::Framework {
21 
JSPath2D()22 JSPath2D::JSPath2D()
23 {
24 }
25 
Constructor(const JSCallbackInfo & args)26 void JSPath2D::Constructor(const JSCallbackInfo& args)
27 {
28     auto jsPath2d = Referenced::MakeRefPtr<JSPath2D>();
29     jsPath2d->IncRefCount();
30     args.SetReturnValue(Referenced::RawPtr(jsPath2d));
31     jsPath2d->SetCanvasPath2d(JSCanvasRenderer::JsMakePath2D(args));
32 }
33 
Destructor(JSPath2D * controller)34 void JSPath2D::Destructor(JSPath2D* controller)
35 {
36     if (controller != nullptr) {
37         controller->DecRefCount();
38     }
39 }
40 
JSBind(BindingTarget globalObj)41 void JSPath2D::JSBind(BindingTarget globalObj)
42 {
43     JSClass<JSPath2D>::Declare("Path2D");
44     JSClass<JSPath2D>::CustomMethod("addPath", &JSPath2D::JsPath2DAddPath);
45     JSClass<JSPath2D>::CustomMethod("setTransform", &JSCanvasPath::JsPath2DSetTransform);
46     JSClass<JSPath2D>::CustomMethod("moveTo", &JSCanvasPath::JsPath2DMoveTo);
47     JSClass<JSPath2D>::CustomMethod("lineTo", &JSCanvasPath::JsPath2DLineTo);
48     JSClass<JSPath2D>::CustomMethod("arc", &JSCanvasPath::JsPath2DArc);
49     JSClass<JSPath2D>::CustomMethod("arcTo", &JSCanvasPath::JsPath2DArcTo);
50     JSClass<JSPath2D>::CustomMethod("quadraticCurveTo", &JSCanvasPath::JsPath2DQuadraticCurveTo);
51     JSClass<JSPath2D>::CustomMethod("bezierCurveTo", &JSCanvasPath::JsPath2DBezierCurveTo);
52     JSClass<JSPath2D>::CustomMethod("ellipse", &JSCanvasPath::JsPath2DEllipse);
53     JSClass<JSPath2D>::CustomMethod("rect", &JSCanvasPath::JsPath2DRect);
54     JSClass<JSPath2D>::CustomMethod("closePath", &JSCanvasPath::JsPath2DClosePath);
55     JSClass<JSPath2D>::Bind(globalObj, JSPath2D::Constructor, JSPath2D::Destructor);
56 }
57 
JsPath2DAddPath(const JSCallbackInfo & info)58 void JSPath2D::JsPath2DAddPath(const JSCallbackInfo& info)
59 {
60     JSPath2D* jsPath2d = JSRef<JSObject>::Cast(info[0])->Unwrap<JSPath2D>();
61     if (jsPath2d == nullptr) {
62         LOGE("The arg is wrong, it is supposed to have JSPath2D argument");
63         return;
64     }
65     auto toBeAdd = jsPath2d->GetCanvasPath2d();
66     path2d_->AddPath(toBeAdd);
67 }
68 
69 } // namespace OHOS::Ace::Framework