ws-arch: wip font/ttf + font fixtures

This commit is contained in:
4DBug committed 2026-10-31 08:38:47 -05:00
1 parent 9fadc7155f
commit 20092f6324
3 files changed
+324

No files matched your search

+35
View File
@@ -0,0 +1,35 @@
# Font fixtures (tools/fixtures.py): the imgui-luau fonts (TrueType: Cousine, DroidSans, Karla, Proggy*, Roboto, read
# from ~/dev/luau/imgui/imgui-luau/fonts or $IMGUI_FONTS; skipped if missing) and Source Sans 3 (CFF OpenType, nixpkgs
# source-sans), plus a copy of ProggyClean with a 'kern' table and a two-font collection, both made with fontTools.
# Reference values come from tools/fixtures/_font_reference.py: fontTools (metrics, names, cmap, hmtx, control boxes,
# areas, WOFF / WOFF2), HarfBuzz (GPOS kerning), FreeType (kern tables, unhinted renders).
# tests/gen/fonts.luau { fonts = { { name, data, upem, ..., cmap, glyphs, kern, renders } }, woff = { ... }, ttc }
import base64, glob, json, os, subprocess
FONTS = os.environ.get("IMGUI_FONTS", os.path.expanduser("~/dev/luau/imgui/imgui-luau/fonts"))
PICK = ["Cousine-Regular", "DroidSans", "Karla-Regular", "ProggyClean", "Roboto-Medium"]
def generate(ctx):
specs = []
for name in PICK:
p = os.path.join(FONTS, name + ".ttf")
if os.path.exists(p):
specs.append({"name": name, "b64": base64.b64encode(open(p, "rb").read()).decode()})
out = subprocess.run(["nix", "build", "--no-link", "--print-out-paths", "nixpkgs#source-sans"], capture_output=True,
check=True, text=True).stdout.strip().split("\n")[-1]
otf = os.path.join(out, "share", "fonts", "opentype", "SourceSans3-Regular.otf")
specs.append({"name": "SourceSans3-Regular", "b64": base64.b64encode(open(otf, "rb").read()).decode()})
code = open(os.path.join(ctx.root, "tools", "fixtures", "_font_reference.py")).read()
raw = ctx.python(["fonttools", "freetype-py", "uharfbuzz", "brotli"], code, input=json.dumps(specs).encode())
res = json.loads(raw)
d = base64.b64decode
for f in res["fonts"]:
f["data"] = d(f["data"])
for r in f["renders"]:
r["pixels"] = d(r["pixels"])
for w in res["woff"]:
w["woff"], w["woff2"] = d(w["woff"]), d(w["woff2"])
if "ttc" in res:
res["ttc"]["data"] = d(res["ttc"]["data"])
ctx.emit("fonts", res)