Guard against a ZeroDivisonError

The code was copied from ufo2ft.
This commit is contained in:
Nikolaus Waxweiler 2023-03-01 19:52:43 +00:00
parent 13a983daaf
commit 54d6aaffb6

View File

@ -340,9 +340,10 @@ class table_O_S_2f_2(DefaultTable.DefaultTable):
"""
avg_width = 0
hmtx = ttFont.get("hmtx")
if hmtx:
widths = [m[0] for m in hmtx.metrics.values() if m[0] > 0]
avg_width = otRound(sum(widths) / len(widths))
if hmtx is not None:
widths = [width for width, _ in hmtx.metrics.values() if width > 0]
if widths:
avg_width = otRound(sum(widths) / len(widths))
self.xAvgCharWidth = avg_width
return avg_width