aboutsummaryrefslogtreecommitdiff
path: root/include/font.h
diff options
context:
space:
mode:
authorDavid Moc <personal@cdatgoose.org>2026-05-30 21:53:05 +0200
committerDavid Moc <personal@cdatgoose.org>2026-05-30 21:53:05 +0200
commite930cc6bdc7f62befac063d7d9d016ffb0a64f1a (patch)
tree52118a1e990ae88f5f0410c8caea129609e22e19 /include/font.h
Added the old repo, refactored it, added the C jit.
Diffstat (limited to 'include/font.h')
-rw-r--r--include/font.h36
1 files changed, 36 insertions, 0 deletions
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 <GLFW/glfw3.h>
+#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