From 5d5533b3d255b9f3940c77d3b4c551a588d6febb Mon Sep 17 00:00:00 2001 From: jpirnay Date: Sun, 10 May 2026 17:07:08 +0200 Subject: [PATCH] fix: capture instantiateVariableFont return value (#1911) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit instantiateVariableFont() returns a *new* TTFont with the requested axes pinned; the existing call discards that return and proceeds to font.save() the original (still-variable) font. The "static instance" written to disk is therefore identical to the source variable font and the requested axis values are silently ignored. For sd-fonts.yaml entries that use the `variable: {wght: 400}` form (e.g. Bitter, Lora) this means every weight ends up rasterised from the same default-weight glyphs — bold and regular look the same. Capture the return value, and pass two diagnostically useful kwargs while we're touching the call: * updateFontNames=True — rewrite the name table so the saved TTF reports its actual weight/style instead of retaining the source variable-font names. * optimize=False — skip the gvar interpolation optimisation; fully pinning every axis drops gvar anyway, so the work would be wasted. The atomic-write scaffolding around the call is left untouched. ## Summary * **What is the goal of this PR?** (e.g., Implements the new feature for file uploading.) * **What changes are included?** ## Additional Context * Add any other information that might be helpful for the reviewer (e.g., performance implications, potential risks, specific areas to focus on). --- ### AI Usage While CrossPoint doesn't have restrictions on AI tools in contributing, please be transparent about their usage as it helps set the right context for reviewers. Did you use AI tools to help write this code? _**< YES | PARTIALLY | NO >**_ --- lib/EpdFont/scripts/build-sd-fonts.py | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/lib/EpdFont/scripts/build-sd-fonts.py b/lib/EpdFont/scripts/build-sd-fonts.py index 50bc67a8..9f29c00d 100755 --- a/lib/EpdFont/scripts/build-sd-fonts.py +++ b/lib/EpdFont/scripts/build-sd-fonts.py @@ -85,15 +85,29 @@ def extract_static_instance(source_path: Path, axes: dict, family_name: str, sty tmp_fd, tmp_name = tempfile.mkstemp(suffix=".ttf", dir=cached.parent) os.close(tmp_fd) tmp_path = Path(tmp_name) - font = TTFont(str(source_path)) + # Keep separate handles for the source variable font and the static + # instance: instantiateVariableFont with default inplace=False returns a + # *new* TTFont, so rebinding `font` would otherwise strand the source's + # file handle open until GC runs. + # + # updateFontNames=True — rewrite the name table so the saved font + # reports its weight/style accurately rather + # than retaining the variable-font names. + # optimize=False — skip the gvar interpolation optimisation; + # fully pinning every axis drops gvar anyway, + # so the work would be wasted. + source_font = TTFont(str(source_path)) try: - instantiateVariableFont(font, axes) - font.save(str(tmp_path)) + font = instantiateVariableFont(source_font, axes, updateFontNames=True, optimize=False) + try: + font.save(str(tmp_path)) + finally: + font.close() except Exception: tmp_path.unlink(missing_ok=True) raise finally: - font.close() + source_font.close() tmp_path.replace(cached) return cached