mirror of
https://github.com/ryanoasis/nerd-fonts.git
synced 2025-01-06 21:49:40 +02:00
name-parser: Remove filename parsing code
[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>
This commit is contained in:
parent
1050729d6b
commit
b0e5a35477
@ -7,8 +7,8 @@ from FontnameTools import FontnameTools
|
|||||||
class FontnameParser:
|
class FontnameParser:
|
||||||
"""Parse a font name and generate all kinds of names"""
|
"""Parse a font name and generate all kinds of names"""
|
||||||
|
|
||||||
def __init__(self, filename, logger):
|
def __init__(self, fontname, logger):
|
||||||
"""Parse a font filename and store the results"""
|
"""Parse a fontname and store the results"""
|
||||||
self.parse_ok = False
|
self.parse_ok = False
|
||||||
self.use_short_families = (False, False, False) # ( camelcase name, short styles, aggressive )
|
self.use_short_families = (False, False, False) # ( camelcase name, short styles, aggressive )
|
||||||
self.keep_regular_in_family = None # None = auto, True, False
|
self.keep_regular_in_family = None # None = auto, True, False
|
||||||
@ -17,7 +17,7 @@ class FontnameParser:
|
|||||||
self.ps_fontname_suff = ''
|
self.ps_fontname_suff = ''
|
||||||
self.short_family_suff = ''
|
self.short_family_suff = ''
|
||||||
self.name_subst = []
|
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.basename = self._basename
|
||||||
self.rest = self._rest
|
self.rest = self._rest
|
||||||
self.add_name_substitution_table(FontnameTools.SIL_TABLE)
|
self.add_name_substitution_table(FontnameTools.SIL_TABLE)
|
||||||
|
@ -5,7 +5,7 @@ import re
|
|||||||
import sys
|
import sys
|
||||||
|
|
||||||
class FontnameTools:
|
class FontnameTools:
|
||||||
"""Deconstruct a font filename to get standardized name parts"""
|
"""Deconstruct a fontname to get standardized name parts"""
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def front_upper(word):
|
def front_upper(word):
|
||||||
@ -69,15 +69,7 @@ class FontnameTools:
|
|||||||
'text': '',
|
'text': '',
|
||||||
'ce': 'CE',
|
'ce': 'CE',
|
||||||
#'semibold': 'Demi',
|
#'semibold': 'Demi',
|
||||||
'ob': 'Oblique',
|
|
||||||
'it': 'Italic',
|
|
||||||
'i': 'Italic',
|
|
||||||
'b': 'Bold',
|
|
||||||
'normal': 'Regular',
|
'normal': 'Regular',
|
||||||
'c': 'Condensed',
|
|
||||||
'r': 'Regular',
|
|
||||||
'm': 'Medium',
|
|
||||||
'l': 'Light',
|
|
||||||
}
|
}
|
||||||
if style_name in known_names:
|
if style_name in known_names:
|
||||||
return known_names[style_name.lower()]
|
return known_names[style_name.lower()]
|
||||||
@ -306,8 +298,9 @@ class FontnameTools:
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _parse_simple_font_name(name):
|
def _parse_simple_font_name(name):
|
||||||
"""Parse a filename that does not follow the 'FontFamilyName-FontStyle' pattern"""
|
"""Parse a fontname that does not follow the 'FontFamilyName-FontStyle' pattern"""
|
||||||
# No dash in name, maybe we have blanc separated filename?
|
# This is the usual case, because the font-patcher usually uses the fullname and
|
||||||
|
# not the PS name
|
||||||
if ' ' in name:
|
if ' ' in name:
|
||||||
return FontnameTools.parse_font_name(name.replace(' ', '-'))
|
return FontnameTools.parse_font_name(name.replace(' ', '-'))
|
||||||
# Do we have a number-name boundary?
|
# Do we have a number-name boundary?
|
||||||
@ -322,7 +315,8 @@ class FontnameTools:
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def parse_font_name(name):
|
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(r'\bsemi-condensed\b', 'SemiCondensed', name, 1, re.IGNORECASE) # Just for "3270 Semi-Condensed" :-/
|
||||||
name = re.sub('[_\s]+', ' ', name)
|
name = re.sub('[_\s]+', ' ', name)
|
||||||
matches = re.match(r'([^-]+)(?:-(.*))?', name)
|
matches = re.match(r'([^-]+)(?:-(.*))?', name)
|
||||||
@ -353,19 +347,9 @@ class FontnameTools:
|
|||||||
r'(?:uni-)?1[14]', # GohuFont uni
|
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, weight_token ) = FontnameTools.get_name_token(style, weights)
|
||||||
( style, style_token ) = FontnameTools.get_name_token(style, styles)
|
( style, style_token ) = FontnameTools.get_name_token(style, styles)
|
||||||
( style, other_token ) = FontnameTools.get_name_token(style, other, True)
|
( 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:
|
while 'Regular' in style_token and len(style_token) > 1:
|
||||||
# Correct situation where "Regular" and something else is given
|
# Correct situation where "Regular" and something else is given
|
||||||
style_token.remove('Regular')
|
style_token.remove('Regular')
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
from __future__ import absolute_import, print_function, unicode_literals
|
from __future__ import absolute_import, print_function, unicode_literals
|
||||||
|
|
||||||
# Change the script version when you edit this script:
|
# Change the script version when you edit this script:
|
||||||
script_version = "4.3.2"
|
script_version = "4.3.3"
|
||||||
|
|
||||||
version = "3.0.1"
|
version = "3.0.1"
|
||||||
projectName = "Nerd Fonts"
|
projectName = "Nerd Fonts"
|
||||||
|
Loading…
Reference in New Issue
Block a user