diff --git a/firmware/src/gfx.c b/firmware/src/gfx.c index 5ae3c821..78afc0e9 100644 --- a/firmware/src/gfx.c +++ b/firmware/src/gfx.c @@ -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) */ diff --git a/tests/run_tests.sh b/tests/run_tests.sh index f2cae7ce..75b89f6c 100755 --- a/tests/run_tests.sh +++ b/tests/run_tests.sh @@ -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 diff --git a/tests/text_spacing_test.py b/tests/text_spacing_test.py index e2bc3d06..351efb01 100644 --- a/tests/text_spacing_test.py +++ b/tests/text_spacing_test.py @@ -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) diff --git a/tools/gen_aa_font.py b/tools/gen_aa_font.py index a8784855..46b1f62a 100644 --- a/tools/gen_aa_font.py +++ b/tools/gen_aa_font.py @@ -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")]