Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix/visualstudio2022 #1442

Merged
merged 4 commits into from
Mar 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 32 additions & 12 deletions bin/scripts/name_parser/FontnameParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,16 +180,29 @@ def psname(self):
sub = FontnameTools.postscript_char_filter(sub)
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)"""
# When short_alternative we get the short named alternative needed for some Windows applications
(name, rest) = self._shortened_name()
if short_alternative:
# Try to come up with a shortened family name
# This is in principle the code from family() but without including weights
# because weights shall still end up in ID 17
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)
# Only return something if it is different to our standard behavior
if pfn == self.preferred_family(False):
return ''
return pfn
pfn = FontnameTools.concat(name, rest, self.other_token, self.family_suff)
if self.suppress_preferred_if_identical and pfn == self.family():
# Do not set if identical to ID 1
return ''
return pfn

def preferred_styles(self):
def preferred_styles(self, _ = False):
"""Get the SFNT Preferred Styles (ID 17)"""
styles = self.style_token
weights = self.weight_token
Expand Down Expand Up @@ -231,7 +244,7 @@ def subfamily(self):

def ps_familyname(self):
"""Get the PS Familyname"""
fam = self.preferred_family()
fam = self.preferred_family(False)
if len(fam) < 1:
fam = self.family()
return self._make_ps_name(fam, True)
Expand Down Expand Up @@ -296,6 +309,18 @@ def check_weights(self, font):
os2_weight, ps_weight, name_weight,
font.os2_weight, font.weight, weight))

def pfam_to_sfnt(self, name_function, entry, message):
"""Prepare SFNT entries for short and long form as two different languages"""
languages = [ 'English (US)', 'English (British)' ]
names = [ name_function(False), name_function(True) ]
ret = [ ]
for i in range(2):
if len(names[i]):
ret += [( languages[i], entry, self.checklen(31, message, names[i]) )]
else:
break
return ret

def rename_font(self, font):
"""Rename the font to include all information we found (font is fontforge font object)"""
font.fondname = None
Expand Down Expand Up @@ -339,23 +364,18 @@ def rename_font(self, font):
# back, but only as 'English (US)'. This makes sure we do not leave contradicting
# names over different languages.
for l, k, v in list(font.sfnt_names):
if not k in TO_DEL:
if not k in TO_DEL and l == 'English (US)':
sfnt_list += [( l, k, v )]
if k == 'Version' and l == 'English (US)':
if k == 'Version':
version_tag = ' ' + v.split()[-1]

sfnt_list += [( 'English (US)', 'Family', self.checklen(31, 'Family (ID 1)', self.family()) )] # 1
sfnt_list += [( 'English (US)', 'SubFamily', self.checklen(31, 'SubFamily (ID 2)', self.subfamily()) )] # 2
sfnt_list += [( 'English (US)', 'UniqueID', self.fullname() + version_tag )] # 3
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

p_fam = self.preferred_family()
if len(p_fam):
sfnt_list += [( 'English (US)', 'Preferred Family', self.checklen(31, 'PrefFamily (ID 16)', p_fam) )] # 16
p_sty = self.preferred_styles()
if len(p_sty):
sfnt_list += [( 'English (US)', 'Preferred Styles', self.checklen(31, 'PrefStyles (ID 17)', p_sty) )] # 17
sfnt_list += self.pfam_to_sfnt(self.preferred_family, 'Preferred Family', 'PrefFamily (ID 16)') # 16
sfnt_list += self.pfam_to_sfnt(self.preferred_styles, 'Preferred Styles', 'PrefStyles (ID 17)') # 17

font.sfnt_names = tuple(sfnt_list)

Expand Down
23 changes: 15 additions & 8 deletions bin/scripts/name_parser/query_name
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,14 @@ import fontforge

def get_sfnt_dict(font):
"""Extract SFNT table as nice dict"""
return { k: v for l, k, v in font.sfnt_names }
d = { }
for l, k, v in font.sfnt_names:
if k not in d:
d[k] = [ v ]
else:
d[k] += [ v ]
d = { k: v[0] if v and len(v) == 1 else tuple(v) for k, v in d.items() }
return d

###### Let's go!

Expand All @@ -38,13 +45,13 @@ for filename in sys.argv[1:]:
sfnt_full = sfnt.get('Fullname', None)
sfnt_fam = sfnt.get('Family', None)
sfnt_subfam = sfnt.get('SubFamily', None)
sfnt_pfam = sfnt.get('Preferred Family', '')
sfnt_psubfam = sfnt.get('Preferred Styles', '')
sfnt_psname = sfnt.get('PostScriptName', '')
sfnt_compat = sfnt.get('Compatible Full', '')
sfnt_cidff = sfnt.get('CID findfont Name', '')
sfnt_wfam = sfnt.get('WWS Family', '')
sfnt_wsubfam = sfnt.get('WWS Subfamily', '')
sfnt_pfam = sfnt.get('Preferred Family', '-')
sfnt_psubfam = sfnt.get('Preferred Styles', '-')
sfnt_psname = sfnt.get('PostScriptName', '-')
sfnt_compat = sfnt.get('Compatible Full', '-')
sfnt_cidff = sfnt.get('CID findfont Name', '-')
sfnt_wfam = sfnt.get('WWS Family', '-')
sfnt_wsubfam = sfnt.get('WWS Subfamily', '-')


if add_line:
Expand Down
5 changes: 3 additions & 2 deletions 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.9.0"
script_version = "4.10.0"

version = "3.1.1"
projectName = "Nerd Fonts"
Expand Down Expand Up @@ -308,7 +308,8 @@ def get_old_average_x_width(font):

def create_filename(fonts):
""" 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_psubfam = sfnt.get('Preferred Styles', sfnt['SubFamily'])
if len(fonts) > 1:
Expand Down