aienux
Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately.
Brought by drakestapleton
aienux / native / kernel / ui / allen_font.h
| 1 | /* allen_font.h -- Allen's typeface: every printable ASCII character drawn as |
| 2 | * round-capped pen strokes (lines and elliptical arcs) on a design grid, and |
| 3 | * rasterized on demand into anti-aliased alpha masks at any size. Integer math |
| 4 | * only (the kernel builds -mgeneral-regs-only); no font files, no outside |
| 5 | * data. Pure: no MMIO, host tested in ui/tests/allen_ui_test.c. |
| 6 | * |
| 7 | * Design grid: cap height and ascenders at y=0, lowercase x-height at y=8, |
| 8 | * baseline at y=20, descenders to y=27; x grows right, y grows down. */ |
| 9 | #ifndef AIENOS_ALLEN_FONT_H |
| 10 | #define AIENOS_ALLEN_FONT_H |
| 11 | #include <stddef.h> |
| 12 | #include <stdint.h> |
| 13 | |
| 14 | #define CK_AF_FIRST 32 |
| 15 | #define CK_AF_LAST 126 |
| 16 | #define CK_AF_COUNT (CK_AF_LAST - CK_AF_FIRST + 1) |
| 17 | |
| 18 | typedef struct { |
| 19 | uint8_t *alpha; /* w*h coverage, 0..255; NULL when not rasterized yet */ |
| 20 | uint16_t w, h; |
| 21 | int16_t ox, oy; /* mask top-left relative to the pen on the baseline, px */ |
| 22 | } ck_af_glyph; |
| 23 | |
| 24 | typedef struct { |
| 25 | uint32_t s256; /* 1/256 px per design unit */ |
| 26 | uint32_t hw256; /* half the stroke width, 1/256 px */ |
| 27 | uint8_t *pool; /* mask storage, filled as glyphs are first used */ |
| 28 | size_t pool_len, pool_used; |
| 29 | ck_af_glyph g[CK_AF_COUNT]; |
| 30 | } ck_af_face; |
| 31 | |
| 32 | /* cap_px: cap height in pixels; weight: half the stroke width in |
| 33 | * thousandths of a design unit (1250 = regular). pool holds the masks. */ |
| 34 | void ck_af_face_init(ck_af_face *f, unsigned cap_px, unsigned weight, uint8_t *pool, size_t pool_len); |
| 35 | /* The mask for c (anything outside 32..126 draws as '?'); NULL only when the |
| 36 | * pool is full. Rasterized on first use. */ |
| 37 | const ck_af_glyph *ck_af_glyph_get(ck_af_face *f, char c); |
| 38 | /* Advance after c, 1/256 px. */ |
| 39 | uint32_t ck_af_advance(const ck_af_face *f, char c); |
| 40 | /* Width of the first n characters of s, whole px (rounded up). */ |
| 41 | uint32_t ck_af_measure(const ck_af_face *f, const char *s, size_t n); |
| 42 | /* Integer square root (floor). */ |
| 43 | uint64_t ck_af_isqrt(uint64_t v); |
| 44 | /* sin and cos of whole degrees (any sign), scaled by 16384. */ |
| 45 | int32_t ck_af_sin(int32_t deg); |
| 46 | int32_t ck_af_cos(int32_t deg); |
| 47 | |
| 48 | #endif |