Dont return a valid weight range if a family contains only a single weight

This commit is contained in:
Kovid Goyal
2024-07-20 14:21:30 +05:30
parent 33131ff5eb
commit 25c63bf2e1

View File

@@ -100,9 +100,11 @@ wr = WeightRange()
def weight_range_for_family(family: str) -> WeightRange:
faces = all_fonts_map(True)['family_map'].get(family_name_to_key(family), ())
mini, maxi, medium, bold = wr.minimum, wr.maximum, wr.medium, wr.bold
seen_weights = set()
for face in faces:
w = face['weight']
mini, maxi = min(w, mini), max(w, maxi)
seen_weights.add(w)
s = face['style'].lower()
if not s:
continue
@@ -115,6 +117,8 @@ def weight_range_for_family(family: str) -> WeightRange:
medium = w
elif s == 'medium' and medium == wr.medium:
medium = w
if len(seen_weights) < 2:
return wr
return WeightRange(mini, maxi, medium, bold)