primordial-soup/scripts/build-display-font.py

30 lines
947 B
Python

"""Rebuild with: uv run --with fonttools --with brotli scripts/build-display-font.py"""
from pathlib import Path
from fontTools.ttLib import TTFont
assets = Path(__file__).resolve().parent.parent / "viewer" / "assets"
font = TTFont(assets / "font-4.ttf", recalcTimestamp=False)
# Upstream Lilita One has undersized glyph bounds that Firefox flags. Keep its
# outlines, but recalculate the bounds and rename this derivative per the OFL.
for glyph in font["glyf"].glyphs.values():
glyph.expand(font["glyf"])
glyph.recalcBounds(font["glyf"])
names = {
1: "Soup Display",
2: "Regular",
3: "Soup Display Regular 1.0",
4: "Soup Display Regular",
6: "SoupDisplay-Regular",
16: "Soup Display",
17: "Regular",
}
for record in font["name"].names:
if record.nameID in names:
record.string = names[record.nameID].encode(record.getEncoding())
font.flavor = "woff2"
font.save(assets / "soup-display.woff2")