30 lines
1.7 KiB
Python
30 lines
1.7 KiB
Python
"""Bake the two small Arizona faces used by the GPU consent card."""
|
|
from pathlib import Path
|
|
from tempfile import TemporaryDirectory
|
|
import subprocess
|
|
import re
|
|
from fontTools.ttLib import TTFont
|
|
from fontTools.varLib.instancer import instantiateVariableFont
|
|
|
|
root = Path(__file__).resolve().parents[2]
|
|
messages = '\n'.join((root / f'src/apps/product/content/{locale}-messages.ts').read_text() for locale in ['english', 'french'])
|
|
cards = (root / 'src/apps/product/content/persona-rewrite-cards.ts').read_text()
|
|
titles = ' '.join(re.findall(r'title:\s*"([^"]+)"', cards))
|
|
body = ' '.join(re.findall(r'intervention(?:Title|Effect): "([^"]+)"', messages))
|
|
body += ' '.join(re.findall(r'description:\s*"([^"]+)"', cards))
|
|
for definition in (root / 'src/apps/product/personas').glob('*/definition.ts'):
|
|
body += ' '.join(re.findall(r'label: "([^"]+)"', definition.read_text()))
|
|
with TemporaryDirectory() as temp:
|
|
for name, weight in [('rewrite', 900), ('card-body', 450)]:
|
|
font = TTFont(root / 'public/assets/fonts/Arizona/ABCArizonaSansVariable.woff2')
|
|
axes = {axis.axisTag: axis.defaultValue for axis in font['fvar'].axes}
|
|
axes['wght'] = weight
|
|
font = instantiateVariableFont(font, axes, inplace=True)
|
|
font.flavor = None
|
|
source = Path(temp) / f'arizona-{name}.ttf'
|
|
font.save(source)
|
|
subprocess.run([
|
|
'pnpm', 'exec', 'glyph', 'bake', '--input', str(source),
|
|
'--output', str(root / f'public/assets/fonts/Arizona/arizona-{name}.font.glb'),
|
|
'--unicodes', ','.join(f'U+{ord(char):04X}' for char in sorted(set(' ' + (titles if name == 'rewrite' else body)))), '--msdf', '--yes'
|
|
], cwd=root, check=True)
|