1a3e0fd82Sopenharmony_ci/*
2a3e0fd82Sopenharmony_ci * Copyright (c) 2020-2022 Huawei Device Co., Ltd.
3a3e0fd82Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4a3e0fd82Sopenharmony_ci * you may not use this file except in compliance with the License.
5a3e0fd82Sopenharmony_ci * You may obtain a copy of the License at
6a3e0fd82Sopenharmony_ci *
7a3e0fd82Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8a3e0fd82Sopenharmony_ci *
9a3e0fd82Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10a3e0fd82Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11a3e0fd82Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12a3e0fd82Sopenharmony_ci * See the License for the specific language governing permissions and
13a3e0fd82Sopenharmony_ci * limitations under the License.
14a3e0fd82Sopenharmony_ci */
15a3e0fd82Sopenharmony_ci
16a3e0fd82Sopenharmony_ci#ifndef BASE_FONT
17a3e0fd82Sopenharmony_ci#define BASE_FONT
18a3e0fd82Sopenharmony_ci#include "common/text.h"
19a3e0fd82Sopenharmony_ci#include "font/ui_font_header.h"
20a3e0fd82Sopenharmony_ci#include "font/ui_font_builder.h"
21a3e0fd82Sopenharmony_ci#include "graphic_config.h"
22a3e0fd82Sopenharmony_ci
23a3e0fd82Sopenharmony_cinamespace OHOS {
24a3e0fd82Sopenharmony_ciclass BaseFont : public HeapBase {
25a3e0fd82Sopenharmony_cipublic:
26a3e0fd82Sopenharmony_ci    enum FontType : uint8_t {
27a3e0fd82Sopenharmony_ci        DYNAMIC_FONT = 0,
28a3e0fd82Sopenharmony_ci        STATIC_FONT = 1,
29a3e0fd82Sopenharmony_ci        VECTOR_FONT = 2,
30a3e0fd82Sopenharmony_ci    };
31a3e0fd82Sopenharmony_ci
32a3e0fd82Sopenharmony_ci    BaseFont() : ramAddr_(0), ramLen_(0) {}
33a3e0fd82Sopenharmony_ci    virtual ~BaseFont() {}
34a3e0fd82Sopenharmony_ci
35a3e0fd82Sopenharmony_ci    /**
36a3e0fd82Sopenharmony_ci     * @brief Indicates whether the current font library is a vector font library.
37a3e0fd82Sopenharmony_ci     * @return uint8_t: 0 BitmapFont  1 VectorFont
38a3e0fd82Sopenharmony_ci     */
39a3e0fd82Sopenharmony_ci    virtual bool IsVectorFont() const = 0;
40a3e0fd82Sopenharmony_ci
41a3e0fd82Sopenharmony_ci    /**
42a3e0fd82Sopenharmony_ci     * @brief Get height for specific font
43a3e0fd82Sopenharmony_ci     *
44a3e0fd82Sopenharmony_ci     * @return uint16_t
45a3e0fd82Sopenharmony_ci     */
46a3e0fd82Sopenharmony_ci    virtual uint16_t GetHeight(uint16_t fontId, uint8_t fontSize) = 0;
47a3e0fd82Sopenharmony_ci
48a3e0fd82Sopenharmony_ci    /**
49a3e0fd82Sopenharmony_ci     * @brief Get font id
50a3e0fd82Sopenharmony_ci     *
51a3e0fd82Sopenharmony_ci     * @param ttfName
52a3e0fd82Sopenharmony_ci     * @param size   0: invalid size
53a3e0fd82Sopenharmony_ci     * @return uint8_t
54a3e0fd82Sopenharmony_ci     */
55a3e0fd82Sopenharmony_ci    virtual uint16_t GetFontId(const char* ttfName, uint8_t fontSize) const = 0;
56a3e0fd82Sopenharmony_ci
57a3e0fd82Sopenharmony_ci    /**
58a3e0fd82Sopenharmony_ci     * @brief Get width
59a3e0fd82Sopenharmony_ci     *
60a3e0fd82Sopenharmony_ci     * @param unicode
61a3e0fd82Sopenharmony_ci     * @return int16_t
62a3e0fd82Sopenharmony_ci     */
63a3e0fd82Sopenharmony_ci    virtual int16_t GetWidth(uint32_t unicode, uint16_t fontId, uint8_t fontSize) = 0;
64a3e0fd82Sopenharmony_ci
65a3e0fd82Sopenharmony_ci    virtual int32_t OpenVectorFont(uint8_t ttfId)
66a3e0fd82Sopenharmony_ci    {
67a3e0fd82Sopenharmony_ci        return -1;
68a3e0fd82Sopenharmony_ci    }
69a3e0fd82Sopenharmony_ci
70a3e0fd82Sopenharmony_ci    virtual bool GetTtfInfo(uint8_t ttfId, uint8_t* ttfBuffer, uint32_t bufferSize, TtfHeader& TtfHeader)
71a3e0fd82Sopenharmony_ci    {
72a3e0fd82Sopenharmony_ci        return -1;
73a3e0fd82Sopenharmony_ci    }
74a3e0fd82Sopenharmony_ci
75a3e0fd82Sopenharmony_ci    /**
76a3e0fd82Sopenharmony_ci     * @brief Get bitmap for specific unicode
77a3e0fd82Sopenharmony_ci     *
78a3e0fd82Sopenharmony_ci     * @param unicode
79a3e0fd82Sopenharmony_ci     * @return uint8_t*
80a3e0fd82Sopenharmony_ci     */
81a3e0fd82Sopenharmony_ci    virtual uint8_t* GetBitmap(uint32_t unicode, GlyphNode& glyphNode, uint16_t fontId, uint8_t fontSize) = 0;
82a3e0fd82Sopenharmony_ci
83a3e0fd82Sopenharmony_ci    /**
84a3e0fd82Sopenharmony_ci     * @brief Get font header
85a3e0fd82Sopenharmony_ci     *
86a3e0fd82Sopenharmony_ci     * @param fontHeader
87a3e0fd82Sopenharmony_ci     * @return int8_t
88a3e0fd82Sopenharmony_ci     */
89a3e0fd82Sopenharmony_ci    virtual int8_t GetFontHeader(FontHeader& fontHeader, uint16_t fontId, uint8_t fontSize) = 0;
90a3e0fd82Sopenharmony_ci
91a3e0fd82Sopenharmony_ci    /**
92a3e0fd82Sopenharmony_ci     * @brief Get the glyph node
93a3e0fd82Sopenharmony_ci     *
94a3e0fd82Sopenharmony_ci     * @param unicode
95a3e0fd82Sopenharmony_ci     * @param glyphNode
96a3e0fd82Sopenharmony_ci     * @param isGlyph
97a3e0fd82Sopenharmony_ci     * @return int8_t
98a3e0fd82Sopenharmony_ci     */
99a3e0fd82Sopenharmony_ci    virtual int8_t GetGlyphNode(uint32_t unicode, GlyphNode& glyphNode, uint16_t fontId, uint8_t fontSize) = 0;
100a3e0fd82Sopenharmony_ci    virtual uint8_t GetFontWeight(uint16_t fontId) = 0;
101a3e0fd82Sopenharmony_ci
102a3e0fd82Sopenharmony_ci    virtual int8_t SetCurrentLangId(uint8_t langId)
103a3e0fd82Sopenharmony_ci    {
104a3e0fd82Sopenharmony_ci        return 0;
105a3e0fd82Sopenharmony_ci    }
106a3e0fd82Sopenharmony_ci
107a3e0fd82Sopenharmony_ci    virtual uint8_t GetCurrentLangId() const
108a3e0fd82Sopenharmony_ci    {
109a3e0fd82Sopenharmony_ci        return UIFontBuilder::GetInstance()->GetTotalLangId();
110a3e0fd82Sopenharmony_ci    }
111a3e0fd82Sopenharmony_ci
112a3e0fd82Sopenharmony_ci    int8_t GetDefaultParamByLangId(uint8_t langId, LangTextParam** pParam) const;
113a3e0fd82Sopenharmony_ci
114a3e0fd82Sopenharmony_ci    /**
115a3e0fd82Sopenharmony_ci     * @brief Get the Font Shaping Property
116a3e0fd82Sopenharmony_ci     * @param text [in] the content
117a3e0fd82Sopenharmony_ci     * @param ttfId [out] the ttf id
118a3e0fd82Sopenharmony_ci     * @param fontId [in] the font id
119a3e0fd82Sopenharmony_ci     * @param size [in] the font size
120a3e0fd82Sopenharmony_ci     * @return uint8_t: needShaping property
121a3e0fd82Sopenharmony_ci     */
122a3e0fd82Sopenharmony_ci    virtual uint16_t GetShapingFontId(char* text, uint8_t& ttfId, uint32_t& script, uint16_t fontId, uint8_t size) const
123a3e0fd82Sopenharmony_ci    {
124a3e0fd82Sopenharmony_ci        return 0;
125a3e0fd82Sopenharmony_ci    }
126a3e0fd82Sopenharmony_ci
127a3e0fd82Sopenharmony_ci    /**
128a3e0fd82Sopenharmony_ci     * @brief Set the Font Path
129a3e0fd82Sopenharmony_ci     *
130a3e0fd82Sopenharmony_ci     * @param path
131a3e0fd82Sopenharmony_ci     * @param type
132a3e0fd82Sopenharmony_ci     * @return int8_t
133a3e0fd82Sopenharmony_ci     */
134a3e0fd82Sopenharmony_ci    virtual int8_t SetFontPath(const char* path, FontType type) = 0;
135a3e0fd82Sopenharmony_ci
136a3e0fd82Sopenharmony_ci    virtual int8_t GetFontVersion(FontType type, const char* path, char* version, uint8_t len)
137a3e0fd82Sopenharmony_ci    {
138a3e0fd82Sopenharmony_ci        return INVALID_RET_VALUE;
139a3e0fd82Sopenharmony_ci    }
140a3e0fd82Sopenharmony_ci
141a3e0fd82Sopenharmony_ci    /**
142a3e0fd82Sopenharmony_ci     * @brief Get the text in utf-8 format
143a3e0fd82Sopenharmony_ci     *
144a3e0fd82Sopenharmony_ci     * @param textId
145a3e0fd82Sopenharmony_ci     * @param utf8Addr
146a3e0fd82Sopenharmony_ci     * @param utf8Len
147a3e0fd82Sopenharmony_ci     * @return int8_t
148a3e0fd82Sopenharmony_ci     */
149a3e0fd82Sopenharmony_ci    virtual int8_t GetTextUtf8(uint16_t textId, uint8_t** utf8Addr, uint16_t& utf8Len) const
150a3e0fd82Sopenharmony_ci    {
151a3e0fd82Sopenharmony_ci        return 0;
152a3e0fd82Sopenharmony_ci    }
153a3e0fd82Sopenharmony_ci
154a3e0fd82Sopenharmony_ci    /**
155a3e0fd82Sopenharmony_ci     * @brief Get the ttfId
156a3e0fd82Sopenharmony_ci     * @param fontId [in] the font id
157a3e0fd82Sopenharmony_ci     * @param size [in] the font size
158a3e0fd82Sopenharmony_ci     * @return uint8_t: ttfId property
159a3e0fd82Sopenharmony_ci     */
160a3e0fd82Sopenharmony_ci    virtual uint8_t GetFontTtfId(uint16_t fontId, uint8_t size) const
161a3e0fd82Sopenharmony_ci    {
162a3e0fd82Sopenharmony_ci        return 0;
163a3e0fd82Sopenharmony_ci    }
164a3e0fd82Sopenharmony_ci
165a3e0fd82Sopenharmony_ci    virtual const UITextLanguageFontParam* GetFontInfo(uint16_t fontId) const
166a3e0fd82Sopenharmony_ci    {
167a3e0fd82Sopenharmony_ci        return nullptr;
168a3e0fd82Sopenharmony_ci    }
169a3e0fd82Sopenharmony_ci
170a3e0fd82Sopenharmony_ci    virtual uint8_t RegisterFontInfo(const char* ttfName, uint8_t shaping)
171a3e0fd82Sopenharmony_ci    {
172a3e0fd82Sopenharmony_ci        return 0;
173a3e0fd82Sopenharmony_ci    }
174a3e0fd82Sopenharmony_ci
175a3e0fd82Sopenharmony_ci    virtual uint8_t RegisterFontInfo(const UITextLanguageFontParam* fontsTable, uint8_t num)
176a3e0fd82Sopenharmony_ci    {
177a3e0fd82Sopenharmony_ci        return 0;
178a3e0fd82Sopenharmony_ci    }
179a3e0fd82Sopenharmony_ci
180a3e0fd82Sopenharmony_ci    virtual uint8_t RegisterTtcFontInfo(const char* ttcName, const TtfInfo* ttfInfo, uint8_t count)
181a3e0fd82Sopenharmony_ci    {
182a3e0fd82Sopenharmony_ci        return 0;
183a3e0fd82Sopenharmony_ci    }
184a3e0fd82Sopenharmony_ci
185a3e0fd82Sopenharmony_ci    virtual uint8_t UnregisterTtcFontInfo(const char* ttcName, const TtfInfo* ttfInfo, uint8_t count)
186a3e0fd82Sopenharmony_ci    {
187a3e0fd82Sopenharmony_ci        return 0;
188a3e0fd82Sopenharmony_ci    }
189a3e0fd82Sopenharmony_ci
190a3e0fd82Sopenharmony_ci    virtual uint8_t UnregisterFontInfo(const char* ttfName)
191a3e0fd82Sopenharmony_ci    {
192a3e0fd82Sopenharmony_ci        return 0;
193a3e0fd82Sopenharmony_ci    }
194a3e0fd82Sopenharmony_ci
195a3e0fd82Sopenharmony_ci    virtual uint8_t UnregisterFontInfo(const UITextLanguageFontParam* fontsTable, uint8_t num)
196a3e0fd82Sopenharmony_ci    {
197a3e0fd82Sopenharmony_ci        return 0;
198a3e0fd82Sopenharmony_ci    }
199a3e0fd82Sopenharmony_ci
200a3e0fd82Sopenharmony_ci    virtual int8_t GetWildCardStaticStr(uint16_t textId,
201a3e0fd82Sopenharmony_ci                                        UITextWildcardStaticType type,
202a3e0fd82Sopenharmony_ci                                        uint8_t** strAddr,
203a3e0fd82Sopenharmony_ci                                        uint16_t& strLen) const
204a3e0fd82Sopenharmony_ci    {
205a3e0fd82Sopenharmony_ci        return 0;
206a3e0fd82Sopenharmony_ci    }
207a3e0fd82Sopenharmony_ci
208a3e0fd82Sopenharmony_ci    virtual int8_t GetCodePoints(uint16_t textId, uint32_t** codePoints, uint16_t& codePointsNum) const
209a3e0fd82Sopenharmony_ci    {
210a3e0fd82Sopenharmony_ci        return 0;
211a3e0fd82Sopenharmony_ci    }
212a3e0fd82Sopenharmony_ci
213a3e0fd82Sopenharmony_ci    virtual int8_t GetTextParam(uint16_t textId, UITextLanguageTextParam& param) const
214a3e0fd82Sopenharmony_ci    {
215a3e0fd82Sopenharmony_ci        return 0;
216a3e0fd82Sopenharmony_ci    }
217a3e0fd82Sopenharmony_ci
218a3e0fd82Sopenharmony_ci    virtual void SetFontFileOffset(uint32_t offset) {}
219a3e0fd82Sopenharmony_ci
220a3e0fd82Sopenharmony_ci    void SetRamAddr(uintptr_t ramAddr);
221a3e0fd82Sopenharmony_ci    uintptr_t GetRamAddr();
222a3e0fd82Sopenharmony_ci    uint32_t GetRamLen();
223a3e0fd82Sopenharmony_ci    void SetRamLen(uint32_t ramLen);
224a3e0fd82Sopenharmony_ci    virtual void SetPsramMemory(uintptr_t psramAddr, uint32_t psramLen);
225a3e0fd82Sopenharmony_ci
226a3e0fd82Sopenharmony_ci    virtual uint16_t GetOffsetPosY(const char* text, uint16_t lineLength, bool& isEmoijLarge,
227a3e0fd82Sopenharmony_ci                                   uint16_t fontId, uint8_t fontSize) = 0;
228a3e0fd82Sopenharmony_ci    virtual uint16_t GetLineMaxHeight(const char* text, uint16_t lineLength, uint16_t fontId, uint8_t fontSize,
229a3e0fd82Sopenharmony_ci                                      uint16_t& letterIndex, SpannableString* spannableString) = 0;
230a3e0fd82Sopenharmony_ci    virtual bool IsEmojiFont(uint16_t fontId) = 0;
231a3e0fd82Sopenharmony_ci
232a3e0fd82Sopenharmony_ciprivate:
233a3e0fd82Sopenharmony_ci    uintptr_t ramAddr_;
234a3e0fd82Sopenharmony_ci    uint32_t ramLen_;
235a3e0fd82Sopenharmony_ci};
236a3e0fd82Sopenharmony_ci} // namespace OHOS
237a3e0fd82Sopenharmony_ci#endif /* UI_BASE_FONT_H */
238