Skip to content

Instantly share code, notes, and snippets.

@yashsavani
Created June 22, 2021 08:19
Show Gist options
  • Save yashsavani/3c353d152d462c4af61dd3d47f1b56e3 to your computer and use it in GitHub Desktop.
Save yashsavani/3c353d152d462c4af61dd3d47f1b56e3 to your computer and use it in GitHub Desktop.
Download the latest Cascadia Code font, patch it with Nerd Fonts, and finally combine the italics fonts with the regular ones so they are all part of the same family.
import fontforge
from pathlib import Path
import os
import re
import requests
response = requests.get(
"https://api.github.com/repos/microsoft/cascadia-code/releases",
{"Accept": "application/vnd.github.v3+json"}
)
assert(response.status_code == 200)
url = response.json()[0]["assets"][0]['browser_download_url']
os.system(f"curl -fL {url} -o tmp.zip")
os.system(f"unzip tmp.zip")
os.system(f"mkdir in")
os.system(f"mv otf/static/CascadiaCodePL* in/")
os.system(f"rm -r ttf woff2 tmp.zip otf")
os.system("docker pull cdalvaro/nerd-fonts-patcher:latest")
os.system("""docker run --rm \
--volume $(pwd)/in:/nerd-fonts/in:ro \
--volume $(pwd)/out:/nerd-fonts/out \
--user $(id -u):$(id -g) \
cdalvaro/nerd-fonts-patcher:latest \
--quiet --no-progressbars \
--mono --adjust-line-height --complete --careful""")
fonts = [fontforge.open(str(fname)) for fname in Path("out/").glob("*")]
styles = [z.split('-')[-1] for x in fonts for _,y,z in x.sfnt_names if y == 'UniqueID']
name = "CasKa_NF"
for font, style in zip(fonts, styles):
font.fontname = name+"-"+style
font.familyname = name
font.fullname = name+"-"+style+".otf"
font.copyright = ""
for font in fonts:
newsfnt = []
for x, y, z in font.sfnt_names:
if y == "Family":
newsfnt.append((x,y,name))
elif y == "Preferred Family":
continue
else:
newsfnt.append((x,y,z))
font.sfnt_names = newsfnt
Path(name).mkdir(exist_ok=True)
for font in fonts:
font.generate(name+"/"+font.fullname)
os.system(f"rm -r in out")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment