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 16 #include <filesystem> 17 18 #include "drawing_font_collection.h" 19 #include "drawing_register_font.h" 20 #include "drawing_text_font_descriptor.h" 21 #include "font_descriptor_mgr.h" 22 #include "gtest/gtest.h" 23 24 using namespace testing; 25 using namespace testing::ext; 26 27 namespace OHOS { 28 namespace { 29 namespace fs = std::filesystem; 30 31 const std::string STYLISH_FONT_CONFIG_FILE = "/system/fonts/visibility_list.json"; 32 const std::string STYLISH_FONT_CONFIG_PROD_FILE = "/sys_prod/fonts/visibility_list.json"; 33 const std::string INSTALLED_FONT_CONFIG_FILE = 34 "/data/service/el1/public/for-all-app/fonts/install_fontconfig.json"; 35 } 36 37 class OH_Drawing_FontDescriptorTest : public testing::Test { 38 }; 39 40 /* 41 * @tc.name: OH_Drawing_FontDescriptorTest001 42 * @tc.desc: test for the fontDescriptor. 43 * @tc.type: FUNC 44 */ 45 HWTEST_F(OH_Drawing_FontDescriptorTest, OH_Drawing_FontDescriptorTest001, TestSize.Level1) 46 { 47 OH_Drawing_FontDescriptor* descArr = OH_Drawing_MatchFontDescriptors(nullptr, nullptr); 48 EXPECT_EQ(descArr, nullptr); 49 } 50 51 /* 52 * @tc.name: OH_Drawing_FontDescriptorTest002 53 * @tc.desc: test for the fontDescriptor. 54 * @tc.type: FUNC 55 */ 56 HWTEST_F(OH_Drawing_FontDescriptorTest, OH_Drawing_FontDescriptorTest002, TestSize.Level1) 57 { 58 OH_Drawing_FontDescriptor* desc = OH_Drawing_CreateFontDescriptor(); 59 size_t num = 0; 60 OH_Drawing_FontDescriptor* descArr = OH_Drawing_MatchFontDescriptors(desc, &num); 61 OH_Drawing_DestroyFontDescriptor(desc); 62 EXPECT_NE(descArr, nullptr); 63 EXPECT_NE(num, 0); 64 OH_Drawing_DestroyFontDescriptors(descArr, num); 65 } 66 67 /* 68 * @tc.name: OH_Drawing_FontDescriptorTest003 69 * @tc.desc: test for the fontDescriptor. 70 * @tc.type: FUNC 71 */ 72 HWTEST_F(OH_Drawing_FontDescriptorTest, OH_Drawing_FontDescriptorTest003, TestSize.Level1) 73 { 74 OH_Drawing_FontDescriptor* desc = OH_Drawing_CreateFontDescriptor(); 75 desc->weight = -1; 76 size_t num = 0; 77 OH_Drawing_FontDescriptor* descArr = OH_Drawing_MatchFontDescriptors(desc, &num); 78 OH_Drawing_DestroyFontDescriptor(desc); 79 EXPECT_EQ(descArr, nullptr); 80 EXPECT_EQ(num, 0); 81 OH_Drawing_DestroyFontDescriptors(descArr, num); 82 } 83 84 /* 85 * @tc.name: OH_Drawing_FontDescriptorTest004 86 * @tc.desc: test for the fontDescriptor. 87 * @tc.type: FUNC 88 */ 89 HWTEST_F(OH_Drawing_FontDescriptorTest, OH_Drawing_FontDescriptorTest004, TestSize.Level1) 90 { 91 OH_Drawing_FontDescriptor* desc = OH_Drawing_CreateFontDescriptor(); 92 char* fontFamily = strdup("HarmonyOS Sans"); 93 desc->fontFamily = fontFamily; 94 size_t num = 0; 95 OH_Drawing_FontDescriptor* descArr = OH_Drawing_MatchFontDescriptors(desc, &num); 96 ASSERT_NE(descArr, nullptr); 97 EXPECT_LE(1, num); 98 EXPECT_STREQ(descArr[0].fontFamily, fontFamily); 99 OH_Drawing_DestroyFontDescriptors(descArr, num); 100 free(fontFamily); 101 102 fontFamily = strdup("HarmonyOS Sans Condensed"); 103 desc->fontFamily = fontFamily; 104 descArr = OH_Drawing_MatchFontDescriptors(desc, &num); 105 ASSERT_NE(descArr, nullptr); 106 EXPECT_EQ(num, 1); 107 EXPECT_STREQ(descArr[0].fontFamily, fontFamily); 108 OH_Drawing_DestroyFontDescriptors(descArr, num); 109 OH_Drawing_DestroyFontDescriptor(desc); 110 } 111 112 /* 113 * @tc.name: OH_Drawing_FontDescriptorTest005 114 * @tc.desc: test for the fontDescriptor. 115 * @tc.type: FUNC 116 */ 117 HWTEST_F(OH_Drawing_FontDescriptorTest, OH_Drawing_FontDescriptorTest005, TestSize.Level1) 118 { 119 OH_Drawing_FontDescriptor* desc = OH_Drawing_CreateFontDescriptor(); 120 char* fontFamily = strdup("HarmonyOS Sans"); 121 desc->fontFamily = fontFamily; 122 desc->weight = 400; 123 124 size_t num = 0; 125 OH_Drawing_FontDescriptor* descArr = OH_Drawing_MatchFontDescriptors(desc, &num); 126 ASSERT_NE(descArr, nullptr); 127 EXPECT_LE(1, num); 128 EXPECT_STREQ(descArr[0].fontFamily, fontFamily); 129 EXPECT_EQ(descArr[0].weight, 400); 130 OH_Drawing_DestroyFontDescriptors(descArr, num); 131 OH_Drawing_DestroyFontDescriptor(desc); 132 } 133 134 /* 135 * @tc.name: OH_Drawing_FontDescriptorTest006 136 * @tc.desc: test for abnormal parameters when obtaining the font list and obtaining the FontDescriptor by fullName. 137 * @tc.type: FUNC 138 */ 139 HWTEST_F(OH_Drawing_FontDescriptorTest, OH_Drawing_FontDescriptorTest006, TestSize.Level1) 140 { 141 OH_Drawing_SystemFontType fontType = OH_Drawing_SystemFontType(0b10000); 142 OH_Drawing_Array *fontList = OH_Drawing_GetSystemFontFullNamesByType(fontType); 143 EXPECT_EQ(fontList, nullptr); 144 145 OH_Drawing_FontDescriptor *descriptor = OH_Drawing_GetFontDescriptorByFullName(nullptr, fontType); 146 EXPECT_EQ(descriptor, nullptr); 147 148 // The array TTF_FULLNAME represents the UTF-16 encoded version of a non-existent font full name "你好openharmony". 149 const uint8_t TTF_FULLNAME[] = { 150 0x4F, 0x60, 151 0x59, 0x7D, 152 0x00, 0x6F, 153 0x00, 0x70, 154 0x00, 0x65, 155 0x00, 0x6E, 156 0x00, 0x68, 157 0x00, 0x61, 158 0x00, 0x72, 159 0x00, 0x6D, 160 0x00, 0x6F, 161 0x00, 0x6E, 162 0x00, 0x79 163 }; 164 OH_Drawing_String drawingString; 165 drawingString.strData = const_cast<uint8_t*>(TTF_FULLNAME); 166 drawingString.strLen = sizeof(TTF_FULLNAME); 167 OH_Drawing_FontDescriptor *descriptor1 = 168 OH_Drawing_GetFontDescriptorByFullName(&drawingString, OH_Drawing_SystemFontType::ALL); 169 EXPECT_EQ(descriptor1, nullptr); 170 } 171 172 /* 173 * @tc.name: OH_Drawing_FontDescriptorTest007 174 * @tc.desc: test for obtaining the array of installed fonts. 175 * @tc.type: FUNC 176 */ 177 HWTEST_F(OH_Drawing_FontDescriptorTest, OH_Drawing_FontDescriptorTest007, TestSize.Level1) 178 { 179 if (!fs::exists(INSTALLED_FONT_CONFIG_FILE)) { 180 return; 181 } 182 OH_Drawing_SystemFontType fontType = OH_Drawing_SystemFontType::INSTALLED; 183 OH_Drawing_Array *fontList = OH_Drawing_GetSystemFontFullNamesByType(fontType); 184 ASSERT_NE(fontList, nullptr); 185 size_t size = OH_Drawing_GetDrawingArraySize(fontList); 186 EXPECT_NE(size, 0); 187 for (size_t i = 0; i < size; i++) { 188 const OH_Drawing_String *fontFullName = OH_Drawing_GetSystemFontFullNameByIndex(fontList, i); 189 EXPECT_NE(fontFullName, nullptr); 190 OH_Drawing_FontDescriptor *descriptor = OH_Drawing_GetFontDescriptorByFullName(fontFullName, fontType); 191 EXPECT_NE(descriptor, nullptr); 192 OH_Drawing_DestroyFontDescriptor(descriptor); 193 } 194 OH_Drawing_DestroySystemFontFullNames(fontList); 195 } 196 197 /* 198 * @tc.name: OH_Drawing_FontDescriptorTest008 199 * @tc.desc: test for obtaining the array of stylish fonts. 200 * @tc.type: FUNC 201 */ 202 HWTEST_F(OH_Drawing_FontDescriptorTest, OH_Drawing_FontDescriptorTest008, TestSize.Level1) 203 { 204 if (!fs::exists(STYLISH_FONT_CONFIG_FILE) && !fs::exists(STYLISH_FONT_CONFIG_PROD_FILE)) { 205 return; 206 } 207 OH_Drawing_SystemFontType fontType = OH_Drawing_SystemFontType::STYLISH; 208 OH_Drawing_Array *fontList = OH_Drawing_GetSystemFontFullNamesByType(fontType); 209 ASSERT_NE(fontList, nullptr); 210 size_t size = OH_Drawing_GetDrawingArraySize(fontList); 211 EXPECT_NE(size, 0); 212 for (size_t i = 0; i < size; i++) { 213 const OH_Drawing_String *fontFullName = OH_Drawing_GetSystemFontFullNameByIndex(fontList, i); 214 EXPECT_NE(fontFullName, nullptr); 215 OH_Drawing_FontDescriptor *descriptor = OH_Drawing_GetFontDescriptorByFullName(fontFullName, fontType); 216 EXPECT_NE(descriptor, nullptr); 217 OH_Drawing_DestroyFontDescriptor(descriptor); 218 } 219 OH_Drawing_DestroySystemFontFullNames(fontList); 220 } 221 222 /* 223 * @tc.name: OH_Drawing_FontDescriptorTest009 224 * @tc.desc: test for obtaining the array of system generic fonts. 225 * @tc.type: FUNC 226 */ 227 HWTEST_F(OH_Drawing_FontDescriptorTest, OH_Drawing_FontDescriptorTest009, TestSize.Level1) 228 { 229 OH_Drawing_SystemFontType fontType = OH_Drawing_SystemFontType::GENERIC; 230 OH_Drawing_Array *fontList = OH_Drawing_GetSystemFontFullNamesByType(fontType); 231 ASSERT_NE(fontList, nullptr); 232 size_t size = OH_Drawing_GetDrawingArraySize(fontList); 233 EXPECT_NE(size, 0); 234 for (size_t i = 0; i < size; i++) { 235 const OH_Drawing_String *fontFullName = OH_Drawing_GetSystemFontFullNameByIndex(fontList, i); 236 EXPECT_NE(fontFullName, nullptr); 237 OH_Drawing_FontDescriptor *descriptor = OH_Drawing_GetFontDescriptorByFullName(fontFullName, fontType); 238 EXPECT_NE(descriptor, nullptr); 239 OH_Drawing_DestroyFontDescriptor(descriptor); 240 } 241 OH_Drawing_DestroySystemFontFullNames(fontList); 242 } 243 244 /* 245 * @tc.name: OH_Drawing_FontDescriptorTest010 246 * @tc.desc: test for obtaining the list of composite fonts. 247 * @tc.type: FUNC 248 */ 249 HWTEST_F(OH_Drawing_FontDescriptorTest, OH_Drawing_FontDescriptorTest010, TestSize.Level1) 250 { 251 if (!fs::exists(STYLISH_FONT_CONFIG_FILE) && !fs::exists(STYLISH_FONT_CONFIG_PROD_FILE) && 252 !fs::exists(INSTALLED_FONT_CONFIG_FILE)) { 253 return; 254 } 255 OH_Drawing_SystemFontType fontType = OH_Drawing_SystemFontType(INSTALLED | STYLISH); 256 OH_Drawing_Array *fontList = OH_Drawing_GetSystemFontFullNamesByType(fontType); 257 ASSERT_NE(fontList, nullptr); 258 size_t size = OH_Drawing_GetDrawingArraySize(fontList); 259 EXPECT_NE(size, 0); 260 for (size_t i = 0; i < size; i++) { 261 const OH_Drawing_String *fontFullName = OH_Drawing_GetSystemFontFullNameByIndex(fontList, i); 262 EXPECT_NE(fontFullName, nullptr); 263 OH_Drawing_FontDescriptor *descriptor = OH_Drawing_GetFontDescriptorByFullName(fontFullName, fontType); 264 EXPECT_NE(descriptor, nullptr); 265 OH_Drawing_DestroyFontDescriptor(descriptor); 266 } 267 OH_Drawing_DestroySystemFontFullNames(fontList); 268 } 269 270 /* 271 * @tc.name: OH_Drawing_FontDescriptorTest011 272 * @tc.desc: test for obtaining the list of composite fonts that include "ALL". 273 * @tc.type: FUNC 274 */ 275 HWTEST_F(OH_Drawing_FontDescriptorTest, OH_Drawing_FontDescriptorTest011, TestSize.Level1) 276 { 277 OH_Drawing_SystemFontType fontType = OH_Drawing_SystemFontType(ALL | STYLISH); 278 OH_Drawing_Array *fontList = OH_Drawing_GetSystemFontFullNamesByType(fontType); 279 ASSERT_NE(fontList, nullptr); 280 size_t size = OH_Drawing_GetDrawingArraySize(fontList); 281 EXPECT_NE(size, 0); 282 for (size_t i = 0; i < size; i++) { 283 const OH_Drawing_String *fontFullName = OH_Drawing_GetSystemFontFullNameByIndex(fontList, i); 284 EXPECT_NE(fontFullName, nullptr); 285 OH_Drawing_FontDescriptor *descriptor = OH_Drawing_GetFontDescriptorByFullName(fontFullName, fontType); 286 EXPECT_NE(descriptor, nullptr); 287 OH_Drawing_DestroyFontDescriptor(descriptor); 288 } 289 OH_Drawing_DestroySystemFontFullNames(fontList); 290 } 291 292 /* 293 * @tc.name: OH_Drawing_FontDescriptorTest012 294 * @tc.desc: test for abnormal parameters when obtaining the fullName by index and releasing array memory. 295 * @tc.type: FUNC 296 */ 297 HWTEST_F(OH_Drawing_FontDescriptorTest, OH_Drawing_FontDescriptorTest012, TestSize.Level1) 298 { 299 OH_Drawing_SystemFontType fontType = OH_Drawing_SystemFontType::GENERIC; 300 OH_Drawing_Array *fontList = OH_Drawing_GetSystemFontFullNamesByType(fontType); 301 ASSERT_NE(fontList, nullptr); 302 const OH_Drawing_String* fullName = OH_Drawing_GetSystemFontFullNameByIndex(fontList, 500); 303 EXPECT_EQ(fullName, nullptr); 304 OH_Drawing_DestroySystemFontFullNames(fontList); 305 306 const OH_Drawing_String* fullName1 = OH_Drawing_GetSystemFontFullNameByIndex(nullptr, 0); 307 EXPECT_EQ(fullName1, nullptr); 308 309 const OH_Drawing_String* fullName2 = OH_Drawing_GetSystemFontFullNameByIndex(nullptr, 500); 310 EXPECT_EQ(fullName2, nullptr); 311 312 OH_Drawing_DestroySystemFontFullNames(nullptr); 313 } 314 315 /* 316 * @tc.name: OH_Drawing_FontDescriptorTest013 317 * @tc.desc: test for obtaining the list of composite fonts that include "ALL". 318 * @tc.type: FUNC 319 */ 320 HWTEST_F(OH_Drawing_FontDescriptorTest, OH_Drawing_FontDescriptorTest013, TestSize.Level1) 321 { 322 OH_Drawing_FontCollection *fc = OH_Drawing_CreateSharedFontCollection(); 323 const char* fontFamily = "HM Symbol Regular"; 324 const char* fontPath = "/system/fonts/HMSymbolVF.ttf"; 325 OH_Drawing_RegisterFont(fc, fontFamily, fontPath); 326 327 OH_Drawing_Array *ttfs = OH_Drawing_GetSystemFontFullNamesByType(ALL); 328 size_t num = OH_Drawing_GetDrawingArraySize(ttfs); 329 EXPECT_EQ(num, 140); 330 FontDescriptorMgrInstance.ClearFontFileCache(); 331 OH_Drawing_DestroyFontCollection(fc); 332 } 333 334 /* 335 * @tc.name: OH_Drawing_FontDescriptorTest014 336 * @tc.desc: test for registering a font once and query it. 337 * @tc.type: FUNC 338 */ 339 HWTEST_F(OH_Drawing_FontDescriptorTest, OH_Drawing_FontDescriptorTest014, TestSize.Level1) 340 { 341 OH_Drawing_FontCollection *fc = OH_Drawing_CreateSharedFontCollection(); 342 const char* fontFamily = "HM Symbol Regular"; 343 const char* fontPath = "/system/fonts/HMSymbolVF.ttf"; 344 OH_Drawing_RegisterFont(fc, fontFamily, fontPath); 345 346 OH_Drawing_Array *ttfs = OH_Drawing_GetSystemFontFullNamesByType(CUSTOMIZED); 347 size_t num = OH_Drawing_GetDrawingArraySize(ttfs); 348 EXPECT_EQ(num, 1); 349 for (size_t i = 0; i < num; i++) { 350 const OH_Drawing_String *fullName = OH_Drawing_GetSystemFontFullNameByIndex(ttfs, i); 351 OH_Drawing_FontDescriptor *fd = OH_Drawing_GetFontDescriptorByFullName(fullName, CUSTOMIZED); 352 ASSERT_STREQ(fd->fullName, "HM Symbol Regular"); 353 } 354 FontDescriptorMgrInstance.ClearFontFileCache(); 355 OH_Drawing_DestroyFontCollection(fc); 356 } 357 358 /* 359 * @tc.name: OH_Drawing_FontDescriptorTest015 360 * @tc.desc: test for registering a font five times and query it. 361 * @tc.type: FUNC 362 */ 363 HWTEST_F(OH_Drawing_FontDescriptorTest, OH_Drawing_FontDescriptorTest015, TestSize.Level1) 364 { 365 OH_Drawing_FontCollection *fc = OH_Drawing_CreateSharedFontCollection(); 366 const char* fontFamily = "HM Symbol Regular"; 367 const char* fontPath = "/system/fonts/HMSymbolVF.ttf"; 368 OH_Drawing_RegisterFont(fc, fontFamily, fontPath); 369 OH_Drawing_RegisterFont(fc, fontFamily, fontPath); 370 OH_Drawing_RegisterFont(fc, fontFamily, fontPath); 371 OH_Drawing_RegisterFont(fc, fontFamily, fontPath); 372 OH_Drawing_RegisterFont(fc, fontFamily, fontPath); 373 374 OH_Drawing_Array *ttfs = OH_Drawing_GetSystemFontFullNamesByType(CUSTOMIZED); 375 size_t num = OH_Drawing_GetDrawingArraySize(ttfs); 376 EXPECT_EQ(num, 1); 377 for (size_t i = 0; i < num; i++) { 378 const OH_Drawing_String *fullName = OH_Drawing_GetSystemFontFullNameByIndex(ttfs, i); 379 OH_Drawing_FontDescriptor *fd = OH_Drawing_GetFontDescriptorByFullName(fullName, CUSTOMIZED); 380 ASSERT_STREQ(fd->fullName, "HM Symbol Regular"); 381 } 382 FontDescriptorMgrInstance.ClearFontFileCache(); 383 OH_Drawing_DestroyFontCollection(fc); 384 } 385 386 /* 387 * @tc.name: OH_Drawing_FontDescriptorTest016 388 * @tc.desc: test for registering a TTC font and query it. 389 * @tc.type: FUNC 390 */ 391 HWTEST_F(OH_Drawing_FontDescriptorTest, OH_Drawing_FontDescriptorTest016, TestSize.Level1) 392 { 393 OH_Drawing_FontCollection *fc = OH_Drawing_CreateSharedFontCollection(); 394 const char* fontFamily = "NotoSansCJKjp-Regular-Alphabetic"; 395 const char* fontPath = "/system/fonts/NotoSansCJK-Regular.ttc"; 396 OH_Drawing_RegisterFont(fc, fontFamily, fontPath); 397 398 OH_Drawing_Array *ttfs = OH_Drawing_GetSystemFontFullNamesByType(CUSTOMIZED); 399 size_t num = OH_Drawing_GetDrawingArraySize(ttfs); 400 EXPECT_EQ(num, 1); 401 for (size_t i = 0; i < num; i++) { 402 const OH_Drawing_String *fullName = OH_Drawing_GetSystemFontFullNameByIndex(ttfs, i); 403 OH_Drawing_FontDescriptor *fd = OH_Drawing_GetFontDescriptorByFullName(fullName, CUSTOMIZED); 404 ASSERT_STREQ(fd->fullName, "Noto Sans CJK JP"); 405 } 406 FontDescriptorMgrInstance.ClearFontFileCache(); 407 OH_Drawing_DestroyFontCollection(fc); 408 } 409 410 /* 411 * @tc.name: OH_Drawing_FontDescriptorTest017 412 * @tc.desc: test for registering a OTF font and query it. 413 * @tc.type: FUNC 414 */ 415 HWTEST_F(OH_Drawing_FontDescriptorTest, OH_Drawing_FontDescriptorTest017, TestSize.Level1) 416 { 417 OH_Drawing_FontCollection *fc = OH_Drawing_CreateSharedFontCollection(); 418 const char* fontFamily = "Birch std"; 419 const char* fontPath = "/system/fonts/Birchstd.otf"; 420 if (!fs::exists(fontPath)) { 421 return; 422 } 423 OH_Drawing_RegisterFont(fc, fontFamily, fontPath); 424 425 OH_Drawing_Array *ttfs = OH_Drawing_GetSystemFontFullNamesByType(CUSTOMIZED); 426 size_t num = OH_Drawing_GetDrawingArraySize(ttfs); 427 EXPECT_EQ(num, 1); 428 for (size_t i = 0; i < num; i++) { 429 const OH_Drawing_String *fullName = OH_Drawing_GetSystemFontFullNameByIndex(ttfs, i); 430 OH_Drawing_FontDescriptor *fd = OH_Drawing_GetFontDescriptorByFullName(fullName, CUSTOMIZED); 431 ASSERT_STREQ(fd->fullName, "Birch std"); 432 } 433 FontDescriptorMgrInstance.ClearFontFileCache(); 434 OH_Drawing_DestroyFontCollection(fc); 435 } 436 437 /* 438 * @tc.name: OH_Drawing_FontDescriptorTest018 439 * @tc.desc: test for registering failed. 440 * @tc.type: FUNC 441 */ 442 HWTEST_F(OH_Drawing_FontDescriptorTest, OH_Drawing_FontDescriptorTest018, TestSize.Level1) 443 { 444 OH_Drawing_FontCollection *fc = OH_Drawing_CreateSharedFontCollection(); 445 const char* fontFamily = "xxxxxxx"; 446 const char* fontPath = "/system/fonts/xxxxxxx.ttf"; 447 OH_Drawing_RegisterFont(fc, fontFamily, fontPath); 448 449 OH_Drawing_Array *ttfs = OH_Drawing_GetSystemFontFullNamesByType(CUSTOMIZED); 450 size_t num = OH_Drawing_GetDrawingArraySize(ttfs); 451 EXPECT_EQ(num, 0); 452 FontDescriptorMgrInstance.ClearFontFileCache(); 453 OH_Drawing_DestroyFontCollection(fc); 454 } 455 456 /* 457 * @tc.name: OH_Drawing_FontDescriptorTest019 458 * @tc.desc: test for registering a font with a local fontCollection. 459 * @tc.type: FUNC 460 */ 461 HWTEST_F(OH_Drawing_FontDescriptorTest, OH_Drawing_FontDescriptorTest019, TestSize.Level1) 462 { 463 OH_Drawing_FontCollection *fc = OH_Drawing_CreateFontCollection(); 464 const char* fontFamily = "HM Symbol Regular"; 465 const char* fontPath = "/system/fonts/HMSymbolVF.ttf"; 466 OH_Drawing_RegisterFont(fc, fontFamily, fontPath); 467 468 OH_Drawing_Array *ttfs = OH_Drawing_GetSystemFontFullNamesByType(CUSTOMIZED); 469 size_t num = OH_Drawing_GetDrawingArraySize(ttfs); 470 EXPECT_EQ(num, 1); 471 for (size_t i = 0; i < num; i++) { 472 const OH_Drawing_String *fullName = OH_Drawing_GetSystemFontFullNameByIndex(ttfs, i); 473 OH_Drawing_FontDescriptor *fd = OH_Drawing_GetFontDescriptorByFullName(fullName, CUSTOMIZED); 474 ASSERT_STREQ(fd->fullName, "HM Symbol Regular"); 475 } 476 477 OH_Drawing_TypographyStyle *typoStyle = OH_Drawing_CreateTypographyStyle(); 478 OH_Drawing_CreateTypographyHandler(typoStyle, fc); 479 OH_Drawing_Array *ttfs1 = OH_Drawing_GetSystemFontFullNamesByType(CUSTOMIZED); 480 size_t num1 = OH_Drawing_GetDrawingArraySize(ttfs1); 481 EXPECT_EQ(num1, 0); 482 FontDescriptorMgrInstance.ClearFontFileCache(); 483 OH_Drawing_DestroyFontCollection(fc); 484 } 485 }