fixes name table entries for static files, re issue #519

This commit is contained in:
Rasmus Andersson 2023-06-08 10:10:47 -07:00
parent 9e6dd3d7fb
commit d88ab4204a
5 changed files with 35 additions and 5 deletions

View file

@ -1,7 +1,14 @@
import sys
import sys, re
import defcon
WHITESPACE_RE = re.compile(r'\s+')
def rmspace(s):
return WHITESPACE_RE.sub('', s)
# See https://github.com/rsms/inter/issues/508
# TODO: Remove when https://github.com/googlefonts/glyphsLib/issues/821 is fixed
def fix_fractional_advance_width(ufo):
@ -19,6 +26,20 @@ def main(argv):
ufo_file = argv[1]
ufo = defcon.Font(ufo_file)
fix_fractional_advance_width(ufo)
# fix legacy names to make style linking work in MS Windows
familyName = ufo.info.familyName # e.g. "Inter Display"
styleName = ufo.info.styleName # e.g. "ExtraBold"
ufo.info.openTypeNamePreferredFamilyName = familyName
ufo.info.openTypeNamePreferredSubfamilyName = styleName
ufo.info.familyName = familyName + ' ' + styleName
ufo.info.styleName = 'Regular' if styleName.find('Italic') == -1 else 'Italic'
# must also set these explicitly to avoid PostScript names like "Inter-ThinRegular":
# "postscriptFontName" maps to name ID 6 "postscriptName"
ufo.info.postscriptFontName = rmspace(familyName) + '-' + rmspace(styleName)
ufo.save(ufo_file)