1 /*
2 * Copyright (c) 2024 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 #include "dtk_test_ext.h"
16 #include "text/font.h"
17 #include "recording/mem_allocator.h"
18 #include "text/font_mgr.h"
19 #include "text/font_style_set.h"
20 #include "text/rs_xform.h"
21 #include "utils/point.h"
22 #include "utils/rect.h"
23 #include "text/typeface.h"
24
25 /*
26 测试类:FontMgr
27 测试接口:LoadThemeFont
28 测试内容:对接口入参themeName和typeface取值组合,构造typeface字体格式,并指定在font上,最终通过drawtextblob接口将text内容绘制在画布上
29 */
30
31 namespace OHOS {
32 namespace Rosen {
33
DrawTexts(TestPlaybackCanvas * playbackCanvas,std::shared_ptr<Drawing::Typeface> & emoji_typeface)34 static void DrawTexts(TestPlaybackCanvas* playbackCanvas, std::shared_ptr<Drawing::Typeface>& emoji_typeface)
35 {
36 auto font = Drawing::Font(emoji_typeface, 50.f, 1.0f, 0.f);
37 std::string text1 = "DDGR ddgr 鸿蒙 !@#%¥^&*;:,。";
38 std::string text2 = "-_=+()123`.---~|{}【】,./?、?<>《》";
39 std::string text3 = "\xE2\x99\x88\xE2\x99\x8A\xE2\x99\x88\xE2\x99\x8C\xE2\x99\x8D\xE2\x99\x8D";
40 std::string texts[] = {text1, text2, text3};
41 int line = 200;
42 int interval2 = 200;
43 for (auto text :texts) {
44 std::shared_ptr<Drawing::TextBlob> textBlob = Drawing::TextBlob::MakeFromText(text.c_str(), text.size(), font);
45 Drawing::Brush brush;
46 playbackCanvas->AttachBrush(brush);
47 playbackCanvas->DrawTextBlob(textBlob.get(), interval2, line);
48 line += interval2;
49 playbackCanvas->DetachBrush();
50 Drawing::Pen pen;
51 playbackCanvas->AttachPen(pen);
52 playbackCanvas->DrawTextBlob(textBlob.get(), interval2, line);
53 line += interval2;
54 playbackCanvas->DetachPen();
55 }
56 }
57
58 //对应用例 FontMgr_LoadThemeFont2_3001
59 DEF_DTK(fontmgr_loadthemefont2, TestLevel::L1, 1)
60 {
61 std::shared_ptr<Drawing::FontMgr> fontMgr(Drawing::FontMgr::CreateDefaultFontMgr());
62 std::string themeName = "abcd";
63 std::string emoji_familyName = "HMOS Color Emoji";
64 std::shared_ptr<Drawing::FontStyleSet> fontStyleSet(fontMgr->MatchFamily(emoji_familyName.c_str()));
65 auto emoji_typeface = std::shared_ptr<Drawing::Typeface>(fontStyleSet->CreateTypeface(0));
66 fontMgr->LoadThemeFont(themeName, emoji_typeface);
67
68 DrawTexts(playbackCanvas_, emoji_typeface);
69 }
70
71 //对应用例 FontMgr_LoadThemeFont2_3002
72 DEF_DTK(fontmgr_loadthemefont2, TestLevel::L1, 2)
73 {
74 std::shared_ptr<Drawing::FontMgr> fontMgr(Drawing::FontMgr::CreateDynamicFontMgr());
75 std::string themeName = "abcd";
76 std::string emoji_familyName = "HMOS Color Emoji";
77 std::shared_ptr<Drawing::FontStyleSet> fontStyleSet(fontMgr->MatchFamily(emoji_familyName.c_str()));
78 auto emoji_typeface = std::shared_ptr<Drawing::Typeface>(fontStyleSet->CreateTypeface(0));
79 fontMgr->LoadThemeFont(themeName, emoji_typeface);
80
81 DrawTexts(playbackCanvas_, emoji_typeface);
82 }
83
84 //对应用例 FontMgr_LoadThemeFont2_3003
85 DEF_DTK(fontmgr_loadthemefont2, TestLevel::L1, 3)
86 {
87 std::shared_ptr<Drawing::FontMgr> fontMgr(Drawing::FontMgr::CreateDefaultFontMgr());
88 std::string themeName = "";
89 fontMgr->GetFamilyName(0, themeName);
90 std::string emoji_familyName = "HMOS Color Emoji";
91 std::shared_ptr<Drawing::FontStyleSet> fontStyleSet(fontMgr->MatchFamily(emoji_familyName.c_str()));
92 auto emoji_typeface = std::shared_ptr<Drawing::Typeface>(fontStyleSet->CreateTypeface(0));
93 fontMgr->LoadThemeFont(themeName, emoji_typeface);
94
95 DrawTexts(playbackCanvas_, emoji_typeface);
96 }
97
98 //对应用例 FontMgr_LoadThemeFont2_3004
99 DEF_DTK(fontmgr_loadthemefont2, TestLevel::L1, 4)
100 {
101 std::shared_ptr<Drawing::FontMgr> fontMgr(Drawing::FontMgr::CreateDynamicFontMgr());
102 std::string themeName = "";
103 fontMgr->GetFamilyName(0, themeName);
104 std::string emoji_familyName = "HMOS Color Emoji";
105 std::shared_ptr<Drawing::FontStyleSet> fontStyleSet(fontMgr->CreateStyleSet(0));
106 auto emoji_typeface = std::shared_ptr<Drawing::Typeface>(fontStyleSet->CreateTypeface(0));
107 fontMgr->LoadThemeFont(themeName, emoji_typeface);
108
109 DrawTexts(playbackCanvas_, emoji_typeface);
110 }
111
112 //对应用例 FontMgr_LoadThemeFont2_3005
113 DEF_DTK(fontmgr_loadthemefont2, TestLevel::L1, 5)
114 {
115 std::shared_ptr<Drawing::FontMgr> fontMgr(Drawing::FontMgr::CreateDynamicFontMgr());
116 std::string themeName = "HMOS Color Emoji";
117 std::string emoji_familyName = "HMOS Color Emoji";
118 std::shared_ptr<Drawing::FontStyleSet> fontStyleSet(fontMgr->MatchFamily(emoji_familyName.c_str()));
119 auto emoji_typeface = std::shared_ptr<Drawing::Typeface>(fontStyleSet->CreateTypeface(0));
120 fontMgr->LoadThemeFont(themeName, nullptr);
121
122 DrawTexts(playbackCanvas_, emoji_typeface);
123 }
124
125 //对应用例 FontMgr_LoadThemeFont2_3006
126 DEF_DTK(fontmgr_loadthemefont2, TestLevel::L1, 6)
127 {
128 std::shared_ptr<Drawing::FontMgr> fontMgr(Drawing::FontMgr::CreateDefaultFontMgr());
129 std::string themeName = "abcd";
130 std::string emoji_familyName = "HMOS Color Emoji";
131 std::shared_ptr<Drawing::FontStyleSet> fontStyleSet(fontMgr->MatchFamily(emoji_familyName.c_str()));
132 auto emoji_typeface = std::shared_ptr<Drawing::Typeface>(fontStyleSet->CreateTypeface(0));
133 fontMgr->LoadThemeFont(themeName, nullptr);
134
135 DrawTexts(playbackCanvas_, emoji_typeface);
136 }
137
138 //对应用例 FontMgr_LoadThemeFont2_3007
139 DEF_DTK(fontmgr_loadthemefont2, TestLevel::L1, 7)
140 {
141 std::shared_ptr<Drawing::FontMgr> fontMgr(Drawing::FontMgr::CreateDynamicFontMgr());
142 std::string themeName = "";
143 fontMgr->GetFamilyName(0, themeName);
144 std::string emoji_familyName = "HMOS Color Emoji";
145 std::shared_ptr<Drawing::FontStyleSet> fontStyleSet(fontMgr->MatchFamily(emoji_familyName.c_str()));
146 auto emoji_typeface = std::shared_ptr<Drawing::Typeface>(fontStyleSet->CreateTypeface(0));
147 fontMgr->LoadThemeFont(themeName, nullptr);
148
149 DrawTexts(playbackCanvas_, emoji_typeface);
150 }
151
152 //对应用例 FontMgr_LoadThemeFont2_3008
153 DEF_DTK(fontmgr_loadthemefont2, TestLevel::L1, 8)
154 {
155 std::shared_ptr<Drawing::FontMgr> fontMgr(Drawing::FontMgr::CreateDynamicFontMgr());
156 std::string themeName = "HMOS Color Emoji";
157 std::string emoji_familyName = "HMOS Color Emoji";
158 std::shared_ptr<Drawing::FontStyleSet> fontStyleSet(fontMgr->CreateStyleSet(0));
159 auto emoji_typeface = std::shared_ptr<Drawing::Typeface>(fontStyleSet->CreateTypeface(0));
160 fontMgr->LoadThemeFont(themeName, emoji_typeface);
161
162 DrawTexts(playbackCanvas_, emoji_typeface);
163 }
164
165 //对应用例 FontMgr_LoadThemeFont2_3009
166 DEF_DTK(fontmgr_loadthemefont2, TestLevel::L1, 9)
167 {
168 std::shared_ptr<Drawing::FontMgr> fontMgr(Drawing::FontMgr::CreateDefaultFontMgr());
169 std::string themeName = "";
170 std::string emoji_familyName = "HMOS Color Emoji";
171 std::shared_ptr<Drawing::FontStyleSet> fontStyleSet(fontMgr->CreateStyleSet(0));
172 auto emoji_typeface = std::shared_ptr<Drawing::Typeface>(fontStyleSet->CreateTypeface(0));
173 fontMgr->LoadThemeFont(themeName, emoji_typeface);
174
175 DrawTexts(playbackCanvas_, emoji_typeface);
176 }
177
178 //对应用例 FontMgr_LoadThemeFont2_3010
179 DEF_DTK(fontmgr_loadthemefont2, TestLevel::L1, 10)
180 {
181 std::shared_ptr<Drawing::FontMgr> fontMgr(Drawing::FontMgr::CreateDefaultFontMgr());
182 std::string themeName = "";
183 std::string emoji_familyName = "HMOS Color Emoji";
184 std::shared_ptr<Drawing::FontStyleSet> fontStyleSet(fontMgr->MatchFamily(emoji_familyName.c_str()));
185 auto emoji_typeface = std::shared_ptr<Drawing::Typeface>(fontStyleSet->CreateTypeface(0));
186 fontMgr->LoadThemeFont(themeName, nullptr);
187
188 DrawTexts(playbackCanvas_, emoji_typeface);
189 }
190
191 //对应用例 FontMgr_LoadThemeFont2_3011
192 DEF_DTK(fontmgr_loadthemefont2, TestLevel::L1, 11)
193 {
194 std::shared_ptr<Drawing::FontMgr> fontMgr(Drawing::FontMgr::CreateDefaultFontMgr());
195 std::string themeName = "HMOS Color Emoji";
196 std::string emoji_familyName = "HMOS Color Emoji";
197 std::shared_ptr<Drawing::FontStyleSet> fontStyleSet(fontMgr->CreateStyleSet(0));
198 auto emoji_typeface = std::shared_ptr<Drawing::Typeface>(fontStyleSet->CreateTypeface(0));
199 fontMgr->LoadThemeFont(themeName, emoji_typeface);
200
201 DrawTexts(playbackCanvas_, emoji_typeface);
202 }
203
204 //对应用例 FontMgr_LoadThemeFont2_3012
205 DEF_DTK(fontmgr_loadthemefont2, TestLevel::L1, 12)
206 {
207 std::shared_ptr<Drawing::FontMgr> fontMgr(Drawing::FontMgr::CreateDefaultFontMgr());
208 std::string themeName = "";
209 std::string emoji_familyName = "HMOS Color Emoji";
210 std::shared_ptr<Drawing::FontStyleSet> fontStyleSet(fontMgr->MatchFamily(emoji_familyName.c_str()));
211 auto emoji_typeface = std::shared_ptr<Drawing::Typeface>(fontStyleSet->CreateTypeface(0));
212 fontMgr->LoadThemeFont(themeName, emoji_typeface);
213
214 DrawTexts(playbackCanvas_, emoji_typeface);
215 }
216
217 //对应用例 FontMgr_LoadThemeFont2_3013
218 DEF_DTK(fontmgr_loadthemefont2, TestLevel::L1, 13)
219 {
220 std::shared_ptr<Drawing::FontMgr> fontMgr(Drawing::FontMgr::CreateDefaultFontMgr());
221 std::string themeName = "abcd";
222 std::string emoji_familyName = "HMOS Color Emoji";
223 std::shared_ptr<Drawing::FontStyleSet> fontStyleSet(fontMgr->CreateStyleSet(0));
224 auto emoji_typeface = std::shared_ptr<Drawing::Typeface>(fontStyleSet->CreateTypeface(0));
225 fontMgr->LoadThemeFont(themeName, emoji_typeface);
226
227 DrawTexts(playbackCanvas_, emoji_typeface);
228 }
229
230 //对应用例 FontMgr_LoadThemeFont2_3014
231 DEF_DTK(fontmgr_loadthemefont2, TestLevel::L1, 14)
232 {
233 std::shared_ptr<Drawing::FontMgr> fontMgr(Drawing::FontMgr::CreateDynamicFontMgr());
234 std::string themeName = "";
235 std::string emoji_familyName = "HMOS Color Emoji";
236 std::shared_ptr<Drawing::FontStyleSet> fontStyleSet(fontMgr->MatchFamily(emoji_familyName.c_str()));
237 auto emoji_typeface = std::shared_ptr<Drawing::Typeface>(fontStyleSet->CreateTypeface(0));
238 fontMgr->LoadThemeFont(themeName, emoji_typeface);
239
240 DrawTexts(playbackCanvas_, emoji_typeface);
241 }
242
243 //对应用例 FontMgr_LoadThemeFont2_3015
244 DEF_DTK(fontmgr_loadthemefont2, TestLevel::L1, 15)
245 {
246 std::shared_ptr<Drawing::FontMgr> fontMgr(Drawing::FontMgr::CreateDefaultFontMgr());
247 std::string themeName = "HMOS Color Emoji";
248 std::string emoji_familyName = "HMOS Color Emoji";
249 std::shared_ptr<Drawing::FontStyleSet> fontStyleSet(fontMgr->MatchFamily(emoji_familyName.c_str()));
250 auto emoji_typeface = std::shared_ptr<Drawing::Typeface>(fontStyleSet->CreateTypeface(0));
251 fontMgr->LoadThemeFont(themeName, nullptr);
252
253 DrawTexts(playbackCanvas_, emoji_typeface);
254 }
255
256 //对应用例 FontMgr_LoadThemeFont2_3016
257 DEF_DTK(fontmgr_loadthemefont2, TestLevel::L1, 16)
258 {
259 std::shared_ptr<Drawing::FontMgr> fontMgr(Drawing::FontMgr::CreateDefaultFontMgr());
260 std::string themeName = "";
261 fontMgr->GetFamilyName(0, themeName);
262 std::string emoji_familyName = "HMOS Color Emoji";
263 std::shared_ptr<Drawing::FontStyleSet> fontStyleSet(fontMgr->CreateStyleSet(0));
264 auto emoji_typeface = std::shared_ptr<Drawing::Typeface>(fontStyleSet->CreateTypeface(0));
265 fontMgr->LoadThemeFont(themeName, emoji_typeface);
266
267 DrawTexts(playbackCanvas_, emoji_typeface);
268 }
269
270 //对应用例 FontMgr_LoadThemeFont2_3017
271 DEF_DTK(fontmgr_loadthemefont2, TestLevel::L1, 17)
272 {
273 std::shared_ptr<Drawing::FontMgr> fontMgr(Drawing::FontMgr::CreateDynamicFontMgr());
274 std::string themeName = "abcd";
275 std::string emoji_familyName = "HMOS Color Emoji";
276 std::shared_ptr<Drawing::FontStyleSet> fontStyleSet(fontMgr->CreateStyleSet(0));
277 auto emoji_typeface = std::shared_ptr<Drawing::Typeface>(fontStyleSet->CreateTypeface(0));
278 fontMgr->LoadThemeFont(themeName, emoji_typeface);
279
280 DrawTexts(playbackCanvas_, emoji_typeface);
281 }
282
283 //对应用例 FontMgr_LoadThemeFont2_3018
284 DEF_DTK(fontmgr_loadthemefont2, TestLevel::L1, 18)
285 {
286 std::shared_ptr<Drawing::FontMgr> fontMgr(Drawing::FontMgr::CreateDynamicFontMgr());
287 std::string themeName = "";
288 std::string emoji_familyName = "HMOS Color Emoji";
289 std::shared_ptr<Drawing::FontStyleSet> fontStyleSet(fontMgr->CreateStyleSet(0));
290 auto emoji_typeface = std::shared_ptr<Drawing::Typeface>(fontStyleSet->CreateTypeface(0));
291 fontMgr->LoadThemeFont(themeName, emoji_typeface);
292
293 DrawTexts(playbackCanvas_, emoji_typeface);
294 }
295
296 //对应用例 FontMgr_LoadThemeFont2_3019
297 DEF_DTK(fontmgr_loadthemefont2, TestLevel::L1, 19)
298 {
299 std::shared_ptr<Drawing::FontMgr> fontMgr(Drawing::FontMgr::CreateDefaultFontMgr());
300 std::string themeName = "";
301 fontMgr->GetFamilyName(0, themeName);
302 std::string emoji_familyName = "HMOS Color Emoji";
303 std::shared_ptr<Drawing::FontStyleSet> fontStyleSet(fontMgr->MatchFamily(emoji_familyName.c_str()));
304 auto emoji_typeface = std::shared_ptr<Drawing::Typeface>(fontStyleSet->CreateTypeface(0));
305 fontMgr->LoadThemeFont(themeName, nullptr);
306
307 DrawTexts(playbackCanvas_, emoji_typeface);
308 }
309
310 //对应用例 FontMgr_LoadThemeFont2_3020
311 DEF_DTK(fontmgr_loadthemefont2, TestLevel::L1, 20)
312 {
313 std::shared_ptr<Drawing::FontMgr> fontMgr(Drawing::FontMgr::CreateDynamicFontMgr());
314 std::string themeName = "";
315 fontMgr->GetFamilyName(0, themeName);
316 std::string emoji_familyName = "HMOS Color Emoji";
317 std::shared_ptr<Drawing::FontStyleSet> fontStyleSet(fontMgr->MatchFamily(emoji_familyName.c_str()));
318 auto emoji_typeface = std::shared_ptr<Drawing::Typeface>(fontStyleSet->CreateTypeface(0));
319 fontMgr->LoadThemeFont(themeName, emoji_typeface);
320
321 DrawTexts(playbackCanvas_, emoji_typeface);
322 }
323
324 //对应用例 FontMgr_LoadThemeFont2_3021
325 DEF_DTK(fontmgr_loadthemefont2, TestLevel::L1, 21)
326 {
327 std::shared_ptr<Drawing::FontMgr> fontMgr(Drawing::FontMgr::CreateDefaultFontMgr());
328 std::string themeName = "HMOS Color Emoji";
329 std::string emoji_familyName = "HMOS Color Emoji";
330 std::shared_ptr<Drawing::FontStyleSet> fontStyleSet(fontMgr->MatchFamily(emoji_familyName.c_str()));
331 auto emoji_typeface = std::shared_ptr<Drawing::Typeface>(fontStyleSet->CreateTypeface(0));
332 fontMgr->LoadThemeFont(themeName, emoji_typeface);
333
334 DrawTexts(playbackCanvas_, emoji_typeface);
335 }
336
337 //对应用例 FontMgr_LoadThemeFont2_3022
338 DEF_DTK(fontmgr_loadthemefont2, TestLevel::L1, 22)
339 {
340 std::shared_ptr<Drawing::FontMgr> fontMgr(Drawing::FontMgr::CreateDynamicFontMgr());
341 std::string themeName = "";
342 std::string emoji_familyName = "HMOS Color Emoji";
343 std::shared_ptr<Drawing::FontStyleSet> fontStyleSet(fontMgr->MatchFamily(emoji_familyName.c_str()));
344 auto emoji_typeface = std::shared_ptr<Drawing::Typeface>(fontStyleSet->CreateTypeface(0));
345 fontMgr->LoadThemeFont(themeName, nullptr);
346
347 DrawTexts(playbackCanvas_, emoji_typeface);
348 }
349
350 //对应用例 FontMgr_LoadThemeFont2_3023
351 DEF_DTK(fontmgr_loadthemefont2, TestLevel::L1, 23)
352 {
353 std::shared_ptr<Drawing::FontMgr> fontMgr(Drawing::FontMgr::CreateDynamicFontMgr());
354 std::string themeName = "abcd";
355 std::string emoji_familyName = "HMOS Color Emoji";
356 std::shared_ptr<Drawing::FontStyleSet> fontStyleSet(fontMgr->MatchFamily(emoji_familyName.c_str()));
357 auto emoji_typeface = std::shared_ptr<Drawing::Typeface>(fontStyleSet->CreateTypeface(0));
358 fontMgr->LoadThemeFont(themeName, nullptr);
359
360 DrawTexts(playbackCanvas_, emoji_typeface);
361 }
362
363 //对应用例 FontMgr_LoadThemeFont2_3024
364 DEF_DTK(fontmgr_loadthemefont2, TestLevel::L1, 24)
365 {
366 std::shared_ptr<Drawing::FontMgr> fontMgr(Drawing::FontMgr::CreateDynamicFontMgr());
367 std::string themeName = "HMOS Color Emoji";
368 std::string emoji_familyName = "HMOS Color Emoji";
369 std::shared_ptr<Drawing::FontStyleSet> fontStyleSet(fontMgr->MatchFamily(emoji_familyName.c_str()));
370 auto emoji_typeface = std::shared_ptr<Drawing::Typeface>(fontStyleSet->CreateTypeface(0));
371 fontMgr->LoadThemeFont(themeName, emoji_typeface);
372
373 DrawTexts(playbackCanvas_, emoji_typeface);
374 }
375
376 }
377 }
378