Last active
August 11, 2023 01:24
-
-
Save al3xtjames/28cf6bc870c656cb90483af8607bb256 to your computer and use it in GitHub Desktop.
This file contains 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
#!/usr/bin/env python3 | |
# | |
# git clone https://github.com/ryanoasis/nerd-fonts && cd nerd-fonts | |
# curl -O <this script> | |
# mkdir incomplete | |
# find ~/Downloads/Input-Font/Input_Fonts/InputMono/InputMono -name '*.ttf' | parallel fontforge -script font-patcher --mono --adjust-line-height --quiet --outputdir incomplete {} | |
# mkdir complete | |
# find ~/Downloads/Input-Font/Input_Fonts/InputMono/InputMono -name '*.ttf' | parallel fontforge -script font-patcher --mono --adjust-line-height --quiet --complete --outputdir complete {} | |
# python3 gen-input-mono-nf.py | |
# rm -rf incomplete complete | |
import fontforge | |
import sys | |
families = ["InputMonoNarrow"] | |
full_families = { | |
"InputMono": "Input Mono", | |
"InputMonoCompressed": "Input Mono Compressed", | |
"InputMonoCondensed": "Input Mono Condensed", | |
"InputMonoNarrow": "Input Mono Narrow" | |
} | |
variants = [None, "Black", "BlackIta", "Bold", "BoldIta", "ExLight", "ExLightIta", "Italic", "Light", "LightIta", "Medium", "MediumIta"] | |
full_variants = { | |
None: "Regular", | |
"Black": "Black", | |
"BlackIta": "Black Italic", | |
"Bold": "Bold", | |
"BoldIta": "Bold Italic", | |
"ExLight": "Extra Light", | |
"ExLightIta": "Extra Light Italic", | |
"Italic": "Italic", | |
"Light": "Light", | |
"LightIta": "Light Italic", | |
"Medium": "Medium", | |
"MediumIta": "Medium Italic", | |
} | |
def gen_fixed_font(family, variant=None): | |
full_family = full_families[family] | |
if not variant: | |
filename = f"{family} Nerd Font" | |
fontname_suffix = "" | |
fullname_suffix = "" | |
else: | |
filename = f"{family} {variant} Nerd Font" | |
fontname_suffix = f"-{full_variants[variant].replace(' ', '')}" | |
fullname_suffix = f" {full_variants[variant]}" | |
incomplete_font = fontforge.open(f"incomplete/{filename} Mono.ttf") | |
complete_font = fontforge.open(f"complete/{filename} Complete Mono.ttf") | |
incomplete_font.selection.select("u0237") | |
incomplete_font.copy() | |
complete_font.selection.select("u0237") | |
complete_font.paste() | |
complete_font.familyname = f"{full_family} NF" | |
complete_font.fontname = f"{family}NF{fontname_suffix}" | |
complete_font.fullname = f"{complete_font.familyname}{fullname_suffix}" | |
complete_font.appendSFNTName("English (US)", "UniqueID", f"0.000;FBI ;{complete_font.fontname}") | |
complete_font.appendSFNTName("English (US)", "Preferred Family", complete_font.familyname) | |
complete_font.appendSFNTName("English (US)", "Preferred Styles", full_variants[variant]) | |
complete_font.sfnt_names = tuple(x for x in complete_font.sfnt_names if x[1] != "Compatible Full") | |
if not variant: | |
complete_font.appendSFNTName("English (US)", "SubFamily", "Regular") | |
complete_font.generate(f"fixed/{complete_font.fontname}-Regular.ttf") | |
else: | |
complete_font.generate(f"fixed/{complete_font.fontname}.ttf") | |
if len(sys.argv) != 2: | |
exit(1) | |
for variant in variants: | |
gen_fixed_font(sys.argv[1], variant) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment