1"""Emit the retained-codepoint manifest for the bundled primary font.
2
3The ranges are the terminal's own surface: every script and symbol block a cell
4can hold, plus Symbols for Legacy Computing, where the sextants and octants a
5program draws charts with live. What is dropped above them — mathematical
6alphanumerics, musical notation, emoji, and the historic scripts — is most of
7what makes an unsubset face 1.4 MB, and none of it reaches a terminal cell from
8a monospace primary.
9"""
10
11from pathlib import Path
12import sys
13
14from fontTools.ttLib import TTFont
15
16
17RETAINED_RANGES = (
18 (0x0000, 0x2BFF), # Latin through Miscellaneous Symbols and Arrows
19 (0x1FB00, 0x1FBFF), # Symbols for Legacy Computing
20)
21
22
23def main() -> None:
24 if len(sys.argv) != 3:
25 raise SystemExit("usage: subset-primary.py INPUT.ttf OUTPUT.txt")
26
27 source = TTFont(sys.argv[1])
28 cmap = source.getBestCmap()
29 if cmap is None:
30 raise SystemExit("input font has no Unicode cmap")
31
32 codepoints = sorted(
33 codepoint
34 for codepoint in cmap
35 if any(start <= codepoint <= end for start, end in RETAINED_RANGES)
36 )
37 Path(sys.argv[2]).write_text(
38 "".join(f"U+{codepoint:04X}\n" for codepoint in codepoints), encoding="ascii"
39 )
40
41
42if __name__ == "__main__":
43 main()