50 lines
1.2 KiB
C
Raw Normal View History

2023-02-12 09:34:44 +01:00
#ifndef _FONT_H
#define _FONT_H
/* width and height of a glyph contain the kering advance
* (u,v)
2023-02-21 22:05:28 +01:00
* +-------------*---+ -
* | ^ | | ^
* | |oy | | |
* | v | | |
* | .ii. | | |
* | @@@@@@. |<->| |
* | V@Mio@@o |adv| |
* | :i. V@V | | |
* | :oM@@M | | |
* | :@@@MM@M | | |
* | @@o o@M | | |
* |<->:@@. M@M | | |
* |ox @@@o@@@@ | | |
* | :M@@V:@@.| | v
* +-------------*---+ -
2023-02-12 09:34:44 +01:00
* |<------------->|
* w
*/
2023-02-21 22:05:28 +01:00
// TODO: the advance isn't unique for every pair of characters
2023-02-12 09:34:44 +01:00
struct font_glyph {
unsigned int codepoint;
2023-03-08 18:10:28 +01:00
unsigned int u, v;
unsigned short int w, h, a, x, y;
2023-02-12 09:34:44 +01:00
};
2023-02-19 23:40:58 +01:00
struct font_atlas {
2023-02-21 22:05:28 +01:00
unsigned int width, height;
2023-02-19 23:40:58 +01:00
unsigned char *atlas;
2023-02-21 22:05:28 +01:00
unsigned int glyph_max_w, glyph_max_h;
int size;
2023-02-19 23:40:58 +01:00
int file_size;
char *file;
void *priv;
};
2023-02-12 09:34:44 +01:00
2023-02-15 02:15:44 +01:00
struct font_atlas * font_init(void);
2023-02-21 22:05:28 +01:00
int font_load(struct font_atlas *atlas, const char *path, int size);
2023-02-13 23:42:44 +01:00
int font_free(struct font_atlas *atlas);
2023-02-19 23:40:58 +01:00
const struct font_glyph * font_get_glyph_texture(struct font_atlas *atlas, unsigned int code, int *updated);
2023-02-15 02:15:44 +01:00
void font_dump(const struct font_atlas *atlas, const char *path);
2023-02-12 09:34:44 +01:00
#endif