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
37
38
39
40
41
42
43
44
45
46
|
// Tiny C shim over FreeType, so gui.zig only imports the stable renderer API.
// The implementation owns FreeType's library and face objects and keeps the
// caller's font bytes borrowed for the face lifetime.
#ifndef UI_FONT_H
#define UI_FONT_H
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef struct UIFont UIFont;
// Parse the first face in an in-memory font. `data` must stay alive for the
// lifetime of the font. Returns NULL on failure.
UIFont *ui_font_new(const uint8_t *data, int32_t len);
// The face FreeType actually accepted. Prefer its PostScript name (the same
// identity the macOS shell reports); fall back to the family name when the
// font has no PostScript table. Borrowed for the UIFont lifetime.
const char *ui_font_name(UIFont *f);
// Whether the selected Unicode charmap maps `cp` to a real glyph. Glyph zero is
// the face's .notdef box and deliberately does not count for fallback choice.
int ui_font_has_glyph(UIFont *f, int32_t cp);
// The size token is a pixel height. Metrics and rasterization both configure
// FreeType at that size, so hinted advances, baseline and bitmaps stay in step.
float ui_font_scale_for_height(UIFont *f, float px);
void ui_font_cell_metrics(UIFont *f, float px, int32_t *cell_w, int32_t *cell_h,
int32_t *ascent);
// Rasterize `cp` into `out` as a hinted grayscale cell mask (`stride` bytes per
// row). The origin is the baseline `ascent` pixels from the top. Pixels outside
// the glyph are zero. Missing codepoints render the face's .notdef glyph.
// Returns 1 when the glyph produced coverage, 0 for blank/error.
int ui_font_raster(UIFont *f, float px, int32_t cp, uint8_t *out,
int32_t stride, int32_t cell_w, int32_t cell_h,
int32_t ascent);
void ui_font_free(UIFont *f);
#ifdef __cplusplus
}
#endif
#endif
|