Preserve named font metadata and exercise glyph maintenance

Keep the baseline glyph names and add Cursor with compatible format-2 post and format-12 cmap tables. Exercise listing, disposable SVG addition and occupied-codepoint rejection.
This commit is contained in:
Ryan Hughes committed 2026-09-07 21:34:52 -04:00
1 parent d57cec42d4
commit 7cc9057413
2 files changed
+55

No files matched your search

Binary file not shown.
+55
View File
@@ -65,3 +65,58 @@ pass "baseline mise setup tolerates an unfinished Hermes Desktop and disables pr
PATH="$test_tmp/bin:$PATH" bash -euo pipefail "$ROOT/migrations/1787215483.sh" >/dev/null
grep -qx 'mise:settings set upgrade.auto_prune false' "$TEST_CALLS" || fail "existing users retain running mise versions"
pass "mise migration applies the same no-pruning setting"
# Exercise the documented font workflow, not just fontconfig's charset reader.
# Work on a disposable copy: adding a fixture must never edit the source font.
python3 - "$ROOT" "$test_tmp" <<'PY'
import pathlib
import runpy
import shutil
import struct
import subprocess
import sys
root, temporary = map(pathlib.Path, sys.argv[1:])
tool = root / 'bin/omarchy-dev-font'
font = temporary / 'omarchy.ttf'
shutil.copyfile(root / 'default/fonts/omarchy/omarchy.ttf', font)
api = runpy.run_path(str(tool))
def snapshot():
data, tables, count = api['load_font'](str(font))
offsets = api['read_loca'](data, tables, count)
names = api['read_names'](data, tables['post'][0], count)
cmap = api['read_cmap'](data, tables['cmap'][0])
start = tables['glyf'][0]
glyphs = [data[start + offsets[i]:start + offsets[i + 1]].rstrip(b'\0') for i in range(count)]
metrics = data[tables['hmtx'][0]:sum(tables['hmtx'])]
assert struct.unpack_from('>I', data, tables['post'][0])[0] == 0x20000
return names, cmap, glyphs, metrics
before = snapshot()
assert before[0][before[1][0xE90D]] == 'cursor'
assert 0xE909 not in before[1]
listing = subprocess.check_output([sys.executable, str(tool), 'list', '--font', str(font)], text=True)
for cp, name, _ in api['glyph_list'](str(font)):
assert f'U+{cp:04X}' in listing and name in listing
assert 'U+E90D' in listing and 'cursor' in listing
print('ok - the shipped font lists its named Cursor mark through the real font tool')
svg = temporary / 'fixture.svg'
svg.write_text('<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M2 2 L22 2 L22 22 L2 22 Z"/></svg>')
subprocess.run([sys.executable, str(tool), 'add', 'release-fixture', str(svg), '--font', str(font)], check=True, stdout=subprocess.DEVNULL)
after = snapshot()
assert after[0] == before[0] + ['release-fixture']
assert after[1] == before[1] | {0xE90E: len(before[0])}
assert after[2][:-1] == before[2]
assert after[3].startswith(before[3])
print('ok - adding a local SVG preserves every existing name, codepoint, outline and metric')
listing = subprocess.check_output([sys.executable, str(tool), 'list', '--font', str(font)], text=True)
assert 'U+E90E' in listing and 'release-fixture' in listing and 'cursor' in listing
print('ok - the real font tool lists the newly added disposable glyph')
unchanged = font.read_bytes()
result = subprocess.run([sys.executable, str(tool), 'add', 'collision', str(svg), '--codepoint', 'E90D', '--font', str(font)], capture_output=True, text=True)
assert result.returncode != 0 and 'already used' in result.stderr
assert font.read_bytes() == unchanged
print('ok - adding over Cursor is rejected without changing the font')
PY