natiny_font_get_glyph
C
bool natiny_font_get_glyph(NatinyFont font, uint32_t codepoint,
NatinyGlyph* glyph);
Fills in 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 for an invalid handle or output pointer, or when the atlas is full |
NatinyGlyph fields
| Field |
Type |
Description |
advance |
float |
Pen advance in drawing units |
x, y |
float |
Glyph offset from the pen and baseline in drawing units |
width, height |
float |
Glyph image size in drawing units |
u0, v0, u1, v1 |
float |
Normalized rectangle in atlas |
atlas |
NatinyTexture |
Atlas containing the glyph, including a fallback font's atlas |
Example
C
NatinyGlyph glyph;
if (natiny_font_get_glyph(font, 0x41, &glyph)) {
float baseline = 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 atlas region. */
pen += glyph.advance + natiny_font_get_letter_spacing(font);
}
Notes
y is measured from the baseline and is normally negative - the picture
sits above it. natiny_font_get_ascent turns a
top-of-line coordinate into a baseline.
advance includes neither kerning nor the font's letter spacing. Add the
current letter spacing explicitly; text placed this way remains unkerned.
- The call bakes an uncached glyph. Atlas coordinates remain valid until the
atlas is re-baked at another display scale.
- Follows the fallback chain, and
glyph.atlas says which font's atlas the
glyph actually came from.
- A missing code point returns the primary font's missing-glyph symbol and is
not itself a failure.