Skip to content

Commit 24d971d

Browse files
committed
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>
1 parent ef669f8 commit 24d971d

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

bin/scripts/name_parser/FontnameParser.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,9 +180,18 @@ def psname(self):
180180
sub = FontnameTools.postscript_char_filter(sub)
181181
return self._make_ps_name(fam + sub, False)
182182

183-
def preferred_family(self):
183+
def preferred_family(self, short_alternative = False):
184184
"""Get the SFNT Preferred Familyname (ID 16)"""
185+
# When short_alternative we get the short named alternative needed for some Windows applications
185186
(name, rest) = self._shortened_name()
187+
other = self.other_token
188+
if short_alternative:
189+
if self.use_short_families[1]:
190+
[ other ] = FontnameTools.short_styles([ other ], self.use_short_families[2])
191+
pfn = FontnameTools.concat(name, rest, self.other_token, self.short_family_suff)
192+
if pfn == self.preferred_family(False):
193+
return ''
194+
return pfn
186195
pfn = FontnameTools.concat(name, rest, self.other_token, self.family_suff)
187196
if self.suppress_preferred_if_identical and pfn == self.family():
188197
# Do not set if identical to ID 1
@@ -231,7 +240,7 @@ def subfamily(self):
231240

232241
def ps_familyname(self):
233242
"""Get the PS Familyname"""
234-
fam = self.preferred_family()
243+
fam = self.preferred_family(False)
235244
if len(fam) < 1:
236245
fam = self.family()
237246
return self._make_ps_name(fam, True)
@@ -350,12 +359,18 @@ def rename_font(self, font):
350359
sfnt_list += [( 'English (US)', 'Fullname', self.checklen(63, 'Fullname (ID 4)', self.fullname()) )] # 4
351360
sfnt_list += [( 'English (US)', 'PostScriptName', self.checklen(63, 'PSN (ID 6)', self.psname()) )] # 6
352361

353-
p_fam = self.preferred_family()
362+
p_fam = self.preferred_family(False)
354363
if len(p_fam):
355364
sfnt_list += [( 'English (US)', 'Preferred Family', self.checklen(31, 'PrefFamily (ID 16)', p_fam) )] # 16
365+
p_fam = self.preferred_family(True)
366+
if len(p_fam):
367+
sfnt_list += [( 'English (British)', 'Preferred Family', self.checklen(31, 'PrefFamily (ID 16)', p_fam) )]
356368
p_sty = self.preferred_styles()
357369
if len(p_sty):
358370
sfnt_list += [( 'English (US)', 'Preferred Styles', self.checklen(31, 'PrefStyles (ID 17)', p_sty) )] # 17
371+
if len(p_fam):
372+
# Set only if ID16 for British has been set
373+
sfnt_list += [( 'English (British)', 'Preferred Styles', self.checklen(31, 'PrefStyles (ID 17)', p_sty) )]
359374

360375
font.sfnt_names = tuple(sfnt_list)
361376

0 commit comments

Comments
 (0)