Files
JIANT/tools/gen_px_font.py
Claude da1b1dd2c1 Copyright headers: name Juan Jiant on JIANT's own files, add him on the modified Felucca ones
Comment-only change (the built image is byte-identical: felucca.bin 583936 B, felucca.fwsc 684736 B, same SHA-256).

- 37 files written new for JIANT FM after the fork (no Felucca text in them: checked against ac6bfcbd by literal
  code lines, runs of consecutive lines, same-named functions and moves in their creating commit) carried Leo
  Kuroshita's copyright line copied from a template: it is now Juan Jiant's (SPDX GPL-3.0-only kept). Among them
  sing.c, eng_animal.c, eng_input.c, eng_string.c, pfx.c, seq_live.c, ui_engvis.c, ui_lens.c, ui_lz*.c, ui_being.c,
  ui_organic.c, ui_tech.c, ui_dx.c, ui_live.c, tools/lyrics/*.txt, gen_drum_maps.py, gen_px_font.py and 14 tests.
- 140 files that hold Felucca's code (Felucca 1.1.5.1 files changed since, imports of Felucca 1.5.x, the SLOOP-based
  song_main/song_play, and new files that carry copied Felucca helpers: drumx_voice.c dv_exp2/dv_kb, gen_lyrics.py's
  Huffman, test harness helpers) keep Leo's notice and add "Portions Copyright (C) 2026 Juan Ignacio Antonucci
  (Juan Jiant)". Files unchanged since the fork are left as they were.
- LICENSING.md and README.md name both copyright holders.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KMHk6yH4XbP1xxHYKCo9Mh
2026-11-11 18:04:53 +00:00

176 lines
10 KiB
Python

#!/usr/bin/env python3
# SPDX-License-Identifier: GPL-3.0-only
# Copyright (C) 2026 Juan Ignacio Antonucci (Juan Jiant)
"""(0.8.5) The UI's smallest face, AF_X: a crisp 5 x 7 mono pixel font (run by tools/build.py generate()).
gen_px_font.py OUT.h
The approved LENTE mock-up sets its card labels, level tabs, breadcrumb and chips in ~8 px mono capitals; the
antialiased faces start at S (12 px, capitals 9 px tall). AF_X is a 5 x 7 cell on a 6 px pitch (capitals 7 px), the
classic character-LCD shapes, one bit a pixel: no ramp, no phases, no kerning. Capitals, figures and punctuation
and lower case (0x20 .. 0x7A: the units' "ms", "Hz", "dB" as the mock-up writes them), '|', the middle dot (0xB7) and
the ellipsis (0x85).
A glyph is trimmed to its ink box and packed MSB first, a byte boundary per glyph; gfx.c text_run draws it with
cv_bits (aafont_t.bits = 1). The same aafont_t as the other faces, so text_w, cv_text_in, text_fit and the host lint
work unchanged. Line 9 px: the capitals rows 1 .. 7, a descender row 8 (, ; g j p q y).
"""
import sys
from pathlib import Path
sys.path.insert(0, str(Path(__file__).resolve().parent))
import aa_raster as ar # noqa: E402
PITCH = 6 # advance, px
H, ASC, CAP_Y = 9, 8, 1
G = {
' ': [],
'!': ["..#..", "..#..", "..#..", "..#..", "..#..", ".....", "..#.."],
'"': [".#.#.", ".#.#.", ".#.#."],
'#': [".#.#.", ".#.#.", "#####", ".#.#.", "#####", ".#.#.", ".#.#."],
'$': ["..#..", ".####", "#.#..", ".###.", "..#.#", "####.", "..#.."],
'%': ["##...", "##..#", "...#.", "..#..", ".#...", "#..##", "...##"],
'&': [".##..", "#..#.", "#.#..", ".#...", "#.#.#", "#..#.", ".##.#"],
"'": ["..#..", "..#..", ".#..."],
'(': ["...#.", "..#..", ".#...", ".#...", ".#...", "..#..", "...#."],
')': [".#...", "..#..", "...#.", "...#.", "...#.", "..#..", ".#..."],
'*': [".....", "..#..", "#.#.#", ".###.", "#.#.#", "..#..", "....."],
'+': [".....", "..#..", "..#..", "#####", "..#..", "..#..", "....."],
',': [".....", ".....", ".....", ".....", ".....", ".##..", "..#..", ".#..."],
'-': [".....", ".....", ".....", ".###.", ".....", ".....", "....."],
'.': [".....", ".....", ".....", ".....", ".....", ".##..", ".##.."],
'/': [".....", "....#", "...#.", "..#..", ".#...", "#....", "....."],
'0': [".###.", "#...#", "#..##", "#.#.#", "##..#", "#...#", ".###."],
'1': ["..#..", ".##..", "..#..", "..#..", "..#..", "..#..", ".###."],
'2': [".###.", "#...#", "....#", "...#.", "..#..", ".#...", "#####"],
'3': ["#####", "...#.", "..#..", "...#.", "....#", "#...#", ".###."],
'4': ["...#.", "..##.", ".#.#.", "#..#.", "#####", "...#.", "...#."],
'5': ["#####", "#....", "####.", "....#", "....#", "#...#", ".###."],
'6': ["..##.", ".#...", "#....", "####.", "#...#", "#...#", ".###."],
'7': ["#####", "....#", "...#.", "..#..", ".#...", ".#...", ".#..."],
'8': [".###.", "#...#", "#...#", ".###.", "#...#", "#...#", ".###."],
'9': [".###.", "#...#", "#...#", ".####", "....#", "...#.", ".##.."],
':': [".....", ".##..", ".##..", ".....", ".##..", ".##..", "....."],
';': [".....", ".##..", ".##..", ".....", ".##..", "..#..", ".#..."],
'<': ["...#.", "..#..", ".#...", "#....", ".#...", "..#..", "...#."],
'=': [".....", ".....", "#####", ".....", "#####", ".....", "....."],
'>': [".#...", "..#..", "...#.", "....#", "...#.", "..#..", ".#..."],
'?': [".###.", "#...#", "....#", "...#.", "..#..", ".....", "..#.."],
'@': [".###.", "#...#", "....#", ".##.#", "#.#.#", "#.#.#", ".###."],
'A': [".###.", "#...#", "#...#", "#...#", "#####", "#...#", "#...#"],
'B': ["####.", "#...#", "#...#", "####.", "#...#", "#...#", "####."],
'C': [".###.", "#...#", "#....", "#....", "#....", "#...#", ".###."],
'D': ["###..", "#..#.", "#...#", "#...#", "#...#", "#..#.", "###.."],
'E': ["#####", "#....", "#....", "####.", "#....", "#....", "#####"],
'F': ["#####", "#....", "#....", "####.", "#....", "#....", "#...."],
'G': [".###.", "#...#", "#....", "#.###", "#...#", "#...#", ".####"],
'H': ["#...#", "#...#", "#...#", "#####", "#...#", "#...#", "#...#"],
'I': [".###.", "..#..", "..#..", "..#..", "..#..", "..#..", ".###."],
'J': ["..###", "...#.", "...#.", "...#.", "...#.", "#..#.", ".##.."],
'K': ["#...#", "#..#.", "#.#..", "##...", "#.#..", "#..#.", "#...#"],
'L': ["#....", "#....", "#....", "#....", "#....", "#....", "#####"],
'M': ["#...#", "##.##", "#.#.#", "#.#.#", "#...#", "#...#", "#...#"],
'N': ["#...#", "#...#", "##..#", "#.#.#", "#..##", "#...#", "#...#"],
'O': [".###.", "#...#", "#...#", "#...#", "#...#", "#...#", ".###."],
'P': ["####.", "#...#", "#...#", "####.", "#....", "#....", "#...."],
'Q': [".###.", "#...#", "#...#", "#...#", "#.#.#", "#..#.", ".##.#"],
'R': ["####.", "#...#", "#...#", "####.", "#.#..", "#..#.", "#...#"],
'S': [".####", "#....", "#....", ".###.", "....#", "....#", "####."],
'T': ["#####", "..#..", "..#..", "..#..", "..#..", "..#..", "..#.."],
'U': ["#...#", "#...#", "#...#", "#...#", "#...#", "#...#", ".###."],
'V': ["#...#", "#...#", "#...#", "#...#", "#...#", ".#.#.", "..#.."],
'W': ["#...#", "#...#", "#...#", "#.#.#", "#.#.#", "#.#.#", ".#.#."],
'X': ["#...#", "#...#", ".#.#.", "..#..", ".#.#.", "#...#", "#...#"],
'Y': ["#...#", "#...#", "#...#", ".#.#.", "..#..", "..#..", "..#.."],
'Z': ["#####", "....#", "...#.", "..#..", ".#...", "#....", "#####"],
'[': [".###.", ".#...", ".#...", ".#...", ".#...", ".#...", ".###."],
'\\': [".....", "#....", ".#...", "..#..", "...#.", "....#", "....."],
']': [".###.", "...#.", "...#.", "...#.", "...#.", "...#.", ".###."],
'^': ["..#..", ".#.#.", "#...#"],
'_': [".....", ".....", ".....", ".....", ".....", ".....", "#####"],
'a': ['.....', '.....', '.###.', '....#', '.####', '#...#', '.####'],
'b': ['#....', '#....', '#.##.', '##..#', '#...#', '#...#', '####.'],
'c': ['.....', '.....', '.###.', '#....', '#....', '#...#', '.###.'],
'd': ['....#', '....#', '.##.#', '#..##', '#...#', '#...#', '.####'],
'e': ['.....', '.....', '.###.', '#...#', '#####', '#....', '.###.'],
'f': ['..##.', '.#..#', '.#...', '###..', '.#...', '.#...', '.#...'],
'g': ['.....', '.....', '.####', '#...#', '#...#', '.####', '....#', '.###.'],
'h': ['#....', '#....', '#.##.', '##..#', '#...#', '#...#', '#...#'],
'i': ['..#..', '.....', '.##..', '..#..', '..#..', '..#..', '.###.'],
'j': ['...#.', '.....', '..##.', '...#.', '...#.', '...#.', '#..#.', '.##..'],
'k': ['#....', '#....', '#..#.', '#.#..', '##...', '#.#..', '#..#.'],
'l': ['.##..', '..#..', '..#..', '..#..', '..#..', '..#..', '.###.'],
'm': ['.....', '.....', '##.#.', '#.#.#', '#.#.#', '#...#', '#...#'],
'n': ['.....', '.....', '#.##.', '##..#', '#...#', '#...#', '#...#'],
'o': ['.....', '.....', '.###.', '#...#', '#...#', '#...#', '.###.'],
'p': ['.....', '.....', '####.', '#...#', '#...#', '####.', '#....', '#....'],
'q': ['.....', '.....', '.####', '#...#', '#...#', '.####', '....#', '....#'],
'r': ['.....', '.....', '#.##.', '##..#', '#....', '#....', '#....'],
's': ['.....', '.....', '.###.', '#....', '.###.', '....#', '####.'],
't': ['.#...', '.#...', '###..', '.#...', '.#...', '.#..#', '..##.'],
'u': ['.....', '.....', '#...#', '#...#', '#...#', '#..##', '.##.#'],
'v': ['.....', '.....', '#...#', '#...#', '#...#', '.#.#.', '..#..'],
'w': ['.....', '.....', '#...#', '#...#', '#.#.#', '#.#.#', '.#.#.'],
'x': ['.....', '.....', '#...#', '.#.#.', '..#..', '.#.#.', '#...#'],
'y': ['.....', '.....', '#...#', '#...#', '#...#', '.####', '....#', '.###.'],
'z': ['.....', '.....', '#####', '...#.', '..#..', '.#...', '#####'],
'`': ['.#...', '..#..', '...#.'],
}
EXTRA = {
0x7C: ["..#..", "..#..", "..#..", "..#..", "..#..", "..#..", "..#.."], # |
0xB7: [".....", ".....", ".....", "..#..", ".....", ".....", "....."], # the middle dot
0x85: [".....", ".....", ".....", ".....", ".....", ".....", "#.#.#"], # the ellipsis
}
def glyph(rows):
"""(bx, by, bw, bh, bytes) of a glyph's ink box, rows top down (row 0 = the capitals' top)"""
ink = [(x, y) for y, r in enumerate(rows) for x, c in enumerate(r) if c == '#']
if not ink:
return 0, 0, 0, 0, b""
x0, x1 = min(p[0] for p in ink), max(p[0] for p in ink)
y0, y1 = min(p[1] for p in ink), max(p[1] for p in ink)
bits = [1 if rows[y][x] == '#' else 0 for y in range(y0, y1 + 1) for x in range(x0, x1 + 1)]
data = bytearray()
for i in range(0, len(bits), 8):
b = 0
for k, v in enumerate(bits[i:i + 8]):
b |= v << (7 - k)
data.append(b)
return x0, y0 + CAP_Y, x1 - x0 + 1, y1 - y0 + 1, bytes(data)
def main():
out = Path(sys.argv[1])
codes = list(range(0x20, 0x7B))
ex = sorted(EXTRA)
tab, data = [], bytearray()
for c in codes + ex:
rows = G[chr(c)] if c < 0x7B else EXTRA[c]
for r in rows:
assert len(r) == 5, (chr(c), r)
bx, by, bw, bh, d = glyph(rows)
tab.append((len(data), PITCH * 16, bx, by, bw, bh))
data += d
data += b"\0\0"
hb = [r for r in G['H']]
assert glyph(hb)[1] == CAP_Y and glyph(hb)[3] == 7
lines = ["/* generated by tools/gen_px_font.py: AF_X, the 5 x 7 mono pixel face (1 bit a pixel) */",
f"static const uint8_t AF_X_DATA[{len(data)}] = {{"]
for i in range(0, len(data), 24):
lines.append(" " + ", ".join(str(b) for b in data[i:i + 24]) + ",")
lines.append("};")
gtext, gsize = ar.glyph_tables("X", tab, 1) # (0.9.0: packed, as the other faces')
lines.append(gtext)
lines.append(f"static const uint8_t AF_X_EX[{len(ex)}] = {{{', '.join(str(c) for c in ex)}}};")
lines.append(f"static const aafont_t AF_X = {{{H}, {ASC}, 32, 122, {len(ex)}, 0, AF_X_GH, AF_X_GP, AF_X_DATA, 0, 0, AF_X_EX, 0, 0, 1}};")
lines.append(f"#define AF_X_CAP_Y {CAP_Y} /* the ink of H: rows {CAP_Y} .. {CAP_Y + 6} of the line */")
lines.append("#define AF_X_CAP_H 7")
lines.append(f"#define AF_X_PITCH {PITCH}")
out.write_text("\n".join(lines) + "\n")
size = len(data) + gsize + len(ex)
print(f"face X: 5x7 pixel mono, {len(tab)} glyphs, data {len(data)} B + table {gsize} B = {size} B -> {out}")
if __name__ == "__main__":
main()