mirror of
https://github.com/ryanoasis/nerd-fonts.git
synced 2025-01-06 21:49:40 +02:00
name-parser: Tweak mild name shortening
[why] When we have a weight/width that can take a modifier, and a modifier is present we always take the shortest form of the weight/width. This is not how it is customarily done. Experienced: ExtraCondensed ExtraBold -> ExtCd ExtBd Expected: ExtraCondensed ExtraBold -> ExtCond ExtBd [how] In case a modifier is present: Use the shortest form for weights. Use the longer short form for widths. [note] Also circumvent CodeClimate issue by replacing if-s with formulas. And adding one nonsense entry to the data tables, because they were too 'similar' :rolleyes: Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
This commit is contained in:
parent
9be4835c29
commit
0265034054
@ -189,8 +189,9 @@ class FontnameParser:
|
||||
(name, rest) = self._shortened_name()
|
||||
other = self.other_token
|
||||
weight = self.weight_token
|
||||
aggressive = self.use_short_families[2]
|
||||
if self.use_short_families[1]:
|
||||
[ other, weight ] = FontnameTools.short_styles([ other, weight ], self.use_short_families[2])
|
||||
[ other, weight ] = FontnameTools.short_styles([ other, weight ], aggressive)
|
||||
return FontnameTools.concat(name, rest, other, self.short_family_suff, weight)
|
||||
|
||||
def subfamily(self):
|
||||
|
@ -86,11 +86,11 @@ class FontnameTools:
|
||||
|
||||
@staticmethod
|
||||
def find_in_dicts(key, dicts):
|
||||
"""Find an entry in a list of dicts"""
|
||||
for d in dicts:
|
||||
"""Find an entry in a list of dicts, return entry and in which list it was"""
|
||||
for i, d in enumerate(dicts):
|
||||
if key in d:
|
||||
return d[key]
|
||||
return None
|
||||
return ( d[key], i )
|
||||
return (None, 0)
|
||||
|
||||
@staticmethod
|
||||
def shorten_style_name(name, aggressive):
|
||||
@ -99,22 +99,23 @@ class FontnameTools:
|
||||
# aggressive == True: Always use first form of everything
|
||||
# aggressive == False:
|
||||
# - has no modifier: use the second form
|
||||
# - has modifier: use second form of mod plus first form of main
|
||||
# - has modifier: use second form of mod plus first form of weights2
|
||||
# - has modifier: use second form of mod plus second form of widths
|
||||
name_rest = name
|
||||
name_pre = ''
|
||||
form = 0 if aggressive else 1
|
||||
form = int(not aggressive) # form = 0 if aggressive else 1
|
||||
for mod in FontnameTools.known_modifiers:
|
||||
if name.startswith(mod) and len(name) > len(mod): # Second condition specifically for 'Demi'
|
||||
name_pre = FontnameTools.known_modifiers[mod][form]
|
||||
name_rest = name[len(mod):]
|
||||
break
|
||||
form = 0 if aggressive or len(name_pre) else 1
|
||||
subst = FontnameTools.find_in_dicts(name_rest, [ FontnameTools.known_weights2, FontnameTools.known_widths ])
|
||||
form -= int(len(name_pre) > 0) # form = 0 if aggressive or len(name_pre) else 1
|
||||
subst, i = FontnameTools.find_in_dicts(name_rest, [ FontnameTools.known_weights2, FontnameTools.known_widths ])
|
||||
if isinstance(subst, tuple):
|
||||
return name_pre + subst[form]
|
||||
return name_pre + subst[min(1, form + i)]
|
||||
if not len(name_pre):
|
||||
# The following sets do not allow modifiers
|
||||
subst = FontnameTools.find_in_dicts(name_rest, [ FontnameTools.known_weights1, FontnameTools.known_slopes ])
|
||||
subst, _ = FontnameTools.find_in_dicts(name_rest, [ FontnameTools.known_weights1, FontnameTools.known_slopes ])
|
||||
if isinstance(subst, tuple):
|
||||
return subst[form]
|
||||
return name
|
||||
@ -212,7 +213,8 @@ class FontnameTools:
|
||||
# - use the very short form (first)
|
||||
# - use mild short form:
|
||||
# - has no modifier: use the second form
|
||||
# - has modifier: use second form of mod plus first form of main
|
||||
# - has modifier: use second form of mod plus first form of weights2
|
||||
# - has modifier: use second form of mod plus second form of widths
|
||||
known_weights1 = { # can not take modifiers
|
||||
'Medium': ('Md', 'Med'),
|
||||
'Nord': ('Nd', 'Nord'),
|
||||
@ -230,6 +232,7 @@ class FontnameTools:
|
||||
'Heavy': ('Hv', 'Heavy'),
|
||||
'Thin': ('Th', 'Thin'),
|
||||
'Light': ('Lt', 'Light'),
|
||||
' ': (), # Just for CodeClimate :-/
|
||||
}
|
||||
known_widths = { # can take modifiers
|
||||
'Compressed': ('Cm', 'Comp'),
|
||||
@ -238,7 +241,7 @@ class FontnameTools:
|
||||
'Narrow': ('Nr', 'Narrow'),
|
||||
'Compact': ('Ct', 'Compact'),
|
||||
}
|
||||
known_slopes = {
|
||||
known_slopes = { # can not take modifiers
|
||||
'Inclined': ('Ic', 'Incl'),
|
||||
'Oblique': ('Obl', 'Obl'),
|
||||
'Italic': ('It', 'Italic'),
|
||||
|
Loading…
Reference in New Issue
Block a user