natiny_font_get_glyph
C
bool natiny_font_get_glyph(NatinyFont font, uint32_t codepoint,
NatinyGlyph* glyph);
Gets one glyph's metrics and its rectangle in the atlas, for drawing it by hand.
Parameters
| Name |
Type |
Description |
font |
NatinyFont |
Font handle from natiny_font_create |
codepoint |
uint32_t |
Unicode code point |
glyph |
NatinyGlyph* |
Receives metrics and atlas coordinates; must not be NULL and is untouched on failure |
Returns
| Type |
Description |
bool |
true when glyph was filled; false if the font or output pointer is invalid, or the glyph cannot be resolved or packed into the atlas |
NatinyGlyph fields
| Field |
Type |
Description |
advance |
float |
Pen advance in drawing units |
x |
float |
Glyph left edge relative to the pen, in drawing units |
y |
float |
Glyph top edge relative to the baseline, in drawing units |
width |
float |
Glyph width in drawing units |
height |
float |
Glyph height in drawing units |
u0 |
float |
Normalized atlas left edge |
v0 |
float |
Normalized atlas top edge |
u1 |
float |
Normalized atlas right edge |
v1 |
float |
Normalized atlas bottom edge |
atlas |
NatinyTexture |
Texture handle containing the glyph, including a fallback font's atlas |
Example
C
NatinyGlyph glyph;
if (natiny_font_get_glyph(font, 0x41, &glyph)) {
float baseline = line_y + natiny_font_get_ascent(font);
float left = pen + glyph.x;
float top = baseline + glyph.y;
/* glyph.u0, glyph.v0, glyph.u1, and glyph.v1 select the region in glyph.atlas. */
pen += glyph.advance + natiny_font_get_letter_spacing(font);
}
Notes
- The call bakes an uncached glyph. Atlas coordinates remain valid until the
atlas is re-baked at another display scale.