1 /*
2 * Copyright (c) 2020-2021 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 "ui_test_vector_font.h"
17 #if ENABLE_VECTOR_FONT
18 #include <iostream>
19
20 #include "common/screen.h"
21 #include "components/ui_label.h"
22 #if ENABLE_MULTI_FONT
23 #include "font/ui_multi_font_manager.h"
24 #endif
25 namespace {
26 const int16_t GAP = 5;
27 const int16_t TITLE_HEIGHT = 29;
28 const uint16_t LABEL_WIDTH = 200;
29 const uint16_t LABEL_HEIGHT = 50;
30 const uint16_t BUF_SIZE = 200;
31 const uint16_t LANGUAGE_FILE_ID_MAX = 9;
32 const char* HYQIHEI_65S = "HYQiHei-65S.otf";
33 const char* NOTONASKHARABIC_REGULAR = "NotoNaskhArabic-Regular.ttf";
34 const char* ROBOTOCONDENSED_REGULAR = "RobotoCondensed-Regular.ttf";
35 const char* NOTOSANSCJKJP_REGULAR = "NotoSansCJKjp-Regular.otf";
36 const char* NOTOSANSTHAI_REGULAR = "NotoSansThai-Regular.ttf";
37 const char* NOTOSANSHEBREW_REGULAR = "NotoSansHebrew-Regular.ttf";
38 const char* NOTOSANSDEVANAGARI_REGULAR = "NotoSansDevanagari-Regular.otf";
39 const char* NOTOSANSMYANMAR_CONDENSED = "NotoSansMyanmar-Condensed.ttf";
40 const char* NOTOSANSBENGALI_REGULAR = "NotoSansBengali-Regular.ttf";
41 } // namespace
42 namespace OHOS {
SetUp()43 void UITestVectorFont::SetUp()
44 {
45 if (container_ == nullptr) {
46 container_ = new UIScrollView();
47 container_->SetThrowDrag(true);
48 container_->SetHorizontalScrollState(false);
49 container_->Resize(Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight() - BACK_BUTTON_HEIGHT);
50 positionX_ = 50; // 50: init position x
51 positionY_ = 5; // 5: init position y
52 }
53 }
54
TearDown()55 void UITestVectorFont::TearDown()
56 {
57 DeleteChildren(container_);
58 container_ = nullptr;
59 }
60
InnerTestTitle(const char * title)61 void UITestVectorFont::InnerTestTitle(const char* title)
62 {
63 UILabel* titleLabel = new UILabel();
64 UIFont::GetInstance()->RegisterFontInfo(DEFAULT_VECTOR_FONT_FILENAME);
65 titleLabel->SetPosition(TEXT_DISTANCE_TO_LEFT_SIDE, positionY_, Screen::GetInstance().GetWidth(),
66 TITLE_LABEL_DEFAULT_HEIGHT);
67 titleLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_DEFAULT_SIZE);
68 titleLabel->SetText(title);
69 container_->Add(titleLabel);
70 positionY_ += TITLE_HEIGHT + GAP;
71 }
72
GetTestView()73 const UIView* UITestVectorFont::GetTestView()
74 {
75 Font_FontEngine_Vector_Test_CH_Lang_001();
76 Font_FontEngine_Vector_Test_CH_Lang_002();
77 Font_FontEngine_Vector_Test_JA_Lang_001();
78 Font_FontEngine_Vector_Test_JA_Lang_002();
79 Font_FontEngine_Vector_Test_KR_Lang_001();
80 Font_FontEngine_Vector_Test_VI_Lang_001();
81 #if ENABLE_MULTI_FONT
82 Font_FontEngine_MultiLanguage_Test_JA_Lang_001();
83 Font_FontEngine_MultiLanguage_Test_JA_Lang_002();
84 Font_FontEngine_MultiLanguage_Test_KR_Lang_001();
85 Font_FontEngine_MultiLanguage_Test_VI_Lang_001();
86 Font_FontEngine_MultiLanguage_Test_CS_Lang_001();
87 Font_FontEngine_MultiLanguage_Test_EL_Lang_001();
88 Font_FontEngine_MultiLanguage_Test_RO_Lang_001();
89 #endif
90 return container_;
91 }
92
Font_FontEngine_Vector_Test_CH_Lang_001()93 void UITestVectorFont::Font_FontEngine_Vector_Test_CH_Lang_001()
94 {
95 if (container_ != nullptr) {
96 InnerTestTitle("CH Language");
97 UILabel* label = new UILabel();
98 UIFont::GetInstance()->RegisterFontInfo(HYQIHEI_65S);
99 label->SetPosition(positionX_, positionY_);
100 label->Resize(LABEL_WIDTH, LABEL_HEIGHT);
101 label->SetLineBreakMode(UILabel::LINE_BREAK_MARQUEE);
102 label->SetFont(HYQIHEI_65S, 24); // 24 : size
103 label->SetText("测试中文");
104 container_->Add(label);
105 positionY_ += LABEL_HEIGHT + GAP;
106 }
107 }
108
Font_FontEngine_Vector_Test_CH_Lang_002()109 void UITestVectorFont::Font_FontEngine_Vector_Test_CH_Lang_002()
110 {
111 if (container_ != nullptr) {
112 InnerTestTitle("Multiline text");
113 UILabel* label = new UILabel();
114 UIFont::GetInstance()->RegisterFontInfo(HYQIHEI_65S);
115 label->SetPosition(positionX_, positionY_);
116 label->Resize(LABEL_WIDTH, LABEL_HEIGHT * 2); // 2:double
117 label->SetFont(HYQIHEI_65S, 24); // 24 : size
118 label->SetText("测试中英文混合:text和text text和text text和text");
119 container_->Add(label);
120 positionY_ += LABEL_HEIGHT * 2 + GAP; // 2:double
121 }
122 }
123
Font_FontEngine_Vector_Test_JA_Lang_001()124 void UITestVectorFont::Font_FontEngine_Vector_Test_JA_Lang_001()
125 {
126 if (container_ != nullptr) {
127 InnerTestTitle("JA Language");
128 UILabel* label = new UILabel();
129 UIFont::GetInstance()->RegisterFontInfo(NOTOSANSCJKJP_REGULAR);
130 label->SetPosition(positionX_, positionY_);
131 label->Resize(LABEL_WIDTH, LABEL_HEIGHT);
132 label->SetLineBreakMode(UILabel::LINE_BREAK_MARQUEE);
133 label->SetFont(NOTOSANSCJKJP_REGULAR, 24); // 24 : size
134 label->SetText("ランニン");
135 container_->Add(label);
136 positionY_ += LABEL_HEIGHT + GAP;
137 }
138 }
139
Font_FontEngine_Vector_Test_JA_Lang_002()140 void UITestVectorFont::Font_FontEngine_Vector_Test_JA_Lang_002()
141 {
142 if (container_ != nullptr) {
143 InnerTestTitle("JA Language");
144 UILabel* label = new UILabel();
145 UIFont::GetInstance()->RegisterFontInfo(NOTOSANSCJKJP_REGULAR);
146 label->SetPosition(positionX_, positionY_);
147 label->Resize(LABEL_WIDTH, LABEL_HEIGHT);
148 label->SetLineBreakMode(UILabel::LINE_BREAK_MARQUEE);
149 label->SetFont(NOTOSANSCJKJP_REGULAR, 30); // 30 : size
150 label->SetText("ランニン");
151 container_->Add(label);
152 positionY_ += LABEL_HEIGHT + GAP;
153 }
154 }
155
Font_FontEngine_Vector_Test_KR_Lang_001()156 void UITestVectorFont::Font_FontEngine_Vector_Test_KR_Lang_001()
157 {
158 if (container_ != nullptr) {
159 InnerTestTitle("KR Language");
160 UILabel* label = new UILabel();
161 label->SetPosition(positionX_, positionY_);
162 label->Resize(LABEL_WIDTH, LABEL_HEIGHT);
163 label->SetLineBreakMode(UILabel::LINE_BREAK_MARQUEE);
164 UIFont::GetInstance()->RegisterFontInfo(NOTOSANSCJKJP_REGULAR);
165 label->SetFont(NOTOSANSCJKJP_REGULAR, 24); // 24 : size
166 label->SetText("韩语리기");
167 container_->Add(label);
168 positionY_ += LABEL_HEIGHT + GAP;
169 }
170 }
171
Font_FontEngine_Vector_Test_VI_Lang_001()172 void UITestVectorFont::Font_FontEngine_Vector_Test_VI_Lang_001()
173 {
174 if (container_ != nullptr) {
175 InnerTestTitle("VI Language");
176 UIFont::GetInstance()->RegisterFontInfo(NOTOSANSCJKJP_REGULAR);
177 UIFont::GetInstance()->RegisterFontInfo(HYQIHEI_65S);
178 UILabel* label = new UILabel();
179 label->SetPosition(positionX_, positionY_);
180 label->Resize(LABEL_WIDTH, LABEL_HEIGHT);
181 label->SetLineBreakMode(UILabel::LINE_BREAK_MARQUEE);
182 label->SetFont(ROBOTOCONDENSED_REGULAR, 24); // 24 : size
183 label->SetText("Kết thúc tập luyện?");
184 container_->Add(label);
185 positionY_ += LABEL_HEIGHT + GAP;
186 }
187 }
188
189 #if ENABLE_MULTI_FONT
Font_FontEngine_MultiLanguage_Test_JA_Lang_001()190 void UITestVectorFont::Font_FontEngine_MultiLanguage_Test_JA_Lang_001()
191 {
192 if (container_ != nullptr) {
193 InnerTestTitle("CH+JA Language");
194 UIFont::GetInstance()->RegisterFontInfo(NOTOSANSCJKJP_REGULAR);
195 UIFont::GetInstance()->RegisterFontInfo(HYQIHEI_65S);
196 UIFont::GetInstance()->RegisterFontInfo(ROBOTOCONDENSED_REGULAR);
197 uint8_t findPath[] = {UIFont::GetInstance()->GetFontId(HYQIHEI_65S),
198 UIFont::GetInstance()->GetFontId(ROBOTOCONDENSED_REGULAR)};
199 UIMultiFontManager::GetInstance()->SetSearchFontList(UIFont::GetInstance()->GetFontId(HYQIHEI_65S), findPath,
200 sizeof(findPath));
201 UILabel* label = new UILabel();
202 label->SetPosition(positionX_, positionY_);
203 label->Resize(LABEL_WIDTH, LABEL_HEIGHT);
204 label->SetLineBreakMode(UILabel::LINE_BREAK_MARQUEE);
205 label->SetFont(HYQIHEI_65S, 24); // 24 : size
206 label->SetText("日语ランニン");
207 container_->Add(label);
208 positionY_ += LABEL_HEIGHT + GAP;
209 }
210 }
211
Font_FontEngine_MultiLanguage_Test_JA_Lang_002()212 void UITestVectorFont::Font_FontEngine_MultiLanguage_Test_JA_Lang_002()
213 {
214 if (container_ != nullptr) {
215 InnerTestTitle("UnRegister JA Language");
216 UILabel* label = new UILabel();
217 label->SetPosition(positionX_, positionY_);
218 label->Resize(LABEL_WIDTH, LABEL_HEIGHT);
219 label->SetLineBreakMode(UILabel::LINE_BREAK_MARQUEE);
220 label->SetFont(NOTOSANSCJKJP_REGULAR, 24); // 24 : size
221 label->SetText("韩语日语리기ランニン");
222 container_->Add(label);
223 positionY_ += LABEL_HEIGHT + GAP;
224 }
225 }
226
Font_FontEngine_MultiLanguage_Test_KR_Lang_001()227 void UITestVectorFont::Font_FontEngine_MultiLanguage_Test_KR_Lang_001()
228 {
229 if (container_ != nullptr) {
230 InnerTestTitle("CH+KR Language");
231 UIFont::GetInstance()->RegisterFontInfo(NOTOSANSCJKJP_REGULAR);
232 UIFont::GetInstance()->RegisterFontInfo(HYQIHEI_65S);
233 UIFont::GetInstance()->RegisterFontInfo(ROBOTOCONDENSED_REGULAR);
234 uint8_t findPath[] = {UIFont::GetInstance()->GetFontId(HYQIHEI_65S),
235 UIFont::GetInstance()->GetFontId(ROBOTOCONDENSED_REGULAR)};
236 UIMultiFontManager::GetInstance()->SetSearchFontList(UIFont::GetInstance()->GetFontId(NOTOSANSCJKJP_REGULAR),
237 findPath, sizeof(findPath));
238 UILabel* label = new UILabel();
239 label->SetPosition(positionX_, positionY_);
240 label->Resize(LABEL_WIDTH, LABEL_HEIGHT);
241 label->SetLineBreakMode(UILabel::LINE_BREAK_MARQUEE);
242 label->SetFont(NOTOSANSCJKJP_REGULAR, 24); // 24 : size
243 label->SetText("韩语리기");
244 container_->Add(label);
245 positionY_ += LABEL_HEIGHT + GAP;
246 }
247 }
248
Font_FontEngine_MultiLanguage_Test_VI_Lang_001()249 void UITestVectorFont::Font_FontEngine_MultiLanguage_Test_VI_Lang_001()
250 {
251 if (container_ != nullptr) {
252 InnerTestTitle("CH+VI Language");
253 UIFont::GetInstance()->RegisterFontInfo(NOTOSANSCJKJP_REGULAR);
254 UIFont::GetInstance()->RegisterFontInfo(HYQIHEI_65S);
255 UIFont::GetInstance()->RegisterFontInfo(ROBOTOCONDENSED_REGULAR);
256 uint8_t findPath4[] = {UIFont::GetInstance()->GetFontId(HYQIHEI_65S),
257 UIFont::GetInstance()->GetFontId(ROBOTOCONDENSED_REGULAR)};
258 UIMultiFontManager::GetInstance()->SetSearchFontList(UIFont::GetInstance()->GetFontId(NOTOSANSCJKJP_REGULAR),
259 findPath4, sizeof(findPath4));
260 UILabel* label = new UILabel();
261 label->SetPosition(positionX_, positionY_);
262 label->Resize(LABEL_WIDTH, LABEL_HEIGHT);
263 label->SetLineBreakMode(UILabel::LINE_BREAK_MARQUEE);
264 label->SetFont(NOTOSANSCJKJP_REGULAR, 24); // 24 : size
265 label->SetText("越南语Kết thúc tập luyện?");
266 container_->Add(label);
267 positionY_ += LABEL_HEIGHT + GAP;
268 }
269 }
270
Font_FontEngine_MultiLanguage_Test_CS_Lang_001()271 void UITestVectorFont::Font_FontEngine_MultiLanguage_Test_CS_Lang_001()
272 {
273 if (container_ != nullptr) {
274 InnerTestTitle("CH+CS Language");
275 UIFont::GetInstance()->RegisterFontInfo(NOTOSANSCJKJP_REGULAR);
276 UIFont::GetInstance()->RegisterFontInfo(HYQIHEI_65S);
277 UIFont::GetInstance()->RegisterFontInfo(ROBOTOCONDENSED_REGULAR);
278 uint8_t findPath4[] = {UIFont::GetInstance()->GetFontId(HYQIHEI_65S),
279 UIFont::GetInstance()->GetFontId(ROBOTOCONDENSED_REGULAR)};
280 UIMultiFontManager::GetInstance()->SetSearchFontList(UIFont::GetInstance()->GetFontId(NOTOSANSCJKJP_REGULAR),
281 findPath4, sizeof(findPath4));
282 UILabel* label = new UILabel();
283 label->SetPosition(positionX_, positionY_);
284 label->Resize(LABEL_WIDTH, LABEL_HEIGHT);
285 label->SetLineBreakMode(UILabel::LINE_BREAK_MARQUEE);
286 label->SetFont(NOTOSANSCJKJP_REGULAR, 24); // 24 : size
287 label->SetText("捷克语sledování tepové frekvence");
288 container_->Add(label);
289 positionY_ += LABEL_HEIGHT + GAP;
290 }
291 }
292
Font_FontEngine_MultiLanguage_Test_EL_Lang_001()293 void UITestVectorFont::Font_FontEngine_MultiLanguage_Test_EL_Lang_001()
294 {
295 if (container_ != nullptr) {
296 InnerTestTitle("CH+EL Language");
297 UIFont::GetInstance()->RegisterFontInfo(NOTOSANSCJKJP_REGULAR);
298 UIFont::GetInstance()->RegisterFontInfo(HYQIHEI_65S);
299 UIFont::GetInstance()->RegisterFontInfo(ROBOTOCONDENSED_REGULAR);
300 uint8_t findPath4[] = {UIFont::GetInstance()->GetFontId(HYQIHEI_65S),
301 UIFont::GetInstance()->GetFontId(ROBOTOCONDENSED_REGULAR)};
302 UIMultiFontManager::GetInstance()->SetSearchFontList(UIFont::GetInstance()->GetFontId(NOTOSANSCJKJP_REGULAR),
303 findPath4, sizeof(findPath4));
304 UILabel* label = new UILabel();
305 label->SetPosition(positionX_, positionY_);
306 label->Resize(LABEL_WIDTH, LABEL_HEIGHT);
307 label->SetLineBreakMode(UILabel::LINE_BREAK_MARQUEE);
308 label->SetFont(NOTOSANSCJKJP_REGULAR, 24); // 24 : size
309 label->SetText("西班牙España");
310 container_->Add(label);
311 positionY_ += LABEL_HEIGHT + GAP;
312 }
313 }
314
Font_FontEngine_MultiLanguage_Test_RO_Lang_001()315 void UITestVectorFont::Font_FontEngine_MultiLanguage_Test_RO_Lang_001()
316 {
317 if (container_ != nullptr) {
318 InnerTestTitle("RO Language");
319 UIFont::GetInstance()->RegisterFontInfo(NOTOSANSCJKJP_REGULAR);
320 UIFont::GetInstance()->RegisterFontInfo(HYQIHEI_65S);
321 UIFont::GetInstance()->RegisterFontInfo(ROBOTOCONDENSED_REGULAR);
322 uint8_t findPath4[] = {UIFont::GetInstance()->GetFontId(HYQIHEI_65S),
323 UIFont::GetInstance()->GetFontId(ROBOTOCONDENSED_REGULAR)};
324 UIMultiFontManager::GetInstance()->SetSearchFontList(UIFont::GetInstance()->GetFontId(NOTOSANSCJKJP_REGULAR),
325 findPath4, sizeof(findPath4));
326 UILabel* label = new UILabel();
327 label->SetPosition(positionX_, positionY_);
328 label->Resize(LABEL_WIDTH, LABEL_HEIGHT);
329 label->SetLineBreakMode(UILabel::LINE_BREAK_MARQUEE);
330 label->SetFont(NOTOSANSCJKJP_REGULAR, 24); // 24 : size
331 label->SetText("罗马尼亚Română");
332 container_->Add(label);
333 positionY_ += LABEL_HEIGHT + GAP;
334 }
335 }
336 #endif
337 } // namespace OHOS
338 #endif // ENABLE_VECTOR_FONT
339