Cotton code
53 lines · 2.1 KB · PythonRaw
#!/usr/bin/env python3"""Cut the Barlow Condensed SemiBold the letterboard tiles bundle.Cotton Cinemas' fan tiles (the black felt letterboard, Round 19, 6 Nov 2026)set their words in cream upright condensed capitals: Barlow CondensedSemiBold, the upright of the family whose ExtraBoldItalic the record sleevesalready bundle (same OFL, `OFL-BarlowCondensed.txt`). The static filegoogle/fonts ships is 109 KB; this keeps its Latin (Basic, Latin-1 andExtended-A, the punctuation and the rupee) with every layout feature, 75 KB.Needs fonttools (`python3 -m venv .venv && .venv/bin/pip install fonttools`).    python3 scripts/gen-fonts/cut_barlow_condensed.py [<BarlowCondensed-SemiBold.ttf>] [<out-dir>]With no file given it downloads google/fonts' and checks it is the one cut."""import hashlibimport sysimport tempfileimport urllib.requestfrom pathlib import Pathfrom fontTools import subsetSOURCE = "https://github.com/google/fonts/raw/main/ofl/barlowcondensed/BarlowCondensed-SemiBold.ttf"SOURCE_SHA256 = "7b619d14bc2327509a9ef32b0890f709626f7ecc9ff61191c2a4314c5499d2d9"UNICODES = "U+0020-007E,U+00A0-00FF,U+0100-017F,U+2010-2027,U+2030-203A,U+20AC,U+20B9,U+2122"REPO = Path(__file__).resolve().parents[2]DEFAULT_OUT = REPO / "apps/loom/Sources/CottonPaper/Resources/Fonts"def main() -> None:    out = Path(sys.argv[2]) if len(sys.argv) > 2 else DEFAULT_OUT    if len(sys.argv) > 1:        source = Path(sys.argv[1])    else:        source = Path(tempfile.mkdtemp()) / "BarlowCondensed-SemiBold.ttf"        urllib.request.urlretrieve(SOURCE, source)        digest = hashlib.sha256(source.read_bytes()).hexdigest()        if digest != SOURCE_SHA256:            sys.exit(f"{SOURCE} is no longer the file this was cut from ({digest})")    target = out / "BarlowCondensed-SemiBold.ttf"    subset.main([        str(source), f"--unicodes={UNICODES}", "--layout-features=*", "--name-IDs=*", "--name-legacy",        "--name-languages=*", "--drop-tables+=DSIG", f"--output-file={target}",    ])    print(f"{target}: {target.stat().st_size // 1024} KB")if __name__ == "__main__":    main()