mirror of
https://github.com/ChuckBuilds/LEDMatrix.git
synced 2026-08-01 16:58:06 +00:00
feat(layout): add measure_font_crispness — verify a ladder rung isn't blurry
PIL antialiases TTF outlines by default; a 'pixel-style' font only rasterizes without antialiasing at specific sizes (for PressStart2P: exact multiples of its 8px design grid). A ladder rung at an unverified size silently renders blurry on an LED panel — this exact bug shipped in both text-display's and football-scoreboard's custom TTF ladders (non-8-multiple PressStart2P sizes, and '5by7.regular'/'4x6-font' at sizes that were never actually crisp). measure_font_crispness(font, sample_text) renders the sample and reports the fraction of ink-bbox pixels that are neither pure black nor pure white. BDF fonts (real bitmaps) always score 0.0; TTF ladders should be verified against this before shipping — see the new TestFontFitting::test_ladder_arcade_is_crisp pattern. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -9,6 +9,7 @@ from src.adaptive_layout import (
|
||||
LayoutContext,
|
||||
Region,
|
||||
draw_fitted_text,
|
||||
measure_font_crispness,
|
||||
measure_ink,
|
||||
media_row,
|
||||
scoreboard_regions,
|
||||
@@ -182,6 +183,27 @@ class TestFontFitting:
|
||||
assert heights == sorted(heights, reverse=True), (
|
||||
f"ladder not monotonically shrinking: {heights}")
|
||||
|
||||
def test_ladder_grid_is_crisp(self, font_manager):
|
||||
"""LADDER_GRID's BDF fonts are real bitmaps — always 0% antialiased."""
|
||||
for step in LADDER_GRID:
|
||||
font = font_manager.get_font(step.family, step.size_px)
|
||||
assert measure_font_crispness(font, "Ay0") == 0.0
|
||||
|
||||
def test_ladder_arcade_is_crisp(self, font_manager):
|
||||
"""PressStart2P only rasterizes without antialiasing at exact
|
||||
multiples of its 8px design grid — every LADDER_ARCADE rung must
|
||||
land on one."""
|
||||
for step in LADDER_ARCADE:
|
||||
assert step.size_px % 8 == 0, f"{step} is not a multiple of 8"
|
||||
font = font_manager.get_font(step.family, step.size_px)
|
||||
assert measure_font_crispness(font, "17-21") == 0.0
|
||||
|
||||
def test_crispness_catches_a_bad_size(self, font_manager):
|
||||
"""Sanity check the measurement itself: a known-bad size for a
|
||||
pixel-grid font must NOT read as crisp."""
|
||||
font = font_manager.get_font("press_start", 10) # not a multiple of 8
|
||||
assert measure_font_crispness(font, "17-21") > 0.1
|
||||
|
||||
def test_fit_text_grows_on_taller_panel(self, font_manager):
|
||||
small = LayoutContext(64, 32, font_manager)
|
||||
large = LayoutContext(128, 64, font_manager)
|
||||
|
||||
Reference in New Issue
Block a user