• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <include/core/SkCanvas.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 SkTextBlob blob at (x, y), using clip, SkMatrix, and SkPaint paint.
44      */
45     void DrawTextBlob(const std::shared_ptr<TexgineTextBlob> &blob, float x, float y, const TexginePaint &paint);
46 
47     /*
48      * @brief Fills clip with color color using SkBlendMode::kSrc.
49      *        This has the effect of replacing all pixels contained by clip with color.
50      * @param color unpremultiplied ARGB
51      */
52     void Clear(uint32_t color) const;
53 
54     /*
55      * @brief Saves SkMatrix and clip, and allocates a SkBitmap for subsequent drawing.
56      */
57     int Save() const;
58 
59     /*
60      * @brief Translates SkMatrix by dx along the x-axis and dy along the y-axis.
61      */
62     void Translate(float dx, float dy) const;
63 
64     /*
65      * @brief Returns the pointer of SkCanvas what user sets to TexgineCanvas
66      */
67     SkCanvas *GetCanvas() const;
68 
69     /*
70      * @brief Removes changes to SkMatrix and clip since SkCanvas state was
71               last saved. The state is removed from the stack.
72     */
73     void Restore() const;
74 
75     /*
76      * @brief Sets SkCanvas to TexgineCanvas what user want
77      */
78     void SetCanvas(SkCanvas *canvas);
79 
80 private:
81     SkCanvas *canvas_ = nullptr;
82 };
83 } // namespace TextEngine
84 } // namespace Rosen
85 } // namespace OHOS
86 
87 #endif // ROSEN_MODULES_TEXGINE_SRC_TEXGINE_DRAWING_TEXGINE_CANVAS_H
88