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