mirror of
https://github.com/ryanoasis/nerd-fonts.git
synced 2024-09-19 09:51:48 +02:00
font-patcher: Improve weight checking
[why] When the font does not have a PSweight string the font-patcher bugs. [how] Rewrite the code to be more robust against unexpected weight values. Also make detected problems non-fatal. Reported-by: František Hanzlík <frantisek_hanzlik@protonmail.com> Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
This commit is contained in:
parent
3fab6616e5
commit
809101da32
3 changed files with 9 additions and 5 deletions
|
@ -283,10 +283,14 @@ class FontnameParser:
|
||||||
os2_weight = font.os2_weight
|
os2_weight = font.os2_weight
|
||||||
ps_weight = FontnameTools.weight_string_to_number(font.weight)
|
ps_weight = FontnameTools.weight_string_to_number(font.weight)
|
||||||
name_weight = FontnameTools.weight_string_to_number(weight)
|
name_weight = FontnameTools.weight_string_to_number(weight)
|
||||||
|
weightproblem = False
|
||||||
|
if ps_weight is None:
|
||||||
|
self.logger.warn('Can not parse PS-weight: {}'.format(restored_weight_token))
|
||||||
|
weightproblem = True
|
||||||
if name_weight is None:
|
if name_weight is None:
|
||||||
self.logger.error('Can not parse name for weight: {}'.format(restored_weight_token))
|
self.logger.warn('Can not parse name for weight: {}'.format(restored_weight_token))
|
||||||
return
|
weightproblem = True
|
||||||
if abs(os2_weight - ps_weight) > 50 or abs(os2_weight - name_weight) > 50:
|
if weightproblem or abs(os2_weight - ps_weight) > 50 or abs(os2_weight - name_weight) > 50:
|
||||||
self.logger.warning('Possible problem with the weight metadata detected, check with --debug')
|
self.logger.warning('Possible problem with the weight metadata detected, check with --debug')
|
||||||
self.logger.debug('Weight approximations: OS2/PS/Name: {}/{}/{} (from {}/\'{}\'/\'{}\')'.format(
|
self.logger.debug('Weight approximations: OS2/PS/Name: {}/{}/{} (from {}/\'{}\'/\'{}\')'.format(
|
||||||
os2_weight, ps_weight, name_weight,
|
os2_weight, ps_weight, name_weight,
|
||||||
|
|
|
@ -287,7 +287,7 @@ class FontnameTools:
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def weight_string_to_number(w):
|
def weight_string_to_number(w):
|
||||||
""" Convert a common string approximation to a PS/2 weight value """
|
""" Convert a common string approximation to a PS/2 weight value """
|
||||||
if not len(w):
|
if not isinstance(w, str) or len(w) < 1:
|
||||||
return 400
|
return 400
|
||||||
for num, strs in FontnameTools.equivalent_weights.items():
|
for num, strs in FontnameTools.equivalent_weights.items():
|
||||||
if w.lower() in strs:
|
if w.lower() in strs:
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
from __future__ import absolute_import, print_function, unicode_literals
|
from __future__ import absolute_import, print_function, unicode_literals
|
||||||
|
|
||||||
# Change the script version when you edit this script:
|
# Change the script version when you edit this script:
|
||||||
script_version = "4.5.2"
|
script_version = "4.5.3"
|
||||||
|
|
||||||
version = "3.0.2"
|
version = "3.0.2"
|
||||||
projectName = "Nerd Fonts"
|
projectName = "Nerd Fonts"
|
||||||
|
|
Loading…
Reference in a new issue