#!/usr/bin/env python3
"""Recreate the exact distributed Nimbus web subsets, without overwriting the original files."""
from pathlib import Path
import argparse, hashlib
import fontTools
from fontTools import subset
p=argparse.ArgumentParser(); p.add_argument("--output", type=Path, required=True); a=p.parse_args()
assert fontTools.__version__ == "4.63.0", fontTools.__version__
root=Path(__file__).resolve().parent
a.output.mkdir(parents=True,exist_ok=True)
cps=list(range(0x20,0x7f))+list(range(0xa0,0x100))+[0x2014,0x2019,0x2026,0x2192]
for src,name,expected in [("NimbusSans-Bold.otf","FVScoreSans.woff","e1ea79ffe650d3659957397e28a05676d01a5870dd7c9f703ae64bae33f862b7"),("NimbusRoman-Italic.otf","FVScoreSerif.woff","148a382751b0a7710858c0d8f53b8b58cd97b771dd8b29047d46e6855439bfc6")]:
    out=a.output/name
    if out.exists(): raise FileExistsError(out)
    o=subset.Options(); o.flavor="woff"; o.recalc_bounds=True
    n=subset.load_font(str(root/src),o); ss=subset.Subsetter(options=o); ss.populate(unicodes=cps); ss.subset(n); n.flavor="woff"; n.save(out)
    h=hashlib.sha256(out.read_bytes()).hexdigest(); assert h==expected,(name,h); print(name,h)
