Created
May 18, 2026 07:29
-
-
Save BjoernSchilberg/731b7dbc6300136e1df75dc71ae8cddc to your computer and use it in GitHub Desktop.
Extract individual TTF files from TTC collection
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import os | |
| from fontTools.ttLib import TTCollection | |
| ttc_path = '/home/bjoern/.local/share/fonts/Monocraft-nerd-fonts-patched.ttc' | |
| out_dir = '/home/bjoern/.local/share/fonts/' | |
| ttc = TTCollection(ttc_path) | |
| for i, font in enumerate(ttc.fonts): | |
| name_table = font['name'] | |
| ps_name = name_table.getName(6, 3, 1, 0x0409) | |
| if ps_name: | |
| ps_name = ps_name.toUnicode() | |
| else: | |
| ps_name = f'Monocraft-{i}' | |
| out_path = os.path.join(out_dir, f'{ps_name}.ttf') | |
| font.save(out_path) | |
| print(f'Saved: {out_path}') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment