From e930cc6bdc7f62befac063d7d9d016ffb0a64f1a Mon Sep 17 00:00:00 2001 From: David Moc Date: Sat, 30 May 2026 21:53:05 +0200 Subject: Added the old repo, refactored it, added the C jit. --- include/font.h | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 include/font.h (limited to 'include/font.h') diff --git a/include/font.h b/include/font.h new file mode 100644 index 0000000..a1c3d54 --- /dev/null +++ b/include/font.h @@ -0,0 +1,36 @@ +#ifndef ECEX_FONT_H +#define ECEX_FONT_H + +#include +#include "stb_truetype.h" + +#define ECEX_FONT_BITMAP_W 512 +#define ECEX_FONT_BITMAP_H 512 +#define ECEX_FONT_FIRST_CHAR 32 +#define ECEX_FONT_CHAR_COUNT 96 + +typedef struct font { + GLuint texture; + stbtt_bakedchar chars[ECEX_FONT_CHAR_COUNT]; + + float size_px; + + /* + * draw_text() takes y as a baseline. These metrics let render.c place + * baselines, highlights, bars, and cursors from the same font-scaled + * coordinate system instead of fixed pixel constants. + */ + float ascent_px; + float descent_px; + float line_gap_px; + float line_height; +} font_t; + +const char *font_choose_path(const char *explicit_font_path); +int font_load(font_t *font, const char *path, float size_px); +void font_free(font_t *font); + +void draw_text(font_t *font, float x, float y, const char *text); +float text_width(font_t *font, const char *text); + +#endif -- cgit v1.2.3