1 /*
2  * Copyright (c) 2023-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 #ifndef FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_JS_VIEW_MODELS_CANVAS_CANVAS_RENDERING_CONTEXT_2D_MODEL_IMPL_H
17 #define FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_JS_VIEW_MODELS_CANVAS_CANVAS_RENDERING_CONTEXT_2D_MODEL_IMPL_H
18 
19 #include "base/utils/macros.h"
20 #include "core/components_ng/pattern/canvas/rendering_context_2d_model.h"
21 
22 namespace OHOS::Ace {
23 class CanvasTaskPool;
24 }
25 namespace OHOS::Ace::Framework {
26 class CanvasRenderingContext2DModelImpl : public OHOS::Ace::CanvasRenderingContext2DModel {
27     DECLARE_ACE_TYPE(CanvasRenderingContext2DModelImpl, CanvasRenderingContext2DModel)
28 
29 public:
30     CanvasRenderingContext2DModelImpl() = default;
31     ~CanvasRenderingContext2DModelImpl() override = default;
32 
33     void SetPattern(RefPtr<AceType> pattern) override;
34     void SetFillText(const PaintState& state, const FillTextInfo& fillTextInfo) override;
35     void SetStrokeText(const PaintState& state, const FillTextInfo& fillTextInfo) override;
36     void SetAntiAlias(bool anti) override;
37     void SetFontWeight(const FontWeight& weight) override;
38     void SetFontStyle(const FontStyle& fontStyle) override;
39     void SetFontFamilies(const std::vector<std::string>& families) override;
40     void SetFontSize(const Dimension& size) override;
41     std::vector<double> GetLineDash() override;
42     void SetFillGradient(const std::shared_ptr<Ace::Gradient>& gradient) override;
43     void SetFillPattern(const std::shared_ptr<Ace::Pattern>& pattern) override;
44     void SetFillColor(const Color& color, bool colorFlag) override;
45     void SetStrokeGradient(const std::shared_ptr<Ace::Gradient>& gradient) override;
46     void SetStrokePattern(const std::shared_ptr<Ace::Pattern>& pattern) override;
47     void SetStrokeColor(const Color& color, bool colorFlag) override;
48     void DrawImage(const ImageInfo& imageInfo) override;
49     void PutImageData(const ImageData& imageData) override;
50     std::unique_ptr<ImageData> GetImageData(const ImageSize& imageSize) override;
51     void DrawPixelMap(const ImageInfo& imageInfo) override;
52     std::string GetJsonData(const std::string& path) override;
53     std::string ToDataURL(const std::string& dataUrl, double quality) override;
54     void SetLineCap(const LineCapStyle& lineCap) override;
55     void SetLineJoin(const LineJoinStyle& lineJoin) override;
56     void SetMiterLimit(double limit) override;
57     void SetLineWidth(double lineWidth) override;
58     void SetGlobalAlpha(double alpha) override;
59     void SetCompositeType(const CompositeOperation& type) override;
60     void SetLineDashOffset(double lineDashOffset) override;
61     void SetShadowBlur(double blur) override;
62     void SetShadowColor(const Color& color) override;
63     void SetShadowOffsetX(double offsetX) override;
64     void SetShadowOffsetY(double offsetY) override;
65     void SetSmoothingEnabled(bool enabled) override;
66     void SetSmoothingQuality(const std::string& quality) override;
67     void MoveTo(double x, double y) override;
68     void LineTo(double x, double y) override;
69     void BezierCurveTo(const BezierCurveParam& param) override;
70     void QuadraticCurveTo(const QuadraticCurveParam& param) override;
71     void ArcTo(const ArcToParam& param) override;
72     void Arc(const ArcParam& param) override;
73     void Ellipse(const EllipseParam& param) override;
74     void SetFillRuleForPath(const CanvasFillRule& fillRule) override;
75     void SetFillRuleForPath2D(const CanvasFillRule& fillRule, const RefPtr<CanvasPath2D>& path) override;
76     void SetStrokeRuleForPath2D(const CanvasFillRule& fillRule, const RefPtr<CanvasPath2D>& path) override;
77     void SetStrokeRuleForPath(const CanvasFillRule& fillRule) override;
78     void SetClipRuleForPath(const CanvasFillRule& fillRule) override;
79     void SetClipRuleForPath2D(const CanvasFillRule& fillRule, const RefPtr<CanvasPath2D>& path) override;
80     void AddRect(const Rect& rect) override;
81     void BeginPath() override;
82     void ClosePath() override;
83     void Restore() override;
84     void CanvasRendererSave() override;
85     void CanvasRendererRotate(double angle) override;
86     void CanvasRendererScale(double x, double y) override;
87     void SetTransform(TransformParam& param, bool lengthFlag) override;
88     void ResetTransform() override;
89     void Transform(const TransformParam& param) override;
90     void Translate(double x, double y) override;
91     void SetLineDash(const std::vector<double>& lineDash) override;
92     void SetTextAlign(const TextAlign& align) override;
93     void SetTextBaseline(const TextBaseline& baseline) override;
94     double GetMeasureTextWidth(const PaintState& state, const std::string& text) override;
95     double GetMeasureTextHeight(const PaintState& state, const std::string& text) override;
96     void FillRect(const Rect& rect) override;
97     void StrokeRect(const Rect& rect) override;
98     void ClearRect(const Rect& rect) override;
99     void DrawBitmapMesh(const BitmapMeshInfo& bitmapMeshInfo) override;
100     RefPtr<Ace::PixelMap> GetPixelMap(const ImageSize& imageSize) override;
101     void GetImageDataModel(const ImageSize& imageSize, uint8_t* buffer) override;
102     TextMetrics GetMeasureTextMetrics(const PaintState& state, const std::string& text) override;
103 
104     // All interfaces that only the 'CanvasRenderingContext2D' has.
105     void GetWidth(double& width) override;
106     void GetHeight(double& height) override;
107     void SetTransferFromImageBitmap(RefPtr<AceType> offscreenCPattern) override;
108 
109 private:
110     RefPtr<CanvasTaskPool> pattern_;
111 
112     ACE_DISALLOW_COPY_AND_MOVE(CanvasRenderingContext2DModelImpl);
113 };
114 } // namespace OHOS::Ace::Framework
115 #endif // FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_JS_VIEW_MODELS_CANVAS_CANVAS_RENDERING_CONTEXT_2D_MODEL_IMPL_H
116