blob: a1c3d54c011d6895a7111abe38a947fbff372568 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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
|