font-patcher: Fix crash when no xavgwidth data available

[why]
When we did not collect xavgwidth data for some font and want to tweak
it the font-patcher crashes.

[how]
Check if we have a number before accessing it in the array.

[note]
This happens when font_patcher.patch() has not been called.

Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
This commit is contained in:
Fini Jastrow 2023-06-04 10:08:53 +02:00 committed by Fini
parent 7a31c67670
commit decb6d0e3d

View file

@ -6,7 +6,7 @@
from __future__ import absolute_import, print_function, unicode_literals
# Change the script version when you edit this script:
script_version = "4.3.4"
script_version = "4.3.5"
version = "3.0.1"
projectName = "Nerd Fonts"
@ -450,7 +450,7 @@ class font_patcher:
for idx in range(source_font.num_fonts):
logger.debug("Tweaking %d/%d", idx + 1, source_font.num_fonts)
xwidth_s = ''
xwidth = self.xavgwidth[idx]
xwidth = self.xavgwidth[idx] if len(self.xavgwidth) > idx else None
if isinstance(xwidth, int):
if isinstance(xwidth, bool) and xwidth:
source_font.find_table([b'OS/2'], idx)