• 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 
16 #ifndef UI_FONT_VECTOR_H
17 #define UI_FONT_VECTOR_H
18 #include "font/base_font.h"
19 #include "graphic_config.h"
20 #include "ft2build.h"
21 #include "freetype/freetype.h"
22 #include "font/ui_font_cache.h"
23 #include <memory>
24 
25 namespace OHOS {
26 class UIFontVector : public BaseFont {
27 public:
28     UIFontVector();
29 
30     ~UIFontVector();
31     UIFontVector(const UIFontVector&) = delete;
32     UIFontVector& operator=(const UIFontVector&) noexcept = delete;
33     bool IsVectorFont() const override;
34     int8_t SetFontPath(const char* dpath, const char* spath) override;
35     int8_t SetCurrentFontId(uint8_t fontId, uint8_t size = 0) override;
36     uint16_t GetHeight() override;
37     uint8_t GetFontId(const char* ttfName, uint8_t size = 0) const override;
38     int16_t GetWidth(uint32_t unicode, uint8_t fontId) override;
39     uint8_t* GetBitmap(uint32_t unicode, GlyphNode& glyphNode, uint8_t fontId) override;
40     int8_t GetCurrentFontHeader(FontHeader& fontHeader) override;
41     int8_t GetGlyphNode(uint32_t unicode, GlyphNode& glyphNode) override;
42     uint8_t GetFontWeight(uint8_t fontId) override;
43     uint8_t GetShapingFontId(char* text, uint8_t& ttfId, uint32_t& script,
44         uint8_t fontId, uint8_t size)  const override;
45     uint8_t RegisterFontInfo(const char* ttfName, uint8_t shaping = 0) override;
46     uint8_t RegisterFontInfo(const UITextLanguageFontParam* fontsTable, uint8_t num) override;
47     uint8_t UnregisterFontInfo(const char* ttfName) override;
48     uint8_t UnregisterFontInfo(const UITextLanguageFontParam* fontsTable, uint8_t num) override;
49     const UITextLanguageFontParam* GetFontInfo(uint8_t fontId) const override;
50     int32_t OpenVectorFont(uint8_t ttfId) override;
51 
52 private:
53     static constexpr uint8_t FONT_ID_MAX = 0xFF;
54     static constexpr uint8_t FONT_INVALID_TTF_ID = 0xFF;
55     static constexpr uint8_t TTF_NAME_LEN_MAX = 128;
56     static constexpr uint8_t FONT_BPP_8 = 8;
57     UITextLanguageFontParam fontInfo_[FONT_ID_MAX] = {{0}};
58     std::string ttfDir_;
59     FT_Library ftLibrary_;
60     FT_Face ftFaces_[FONT_ID_MAX] = {0};
61     bool freeTypeInited_;
62     uint32_t key_ = 0;
63     UIFontCache* bitmapCache_;
64     struct Metric {
65         int left;
66         int top;
67         int cols;
68         int rows;
69         int advance;
70         uint8_t buf[0];
71     };
72     void SetFace(FT_Face ftface, uint32_t unicode) const;
73     uint8_t GetFontId(uint32_t unicode) const;
74     uint32_t GetKey(uint8_t fontId, uint32_t size);
75     int8_t LoadGlyphIntoFace(uint8_t fontId, uint32_t unicode);
76     uint8_t IsGlyphFont(uint32_t unicode);
77 };
78 } // namespace OHOS
79 #endif
80 
81