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