• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 JsPath2DRoundRect(const JSCallbackInfo& args);
39     void JsPath2DClosePath(const JSCallbackInfo& args);
GetCanvasPath2d()40     RefPtr<CanvasPath2D> GetCanvasPath2d() const
41     {
42         return path2d_;
43     }
SetCanvasPath2d(RefPtr<CanvasPath2D> path2d)44     void SetCanvasPath2d(RefPtr<CanvasPath2D> path2d)
45     {
46         path2d_ = path2d;
47     }
48 
SetUnit(CanvasUnit unit)49     void SetUnit(CanvasUnit unit)
50     {
51         unit_ = unit;
52     }
53 
GetUnit()54     CanvasUnit GetUnit()
55     {
56         return unit_;
57     }
58 
GetDensity()59     double GetDensity()
60     {
61         double density = PipelineBase::GetCurrentDensity();
62         return ((GetUnit() == CanvasUnit::DEFAULT) && !NearZero(density)) ? density : 1.0;
63     }
64 
65     ACE_DISALLOW_COPY_AND_MOVE(JSCanvasPath);
66 protected:
67     void SetPathSize(const JSCallbackInfo& info);
68     size_t lastPathSize_ = 0;
69     panda::CopyableGlobal<panda::JSValueRef> pathCmdObj_;
70     RefPtr<CanvasPath2D> path2d_;
71     CanvasUnit unit_ = CanvasUnit::DEFAULT;
72     bool isJudgeSpecialValue_ = false;
73 };
74 
75 } // namespace OHOS::Ace::Framework
76 
77 #endif // FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_JS_VIEW_JS_CANVAS_PATH_H