Skip to content

Commit

Permalink
name-parser: Extract duplicate code into function
Browse files Browse the repository at this point in the history
CodeClimate issue

Signed-off-by: Fini Jastrow <[email protected]>
  • Loading branch information
Finii committed Apr 3, 2024
1 parent 51d698c commit 9a06ee4
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions bin/scripts/name_parser/FontnameTools.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,14 +291,19 @@ def postscript_char_filter(name):
}

@staticmethod
def check_contains_weight(token):
""" Check if a token set contains a Weight specifier or just Widths or Slopes """
weight_permutations = [ m + s
def weight_permutations():
""" All the weight modifiers we know """
return [ m + s
for s in list(FontnameTools.known_weights2)
for m in list(FontnameTools.known_modifiers) + [''] if m != s
] + list(FontnameTools.known_weights1)

@staticmethod
def check_contains_weight(token):
""" Check if a token set contains a Weight specifier or just Widths or Slopes """
weights = FontnameTools.weight_permutations()
for t in token:
if t in weight_permutations:
if t in weights:
return True
return False

Expand Down Expand Up @@ -410,10 +415,7 @@ def parse_font_name(name):
for s in list(FontnameTools.known_widths)
for m in list(FontnameTools.known_modifiers) + ['']
]
weights = [ m + s
for s in list(FontnameTools.known_weights2)
for m in list(FontnameTools.known_modifiers) + [''] if m != s
] + list(FontnameTools.known_weights1) + list(FontnameTools.known_slopes)
weights = FontnameTools.weight_permutations() + list(FontnameTools.known_slopes)
weights = [ w for w in weights if w not in FontnameTools.known_styles ]
# Some font specialities:
other = [
Expand Down

0 comments on commit 9a06ee4

Please sign in to comment.