diff --git a/CLAUDE.md b/CLAUDE.md index 45408aa..c71b92b 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -245,10 +245,10 @@ deliberately, one at a time, and say why in the code. and URL can't share the frame the code is whole at the top and the URL a page down. The one exception is a ` ```qr ` fence in a written page, where the code is an illustration drawn in the prose where the fence is. Where the font draws braille solid - (`Platform.solid_braille`, the PicoCalc's built fonts) every code — share screen and - page fence alike — is drawn in **braille**, one module a dot, eight a cell - (`qr._GRID`), so the contact card is 29 cells by 15 rows there and shares the 53×26 - panel with its URL at the standard fit. + (`Platform.solid_braille`: the PicoCalc's built fonts, the Cardputer's console host, + `host/font.BRAILLE`) every code — share screen and page fence alike — is drawn in + **braille**, one module a dot, eight a cell (`qr._GRID`), so the contact card is 29 + cells by 15 rows there and shares the 53×26 panel with its URL at the standard fit. ### Written pages diff --git a/meshterm/host/font.py b/meshterm/host/font.py index 9e0f50a..73c97bb 100644 --- a/meshterm/host/font.py +++ b/meshterm/host/font.py @@ -6,7 +6,8 @@ read alike, and at 1,356 glyphs it covers everything MeshTerm draws on this plat handful of its own marks. The host is not a kernel console, so nothing caps the glyph count at 512 — no donor slots, no folding braille away. MeshTerm's marks are drawn over the base from the same pixel art the PicoCalc's font build uses (:data:`MARKS`), so ``★``, ``❯``, -``⚿`` and the rest look the same on both devices. +``⚿`` and the rest look the same on both devices; and so is its braille (:data:`BRAILLE`), +solid tiles where Terminus draws the dots apart. Terminus is licensed under the SIL Open Font License, so it is never shipped inside MeshTerm: the host loads it from a BDF file on the machine (:func:`find_font`). On the @@ -101,6 +102,33 @@ MARKS: dict[int, bytes] = { } # fmt: on +#: Which byte bit lights which pixel columns, and which pixel rows, for each braille dot: +#: two columns of three pixels and four rows of three, tiling the whole cell. +_BRAILLE_COLS = (0xE0, 0x1C) +_BRAILLE_ROWS = ((0, 1, 2), (3, 4, 5), (6, 7, 8), (9, 10, 11)) + +#: Dot bit per (column, row) within a braille cell — the Unicode standard layout. +_BRAILLE_DOTS = ((0x01, 0x02, 0x04, 0x40), (0x08, 0x10, 0x20, 0x80)) + + +def _braille(value: int) -> bytes: + """The braille cell whose low byte is ``value``, each dot a solid 3×3 tile.""" + rows = [0] * CELL_H + for col, bits in enumerate(_BRAILLE_DOTS): + for row, bit in enumerate(bits): + if value & bit: + for y in _BRAILLE_ROWS[row]: + rows[y] |= _BRAILLE_COLS[col] + return bytes(rows) + + +#: Every braille cell, drawn over the base font as solid tiles with no gap between dots or +#: between neighbouring cells — the same tiles as the PicoCalc's font build +#: (``scripts/picocalc/calculinux-console-font-6x12.sh``, ``BANDS12``). MeshTerm never sets +#: braille to be read: every braille cell is pixels, a chart, the map, a QR code, and a +#: dotted one breaks every line it draws into beads. +BRAILLE: dict[int, bytes] = {0x2800 + value: _braille(value) for value in range(256)} + #: Codepoints drawn as another's glyph, as the PicoCalc's font aliases them. ALIASES: dict[int, int] = { 0x22EF: 0x2026, # midline ellipsis -> the ellipsis mark @@ -197,15 +225,18 @@ class Font: def build_font(regular: dict[int, bytes], bold: dict[int, bytes] | None = None) -> Font: - """A :class:`Font` from base glyph tables, with MeshTerm's marks drawn over both. + """A :class:`Font` from base glyph tables, with MeshTerm's marks and braille over both. - A missing bold face reuses the regular one, emboldened by a one-pixel smear. + A missing bold face reuses the regular one, emboldened by a one-pixel smear — all but + the braille, which is pixels rather than letters, so bold has no weight to add to it + and the smear would only close the seam between a cell's two columns. """ - regular = {**regular, **MARKS} + regular = {**regular, **MARKS, **BRAILLE} if bold is None: bold = {code: bytes(row | row >> 1 for row in rows) for code, rows in regular.items()} + bold.update(BRAILLE) else: - bold = {**bold, **MARKS} + bold = {**bold, **MARKS, **BRAILLE} return Font(regular=regular, bold=bold) diff --git a/meshterm/platforms.py b/meshterm/platforms.py index 9d94aba..bda4148 100644 --- a/meshterm/platforms.py +++ b/meshterm/platforms.py @@ -252,6 +252,9 @@ CARDPUTER = Platform( emoji=False, font="cardputer", truecolor=True, + # The console host draws its own braille, as the PicoCalc's built fonts do: solid + # tiles, no gap between dots (meshterm/host/font.py, BRAILLE). + solid_braille=True, effects=False, tick_s=2.0, spinner_tick_s=0.5, diff --git a/tests/test_console_host.py b/tests/test_console_host.py index be1a7ae..f8c83a2 100644 --- a/tests/test_console_host.py +++ b/tests/test_console_host.py @@ -184,6 +184,21 @@ def test_meshterm_marks_draw_over_the_base_and_gaps_show() -> None: assert font.glyph("一") == MISSING +def test_braille_draws_as_solid_tiles_with_no_gap() -> None: + """Braille is pixels here, as on the PicoCalc: each dot a 3x3 tile, the cell tiled whole. + + The base's dotted braille loses to the tiles, and so does the bold smear, which would + only close the seam between a cell's two columns. + """ + dotted = bytes([0x6C, 0x6C, 0, 0x6C, 0x6C, 0, 0x6C, 0x6C, 0, 0x6C, 0x6C, 0]) + font = build_font({0x28FF: dotted}) + assert font.glyph("⣿") == bytes([0xFC] * 12) # every dot: the cell, solid + assert font.glyph("⣿", bold=True) == bytes([0xFC] * 12) + assert font.glyph("⡇") == bytes([0xE0] * 12) # the left column: three pixels wide + assert font.glyph("⠉") == bytes([0xFC] * 3 + [0] * 9) # the top row: three tall + assert font.glyph("⢀", bold=True) == bytes([0] * 9 + [0x1C] * 3) # dot 8, unsmeared + + def test_the_raster_draws_a_cell_in_its_colours() -> None: """A cell's ink and paper land in the right pixels, and only dirty rows redraw.""" term = Terminal(53, 14) @@ -249,12 +264,13 @@ def test_meshterm_runs_inside_the_host(monkeypatch) -> None: def test_the_cardputer_inventory_is_what_the_host_draws() -> None: """``fontset.CARDPUTER_CODEPOINTS`` holds every mark, and the installed font exactly.""" - from meshterm.host.font import ALIASES, font_dir, load_bdf + from meshterm.host.font import ALIASES, BRAILLE, font_dir, load_bdf from meshterm.ui.fontset import CARDPUTER_CODEPOINTS - assert set(MARKS) | set(ALIASES) <= CARDPUTER_CODEPOINTS + ours = set(MARKS) | set(ALIASES) | set(BRAILLE) + assert ours <= CARDPUTER_CODEPOINTS installed = font_dir() / "ter-u12n.bdf" if not installed.is_file(): return # no Terminus on this machine (CI): the marks are the part that is ours - drawn = {cp for cp in load_bdf(installed) if cp >= 0x20} | set(MARKS) | set(ALIASES) + drawn = {cp for cp in load_bdf(installed) if cp >= 0x20} | ours assert drawn == CARDPUTER_CODEPOINTS