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 <mutex>
20
21 #include "utils/text_log.h"
22
23 namespace OHOS::Rosen {
GetInstance()24 FontDescriptorMgr& FontDescriptorMgr::GetInstance()
25 {
26 static FontDescriptorMgr instance;
27 return instance;
28 }
29
~FontDescriptorMgr()30 FontDescriptorMgr::~FontDescriptorMgr() {}
31
ClearFontFileCache()32 void FontDescriptorMgr::ClearFontFileCache()
33 {
34 std::unique_lock guard(parserMtx_);
35 descCache_.ClearFontFileCache();
36 }
37
MatchFontDescriptors(FontDescSharedPtr desc,std::set<FontDescSharedPtr> & descs)38 void FontDescriptorMgr::MatchFontDescriptors(FontDescSharedPtr desc, std::set<FontDescSharedPtr>& descs)
39 {
40 std::unique_lock guard(parserMtx_);
41 descCache_.MatchFromFontDescriptor(desc, descs);
42 }
43
GetFontDescSharedPtrByFullName(const std::string & fullName,const int32_t & systemFontType,FontDescSharedPtr & result)44 void FontDescriptorMgr::GetFontDescSharedPtrByFullName(const std::string& fullName,
45 const int32_t& systemFontType, FontDescSharedPtr& result)
46 {
47 std::shared_lock guard(parserMtx_);
48 descCache_.GetFontDescSharedPtrByFullName(fullName, systemFontType, result);
49 }
50
GetSystemFontFullNamesByType(const int32_t & systemFontType,std::unordered_set<std::string> & fontList)51 void FontDescriptorMgr::GetSystemFontFullNamesByType(
52 const int32_t &systemFontType, std::unordered_set<std::string> &fontList)
53 {
54 std::unique_lock guard(parserMtx_);
55 descCache_.GetSystemFontFullNamesByType(systemFontType, fontList);
56 }
57
CacheDynamicTypeface(std::shared_ptr<Drawing::Typeface> typeface,const std::string & familyName)58 void FontDescriptorMgr::CacheDynamicTypeface(std::shared_ptr<Drawing::Typeface> typeface, const std::string &familyName)
59 {
60 if (typeface == nullptr) {
61 return;
62 }
63 std::unique_lock guard(parserMtx_);
64 descCache_.CacheDynamicTypeface(typeface, familyName);
65 }
66
DeleteDynamicTypefaceFromCache(const std::string & familyName)67 void FontDescriptorMgr::DeleteDynamicTypefaceFromCache(const std::string &familyName)
68 {
69 std::unique_lock guard(parserMtx_);
70 descCache_.DeleteDynamicTypefaceFromCache(familyName);
71 }
72 } // namespace OHOS::Rosen
73