diff options
Diffstat (limited to 'include/font.h')
| -rw-r--r-- | include/font.h | 36 |
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 |
