From 4b5e793f48f6e721c39ab6ddcf755604df73b643 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Sun, 9 Aug 2026 20:31:09 -0300 Subject: Better text rendering --- src/gui/font.h | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 src/gui/font.h (limited to 'src/gui/font.h') diff --git a/src/gui/font.h b/src/gui/font.h new file mode 100644 index 00000000..050fbeb0 --- /dev/null +++ b/src/gui/font.h @@ -0,0 +1,41 @@ +// Tiny C shim over FreeType, so gui.zig only imports the stable renderer API. +// The implementation owns FreeType's library and face objects and keeps the +// caller's font bytes borrowed for the face lifetime. +#ifndef UI_FONT_H +#define UI_FONT_H +#include + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct UIFont UIFont; + +// Parse the first face in an in-memory font. `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); + +// Whether the selected Unicode charmap maps `cp` to a real glyph. Glyph zero is +// the face's .notdef box and deliberately does not count for fallback choice. +int ui_font_has_glyph(UIFont *f, int32_t cp); + +// The size token is a pixel height. Metrics and rasterization both configure +// FreeType at that size, so hinted advances, baseline and bitmaps stay in step. +float ui_font_scale_for_height(UIFont *f, float px); +void ui_font_cell_metrics(UIFont *f, float px, int32_t *cell_w, int32_t *cell_h, + int32_t *ascent); + +// Rasterize `cp` into `out` as a hinted grayscale cell mask (`stride` bytes per +// row). The origin is the baseline `ascent` pixels from the top. Pixels outside +// the glyph are zero. Missing codepoints render the face's .notdef glyph. +// Returns 1 when the glyph produced coverage, 0 for blank/error. +int ui_font_raster(UIFont *f, float px, 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 -- cgit v1.3