• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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 FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_CUSTOM_PAINT_OFFSCREEN_CANVAS_PATTERN_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_CUSTOM_PAINT_OFFSCREEN_CANVAS_PATTERN_H
18 
19 #include "base/memory/referenced.h"
20 #include "core/components/common/properties/paint_state.h"
21 #include "core/components_ng/pattern/pattern.h"
22 #include "core/pipeline_ng/pipeline_context.h"
23 
24 namespace OHOS::Ace::NG {
25 class OffscreenCanvasPaintMethod;
26 // OffscreenCanvasPattern is the base class for custom paint render node to perform paint canvas.
27 class ACE_EXPORT OffscreenCanvasPattern : public Pattern {
28     DECLARE_ACE_TYPE(OffscreenCanvasPattern, Pattern);
29 
30 public:
31     OffscreenCanvasPattern(int32_t width, int32_t height);
32     ~OffscreenCanvasPattern() override = default;
33 
34     void FillRect(const Rect& rect);
35     void StrokeRect(const Rect& rect);
36     void ClearRect(const Rect& rect);
37     void Fill();
38     void Fill(const RefPtr<CanvasPath2D>& path);
39     void Stroke();
40     void Stroke(const RefPtr<CanvasPath2D>& path);
41     void Clip();
42     void Clip(const RefPtr<CanvasPath2D>& path);
43     void BeginPath();
44     void ClosePath();
45     void MoveTo(double x, double y);
46     void LineTo(double x, double y);
47     void Arc(const ArcParam& param);
48     void ArcTo(const ArcToParam& param);
49     void AddRect(const Rect& rect);
50     void Ellipse(const EllipseParam& param);
51     void BezierCurveTo(const BezierCurveParam& param);
52     void QuadraticCurveTo(const QuadraticCurveParam& param);
53 
54     void FillText(const std::string& text, double x, double y, const PaintState& state);
55     void StrokeText(const std::string& text, double x, double y, const PaintState& state);
56     double MeasureText(const std::string& text, const PaintState& state);
57     double MeasureTextHeight(const std::string& text, const PaintState& state);
58     TextMetrics MeasureTextMetrics(const std::string& text, const PaintState& state);
59 
60     void DrawImage(const Ace::CanvasImage& image, double width, double height);
61     void DrawPixelMap(RefPtr<PixelMap> pixelMap, const Ace::CanvasImage& image);
62     std::unique_ptr<Ace::ImageData> GetImageData(double left, double top, double width, double height);
63     void PutImageData(const Ace::ImageData& imageData);
64 
65     void SetAntiAlias(bool isEnabled);
66     void SetFillRuleForPath(const CanvasFillRule rule);
67     void SetFillRuleForPath2D(const CanvasFillRule rule);
68     void SetFillPattern(const Ace::Pattern& pattern);
69     void SetFillGradient(const Ace::Gradient& gradient);
70     void SetAlpha(double alpha);
71     void SetCompositeType(CompositeOperation operation);
72     void SetLineWidth(double width);
73     void SetLineCap(LineCapStyle style);
74     void SetLineJoin(LineJoinStyle style);
75     void SetMiterLimit(double limit);
76     void SetTextAlign(TextAlign align);
77     void SetTextBaseline(TextBaseline baseline);
78     void SetShadowBlur(double blur);
79     void SetShadowOffsetX(double x);
80     void SetShadowOffsetY(double y);
81     void SetSmoothingEnabled(bool enabled);
82     void SetSmoothingQuality(const std::string& quality);
83     void SetLineDashOffset(double offset);
84     void SetShadowColor(const Color& color);
85     void SetStrokePattern(const Ace::Pattern& pattern);
86     void SetStrokeGradient(const Ace::Gradient& gradient);
87     void SetStrokeColor(const Color& color);
88     void SetFontWeight(FontWeight weight);
89     void SetFontStyle(FontStyle style);
90     void SetFontFamilies(const std::vector<std::string>& fontFamilies);
91     void SetFontSize(const Dimension& size);
92     void SetFillColor(const Color& color);
93     int32_t GetWidth();
94     int32_t GetHeight();
95 
96     const LineDashParam& GetLineDash() const;
97     void SetLineDash(const std::vector<double>& segments);
98 
99     void Save();
100     void Restore();
101     void Scale(double x, double y);
102     void Rotate(double angle);
103     void SetTransform(const TransformParam& param);
104     void ResetTransform();
105     void Transform(const TransformParam& param);
106     void Translate(double x, double y);
107     std::string ToDataURL(const std::string& type, const double quality);
108 
109 private:
110     RefPtr<OffscreenCanvasPaintMethod> offscreenPaintMethod_;
111     ACE_DISALLOW_COPY_AND_MOVE(OffscreenCanvasPattern);
112 };
113 } // namespace OHOS::Ace::NG
114 
115 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_CUSTOM_PAINT_OFFSCREEN_CANVAS_PATTERN_H
116