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_RENDER_CANVAS_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_RENDER_CANVAS_H 18 19 #include "base/geometry/matrix3.h" 20 #include "base/geometry/ng/point_t.h" 21 #include "base/geometry/ng/rect_t.h" 22 #include "base/geometry/rrect.h" 23 #include "base/memory/ace_type.h" 24 #include "core/components/common/properties/clip_path.h" 25 #include "core/components/common/properties/color.h" 26 #include "core/components_ng/render/canvas_image.h" 27 #include "core/components_ng/render/paint.h" 28 29 namespace OHOS::Ace::NG { 30 31 enum class ClipQuality { 32 NONE = 0, 33 HARD_EDGE, 34 ANTI_ALIAS, 35 }; 36 37 // Canvas is interface for drawing content. 38 class Canvas : public virtual AceType { 39 DECLARE_ACE_TYPE(NG::Canvas, AceType) 40 41 public: 42 static RefPtr<Canvas> Create(void* rawCanvas); 43 44 // save and restore interfaces 45 virtual void Save() = 0; 46 virtual void Restore() = 0; 47 48 // transform interfaces 49 virtual void Translate(float dx, float dy) = 0; 50 virtual void Scale(float sx, float sy) = 0; 51 virtual void Rotate(float rad) = 0; 52 virtual void Skew(float sx, float sy) = 0; 53 virtual void SetMatrix(const Matrix3& matrix) = 0; 54 virtual void ConcatMatrix(const Matrix3& matrix) = 0; 55 56 // clip interfaces 57 virtual void ClipRect(const RectF& rect, ClipQuality quality) = 0; 58 virtual void ClipRRect(const RRect& rRect, ClipQuality quality) = 0; 59 virtual void ClipWithPath(const ClipPath& path, ClipQuality quality) = 0; 60 61 // drawing interfaces 62 virtual void ClearColor(const Color& color) = 0; 63 virtual void DrawColor(const Color& color) = 0; 64 virtual void DrawLine(const PointF& start, const PointF& end, const RefPtr<Paint>& paint) = 0; 65 virtual void DrawRect(const RectF& rect, const RefPtr<Paint>& paint) = 0; 66 virtual void DrawRRect(const RRect& rect, const RefPtr<Paint>& paint) = 0; 67 virtual void DrawCircle(float centerX, float centerY, float radius, const RefPtr<Paint>& paint) = 0; 68 69 // drawing image. 70 virtual void DrawImage( 71 const RefPtr<CanvasImage>& image, const RectF& srcRect, const RectF& dstRect, const RefPtr<Paint>& paint) = 0; 72 }; 73 74 } // namespace OHOS::Ace::NG 75 76 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_RENDER_CANVAS_H 77