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 
17 #include "font_descriptor_mgr.h"
18 
19 #include "utils/text_log.h"
20 
21 namespace OHOS::Rosen {
GetInstance()22 FontDescriptorMgr& FontDescriptorMgr::GetInstance()
23 {
24     static FontDescriptorMgr instance;
25     return instance;
26 }
27 
FontDescriptorMgr()28 FontDescriptorMgr::FontDescriptorMgr()
29 {
30     ParseAllFontSource();
31 }
32 
~FontDescriptorMgr()33 FontDescriptorMgr::~FontDescriptorMgr() {}
34 
ParseAllFontSource()35 void FontDescriptorMgr::ParseAllFontSource()
36 {
37     std::unique_lock<std::mutex> guard(parserMtx_);
38     descCache_.ParserSystemFonts();
39     descCache_.ParserStylishFonts();
40 }
41 
ClearFontFileCache()42 void FontDescriptorMgr::ClearFontFileCache()
43 {
44     std::unique_lock<std::mutex> guard(parserMtx_);
45     descCache_.ClearFontFileCache();
46 }
47 
GetFontDescSharedPtrByFullName(const std::string & fullName,const int32_t & systemFontType,FontDescSharedPtr & result)48 void FontDescriptorMgr::GetFontDescSharedPtrByFullName(const std::string& fullName,
49     const int32_t& systemFontType, FontDescSharedPtr& result)
50 {
51     std::unique_lock<std::mutex> guard(parserMtx_);
52     descCache_.GetFontDescSharedPtrByFullName(fullName, systemFontType, result);
53 }
54 
GetSystemFontFullNamesByType(const int32_t & systemFontType,std::unordered_set<std::string> & fontList)55 void FontDescriptorMgr::GetSystemFontFullNamesByType(
56     const int32_t &systemFontType, std::unordered_set<std::string> &fontList)
57 {
58     std::unique_lock<std::mutex> guard(parserMtx_);
59     descCache_.GetSystemFontFullNamesByType(systemFontType, fontList);
60 }
61 } // namespace OHOS::Rosen
62