载入中...
搜索中...
未找到
FontData.h
浏览该文件的文档.
1#pragma once
2
3#include "common/Resource.h"
4
5#include <cstdint>
6#include <string>
7#include <vector>
8
9struct FT_FaceRec_;
10typedef struct FT_FaceRec_ *FT_Face;
11
12namespace eve {
13namespace image {
14class ImageData;
15}
16
17namespace font {
18
23class FontData : public Resource {
24public:
26 FontData(std::vector<uint8_t> bytes, int pixelSize, std::string uri = "");
27 ~FontData() override;
28
30 int getSize() const;
31 float getAscent() const;
32 float getDescent() const;
33 float getLineHeight() const;
34 float getBaseline() const;
35
37 std::string getFamilyName() const;
38 std::string getStyleName() const;
39 int getGlyphCount() const;
40
42 bool hasGlyph(int codepoint) const;
43 bool hasGlyphs(std::string text) const;
44 float getWidth(std::string text) const;
45 float getKerning(int leftCodepoint, int rightCodepoint) const;
46
48 void adopt(eve::Resource &replacement) override;
49
51 int getGlyphWidth(int codepoint) const;
52 int getGlyphHeight(int codepoint) const;
53 int getGlyphBearingX(int codepoint) const;
54 int getGlyphBearingY(int codepoint) const;
55 int getGlyphAdvance(int codepoint) const;
56
61 image::ImageData *newGlyphImageData(int codepoint);
62
63private:
64 struct GlyphCache {
65 int width = 0;
66 int height = 0;
67 int bearingX = 0;
68 int bearingY = 0;
69 int advance = 0;
70 bool loaded = false;
71 bool empty = true;
72 };
73
74 const GlyphCache &ensureGlyph(int codepoint) const;
75 unsigned int glyphIndex(int codepoint) const;
76
77 std::vector<uint8_t> bytes;
78 FT_Face face = nullptr;
79 int pixelSize = 16;
80 mutable std::vector<GlyphCache> glyphCache; // indexed by glyph index
81};
82
83} // namespace font
84} // namespace eve
struct FT_FaceRec_ * FT_Face
Definition FontData.h:10
float height
Definition Grass.cpp:235
int width
std::string image
Resource is a game object that is managed by the ResourceManager. It can be loaded from a file or gen...
Definition Resource.h:35
std::string uri
Definition Resource.h:62
CPU-side decoded font face (FreeType FT_Face + owned font bytes). Does not upload to GPU — rasterize ...
Definition FontData.h:23
float getWidth(std::string text) const
Definition FontData.cpp:212
int getGlyphHeight(int codepoint) const
Definition FontData.cpp:230
int getGlyphAdvance(int codepoint) const
Definition FontData.cpp:233
float getBaseline() const
Definition FontData.cpp:125
std::string getFamilyName() const
字体元信息。
Definition FontData.cpp:127
bool hasGlyphs(std::string text) const
Definition FontData.cpp:155
int getGlyphBearingX(int codepoint) const
Definition FontData.cpp:231
image::ImageData * newGlyphImageData(int codepoint)
Rasterize one glyph to RGBA8 ImageData (RGB white, A from FreeType gray). Returns a 0x0 ImageData if ...
Definition FontData.cpp:235
int getGlyphBearingY(int codepoint) const
Definition FontData.cpp:232
void adopt(eve::Resource &replacement) override
Replace this face with replacement's (cache reload).
Definition FontData.cpp:96
float getKerning(int leftCodepoint, int rightCodepoint) const
Definition FontData.cpp:167
float getAscent() const
Definition FontData.cpp:106
int getSize() const
字号 / 度量信息。
Definition FontData.cpp:104
int getGlyphCount() const
Definition FontData.cpp:139
std::string getStyleName() const
Definition FontData.cpp:133
float getLineHeight() const
Definition FontData.cpp:119
float getDescent() const
Definition FontData.cpp:112
~FontData() override
Definition FontData.cpp:89
bool hasGlyph(int codepoint) const
字形 / 文本测量。
Definition FontData.cpp:151
int getGlyphWidth(int codepoint) const
单字形度量(像素)。
Definition FontData.cpp:229
Represents raw pixel data.
Definition ImageData.h:26
Definition Build.cpp:11