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