mirror of
https://github.com/ryanoasis/nerd-fonts.git
synced 2025-01-19 03:12:07 +02:00
name-parser: Generalize and shorten style-shortening
[why] We really struggle to keep the font names below the length limits. To achieve this some styles are abbreviated. The abbreviations have been taken from Noto and were initially used to mimic Noto's naming scheme. But a bit shorter names would help in some instances to produce short enough name entries. Also some styles that are used by fonts other than Noto are not abbreviated at all. [how] In document [1] Adobe gives examples of very short style abbreviations. We just implement all these. Example: 'ExtraCondensed' now becomes 'XCn' instead of the more readable but longer 'ExtCond' that Noto uses. [1] https://adobe-type-tools.github.io/font-tech-notes/pdfs/5088.FontNames.pdf Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
This commit is contained in:
parent
179dae01e0
commit
81e2e1f988
@ -87,19 +87,52 @@ class FontnameTools:
|
||||
@staticmethod
|
||||
def shorten_style_name(name):
|
||||
"""Substitude some known styles to short form"""
|
||||
# From https://adobe-type-tools.github.io/font-tech-notes/pdfs/5088.FontNames.pdf
|
||||
known_names = {
|
||||
# Chiefly from Noto
|
||||
'SemiCondensed': 'SemCond',
|
||||
'Condensed': 'Cond',
|
||||
'ExtraCondensed': 'ExtCond',
|
||||
'SemiBold': 'SemBd',
|
||||
'ExtraBold': 'ExtBd',
|
||||
'Medium': 'Med',
|
||||
'ExtraLight': 'ExtLt',
|
||||
'Black': 'Blk',
|
||||
# Weights
|
||||
'Black': 'Blk',
|
||||
'Medium': 'Md',
|
||||
'Bold': 'Bd',
|
||||
'Nord': 'Nd',
|
||||
'Book': 'Bk',
|
||||
'Poster': 'Po',
|
||||
'Demi': 'Dm', # Demi is sometimes used as a weight, sometimes as a modifier
|
||||
'Regular': 'Rg',
|
||||
'Display': 'DS',
|
||||
'Super': 'Su',
|
||||
'Heavy': 'Hv',
|
||||
'Thin': 'Th',
|
||||
'Light': 'Lt',
|
||||
# Widths
|
||||
'Compressed': 'Cm',
|
||||
'Extended': 'Ex',
|
||||
'Condensed': 'Cn',
|
||||
'Narrow': 'Nr',
|
||||
'Compact': 'Ct',
|
||||
# Slope
|
||||
'Inclined': 'Ic',
|
||||
'Oblique': 'Obl',
|
||||
'Italic': 'It',
|
||||
'Upright': 'Up',
|
||||
'Kursiv': 'Ks',
|
||||
'Sloped': 'Sl',
|
||||
}
|
||||
if name in known_names:
|
||||
return known_names[name]
|
||||
modifiers = {
|
||||
'Demi': 'Dm',
|
||||
'Ultra': 'Ult',
|
||||
'Semi': 'Sm',
|
||||
'Extra': 'X',
|
||||
}
|
||||
name_rest = name
|
||||
name_pre = ''
|
||||
for mod in modifiers:
|
||||
if not name.startswith(mod) or len(name) <= len(mod):
|
||||
continue
|
||||
name_pre = modifiers[mod]
|
||||
name_rest = name[len(mod):]
|
||||
break
|
||||
if name_rest in known_names:
|
||||
return name_pre + known_names[name_rest]
|
||||
return name
|
||||
|
||||
@staticmethod
|
||||
@ -245,6 +278,7 @@ class FontnameTools:
|
||||
'Oblique', 'Condensed', 'SemiCondensed', 'ExtraCondensed',
|
||||
'Narrow', 'SemiNarrow', 'Retina', 'Extended']
|
||||
styles = [ 'Bold', 'Italic', 'Regular', 'Normal', ]
|
||||
weights = [ w for w in weights if w not in styles ]
|
||||
# Some font specialities:
|
||||
other = [
|
||||
'-', 'Book', 'For', 'Powerline',
|
||||
|
Loading…
x
Reference in New Issue
Block a user