!17197 增加能使用主题字的fontCollection接口

Merge pull request !17197 from liumingxiang/fontmgr_add_family_name_limit
This commit is contained in:
openharmony_ci 2024-11-19 09:04:47 +00:00 committed by Gitee
commit 3caafae586
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
4 changed files with 40 additions and 0 deletions

View File

@ -103,6 +103,16 @@ void OH_Drawing_DisableFontCollectionSystemFont(OH_Drawing_FontCollection*);
* @version 1.0
*/
void OH_Drawing_ClearFontCaches(OH_Drawing_FontCollection*);
/**
* @brief Get the <b>OH_Drawing_FontCollection</b> global instance.
*
* @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
* @return Return the pointer to the <b>OH_Drawing_FontCollection</b> global instance.
* @since 14
* @version 1.0
*/
OH_Drawing_FontCollection* OH_Drawing_GetFontCollectionGlobalInstance(void);
#ifdef __cplusplus
}
#endif

View File

@ -127,3 +127,13 @@ void OH_Drawing_ClearFontCaches(OH_Drawing_FontCollection* fontCollection)
}
return;
}
OH_Drawing_FontCollection* OH_Drawing_GetFontCollectionGlobalInstance(void)
{
std::shared_ptr<OHOS::Rosen::FontCollection> fc = OHOS::Rosen::FontCollection::Create();
OH_Drawing_FontCollection* pointer = reinterpret_cast<OH_Drawing_FontCollection*>(fc.get());
if (!FontCollectionMgr::GetInstance().Find(pointer)) {
FontCollectionMgr::GetInstance().Insert(pointer, fc);
}
return pointer;
}

View File

@ -615,6 +615,24 @@ void OHDrawingCreateSharedFontCollectionTest(const uint8_t* data, size_t size)
OH_Drawing_ClearFontCaches(nullptr);
OH_Drawing_DestroyFontCollection(fontCollection);
}
void OHDrawingCreateFontCollectionGlobalInstanceTest(const uint8_t* data, size_t size)
{
if (data == nullptr) {
return;
}
// initialize
g_data = data;
g_size = size;
g_pos = 0;
// initialize
OH_Drawing_FontCollection* fontCollection = OH_Drawing_GetFontCollectionGlobalInstance();
OH_Drawing_DisableFontCollectionFallback(fontCollection);
OH_Drawing_DisableFontCollectionSystemFont(fontCollection);
OH_Drawing_ClearFontCaches(fontCollection);
OH_Drawing_ClearFontCaches(nullptr);
}
} // namespace OHOS::Rosen::Drawing
/* Fuzzer entry point */

View File

@ -34,8 +34,10 @@ HWTEST_F(OH_Drawing_FontCollectionTest, OH_Drawing_FontCollectionTest001, TestSi
{
OH_Drawing_FontCollection* fontCollection = OH_Drawing_CreateFontCollection();
OH_Drawing_FontCollection* fontCollection2 = OH_Drawing_CreateSharedFontCollection();
OH_Drawing_FontCollection* fontCollection3 = OH_Drawing_GetFontCollectionGlobalInstance();
EXPECT_NE(fontCollection, nullptr);
EXPECT_NE(fontCollection2, nullptr);
EXPECT_NE(fontCollection3, nullptr);
OH_Drawing_DisableFontCollectionFallback(fontCollection);
OH_Drawing_DisableFontCollectionFallback(nullptr);
OH_Drawing_DisableFontCollectionSystemFont(fontCollection);