1 /*
2 * Copyright (c) 2023 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 #include "texgine_font_manager.h"
17
18 #include <mutex>
19 #include "texgine_font_style_set.h"
20
21 namespace OHOS {
22 namespace Rosen {
23 namespace TextEngine {
TexgineFontManager()24 TexgineFontManager::TexgineFontManager()
25 {
26 fontMgr_ = SkFontMgr::RefDefault();
27 }
28
RefDefault()29 std::shared_ptr<TexgineFontManager> TexgineFontManager::RefDefault()
30 {
31 auto manager = std::make_shared<TexgineFontManager>();
32 manager->SetFontMgr(SkFontMgr::RefDefault());
33 return manager;
34 }
35
GetFontMgr() const36 sk_sp<SkFontMgr> TexgineFontManager::GetFontMgr() const
37 {
38 return fontMgr_;
39 }
40
SetFontMgr(const sk_sp<SkFontMgr> mgr)41 void TexgineFontManager::SetFontMgr(const sk_sp<SkFontMgr> mgr)
42 {
43 fontMgr_ = mgr;
44 }
45
MatchFamilyStyleCharacter(const std::string & familyName,const TexgineFontStyle & style,const char * bcp47[],int bcp47Count,int32_t character)46 std::shared_ptr<TexgineTypeface> TexgineFontManager::MatchFamilyStyleCharacter(const std::string &familyName,
47 const TexgineFontStyle &style, const char* bcp47[], int bcp47Count, int32_t character)
48 {
49 if (fontMgr_ == nullptr || style.GetFontStyle() == nullptr) {
50 return nullptr;
51 }
52
53 auto tf = fontMgr_->matchFamilyStyleCharacter(familyName.c_str(),
54 *style.GetFontStyle(), bcp47, bcp47Count, character);
55 return std::make_shared<TexgineTypeface>(tf);
56 }
57
MatchFamily(const std::string & familyName)58 std::shared_ptr<TexgineFontStyleSet> TexgineFontManager::MatchFamily(const std::string &familyName)
59 {
60 if (fontMgr_ == nullptr) {
61 return nullptr;
62 }
63
64 auto set = fontMgr_->matchFamily(familyName.c_str());
65 return std::make_shared<TexgineFontStyleSet>(set);
66 }
67 } // namespace TextEngine
68 } // namespace Rosen
69 } // namespace OHOS
70