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 #include "texgine_paint.h"
17
18 namespace OHOS {
19 namespace Rosen {
20 namespace TextEngine {
21 #ifndef USE_ROSEN_DRAWING
TexginePaint()22 TexginePaint::TexginePaint(): paint_(std::make_shared<SkPaint>()) {}
23 #else
24 TexginePaint::TexginePaint()
25 : style_(Style::FILL), brush_(std::make_shared<RSBrush>()), pen_(std::make_shared<RSPen>()) {}
26 #endif
27
28 #ifndef USE_ROSEN_DRAWING
GetPaint() const29 SkPaint TexginePaint::GetPaint() const
30 {
31 return *paint_.get();
32 }
33 #else
GetBrush() const34 RSBrush TexginePaint::GetBrush() const
35 {
36 return *brush_.get();
37 }
38
GetPen() const39 RSPen TexginePaint::GetPen() const
40 {
41 return *pen_.get();
42 }
43
GetStyle() const44 TexginePaint::Style TexginePaint::GetStyle() const
45 {
46 return style_;
47 }
48 #endif
49
50 #ifndef USE_ROSEN_DRAWING
SetPaint(const SkPaint & paint)51 void TexginePaint::SetPaint(const SkPaint &paint)
52 {
53 *paint_ = paint;
54 }
55 #else
SetBrush(const RSBrush & brush)56 void TexginePaint::SetBrush(const RSBrush &brush)
57 {
58 *brush_ = brush;
59 }
60
SetPen(const RSPen & pen)61 void TexginePaint::SetPen(const RSPen &pen)
62 {
63 *pen_ = pen;
64 }
65 #endif
66
SetColor(const uint32_t color)67 void TexginePaint::SetColor(const uint32_t color)
68 {
69 #ifndef USE_ROSEN_DRAWING
70 paint_->setColor(color);
71 #else
72 brush_->SetColor(color);
73 pen_->SetColor(color);
74 #endif
75 }
76
SetAlphaf(const float alpha)77 void TexginePaint::SetAlphaf(const float alpha)
78 {
79 #ifndef USE_ROSEN_DRAWING
80 paint_->setAlphaf(alpha);
81 #else
82 brush_->SetAlphaF(alpha);
83 pen_->SetAlphaF(alpha);
84 #endif
85 }
86
SetStrokeWidth(const double width)87 void TexginePaint::SetStrokeWidth(const double width)
88 {
89 #ifndef USE_ROSEN_DRAWING
90 paint_->setStrokeWidth(width);
91 #else
92 pen_->SetWidth(width);
93 #endif
94 }
95
SetAntiAlias(const bool aa)96 void TexginePaint::SetAntiAlias(const bool aa)
97 {
98 #ifndef USE_ROSEN_DRAWING
99 paint_->setAntiAlias(aa);
100 #else
101 brush_->SetAntiAlias(aa);
102 pen_->SetAntiAlias(aa);
103 #endif
104 }
105
SetARGB(const unsigned int a,const unsigned int r,const unsigned int g,const unsigned int b)106 void TexginePaint::SetARGB(const unsigned int a, const unsigned int r,
107 const unsigned int g, const unsigned int b)
108 {
109 #ifndef USE_ROSEN_DRAWING
110 paint_->setARGB(a, r, g, b);
111 #else
112 brush_->SetARGB(a, r, g, b);
113 pen_->SetARGB(a, r, g, b);
114 #endif
115 }
116
SetStyle(Style style)117 void TexginePaint::SetStyle(Style style)
118 {
119 #ifndef USE_ROSEN_DRAWING
120 paint_->setStyle(static_cast<SkPaint::Style>(style));
121 #else
122 style_ = style;
123 #endif
124 }
125
SetPathEffect(const std::shared_ptr<TexginePathEffect> pathEffect)126 void TexginePaint::SetPathEffect(const std::shared_ptr<TexginePathEffect> pathEffect)
127 {
128 if (pathEffect == nullptr) {
129 return;
130 }
131 #ifndef USE_ROSEN_DRAWING
132 paint_->setPathEffect(pathEffect->GetPathEffect());
133 #else
134 pen_->SetPathEffect(pathEffect->GetPathEffect());
135 #endif
136 }
137
SetMaskFilter(const std::shared_ptr<TexgineMaskFilter> maskFilter)138 void TexginePaint::SetMaskFilter(const std::shared_ptr<TexgineMaskFilter> maskFilter)
139 {
140 if (maskFilter == nullptr) {
141 return;
142 }
143 #ifndef USE_ROSEN_DRAWING
144 paint_->setMaskFilter(maskFilter->GetMaskFilter());
145 #else
146 RSFilter filter;
147 filter.SetMaskFilter(maskFilter->GetMaskFilter());
148 brush_->SetFilter(filter);
149 pen_->SetFilter(filter);
150 #endif
151 }
152
SetAlpha(const unsigned int alpha)153 void TexginePaint::SetAlpha(const unsigned int alpha)
154 {
155 #ifndef USE_ROSEN_DRAWING
156 paint_->setAlpha(alpha);
157 #else
158 brush_->SetAlpha(alpha);
159 pen_->SetAlpha(alpha);
160 #endif
161 }
162
SetBlendMode(TexgineBlendMode mode)163 void TexginePaint::SetBlendMode(TexgineBlendMode mode)
164 {
165 #ifndef USE_ROSEN_DRAWING
166 paint_->setBlendMode(static_cast<SkBlendMode>(mode));
167 #else
168 brush_->SetBlendMode(static_cast<Drawing::BlendMode>(mode));
169 pen_->SetBlendMode(static_cast<Drawing::BlendMode>(mode));
170 #endif
171 }
172
operator ==(const TexginePaint & rhs) const173 bool TexginePaint::operator ==(const TexginePaint &rhs) const
174 {
175 #ifndef USE_ROSEN_DRAWING
176 return *paint_ == rhs.GetPaint();
177 #else
178 return style_ == rhs.GetStyle() && *brush_ == rhs.GetBrush() && *pen_ == rhs.GetPen();
179 #endif
180 }
181 } // namespace TextEngine
182 } // namespace Rosen
183 } // namespace OHOS
184