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 "text/font_mgr.h"
17
18 #include "impl_factory.h"
19 #include "impl_interface/font_mgr_impl.h"
20
21 namespace OHOS {
22 namespace Rosen {
23 namespace Drawing {
FontMgr(std::shared_ptr<FontMgrImpl> fontMgrImpl)24 FontMgr::FontMgr(std::shared_ptr<FontMgrImpl> fontMgrImpl) noexcept : fontMgrImpl_(fontMgrImpl) {}
25
CreateDefaultFontMgr()26 std::shared_ptr<FontMgr> FontMgr::CreateDefaultFontMgr()
27 {
28 return std::make_shared<FontMgr>(ImplFactory::CreateDefaultFontMgrImpl());
29 }
30
31 #ifndef USE_TEXGINE
CreateDynamicFontMgr()32 std::shared_ptr<FontMgr> FontMgr::CreateDynamicFontMgr()
33 {
34 return std::make_shared<FontMgr>(ImplFactory::CreateDynamicFontMgrImpl());
35 }
36
LoadDynamicFont(const std::string & familyName,const uint8_t * data,size_t dataLength)37 Typeface* FontMgr::LoadDynamicFont(const std::string& familyName, const uint8_t* data, size_t dataLength)
38 {
39 if (fontMgrImpl_) {
40 return fontMgrImpl_->LoadDynamicFont(familyName, data, dataLength);
41 }
42 return nullptr;
43 }
44
LoadThemeFont(const std::string & familyName,const std::string & themeName,const uint8_t * data,size_t dataLength)45 Typeface* FontMgr::LoadThemeFont(const std::string& familyName, const std::string& themeName,
46 const uint8_t* data, size_t dataLength)
47 {
48 if (fontMgrImpl_) {
49 return fontMgrImpl_->LoadThemeFont(familyName, themeName, data, dataLength);
50 }
51 return nullptr;
52 }
53
LoadThemeFont(const std::string & themeName,std::shared_ptr<Typeface> typeface)54 void FontMgr::LoadThemeFont(const std::string& themeName, std::shared_ptr<Typeface> typeface)
55 {
56 if (fontMgrImpl_) {
57 fontMgrImpl_->LoadThemeFont(themeName, typeface);
58 }
59 return;
60 }
61 #endif
62
MatchFamilyStyleCharacter(const char familyName[],const FontStyle & fontStyle,const char * bcp47[],int bcp47Count,int32_t character) const63 Typeface* FontMgr::MatchFamilyStyleCharacter(const char familyName[], const FontStyle& fontStyle,
64 const char* bcp47[], int bcp47Count,
65 int32_t character) const
66 {
67 if (fontMgrImpl_) {
68 return fontMgrImpl_->MatchFamilyStyleCharacter(familyName, fontStyle, bcp47, bcp47Count, character);
69 }
70 return nullptr;
71 }
72
MatchFamily(const char familyName[]) const73 FontStyleSet* FontMgr::MatchFamily(const char familyName[]) const
74 {
75 if (fontMgrImpl_) {
76 return fontMgrImpl_->MatchFamily(familyName);
77 }
78 return nullptr;
79 }
80
MatchFamilyStyle(const char familyName[],const FontStyle & fontStyle) const81 Typeface* FontMgr::MatchFamilyStyle(const char familyName[], const FontStyle& fontStyle) const
82 {
83 if (fontMgrImpl_) {
84 return fontMgrImpl_->MatchFamilyStyle(familyName, fontStyle);
85 }
86 return nullptr;
87 }
88
CountFamilies() const89 int FontMgr::CountFamilies() const
90 {
91 if (fontMgrImpl_ == nullptr) {
92 return 0;
93 }
94 return fontMgrImpl_->CountFamilies();
95 }
96
GetFamilyName(int index,std::string & str) const97 void FontMgr::GetFamilyName(int index, std::string& str) const
98 {
99 if (fontMgrImpl_ == nullptr) {
100 return;
101 }
102 fontMgrImpl_->GetFamilyName(index, str);
103 }
104
CreateStyleSet(int index) const105 FontStyleSet* FontMgr::CreateStyleSet(int index) const
106 {
107 if (fontMgrImpl_ == nullptr) {
108 return nullptr;
109 }
110 return fontMgrImpl_->CreateStyleSet(index);
111 }
112
GetFontFullName(int fontFd,std::vector<FontByteArray> & fullnameVec)113 int FontMgr::GetFontFullName(int fontFd, std::vector<FontByteArray>& fullnameVec)
114 {
115 if (fontMgrImpl_ == nullptr) {
116 return ERROR_TYPE_OTHER;
117 }
118 return fontMgrImpl_->GetFontFullName(fontFd, fullnameVec);
119 };
120
ParseInstallFontConfig(const std::string & configPath,std::vector<std::string> & fontPathVec)121 int FontMgr::ParseInstallFontConfig(const std::string& configPath, std::vector<std::string>& fontPathVec)
122 {
123 if (fontMgrImpl_ == nullptr) {
124 return ERROR_TYPE_OTHER;
125 }
126 return fontMgrImpl_->ParseInstallFontConfig(configPath, fontPathVec);
127 }
128 } // namespace Drawing
129 } // namespace Rosen
130 } // namespace OHOS
131