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