import numpy as np
from playwright.sync_api import sync_playwright
LINK=("https://fonts.googleapis.com/css2?family=Inter+Tight:ital,wght@0,600..900"
      "&family=Inter:ital,wght@0,600..900&display=block")
cfg=[("Twenty-four partners, seventeen disciplines,",585,46),
     ("one accountable firm. The proof is the printed object.",693,54)]
with sync_playwright() as p:
    b=p.chromium.launch(args=["--font-render-hinting=none","--force-color-profile=srgb"])
    pg=b.new_page(viewport={"width":800,"height":400})
    pg.set_content(f"""<!doctype html><html><head><meta charset=utf-8>
<link rel=stylesheet href="{LINK}"></head><body></body></html>""")
    pg.wait_for_timeout(1800)
    for fam,wt,size in [("Inter Tight","600",31.5),("Inter Tight","700",31.5),("Inter Tight","800",31.5),
                        ("Inter Tight","700",31.5),("Inter","700",30.0)]:
        m=pg.evaluate("""async ([f,w,s,lines])=>{await document.fonts.load(`${w} 20px "${f}"`);await document.fonts.ready;
          const c=document.createElement('canvas').getContext('2d'); c.font=`${w} ${s}px "${f}"`;
          return lines.map(t=>{const x=c.measureText(t);return x.actualBoundingBoxRight+x.actualBoundingBoxLeft;});}""",
          [fam,wt,size,[t for t,_,_ in cfg]])
        for (t,target,gaps),w in zip(cfg,m):
            tr=(target-w)/gaps
            print(f'{fam} {wt} {size}px  ink={w:.1f} target={target} trk={tr:.2f}px = {tr/size:.4f}em')
    b.close()
