name_parser: Fill short and long name as TypoFamily

[why]
This sets out to circumvent a problem with VisualStudio 2022. That
application seems to have problems with fonts when the ID16 is not a
prefix in ID1.

We have this when --makegroups >= 4, because

ID1  has the short name suffix 'NF'
ID16 has the long suffix 'Nerd Font'

These fonts can be selected in VisualStudio 2022, and the preview works
ok, but once active some replacement default font is used instead.

The problem vanishes if ID16 and ID1 have the same stem, or rather ID1
has someting added on top of ID16; but ID16 is a substring of ID1.

See more discussions in #1442

[how]
Write both forms in ID16 fields, 'NF' and 'Nerd Font' suffixes. This
works as long as the application considers all languages equal.

Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
This commit is contained in:
Fini Jastrow 2023-11-27 14:11:51 +01:00 committed by Fini
parent a5abd847e5
commit a0b080abaf
2 changed files with 21 additions and 5 deletions

View file

@ -180,9 +180,18 @@ class FontnameParser:
sub = FontnameTools.postscript_char_filter(sub) sub = FontnameTools.postscript_char_filter(sub)
return self._make_ps_name(fam + sub, False) return self._make_ps_name(fam + sub, False)
def preferred_family(self): def preferred_family(self, short_alternative = False):
"""Get the SFNT Preferred Familyname (ID 16)""" """Get the SFNT Preferred Familyname (ID 16)"""
# When short_alternative we get the short named alternative needed for some Windows applications
(name, rest) = self._shortened_name() (name, rest) = self._shortened_name()
if short_alternative:
other = self.other_token
if self.use_short_families[1]:
[ other ] = FontnameTools.short_styles([ other ], self.use_short_families[2])
pfn = FontnameTools.concat(name, rest, other, self.short_family_suff)
if pfn == self.preferred_family(False):
return ''
return pfn
pfn = FontnameTools.concat(name, rest, self.other_token, self.family_suff) pfn = FontnameTools.concat(name, rest, self.other_token, self.family_suff)
if self.suppress_preferred_if_identical and pfn == self.family(): if self.suppress_preferred_if_identical and pfn == self.family():
# Do not set if identical to ID 1 # Do not set if identical to ID 1
@ -231,7 +240,7 @@ class FontnameParser:
def ps_familyname(self): def ps_familyname(self):
"""Get the PS Familyname""" """Get the PS Familyname"""
fam = self.preferred_family() fam = self.preferred_family(False)
if len(fam) < 1: if len(fam) < 1:
fam = self.family() fam = self.family()
return self._make_ps_name(fam, True) return self._make_ps_name(fam, True)
@ -350,12 +359,18 @@ class FontnameParser:
sfnt_list += [( 'English (US)', 'Fullname', self.checklen(63, 'Fullname (ID 4)', self.fullname()) )] # 4 sfnt_list += [( 'English (US)', 'Fullname', self.checklen(63, 'Fullname (ID 4)', self.fullname()) )] # 4
sfnt_list += [( 'English (US)', 'PostScriptName', self.checklen(63, 'PSN (ID 6)', self.psname()) )] # 6 sfnt_list += [( 'English (US)', 'PostScriptName', self.checklen(63, 'PSN (ID 6)', self.psname()) )] # 6
p_fam = self.preferred_family() p_fam = self.preferred_family(False)
if len(p_fam): if len(p_fam):
sfnt_list += [( 'English (US)', 'Preferred Family', self.checklen(31, 'PrefFamily (ID 16)', p_fam) )] # 16 sfnt_list += [( 'English (US)', 'Preferred Family', self.checklen(31, 'PrefFamily (ID 16)', p_fam) )] # 16
p_fam = self.preferred_family(True)
if len(p_fam):
sfnt_list += [( 'English (British)', 'Preferred Family', self.checklen(31, 'PrefFamily (ID 16)', p_fam) )]
p_sty = self.preferred_styles() p_sty = self.preferred_styles()
if len(p_sty): if len(p_sty):
sfnt_list += [( 'English (US)', 'Preferred Styles', self.checklen(31, 'PrefStyles (ID 17)', p_sty) )] # 17 sfnt_list += [( 'English (US)', 'Preferred Styles', self.checklen(31, 'PrefStyles (ID 17)', p_sty) )] # 17
if len(p_fam):
# Set only if ID16 for British has been set
sfnt_list += [( 'English (British)', 'Preferred Styles', self.checklen(31, 'PrefStyles (ID 17)', p_sty) )]
font.sfnt_names = tuple(sfnt_list) font.sfnt_names = tuple(sfnt_list)

View file

@ -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.9.0" script_version = "4.10.0"
version = "3.1.1" version = "3.1.1"
projectName = "Nerd Fonts" projectName = "Nerd Fonts"
@ -308,7 +308,8 @@ def get_old_average_x_width(font):
def create_filename(fonts): def create_filename(fonts):
""" Determine filename from font object(s) """ """ Determine filename from font object(s) """
sfnt = { k: v for l, k, v in fonts[0].sfnt_names } # Only consider the standard (i.e. English-US) names
sfnt = { k: v for l, k, v in fonts[0].sfnt_names if l == 'English (US)' }
sfnt_pfam = sfnt.get('Preferred Family', sfnt['Family']) sfnt_pfam = sfnt.get('Preferred Family', sfnt['Family'])
sfnt_psubfam = sfnt.get('Preferred Styles', sfnt['SubFamily']) sfnt_psubfam = sfnt.get('Preferred Styles', sfnt['SubFamily'])
if len(fonts) > 1: if len(fonts) > 1: