• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2020-2021 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 #ifndef UI_FONT_H
16 #define UI_FONT_H
17 #include "font/base_font.h"
18 
19 namespace OHOS {
20 class UIFont : public HeapBase {
21 public:
22     UIFont(const UIFont &) = delete;
23     UIFont& operator=(const UIFont &) = delete;
24 
25     /**
26      * @brief judge whether you need shaping for text
27      *
28      * @param text means input text
29      * @param ttfId font index
30      * @param script shaping script
31      * @param fontId font index
32      * @param size font size
33      * @return int8_t Shaping mode
34      */
GetShapingFontId(char * text,uint8_t & ttfId,uint32_t & script,uint8_t fontId,uint8_t size)35     uint8_t GetShapingFontId(char* text, uint8_t& ttfId, uint32_t& script, uint8_t fontId, uint8_t size) const
36     {
37         return instance_->GetShapingFontId(text, ttfId, script, fontId, size);
38     }
39 
40     /**
41      * @brief Set font id
42      *
43      * @param fontId
44      * @param size
45      * @return int8_t
46      */
47     int8_t SetCurrentFontId(uint8_t fontId, uint8_t size = 0)
48     {
49         return instance_->SetCurrentFontId(fontId, size);
50     }
51 
52     /**
53      * @brief Get width of the letter
54      *
55      * @param unicode: [in] unicode or glyph index according to isGlyph param
56      * @param shapingId: [in]
57      * @return uint16_t: the letter width
58      */
59     uint16_t GetWidth(uint32_t unicode, uint8_t shapingId);
60 
61     /**
62      * @brief Get height for specific font
63      *
64      * @return uint16_t
65      */
GetHeight()66     uint16_t GetHeight()
67     {
68         return instance_->GetHeight();
69     }
70 
71     /**
72      * @brief Get the font weight
73      * @param fontId
74      * @return uint8_t: fontWeight
75      */
GetFontWeight(uint8_t fontId)76     uint8_t GetFontWeight(uint8_t fontId)
77     {
78         return instance_->GetFontWeight(fontId);
79     }
80 
81     /**
82      * @brief Get font header
83      *
84      * @param fontHeader
85      * @return int8_t
86      */
GetCurrentFontHeader(FontHeader & fontHeader)87     int8_t GetCurrentFontHeader(FontHeader& fontHeader)
88     {
89         return instance_->GetCurrentFontHeader(fontHeader);
90     }
91 
92     /**
93      * @brief Get font id
94      *
95      * @param name
96      * @param size
97      * @return uint8_t
98      */
99     uint8_t GetFontId(const char* name, uint8_t size = 0)
100     {
101         return instance_->GetFontId(name, size);
102     }
103 
104     /**
105      * @brief Set the cache start address
106      *
107      * @param psramAddr
108      * @param psramLen
109      */
SetPsramMemory(uintptr_t psramAddr,uint32_t psramLen)110     void SetPsramMemory(uintptr_t psramAddr, uint32_t psramLen)
111     {
112         instance_->SetPsramMemory(psramAddr, psramLen);
113     }
114 
115     /**
116      * @brief Get bitmap for specific unicode
117      *
118      * @param unicode
119      * @return uint8_t*
120      */
121     uint8_t* GetBitmap(uint32_t unicode, GlyphNode& glyphNode, uint8_t shapingFont);
122 
123     /**
124      * @brief Indicates whether the current font library is a vector font library.
125      * @return uint8_t: 0 BitmapFont  1 VectorFont
126      */
IsVectorFont()127     bool IsVectorFont()
128     {
129         return instance_->IsVectorFont();
130     }
131 
132     /**
133      * @brief Get current font id
134      *
135      * @return uint8_t
136      */
GetCurrentFontId()137     uint8_t GetCurrentFontId()
138     {
139         return instance_->GetBaseFontId();
140     }
141 
SetCurrentLangId(uint8_t langId)142     int8_t SetCurrentLangId(uint8_t langId)
143     {
144         return instance_->SetCurrentLangId(langId);
145     }
146 
GetCurrentLangId()147     uint8_t GetCurrentLangId() const
148     {
149         return instance_->GetCurrentLangId();
150     }
151 
GetDefaultParamByLangId(uint8_t langId,LangTextParam ** pParam)152     int8_t GetDefaultParamByLangId(uint8_t langId, LangTextParam** pParam) const
153     {
154         return instance_->GetDefaultParamByLangId(langId, pParam);
155     }
156 
GetTextUtf8(uint16_t textId,uint8_t ** utf8Addr,uint16_t & utf8Len)157     int8_t GetTextUtf8(uint16_t textId, uint8_t** utf8Addr, uint16_t& utf8Len) const
158     {
159         return instance_->GetTextUtf8(textId, utf8Addr, utf8Len);
160     }
161 
GetFontTtfId(uint8_t fontId,uint8_t size)162     uint8_t GetFontTtfId(uint8_t fontId, uint8_t size) const
163     {
164         return instance_->GetFontTtfId(fontId, size);
165     }
166 
OpenVectorFont(uint8_t ttfId)167     int32_t OpenVectorFont(uint8_t ttfId)
168     {
169         return instance_->OpenVectorFont(ttfId);
170     }
171 
GetFontInfo(uint8_t fontId)172     const UITextLanguageFontParam* GetFontInfo(uint8_t fontId) const
173     {
174         return instance_->GetFontInfo(fontId);
175     }
176 
SetFontPath(const char * dpath,const char * spath)177     int8_t SetFontPath(const char* dpath, const char* spath)
178     {
179         return instance_->SetFontPath(dpath, spath);
180     }
181 
GetFontVersion(char * dVersion,uint8_t dLen,char * sVersion,uint8_t sLen)182     int8_t GetFontVersion(char* dVersion, uint8_t dLen, char* sVersion, uint8_t sLen) const
183     {
184         return instance_->GetFontVersion(dVersion, dLen, sVersion, sLen);
185     }
186 
187     uint8_t RegisterFontInfo(const char* ttfName, uint8_t shaping = 0)
188     {
189         return instance_->RegisterFontInfo(ttfName, shaping);
190     }
191 
RegisterFontInfo(const UITextLanguageFontParam * fontsTable,uint8_t num)192     uint8_t RegisterFontInfo(const UITextLanguageFontParam* fontsTable, uint8_t num)
193     {
194         return instance_->RegisterFontInfo(fontsTable, num);
195     }
196 
UnregisterFontInfo(const char * ttfName)197     uint8_t UnregisterFontInfo(const char* ttfName)
198     {
199         return instance_->UnregisterFontInfo(ttfName);
200     }
201 
UnregisterFontInfo(const UITextLanguageFontParam * fontsTable,uint8_t num)202     uint8_t UnregisterFontInfo(const UITextLanguageFontParam* fontsTable, uint8_t num)
203     {
204         return instance_->UnregisterFontInfo(fontsTable, num);
205     }
206 
GetTextParam(uint16_t textId,UITextLanguageTextParam & param)207     int8_t GetTextParam(uint16_t textId, UITextLanguageTextParam& param) const
208     {
209         return instance_->GetTextParam(textId, param);
210     }
211 
GetWildCardStaticStr(uint16_t textId,UITextWildcardStaticType type,uint8_t ** strAddr,uint16_t & strLen)212     int8_t GetWildCardStaticStr(uint16_t textId, UITextWildcardStaticType type,
213         uint8_t** strAddr, uint16_t& strLen) const
214     {
215         return instance_->GetWildCardStaticStr(textId, type, strAddr, strLen);
216     }
217 
GetCodePoints(uint16_t textId,uint32_t ** codePoints,uint16_t & codePointsNum)218     int8_t GetCodePoints(uint16_t textId, uint32_t** codePoints, uint16_t& codePointsNum) const
219     {
220         return instance_->GetCodePoints(textId, codePoints, codePointsNum);
221     }
222 
223     static UIFont* GetInstance();
224     void SetFont(BaseFont* font);
225 
SetFontFileOffset(uint32_t offset)226     void SetFontFileOffset(uint32_t offset)
227     {
228         instance_->SetFontFileOffset(offset);
229     }
230 
231 private:
232     UIFont();
233     /**
234      * @brief Destroy the UIFontFactor object
235      *
236      */
237     ~UIFont();
238 
239     BaseFont* instance_;
240     BaseFont* defaultInstance_;
241     static bool setFontAllocFlag_;
242 };
243 } // namespace OHOS
244 #endif
245