载入中...
搜索中...
未找到
Font.h
浏览该文件的文档.
1#pragma once
2
3#include <cstdint>
4#include <string>
5#include <unordered_map>
6
7namespace eve::font {
8class FontData;
9}
10
11namespace eve::graphics {
12
13class Graphics;
14class Texture;
15
21uint32_t nextCodepointUtf8(const std::string &text, size_t &i);
22
32class Font {
33public:
35 static std::string defaultCharset();
36
37 Font(Graphics *gfx, font::FontData *data, std::string charset = defaultCharset());
39
40 Font(const Font &) = delete;
41 Font &operator=(const Font &) = delete;
42
43 font::FontData *getData() const { return data; }
44 Texture *getTexture() const { return atlas; }
45
47 float getHeight() const;
48 float getAscent() const;
50 float getBaseline() const;
51
53 float getWidth(const std::string &text) const;
54
56 bool hasGlyph(int codepoint) const;
57
58 struct Glyph {
59 float u0 = 0.f, v0 = 0.f, u1 = 0.f, v1 = 0.f; // atlas UV rect (empty if width/height == 0)
60 int width = 0, height = 0; // glyph bitmap size, px
61 int bearingX = 0, bearingY = 0;
62 int advance = 0;
63 };
64
66 const Glyph *findGlyph(int codepoint) const;
67
68private:
69 void buildAtlas(const std::string &charset);
70
71 font::FontData *data = nullptr;
72 Texture *atlas = nullptr;
73 std::unordered_map<int, Glyph> glyphs;
74};
75
76} // namespace eve::graphics
Light2D::Data * data
CPU-side decoded font face (FreeType FT_Face + owned font bytes). Does not upload to GPU — rasterize ...
Definition FontData.h:23
GPU-side font: wraps a decoded font::FontData and rasterizes a fixed set of codepoints into a single ...
Definition Font.h:32
float getAscent() const
Definition Font.cpp:173
static std::string defaultCharset()
Printable ASCII (0x20..0x7E), used when no explicit charset is given.
Definition Font.cpp:58
bool hasGlyph(int codepoint) const
Whether codepoint was rasterized into this Font's atlas.
Definition Font.cpp:178
font::FontData * getData() const
Definition Font.h:43
Texture * getTexture() const
Definition Font.h:44
float getBaseline() const
Distance from the top of a line to the baseline (== getAscent()).
Definition Font.cpp:174
Font(const Font &)=delete
const Glyph * findGlyph(int codepoint) const
Returns nullptr if codepoint isn't in this Font's atlas.
Definition Font.cpp:180
float getHeight() const
Line height in pixels at the FontData's decoded pixel size.
Definition Font.cpp:172
float getWidth(const std::string &text) const
Pixel width of text (UTF-8), including kerning; delegates to FontData.
Definition Font.cpp:176
Font & operator=(const Font &)=delete
GPU texture created via Graphics::newTexture. Owns GPU resources through an opaque backend handle.
Definition Texture.h:17
卡牌游戏 UI 工具模块:工厂 + 脚本绑定入口。 功能参考 ycarowr/UiCard:扇形手牌布局、抽牌/洗牌、悬浮放大、拖拽到落牌区、 敌方手牌(背面/偷看)、费用不足置灰,以及可实时调节的布局...
Definition AnimTrail.h:6
uint32_t nextCodepointUtf8(const std::string &text, size_t &i)
Decodes one UTF-8 codepoint from text starting at byte offset i, advancing i past it....
Definition Font.cpp:17