Export du dépôt interne d'Aleop, révision 0936ea1 (fichiers publiés identiques à e46bc12). Paquets construits depuis cette source : - Android : AAB 2026.10.0, code 4 - iPhone : archive 2026.10.0 (18) - Bureau : macOS universel build 13, Windows build 14, MSIX build 15 - Extensions Chrome, Edge et Firefox : 2026.10.0.3
114 lignes
4.2 KiB
Python
114 lignes
4.2 KiB
Python
#!/usr/bin/env python3
|
|
"""Police Loksi de l'extension navigateur, dérivée de Raleway (OFL-1.1).
|
|
|
|
fonts.py produit extensions/.cache/fonts/woff2/loksi-*.woff2
|
|
fonts.py --canari montre que la vérification refuse un Raleway non renommé
|
|
|
|
Réutilise mobile/ios/fonts.py tel quel (instances statiques, famille « Loksi »,
|
|
chiffres alignés). Sources et empreintes lues dans mobile/upstream.json.
|
|
"""
|
|
import hashlib
|
|
import json
|
|
import os
|
|
from pathlib import Path
|
|
import subprocess
|
|
import sys
|
|
|
|
ROOT = Path(__file__).resolve().parent
|
|
MOBILE = ROOT.parent / "mobile"
|
|
UPSTREAM = json.loads((MOBILE / "upstream.json").read_text())["font"]
|
|
CACHE = ROOT / ".cache" / "fonts"
|
|
VENV = ROOT / ".cache" / "fonts-venv"
|
|
PYTHON = VENV / ("Scripts/python.exe" if sys.platform == "win32" else "bin/python")
|
|
OUT = CACHE / "out"
|
|
WOFF2 = CACHE / "woff2"
|
|
# Fichier produit par mobile/ios/fonts.py vers fichier WOFF2 de l'extension.
|
|
FILES = {"Loksi-Regular": "loksi-400", "Loksi-SemiBold": "loksi-600",
|
|
"Loksi-Bold": "loksi-700", "Loksi-Italic": "loksi-400-italic"}
|
|
|
|
|
|
# fontTools date le tableau head à l'enregistrement. Sans date figée, chaque prepare donne
|
|
# des woff2 différents, donc d'autres noms hachés dans le paquet (vu le 12/10/2026 en
|
|
# reconstruisant depuis l'export public). 1759276800 : 01/10/2025 00:00 UTC.
|
|
SOURCE_DATE_EPOCH = "1759276800"
|
|
|
|
|
|
def run(cmd):
|
|
subprocess.run([str(c) for c in cmd], check=True,
|
|
env={**os.environ, "SOURCE_DATE_EPOCH": SOURCE_DATE_EPOCH})
|
|
|
|
|
|
def sha256(path):
|
|
return hashlib.sha256(path.read_bytes()).hexdigest()
|
|
|
|
|
|
def fetch():
|
|
CACHE.mkdir(parents=True, exist_ok=True)
|
|
for key, name in (("url", "Raleway-wght.ttf"), ("italic_url", "Raleway-Italic-wght.ttf")):
|
|
font = CACHE / name
|
|
if not font.exists():
|
|
run(["curl", "-fsSL", "-o", font, UPSTREAM[key]])
|
|
if sha256(font) != UPSTREAM[key.replace("url", "sha256")]:
|
|
raise RuntimeError(f"{name} incorrecte : SHA-256 différent")
|
|
|
|
|
|
def venv():
|
|
if not PYTHON.exists():
|
|
run([sys.executable, "-m", "venv", VENV])
|
|
run([PYTHON, "-m", "pip", "install", "-q", f"fonttools=={UPSTREAM['fonttools']}", "brotli"])
|
|
|
|
|
|
def instances():
|
|
run([PYTHON, MOBILE / "ios" / "fonts.py", CACHE / "Raleway-wght.ttf",
|
|
CACHE / "Raleway-Italic-wght.ttf", OUT])
|
|
|
|
|
|
def convert():
|
|
"""TTF vers WOFF2, dans le python du venv (fontTools et brotli y sont)."""
|
|
WOFF2.mkdir(parents=True, exist_ok=True)
|
|
code = ("import sys\nfrom fontTools.ttLib import TTFont\n"
|
|
"f = TTFont(sys.argv[1]); f.flavor = 'woff2'; f.save(sys.argv[2])\n")
|
|
for source, target in FILES.items():
|
|
run([PYTHON, "-c", code, OUT / f"{source}.ttf", WOFF2 / f"{target}.woff2"])
|
|
|
|
|
|
def check(paths):
|
|
"""Famille « Loksi » et aucun enregistrement de famille contenant Raleway."""
|
|
code = ("import sys\nfrom fontTools.ttLib import TTFont\n"
|
|
"for p in sys.argv[1:]:\n"
|
|
" n = TTFont(p)['name']\n"
|
|
" fam = n.getDebugName(16) or n.getDebugName(1)\n"
|
|
" tout = '|'.join(r.toUnicode() for r in n.names if r.nameID in (1, 16))\n"
|
|
" print(p, fam, tout, sep='\\t')\n")
|
|
out = subprocess.run([str(PYTHON), "-c", code, *map(str, paths)], check=True,
|
|
capture_output=True, text=True).stdout
|
|
for line in out.splitlines():
|
|
path, family, records = line.split("\t")
|
|
# Le 16 (famille typographique) prime sur le 1, qui porte « Loksi SemiBold ».
|
|
if family != "Loksi":
|
|
raise RuntimeError(f"{Path(path).name} : famille « {family} », « Loksi » attendu")
|
|
if "Raleway" in records:
|
|
raise RuntimeError(f"{Path(path).name} : Raleway dans la famille")
|
|
|
|
|
|
def main():
|
|
fetch()
|
|
venv()
|
|
if "--canari" in sys.argv:
|
|
try:
|
|
check([CACHE / "Raleway-wght.ttf"])
|
|
except RuntimeError as error:
|
|
print(f"canari OK, refus attendu : {error}")
|
|
return
|
|
sys.exit("canari raté : la vérification a accepté un Raleway d'origine")
|
|
instances()
|
|
convert()
|
|
paths = [WOFF2 / f"{name}.woff2" for name in FILES.values()]
|
|
check(paths)
|
|
for path in paths:
|
|
print(f"{path.name} : famille Loksi, {path.stat().st_size} octets")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|