From 442576fb1ff5ebaa466e9c46ec35154c73089db8 Mon Sep 17 00:00:00 2001 From: Cosimo Lupo Date: Fri, 6 Oct 2023 10:28:58 +0100 Subject: [PATCH] Fix UnbouldLocalError and let {h,v}hea be no-op when no {v,h}mtx is present Fixes https://github.com/fonttools/fonttools/issues/3289 --- Lib/fontTools/ttLib/tables/_h_h_e_a.py | 8 +++++--- Lib/fontTools/ttLib/tables/_v_h_e_a.py | 8 +++++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/Lib/fontTools/ttLib/tables/_h_h_e_a.py b/Lib/fontTools/ttLib/tables/_h_h_e_a.py index c293fafcb..5500cf6a9 100644 --- a/Lib/fontTools/ttLib/tables/_h_h_e_a.py +++ b/Lib/fontTools/ttLib/tables/_h_h_e_a.py @@ -67,9 +67,11 @@ class table__h_h_e_a(DefaultTable.DefaultTable): return sstruct.pack(hheaFormat, self) def recalc(self, ttFont): - if "hmtx" in ttFont: - hmtxTable = ttFont["hmtx"] - self.advanceWidthMax = max(adv for adv, _ in hmtxTable.metrics.values()) + if "hmtx" not in ttFont: + return + + hmtxTable = ttFont["hmtx"] + self.advanceWidthMax = max(adv for adv, _ in hmtxTable.metrics.values()) boundsWidthDict = {} if "glyf" in ttFont: diff --git a/Lib/fontTools/ttLib/tables/_v_h_e_a.py b/Lib/fontTools/ttLib/tables/_v_h_e_a.py index 965674203..934f2f12d 100644 --- a/Lib/fontTools/ttLib/tables/_v_h_e_a.py +++ b/Lib/fontTools/ttLib/tables/_v_h_e_a.py @@ -50,9 +50,11 @@ class table__v_h_e_a(DefaultTable.DefaultTable): return sstruct.pack(vheaFormat, self) def recalc(self, ttFont): - if "vmtx" in ttFont: - vmtxTable = ttFont["vmtx"] - self.advanceHeightMax = max(adv for adv, _ in vmtxTable.metrics.values()) + if "vmtx" not in ttFont: + return + + vmtxTable = ttFont["vmtx"] + self.advanceHeightMax = max(adv for adv, _ in vmtxTable.metrics.values()) boundsHeightDict = {} if "glyf" in ttFont: