• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef FONT_MGR_H
17 #define FONT_MGR_H
18 
19 #include <memory>
20 #include <cstdint>
21 
22 #include "impl_interface/font_mgr_impl.h"
23 #include "text/font_style.h"
24 #include "text/font_style_set.h"
25 #include "text/typeface.h"
26 
27 namespace OHOS {
28 namespace Rosen {
29 namespace Drawing {
30 class DRAWING_API FontMgr {
31 public:
32     explicit FontMgr(std::shared_ptr<FontMgrImpl> fontMgrImpl) noexcept;
33     virtual ~FontMgr() = default;
34 
35     /*
36      * @brief   Create a default fontMgr.
37      * @return  A shared pointer to default fontMgr.
38      */
39     static std::shared_ptr<FontMgr> CreateDefaultFontMgr();
40 
41 #ifndef USE_TEXGINE
42     /*
43      * @brief   Create a dynamic fontMgr.
44      * @return  A shared pointer to dynamic fontMgr.
45      */
46     static std::shared_ptr<FontMgr> CreateDynamicFontMgr();
47 
48     /*
49      * @brief             Load dynamic font typeface.
50      * @param familyName  Font family name.
51      * @param data        Font data.
52      * @param dataLength  The size of font data.
53      */
54     void LoadDynamicFont(const std::string& familyName, const uint8_t* data, size_t dataLength);
55 
56     /*
57      * @brief             Load theme font typeface.
58      * @param familyName  Font family name.
59      * @param themeName   Theme name.
60      * @param data        Font data.
61      * @param dataLength  The size of font data.
62      */
63     void LoadThemeFont(const std::string& familyName, const std::string& themeName,
64         const uint8_t* data, size_t dataLength);
65 #endif
66 
67     /*
68      * @brief             Use the system fallback to find a typeface for the given character.
69      * @param familyName  A const char array of familyName.
70      * @param fontStyle   FontStyle.
71      * @param bcp47       Is a combination of ISO 639, 15924, and 3166-1 codes.
72      * @param bcp47Count  Length of bcp47.
73      * @param character   The given character.
74      * @return            If find, return typeface. else, return nullptr.
75      */
76     Typeface* MatchFamilyStyleCharacter(const char familyName[], const FontStyle& fontStyle,
77                                         const char* bcp47[], int bcp47Count,
78                                         int32_t character) const;
79 
80     /*
81      * @brief             Find a fontStyleSet for the given familyName.
82      * @param familyName  A const char array of familyName.
83      * @return            If find, return fontStyleSet. else, return nullptr.
84      */
85     FontStyleSet* MatchFamily(const char familyName[]) const;
86 
87     template<typename T>
GetImpl()88     T* GetImpl() const
89     {
90         return fontMgrImpl_->DowncastingTo<T>();
91     }
92 
93     /* @brief             Find the corresponding font based on the style and font name
94      * @param familyName  The name of the font you want to apply
95      * @param fontStyle   The font style you want to achieve
96      * @return            Returns the corresponding font
97      */
98     Typeface* MatchFamilyStyle(const char familyName[], const FontStyle& fontStyle) const;
99 
100 private:
101     std::shared_ptr<FontMgrImpl> fontMgrImpl_;
102 };
103 } // namespace Drawing
104 } // namespace Rosen
105 } // namespace OHOS
106 #endif