• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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 FACE_DATA_H
17 #define FACE_DATA_H
18 
19 #include <ft2build.h>
20 #include <memory>
21 #include <shared_mutex>
22 #include FT_FREETYPE_H
23 #include <freetype/ftglyph.h>
24 
25 #include <base/containers/vector.h>
26 #include <font/namespace.h>
27 
28 #include "font_defs.h"
29 
30 FONT_BEGIN_NAMESPACE()
31 class FontData;
32 class FontManager;
33 class FontBuffer;
34 
35 class FaceData final : public std::enable_shared_from_this<FaceData> {
36 public:
37     FaceData(std::shared_ptr<FontBuffer> buf, FT_Face ftFace);
38     ~FaceData();
39     FontManager& GetFontManager() const;
40     FontData* CreateFontData(float sizeInPt, uint16_t xDpi, uint16_t yDpi, bool sdf);
41 
42     int UpdateGlyph(bool sdf, FT_Size ftSize, uint32_t glyphIndex, FontDefs::Glyph& glyph);
43 
44     uint32_t GetGlyphIndex(uint32_t utfCode);
45 
46 private:
47     friend class FontBuffer;
48     friend class FontData;
49     friend class Font;
50 
51     std::shared_ptr<FontBuffer> fontBuffer_; // contains the data from font file
52 
53     std::shared_mutex mutex_;
54     FT_Face face_; // face data
55     struct Data {
56         int64_t pixelSize;
57         std::unique_ptr<FontData> fontData;
58     };
59     BASE_NS::vector<Data> datas_;
60 };
61 FONT_END_NAMESPACE()
62 
63 #endif // FACE_DATA_H
64