You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ugui/text_rendering/font.h

51 lines
1.2 KiB

1 year ago
#ifndef _FONT_H
#define _FONT_H
1 year ago
#include <stdint.h>
1 year ago
/* width and height of a glyph contain the kering advance
* (u,v)
* +-------------*---+ -
* | ^ | | ^
* | |oy | | |
* | v | | |
* | .ii. | | |
* | @@@@@@. |<->| |
* | V@Mio@@o |adv| |
* | :i. V@V | | |
* | :oM@@M | | |
* | :@@@MM@M | | |
* | @@o o@M | | |
* |<->:@@. M@M | | |
* |ox @@@o@@@@ | | |
* | :M@@V:@@.| | v
* +-------------*---+ -
1 year ago
* |<------------->|
* w
*/
// TODO: the advance isn't unique for every pair of characters
1 year ago
struct font_glyph {
1 year ago
uint32_t codepoint;
uint32_t u, v;
uint16_t w, h, a, x, y;
1 year ago
};
1 year ago
struct font_atlas {
unsigned int width, height;
1 year ago
unsigned char *atlas;
unsigned int glyph_max_w, glyph_max_h;
int size;
1 year ago
int file_size;
char *file;
void *priv;
};
1 year ago
1 year ago
struct font_atlas * font_init(void);
int font_load(struct font_atlas *atlas, const char *path, int size);
1 year ago
int font_free(struct font_atlas *atlas);
1 year ago
const struct font_glyph * font_get_glyph_texture(struct font_atlas *atlas, unsigned int code, int *updated);
1 year ago
void font_dump(const struct font_atlas *atlas, const char *path);
1 year ago
#endif