diff options
| author | Gabriel Schneider <[email protected]> | 2026-07-02 20:06:25 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-08-01 15:02:07 -0300 |
| commit | bead9f0b78380d1428f40fdab339c1c8f88fa626 (patch) | |
| tree | 960255de5a2cef661ec5d0ad3220a4b2b1738842 /vendor/stb/font.h | |
| parent | 62ef1882ab7878210f05f06504796849e412c318 (diff) | |
| download | pardes-bead9f0b78380d1428f40fdab339c1c8f88fa626.tar.gz pardes-bead9f0b78380d1428f40fdab339c1c8f88fa626.zip | |
sdl ui backend
Diffstat (limited to 'vendor/stb/font.h')
| -rw-r--r-- | vendor/stb/font.h | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/vendor/stb/font.h b/vendor/stb/font.h new file mode 100644 index 00000000..93bbac8d --- /dev/null +++ b/vendor/stb/font.h @@ -0,0 +1,41 @@ +// Tiny C shim over stb_truetype, so ui_sdl.zig can @cInclude a small header +// instead of feeding the whole single-header lib to translate-c. The +// implementation (font.c) pulls in stb_truetype.h (declarations only — +// stb_truetype_impl.c defines STB_TRUETYPE_IMPLEMENTATION once elsewhere). +// +// A "font" is an opaque handle owning a stbtt_fontinfo; all rasterization goes +// through these functions so the Zig side never touches stb internals. +#ifndef UI_FONT_H +#define UI_FONT_H +#include <stdint.h> + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct UIFont UIFont; + +// Parse the embedded TTF. `data` must stay alive for the lifetime of the font. +// Returns NULL on failure. +UIFont *ui_font_new(const uint8_t *data, int32_t len); + +// Font metrics at a given pixel height. cell_w is the monospace advance (rounded +// up); ascent is the baseline offset from the top of a cell. +float ui_font_scale_for_height(UIFont *f, float px); +void ui_font_cell_metrics(UIFont *f, float scale, int32_t *cell_w, int32_t *cell_h, int32_t *ascent); + +// Rasterize `cp` into `out` (a cell_w*cell_h single-channel mask, row-major, +// `stride` bytes per row). The glyph is positioned for a monospace cell: origin +// at the baseline `ascent` pixels from the top. Pixels outside the glyph are 0. +// Returns 1 if the glyph produced any coverage (0 for an empty/missing glyph, +// but `out` is still zeroed). +int ui_font_raster(UIFont *f, float scale, int32_t cp, + uint8_t *out, int32_t stride, int32_t cell_w, int32_t cell_h, + int32_t ascent); + +void ui_font_free(UIFont *f); + +#ifdef __cplusplus +} +#endif +#endif |
