• 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_RECT_H
17 #define ROSEN_MODULES_TEXGINE_SRC_TEXGINE_DRAWING_TEXGINE_RECT_H
18 
19 #include <memory>
20 
21 #ifndef USE_ROSEN_DRAWING
22 #include <include/core/SkRect.h>
23 #include <include/core/SkRRect.h>
24 #else
25 #include "drawing.h"
26 #endif
27 
28 namespace OHOS {
29 namespace Rosen {
30 namespace TextEngine {
31 class TexgineRect {
32 public:
33     TexgineRect();
34 
35     /*
36      * @brief Create TexgineRect
37      * @param left The left boundary of TexgineRect
38      * @param right The right boundary of TexgineRect
39      * @param top The top boundary of TexgineRect
40      * @param bottom The bottom boundary of TexgineRect
41      */
42     static TexgineRect MakeLTRB(float left, float top, float right, float bottom);
43 
44     /*
45      * @brief Create TexgineRect
46      * @param x The left boundary of TexgineRect
47      * @param y The top boundary of TexgineRect
48      * @param w The width of TexgineRect
49      * @param h The height of TexgineRect
50      */
51     static TexgineRect MakeXYWH(float x, float y, float w, float h);
52 
53     /*
54      * @brief Create TexgineRect at (0, 0, w, h)
55      * @param w The width of TexgineRect
56      * @param h The height of TexgineRect
57      */
58     static TexgineRect MakeWH(float w, float h);
59 
60     /*
61      * @brief Create TexgineRect
62      * @param x The left boundary of TexgineRect
63      * @param y The top boundary of TexgineRect
64      * @param w The width of TexgineRect
65      * @param h The height of TexgineRect
66      * @param skRadii The SkVector of TexgineRect
67      */
68     static TexgineRect MakeRRect(float x, float y, float w, float h, const SkVector skRadii[4]);
69 
70     /*
71      * @brief Return SkRect that user init or set to TexgineRect
72      */
73 #ifndef USE_ROSEN_DRAWING
74     std::shared_ptr<SkRect> GetRect() const;
75 #else
76     std::shared_ptr<RSRect> GetRect() const;
77 #endif
78 
79     /*
80      * @brief Return SkRRect that user set to TexgineRect
81      */
82 #ifndef USE_ROSEN_DRAWING
83     std::shared_ptr<SkRRect> GetRRect() const;
84 #else
85     std::shared_ptr<RSRoundRect> GetRRect() const;
86 #endif
87 
88     /*
89      * @brief Sets SkRect to TexgineRect
90      * @param rect SkRect user want
91      */
92 #ifndef USE_ROSEN_DRAWING
93     void SetRect(const SkRect &rect);
94 #else
95     void SetRect(const RSRect &rect);
96 #endif
97 
98     /*
99      * @brief Sets SkRRect to TexgineRect
100      * @param rect SkRRect user want
101      */
102 #ifndef USE_ROSEN_DRAWING
103     void SetRRect(const SkRRect &rrect);
104 #else
105     void SetRRect(const RSRoundRect &rrect);
106 #endif
107 
108     float *fLeft_ = nullptr;
109     float *fTop_ = nullptr;
110     float *fRight_ = nullptr;
111     float *fBottom_ = nullptr;
112 
113 private:
114 #ifndef USE_ROSEN_DRAWING
115     std::shared_ptr<SkRect> rect_ = nullptr;
116     std::shared_ptr<SkRRect> rrect_ = nullptr;
117 #else
118     std::shared_ptr<RSRect> rect_ = nullptr;
119     std::shared_ptr<RSRoundRect> rrect_ = nullptr;
120 #endif
121 };
122 } // namespace TextEngine
123 } // namespace Rosen
124 } // namespace OHOS
125 
126 #endif // ROSEN_MODULES_TEXGINE_SRC_TEXGINE_DRAWING_TEXGINE_RECT_H
127