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