Skip to content

Commit

Permalink
name-parser: Remove filename parsing code
Browse files Browse the repository at this point in the history
[why]
Patching CartographCF-Bold.ttf creates this naming:

    Family (ID 1)      : CartographF Nerd Font Condensed
    SubFamily (ID 2)   : Bold
    Fullname (ID 4)    : CartographF Nerd Font Condensed Bold
    PSN (ID 6)         : CartographFNF-CondensedBold
    PrefFamily (ID 16) : CartographF Nerd Font
    PrefStyles (ID 17) : Condensed Bold

    CartographF Nerd Font Condensed Bold
    \===> 'CartographFNerdFont-CondensedBold.ttf'

[how]
The font-patcher historically used the file name of the to-be-patched
font to come up with the new name. When the FontnameParser has been
developed that mechanics has been copied at least for fallback. The
earliest tests compared old and new naming with all the filenames.

Later, when the FontnameParser has been used to really apply name
changes it has always based the parsing on the Fullname or the PSname,
because they really hold the information (or at least should hold);
while the filename might be completely random.

Still code the dealt with specific problems in FILEnames prevailed. The
Ubuntu font for example has a file name like 'Ubuntu-C.ttf', and we
needed to convert the C to Condensed.

As that requirement vanished we can drop all the code that has been
added specifically only for parsing the Ubuntu font filenames.

Side note: USUALLY font filenames should be roughly equal to the PSname.

Fixes: #1258

Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
  • Loading branch information
Finii committed May 25, 2023
1 parent 1050729 commit 2e7e8b5
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 26 deletions.
6 changes: 3 additions & 3 deletions bin/scripts/name_parser/FontnameParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
class FontnameParser:
"""Parse a font name and generate all kinds of names"""

def __init__(self, filename, logger):
"""Parse a font filename and store the results"""
def __init__(self, fontname, logger):
"""Parse a fontname and store the results"""
self.parse_ok = False
self.use_short_families = (False, False, False) # ( camelcase name, short styles, aggressive )
self.keep_regular_in_family = None # None = auto, True, False
Expand All @@ -17,7 +17,7 @@ def __init__(self, filename, logger):
self.ps_fontname_suff = ''
self.short_family_suff = ''
self.name_subst = []
[ self.parse_ok, self._basename, self.weight_token, self.style_token, self.other_token, self._rest ] = FontnameTools.parse_font_name(filename)
[ self.parse_ok, self._basename, self.weight_token, self.style_token, self.other_token, self._rest ] = FontnameTools.parse_font_name(fontname)
self.basename = self._basename
self.rest = self._rest
self.add_name_substitution_table(FontnameTools.SIL_TABLE)
Expand Down
28 changes: 6 additions & 22 deletions bin/scripts/name_parser/FontnameTools.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import sys

class FontnameTools:
"""Deconstruct a font filename to get standardized name parts"""
"""Deconstruct a fontname to get standardized name parts"""

@staticmethod
def front_upper(word):
Expand Down Expand Up @@ -69,15 +69,7 @@ def unify_style_names(style_name):
'text': '',
'ce': 'CE',
#'semibold': 'Demi',
'ob': 'Oblique',
'it': 'Italic',
'i': 'Italic',
'b': 'Bold',
'normal': 'Regular',
'c': 'Condensed',
'r': 'Regular',
'm': 'Medium',
'l': 'Light',
}
if style_name in known_names:
return known_names[style_name.lower()]
Expand Down Expand Up @@ -306,8 +298,9 @@ def is_keep_regular(basename):

@staticmethod
def _parse_simple_font_name(name):
"""Parse a filename that does not follow the 'FontFamilyName-FontStyle' pattern"""
# No dash in name, maybe we have blanc separated filename?
"""Parse a fontname that does not follow the 'FontFamilyName-FontStyle' pattern"""
# This is the usual case, because the font-patcher usually uses the fullname and
# not the PS name
if ' ' in name:
return FontnameTools.parse_font_name(name.replace(' ', '-'))
# Do we have a number-name boundary?
Expand All @@ -322,7 +315,8 @@ def _parse_simple_font_name(name):

@staticmethod
def parse_font_name(name):
"""Expects a filename following the 'FontFamilyName-FontStyle' pattern and returns ... parts"""
"""Expects a fontname following the 'FontFamilyName-FontStyle' pattern and returns ... parts"""
# This could parse filenames in the beginning but that was never used in production; code removed with this commit
name = re.sub(r'\bsemi-condensed\b', 'SemiCondensed', name, 1, re.IGNORECASE) # Just for "3270 Semi-Condensed" :-/
name = re.sub('[_\s]+', ' ', name)
matches = re.match(r'([^-]+)(?:-(.*))?', name)
Expand Down Expand Up @@ -353,19 +347,9 @@ def parse_font_name(name):
r'(?:uni-)?1[14]', # GohuFont uni
]

# Sometimes used abbreviations
weight_abbrevs = [ 'ob', 'c', 'm', 'l', ]
style_abbrevs = [ 'it', 'r', 'b', 'i', ]

( style, weight_token ) = FontnameTools.get_name_token(style, weights)
( style, style_token ) = FontnameTools.get_name_token(style, styles)
( style, other_token ) = FontnameTools.get_name_token(style, other, True)
if (len(style) < 4
and style.lower() != 'pro'): # Prevent 'r' of Pro to be detected as style_abbrev
( style, weight_token_abbrevs ) = FontnameTools.get_name_token(style, weight_abbrevs)
( style, style_token_abbrevs ) = FontnameTools.get_name_token(style, style_abbrevs)
weight_token += weight_token_abbrevs
style_token += style_token_abbrevs
while 'Regular' in style_token and len(style_token) > 1:
# Correct situation where "Regular" and something else is given
style_token.remove('Regular')
Expand Down
2 changes: 1 addition & 1 deletion font-patcher
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from __future__ import absolute_import, print_function, unicode_literals

# Change the script version when you edit this script:
script_version = "4.3.2"
script_version = "4.3.3"

version = "3.0.1"
projectName = "Nerd Fonts"
Expand Down

0 comments on commit 2e7e8b5

Please sign in to comment.