oficina / docs Public

Vendor the fonts the same way whatever else is in the venv

Branch review finding 8: following the documented steps rebuilt 52 files
differently from the committed ones. That was every preview and every
instanced family. The cause is uharfbuzz. When it is importable (and
scripts/harfbuzz-golden.py needs it, in the same venv), fontTools
serialises GSUB and GPOS with HarfBuzz's repacker instead of its own.
The committed files were built before uharfbuzz was installed.

vendor-fonts.py now always uses fontTools' own serialiser. It rebuilds
the committed files byte for byte, with or without uharfbuzz installed.
The failing case was seen first: 52 differences with uharfbuzz present,
none in a fresh venv without it. --check rebuilds into a scratch copy
and fails on any file that differs. The documented environment now names
its Python (3.14) too. No font file changes, so the shared files the
native branch builds on stay as they are.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Paul Campbell pushed by paul@keymail.dev 6cd43a4988119582010e66e503efed654a729f6b parent b403cc3
1 file changed, +44 −3
  • scripts/vendor-fonts.py +44 −3
diff --git a/scripts/vendor-fonts.py b/scripts/vendor-fonts.py
index dd86657..ffb1569 100644
--- a/scripts/vendor-fonts.py
+++ b/scripts/vendor-fonts.py
@@ -7,11 +7,22 @@ file (what the browser loads), and one tiny name-only woff2 for the font
picker. The woff2 is a lossless wrapper, so the screen and the PDF use
the same font program.
-Run it with fontTools and brotli, outside the repo's own Python:
+Run it with fontTools and brotli, outside the repo's own Python (3.14):
python3 -m venv /tmp/fontvenv
/tmp/fontvenv/bin/pip install fonttools==4.67.0 brotli==1.2.1
/tmp/fontvenv/bin/python -I scripts/vendor-fonts.py
+ /tmp/fontvenv/bin/python -I scripts/vendor-fonts.py --check
+
+--check rebuilds everything into a scratch copy and fails unless every
+file is byte-identical to the committed one. Run it after any change
+here, to fonts.json or to sources.json.
+
+The output is byte-reproducible. One trap: when uharfbuzz is importable
+(scripts/harfbuzz-golden.py needs it, and it may share this venv),
+fontTools serialises GSUB and GPOS with HarfBuzz's repacker instead of
+its own, and every instanced font and preview comes out different. This
+script always uses fontTools' own serialiser.
Downloads are cached under $DOCS_FONT_CACHE (default /tmp/docs-font-cache),
one directory per URL, and checked against internal/fonts/files/SOURCES.lock.
@@ -37,12 +48,19 @@ import zipfile
from fontTools import subset
from fontTools.ttLib import TTFont
+from fontTools.ttLib.tables import otBase
from fontTools.varLib import instancer
+# fontTools' own GSUB/GPOS serialiser, whether or not uharfbuzz happens to
+# be installed: the repacker's layout differs, and the output must not
+# depend on what else is in the venv.
+otBase.have_uharfbuzz = False
+
ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
MANIFEST = os.path.join(ROOT, "internal", "fonts", "fonts.json")
SOURCES = os.path.join(ROOT, "internal", "fonts", "sources.json")
-FILES = os.path.join(ROOT, "internal", "fonts", "files")
+COMMITTED = os.path.join(ROOT, "internal", "fonts", "files")
+FILES = COMMITTED
LOCK = os.path.join(FILES, "SOURCES.lock")
CACHE = os.environ.get("DOCS_FONT_CACHE", "/tmp/docs-font-cache")
@@ -194,5 +212,28 @@ def main():
print(f"{k}: {v / 1e6:.2f} MB", file=sys.stderr)
+def check():
+ """Rebuild into a scratch copy of files/ and compare byte for byte."""
+ import filecmp
+ import tempfile
+
+ global FILES, LOCK
+ with tempfile.TemporaryDirectory() as scratch:
+ FILES = os.path.join(scratch, "files")
+ shutil.copytree(COMMITTED, FILES)
+ LOCK = os.path.join(FILES, "SOURCES.lock")
+ main()
+ differ = []
+ for dirpath, _, names in os.walk(FILES):
+ for n in names:
+ built = os.path.join(dirpath, n)
+ rel = os.path.relpath(built, FILES)
+ if not filecmp.cmp(built, os.path.join(COMMITTED, rel), shallow=False):
+ differ.append(rel)
+ if differ:
+ sys.exit("vendor-fonts: these differ from the committed files:\n " + "\n ".join(sorted(differ)))
+ print("vendor-fonts: every file matches", file=sys.stderr)
+
+
if __name__ == "__main__":
- main()
+ check() if "--check" in sys.argv[1:] else main()