• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 Huawei Device Co., Ltd.. All rights reserved.
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 #include "txt/platform.h"
17 
18 #include <mutex>
19 
20 namespace OHOS {
21 namespace Rosen {
22 namespace SPText {
DefaultFamilyNameMgr()23 DefaultFamilyNameMgr::DefaultFamilyNameMgr()
24 {
25 #ifdef TEXT_SYSTEM_OHOS
26     defaultFamilies_ = { "HarmonyOS-Sans" };
27 #else
28     defaultFamilies_ = { "sans-serif", "PingFang SC" };
29 #endif
30 }
31 
GetInstance()32 DefaultFamilyNameMgr& DefaultFamilyNameMgr::GetInstance()
33 {
34     static DefaultFamilyNameMgr instance;
35     return instance;
36 }
37 
GetDefaultFontFamilies() const38 std::vector<std::string> DefaultFamilyNameMgr::GetDefaultFontFamilies() const
39 {
40     std::shared_lock<std::shared_mutex> readLock(lock_);
41     std::vector<std::string> res(themeFamilies_);
42     res.insert(res.end(), defaultFamilies_.begin(), defaultFamilies_.end());
43     return res;
44 }
45 
GetThemeFontFamilies() const46 std::vector<std::string> DefaultFamilyNameMgr::GetThemeFontFamilies() const
47 {
48     std::shared_lock<std::shared_mutex> readLock(lock_);
49     return themeFamilies_;
50 }
51 
ModifyThemeFontFamilies(size_t index)52 void DefaultFamilyNameMgr::ModifyThemeFontFamilies(size_t index)
53 {
54     std::unique_lock<std::shared_mutex> writeLock(lock_);
55     themeFamilies_.clear();
56     for (size_t i = 0; i < index; i += 1) {
57         themeFamilies_.emplace_back(GenerateThemeFamilyName(i));
58     }
59 }
60 
GenerateThemeFamilyName(size_t index)61 std::string DefaultFamilyNameMgr::GenerateThemeFamilyName(size_t index)
62 {
63     if (index == 0) {
64         return OHOS_THEME_FONT;
65     }
66     std::string res { OHOS_THEME_FONT };
67     res.push_back('0' + index);
68     return res;
69 }
70 
GetDefaultFontManager()71 std::shared_ptr<Drawing::FontMgr> GetDefaultFontManager()
72 {
73     return Drawing::FontMgr::CreateDefaultFontMgr();
74 }
75 
IsThemeFontFamily(std::string familyName)76 bool DefaultFamilyNameMgr::IsThemeFontFamily(std::string familyName)
77 {
78     std::transform(familyName.begin(), familyName.end(), familyName.begin(), ::tolower);
79     return familyName.find(OHOS_THEME_FONT_LOW) == 0;
80 }
81 } // namespace SPText
82 } // namespace Rosen
83 } // namespace OHOS
84