| 1 | """Emit the retained-codepoint manifest for the bundled primary font. |
| 2 | |
| 3 | The ranges are the terminal's own surface: every script and symbol block a cell |
| 4 | can hold, plus Symbols for Legacy Computing, where the sextants and octants a |
| 5 | program draws charts with live. What is dropped above them — mathematical |
| 6 | alphanumerics, musical notation, emoji, and the historic scripts — is most of |
| 7 | what makes an unsubset face 1.4 MB, and none of it reaches a terminal cell from |
| 8 | a monospace primary. |
| 9 | """ |
| 10 | |
| 11 | from pathlib import Path |
| 12 | import sys |
| 13 | |
| 14 | from fontTools.ttLib import TTFont |
| 15 | |
| 16 | |
| 17 | RETAINED_RANGES = ( |
| 18 | (0x0000, 0x2BFF), # Latin through Miscellaneous Symbols and Arrows |
| 19 | (0x1FB00, 0x1FBFF), # Symbols for Legacy Computing |
| 20 | ) |
| 21 | |
| 22 | |
| 23 | def 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 | |
| 42 | if __name__ == "__main__": |
| 43 | main() |