1 /*
2  * Copyright (c) 2021-2022 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 #ifndef FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_JS_VIEW_JS_CANVAS_PATH_H
17 #define FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_JS_VIEW_JS_CANVAS_PATH_H
18 
19 #include "base/memory/referenced.h"
20 #include "bridge/declarative_frontend/engine/bindings_defines.h"
21 
22 namespace OHOS::Ace::Framework {
23 
24 class JSCanvasPath : public Referenced {
25 public:
26     JSCanvasPath();
27     ~JSCanvasPath() override = default;
DestructorInterceptor(void * env,void * controller,void * data)28     static void DestructorInterceptor(void* env, void* controller, void* data) {}
29     void JsPath2DSetTransform(const JSCallbackInfo& args);
30     void JsPath2DMoveTo(const JSCallbackInfo& args);
31     void JsPath2DLineTo(const JSCallbackInfo& args);
32     void JsPath2DArc(const JSCallbackInfo& args);
33     void JsPath2DArcTo(const JSCallbackInfo& args);
34     void JsPath2DQuadraticCurveTo(const JSCallbackInfo& args);
35     void JsPath2DBezierCurveTo(const JSCallbackInfo& args);
36     void JsPath2DEllipse(const JSCallbackInfo& args);
37     void JsPath2DRect(const JSCallbackInfo& args);
38     void JsPath2DClosePath(const JSCallbackInfo& args);
GetCanvasPath2d()39     RefPtr<CanvasPath2D> GetCanvasPath2d() const
40     {
41         return path2d_;
42     }
SetCanvasPath2d(RefPtr<CanvasPath2D> path2d)43     void SetCanvasPath2d(RefPtr<CanvasPath2D> path2d)
44     {
45         path2d_ = path2d;
46     }
47 
SetUnit(CanvasUnit unit)48     void SetUnit(CanvasUnit unit)
49     {
50         unit_ = unit;
51     }
52 
GetUnit()53     CanvasUnit GetUnit()
54     {
55         return unit_;
56     }
57 
GetDensity()58     double GetDensity()
59     {
60         double density = PipelineBase::GetCurrentDensity();
61         return ((GetUnit() == CanvasUnit::DEFAULT) && !NearZero(density)) ? density : 1.0;
62     }
63 
64     ACE_DISALLOW_COPY_AND_MOVE(JSCanvasPath);
65 protected:
66     void SetPathSize(const JSCallbackInfo& info);
67     size_t lastPathSize_ = 0;
68     panda::CopyableGlobal<panda::JSValueRef> pathCmdObj_;
69     RefPtr<CanvasPath2D> path2d_;
70     CanvasUnit unit_ = CanvasUnit::DEFAULT;
71 };
72 
73 } // namespace OHOS::Ace::Framework
74 
75 #endif // FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_JS_VIEW_JS_CANVAS_PATH_H