Skip to content

Commit

Permalink
code climate
Browse files Browse the repository at this point in the history
  • Loading branch information
Finii committed Dec 15, 2021
1 parent e221690 commit 77e89f0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 20 deletions.
23 changes: 10 additions & 13 deletions bin/scripts/name_parser/FontnameParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ def _make_ps_mame(self, n):
return n[:31]
return n

def _shortened_name(self):
"""Return a blank free basename-rest combination"""
if not self.use_short_families[0]
return (self.basename, self.rest)
else:
return (FontnameTools.concat(self.basename, self.rest).replace(' ', ''), '')

def set_for_windows(self, for_windows):
"""Create slightly different names, suitable for Windows use"""
self.for_windows = for_windows
Expand Down Expand Up @@ -174,12 +181,7 @@ def preferred_family(self):
if self.suppress_preferred_if_identical and len(self.weight_token) == 0:
# Do not set if identical to ID 1
return ''
(short_name, _) = self.use_short_families
name = self.basename
rest = self.rest
if short_name:
name = FontnameTools.concat(self.basename, self.rest).replace(' ', '')
rest = ''
(name, rest) = self._shortened_name()
return FontnameTools.concat(name, rest, self.other_token, self.family_suff)

def preferred_styles(self):
Expand All @@ -196,15 +198,10 @@ def preferred_styles(self):
def family(self):
"""Get the SFNT Familyname (ID 1)"""
# We use the short form of the styles to save on number of chars
(short_name, short_styles) = self.use_short_families
name = self.basename
rest = self.rest
if short_name:
name = FontnameTools.concat(self.basename, self.rest).replace(' ', '')
rest = ''
(name, rest) = self._shortened_name()
other = self.other_token
weight = self.weight_token
if short_styles:
if self.use_short_families[1]
other = FontnameTools.short_styles(other)
weight = FontnameTools.short_styles(weight)
return FontnameTools.concat(name, rest, other, self.family_suff, weight)
Expand Down
11 changes: 4 additions & 7 deletions bin/scripts/name_parser/FontnameTools.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,7 @@ def postscript_char_filter(name):
# except for the 10 characters '[', ']', '(', ')', '{', '}', '<', '>', '/', '%'
out = ""
for c in name:
if c in '[](){}<>/%':
continue
if ord(c) < 33 or ord(c) > 126:
if c in '[](){}<>/%' or ord(c) < 33 or ord(c) > 126:
continue
out += c
return out
Expand Down Expand Up @@ -276,10 +274,9 @@ def parse_font_name(name):
style_token.remove('Regular')

# Recurse to see if unmatched stuff between dashes can belong to familyname
if '-' in style:
matches = re.match(r'(\w+)-(.*)', style)
if matches:
return FontnameTools.parse_font_name(familyname + matches.group(1) + '-' + matches.group(2))
matches2 = re.match(r'(\w+)-(.*)', style)
if matches2:
return FontnameTools.parse_font_name(familyname + matches2.group(1) + '-' + matches2.group(2))

style = re.sub(r'(^|\s)\d+(\.\d+)+(\s|$)', r'\1\3', style) # Remove (free standing) version numbers
style_parts = FontnameTools.drop_empty(style.split(' '))
Expand Down

0 comments on commit 77e89f0

Please sign in to comment.