Skip to content

Commit

Permalink
name-parser: Unify abbreviations in family names
Browse files Browse the repository at this point in the history
[why]
Because the newer Preferred/Typographic names ID 16 and ID 17 have not
a very demanding length limit we add the long form of the name
addendum (i.e. Nerd Font, Nerd Font Mono, Nerd Font Propo).

In the more restricted old names ID 1 and ID 2 we use the short forms
(i.e. NF, NFM, NFP).

This seems to be problematic with Visual Studio (Community) 2022 and the
fonts can be selected but are not really used.

The Postscript family name is never shortened which seems to be of no
consequence, but still is different than the other.

[how]
When creating the Preferred/Typographic Family (ID 16) we check the
shortening mode first and abbreviate the parts as needed and alike ID 1.

This will also change the filenames, because they base on the SFNT
table. We can not change that without changing the whole mechanism.

[note]
Also add new tool that lists all names of fonts, including the
Postscript ones.

Fixes: #1242

Signed-off-by: Fini Jastrow <[email protected]>
  • Loading branch information
Finii committed Nov 11, 2023
1 parent 4579b49 commit d3ee35d
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 1 deletion.
7 changes: 6 additions & 1 deletion bin/scripts/name_parser/FontnameParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,12 @@ def psname(self):
def preferred_family(self):
"""Get the SFNT Preferred Familyname (ID 16)"""
(name, rest) = self._shortened_name()
pfn = FontnameTools.concat(name, rest, self.other_token, self.family_suff)
other = self.other_token
weights = self.weight_token
aggressive = self.use_short_families[2]
if self.use_short_families[1]:
[ other, weights ] = FontnameTools.short_styles([ other, weights ], aggressive)
pfn = FontnameTools.concat(name, rest, other, self.short_family_suff)
if self.suppress_preferred_if_identical and pfn == self.family():
# Do not set if identical to ID 1
return ''
Expand Down
60 changes: 60 additions & 0 deletions bin/scripts/name_parser/query_name
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#!/usr/bin/env python3
# coding=utf8
#
# Usually called via
# $ fontforge query_name fontfile.tff 2>/dev/null

import sys
import os.path
import fontforge

###### Some helpers

def get_sfnt_dict(font):
"""Extract SFNT table as nice dict"""
return { k: v for l, k, v in font.sfnt_names }

###### Let's go!

if len(sys.argv) < 2:
print('Usage: {} font_name [font_name ...]\n'.format(sys.argv[0]))
sys.exit(1)

print('Examining {} font files'.format(len(sys.argv) - 1))
add_line = False

for filename in sys.argv[1:]:
fullfile = os.path.basename(filename)
fname = os.path.splitext(fullfile)[0]

font = fontforge.open(filename, 1)
sfnt = get_sfnt_dict(font)
psname = font.fontname
aname = font.fondname
full = font.fullname
fam = font.familyname
font.close()

sfnt_full = sfnt['Fullname']
sfnt_fam = sfnt['Family']
sfnt_subfam = sfnt['SubFamily']
sfnt_pfam = sfnt['Preferred Family'] if 'Preferred Family' in sfnt else ''
sfnt_psubfam = sfnt['Preferred Styles'] if 'Preferred Styles' in sfnt else ''
sfnt_psname = sfnt['PostScriptName'] if 'PostScriptName' in sfnt else ''

if add_line:
print()
else:
add_line = True

print('======== {} ========'.format(fname))
print('SFNT Fullname ID 4 {}'.format(sfnt_full))
print('SFNT Family ID 1 {}'.format(sfnt_fam))
print('SFNT SubFamily ID 2 {}'.format(sfnt_subfam))
print('SFNT Pref Family ID 16 {}'.format(sfnt_pfam))
print('SFNT Pref Styles ID 17 {}'.format(sfnt_psubfam))
print('SFNT PS Name ID 6 {}'.format(sfnt_psname))
print('PS fontname {}'.format(psname))
print('PS fullname {}'.format(full))
print('PS familyname {}'.format(fam))
print('fondname {}'.format(aname))

0 comments on commit d3ee35d

Please sign in to comment.