summaryrefslogtreecommitdiff
path: root/src/gui/font.h
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-08-09 20:31:09 -0300
committerGabriel Schneider <[email protected]>2026-08-10 09:17:07 -0300
commit4b5e793f48f6e721c39ab6ddcf755604df73b643 (patch)
treef3cf8b009bbfbd5667635381f0f624cd6b466084 /src/gui/font.h
parent9085cb5bfdd0b78ff3a62c0c71fc231dd7b5052a (diff)
downloadpardes-4b5e793f48f6e721c39ab6ddcf755604df73b643.tar.gz
pardes-4b5e793f48f6e721c39ab6ddcf755604df73b643.zip
Better text rendering
Diffstat (limited to 'src/gui/font.h')
-rw-r--r--src/gui/font.h41
1 files changed, 41 insertions, 0 deletions
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 <stdint.h>
+
+#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