• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
ClearFontFileCache()30 void FontDescriptorMgr::ClearFontFileCache()
31 {
32     std::unique_lock<std::mutex> guard(parserMtx_);
33     descCache_.ClearFontFileCache();
34 }
35 
MatchFontDescriptors(FontDescSharedPtr desc,std::set<FontDescSharedPtr> & descs)36 void FontDescriptorMgr::MatchFontDescriptors(FontDescSharedPtr desc, std::set<FontDescSharedPtr>& descs)
37 {
38     std::unique_lock<std::mutex> guard(parserMtx_);
39     descCache_.MatchFromFontDescriptor(desc, descs);
40 }
41 
GetFontDescSharedPtrByFullName(const std::string & fullName,const int32_t & systemFontType,FontDescSharedPtr & result)42 void FontDescriptorMgr::GetFontDescSharedPtrByFullName(const std::string& fullName,
43     const int32_t& systemFontType, FontDescSharedPtr& result)
44 {
45     std::unique_lock<std::mutex> guard(parserMtx_);
46     descCache_.GetFontDescSharedPtrByFullName(fullName, systemFontType, result);
47 }
48 
GetSystemFontFullNamesByType(const int32_t & systemFontType,std::unordered_set<std::string> & fontList)49 void FontDescriptorMgr::GetSystemFontFullNamesByType(
50     const int32_t &systemFontType, std::unordered_set<std::string> &fontList)
51 {
52     std::unique_lock<std::mutex> guard(parserMtx_);
53     descCache_.GetSystemFontFullNamesByType(systemFontType, fontList);
54 }
55 
CacheDynamicTypeface(std::shared_ptr<Drawing::Typeface> typeface,const std::string & familyName)56 void FontDescriptorMgr::CacheDynamicTypeface(std::shared_ptr<Drawing::Typeface> typeface, const std::string &familyName)
57 {
58     if (typeface == nullptr) {
59         return;
60     }
61     std::unique_lock<std::mutex> guard(parserMtx_);
62     descCache_.CacheDynamicTypeface(typeface, familyName);
63 }
64 
DeleteDynamicTypefaceFromCache(const std::string & familyName)65 void FontDescriptorMgr::DeleteDynamicTypefaceFromCache(const std::string &familyName)
66 {
67     std::unique_lock<std::mutex> guard(parserMtx_);
68     descCache_.DeleteDynamicTypefaceFromCache(familyName);
69 }
70 } // namespace OHOS::Rosen
71