1 /* 2 * Copyright (c) 2023 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 ROSEN_MODULES_TEXGINE_SRC_TEXGINE_DRAWING_TEXGINE_CANVAS_H 17 #define ROSEN_MODULES_TEXGINE_SRC_TEXGINE_DRAWING_TEXGINE_CANVAS_H 18 19 #include <memory> 20 21 #ifndef USE_ROSEN_DRAWING 22 #include <include/core/SkCanvas.h> 23 #else 24 #include "drawing.h" 25 #endif 26 27 #include "texgine_rect.h" 28 #include "texgine_paint.h" 29 #include "texgine_text_blob.h" 30 31 namespace OHOS { 32 namespace Rosen { 33 namespace TextEngine { 34 class TexgineCanvas { 35 public: 36 /* 37 * @brief Draws line segment from (x0, y0) to (x1, y1) using clip, SkMatrix, and SkPaint paint. 38 */ 39 void DrawLine(double x0, double y0, double x1, double y1, const TexginePaint &paint); 40 41 /* 42 * @brief Draws SkRect rect using clip, SkMatrix, and SkPaint paint. 43 */ 44 void DrawRect(const TexgineRect &rect, const TexginePaint &paint) const; 45 46 /* 47 * @brief Draws SkRRect rect using SkPaint paint. 48 */ 49 void DrawRRect(const TexgineRect &rect, const TexginePaint &paint) const; 50 51 /* 52 * @brief Draws SkTextBlob blob at (x, y), using clip, SkMatrix, and SkPaint paint. 53 */ 54 void DrawTextBlob(const std::shared_ptr<TexgineTextBlob> &blob, float x, float y, const TexginePaint &paint); 55 56 /* 57 * @brief Draws symbol at point, using clip, SkMatrix, and paint. 58 */ 59 #ifndef USE_ROSEN_DRAWING 60 void DrawSymbol(const HMSymbolData &symbol, SkPoint locate, const TexginePaint &paint); 61 #else 62 void DrawSymbol(const RSHMSymbolData &symbol, RSPoint locate, const TexginePaint &paint); 63 #endif 64 65 /* 66 * @brief Draws Path , using SkPath path and SkPaint paint. 67 */ 68 #ifndef USE_ROSEN_DRAWING 69 void DrawPath(const SkPath &path, const TexginePaint &paint); 70 #else 71 void DrawPath(const RSPath &path, const TexginePaint &paint); 72 #endif 73 74 /* 75 * @brief Fills clip with color color using SkBlendMode::kSrc. 76 * This has the effect of replacing all pixels contained by clip with color. 77 * @param color unpremultiplied ARGB 78 */ 79 void Clear(uint32_t color) const; 80 81 /* 82 * @brief Saves SkMatrix and clip, and allocates a SkBitmap for subsequent drawing. 83 */ 84 int Save() const; 85 86 /* 87 * @brief Translates SkMatrix by dx along the x-axis and dy along the y-axis. 88 */ 89 void Translate(float dx, float dy) const; 90 91 /* 92 * @brief Returns the pointer of SkCanvas what user sets to TexgineCanvas 93 */ 94 #ifndef USE_ROSEN_DRAWING 95 SkCanvas *GetCanvas() const; 96 #else 97 RSCanvas *GetCanvas() const; 98 #endif 99 100 /* 101 * @brief Removes changes to SkMatrix and clip since SkCanvas state was 102 last saved. The state is removed from the stack. 103 */ 104 void Restore() const; 105 106 /* 107 * @brief Sets SkCanvas to TexgineCanvas what user want 108 */ 109 #ifndef USE_ROSEN_DRAWING 110 void SetCanvas(SkCanvas *canvas); 111 #else 112 void SetCanvas(RSCanvas *canvas); 113 #endif 114 115 private: 116 #ifndef USE_ROSEN_DRAWING 117 SkCanvas *canvas_ = nullptr; 118 #else 119 RSCanvas *canvas_ = nullptr; 120 #endif 121 }; 122 } // namespace TextEngine 123 } // namespace Rosen 124 } // namespace OHOS 125 126 #endif // ROSEN_MODULES_TEXGINE_SRC_TEXGINE_DRAWING_TEXGINE_CANVAS_H 127