Fonts: S and M at 2 sub-pixel phases (were 4): 12912 B of flash

The small and medium UI faces were rasterised at four horizontal phases
(+0, +1/4, +1/2, +3/4 px); now two (+0, +1/2), as the large face has been
since 0.5. Glyph data and tables of S and M go from 32176 B to 19269 B; the
image from 584116 B to 571204 B (13132 B free in the slot).

A glyph still sits within 1/4 px of its true place and a gap between two
neighbours within 1/2 px (S 0.43 px max, rms 0.19; M 0.40, rms 0.16; with
four phases 0.20 / 0.24). tests/text_spacing_test.py now holds every face to
a phase step (1 / phases px) instead of a fixed 0.25 px for S M. The renderer
(gfx.c text_run) is unchanged: it reads the phase count from the face.
UI renders: 0 lint findings, 0 alignment findings.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KMHk6yH4XbP1xxHYKCo9Mh
This commit is contained in:
Claude committed 2026-10-19 19:44:37 +00:00
1 parent ca2d6c1ad0
commit c430a18c91
4 files changed
+11 -8

No files matched your search

+1 -1
View File
@@ -6,7 +6,7 @@
* byte-swapped (the panel takes RGB565 big-endian).
* Text and icons are 4-bit alpha bitmaps made at build time (tools/gen_aa_font.py: Inter Tight;
* tools/gen_aa_icons.py: Fukiai). A glyph is trimmed to its ink box, advances are in 1/16 px, and
* each glyph is rasterised at 1 << psh horizontal phases (S M 4, L 2: drawn at a pen of +0, +1/4 .. px);
* each glyph is rasterised at 1 << psh horizontal phases (S M L 2, S M 4 until 0.9.15: drawn at a pen of +0, +1/2 px);
* cv_text takes the phase that puts it within a phase step of its true place. Blending uses a 16-entry
* ramp per (ink, background) pair, cached, so a pixel costs a nibble read and a store. Colours come from the theme tokens. */
typedef struct { uint16_t off, adv; int8_t bx; uint8_t by, bw, bh; } aag_t; /* a glyph at a phase (ag) */
+1 -1
View File
@@ -254,7 +254,7 @@ if [ -f build/gen/felucca_tables.h ]; then
$CC -O1 -w -Ibuild/gen -Ifirmware/src -o "$OUT/text_ref_test" tests/text_ref_test.c -lm
run "text: pens, kerning and pixels equal the reference renderer" "$OUT/text_ref_test"
if python3 -c "import PIL" 2>/dev/null; then
run "text spacing: glyph gaps against the font's own (16x supersampled), S M <= 0.25 px, L <= 0.5 px" \
run "text spacing: glyph gaps against the font's own (16x supersampled), a phase step (S M L <= 0.5 px)" \
python3 tests/text_spacing_test.py build/gen/ui_fonts.h
fi
$CC -O1 -w -Ibuild/gen -o "$OUT/settings_test" tests/settings_test.c
+6 -5
View File
@@ -8,7 +8,8 @@ whole string (advances and GPOS kerning at 16 x the size).
Per glyph: its displacement d = ink centroid (tables) - ink centroid (reference); area coverage keeps the first
moment, so d is how far the glyph sits from its true place. Per pair: gap error = d[i+1] - d[i], the error of
the space between two neighbours. Fails when a pair of S or M is off by more than 0.25 px or L by more than 0.5 px.
the space between two neighbours. Fails when a pair is off by more than a phase step (1 / phases px: 0.5 px with 2 phases, S M L since 0.9.16; 0.25
px with 4, S M until 0.9.15).
text_spacing_test.py [ui_fonts.h] [--png DIR [--tag NAME]] [--rule gfx|rounded] [--no-limit]
(PNG: the specimen strings x4, gray on black; --rule rounded measures tables made before the phases)
@@ -33,7 +34,6 @@ LOWER = ["oeo", "coco", "eco", "nono", "minimum", "hello", "level", "decay", "re
UPPER = ["CUTOFF", "RESO", "LEVEL", "DECAY", "RELEASE", "SOUND", "OCOE", "COCO", "NONO", "MINIMUM", "SUPER SAW",
"FELUCCA", "PRESETS", "ANALOG", "DIGITAL", "PITCH", "SWING", "AV AW LT TA YO"]
RULE = ["gfx"] # "gfx": src/gfx.c cv_text; "rounded": the earlier rule (each glyph at the rounded pen, 1 phase)
LIMIT = {"S": 0.25, "M": 0.25, "L": 0.5}
def parse(path):
@@ -192,11 +192,12 @@ def main():
e = sorted(pairs, key=lambda p: -abs(p[1]))
mx = abs(e[0][1])
rms = (sum(v * v for _, v in pairs) / len(pairs)) ** 0.5
over = sum(abs(v) > LIMIT[name] for _, v in pairs)
ok = mx <= LIMIT[name] + 1e-9
limit = 1.0 / (1 << f["psh"]) # a phase step
over = sum(abs(v) > limit for _, v in pairs)
ok = mx <= limit + 1e-9
bad += not ok
print(f" {name} {px}px x{1 << f['psh']} phases: {len(pairs)} pairs, gap error max {mx:.3f} px, rms {rms:.3f} px, "
f"{over} over {LIMIT[name]} px {'ok' if ok else 'FAIL'}")
f"{over} over {limit} px {'ok' if ok else 'FAIL'}")
print(" worst: " + ", ".join(f"{p!r} {v:+.2f}" for p, v in e[:10]))
if a.png:
Path(a.png).mkdir(parents=True, exist_ok=True)
+3 -1
View File
@@ -42,7 +42,9 @@ FONTS = Path(__file__).resolve().parents[1] / "fonts"
LOCAL_INTER = os.path.expanduser("~/Library/Fonts/Inter.ttc") # 4.001: 0 Regular, 10 Medium, 12 SemiBold
EXTRAS = [0xA9, 0xB0, 0xB7, 0xC4, 0xD6, 0xDC, 0xE4, 0xF6, 0xFC, 0x2026] # (c) deg . A: O: U: a: o: u: (Latin-1), ...
CODE = {0x2026: 0x85} # characters outside Latin-1 -> their one-byte code in the firmware
PHASES, PHASES_L = 4, 2 # horizontal phases per glyph (aa_raster.raster_font): S M, L
PHASES, PHASES_L = 2, 2 # horizontal phases per glyph (aa_raster.raster_font): S M, L. (JIANT 0.9.16, flash)
# S M 2, were 4: 12.9 KB less of the glyph tables; a glyph within 1/4 px of its
# place, a gap within 1/2 px (text_spacing_test.py, as L since 0.5)
# faces stored Huffman-coded (--huff): M and L. S, the most drawn and the least compressible (-15 %), stays
# 2 px per byte, so the labels draw at full speed
HUFF = [("M", "L")]