Remove "Display" named-instances from variable font

A lot of software gets confused when there are named instances that differ
only by opsz. This change removes all "Display" instances from the fvar table
and makes opsz=32 the default, so that software without automatic opsz-to-size
mapping displays the "Display" styles instead of the text styles by default.
This is the same approach taken by Apple San Francisco Pro.

Closes #519
This commit is contained in:
Rasmus Andersson 2023-05-29 10:05:47 -07:00
parent a2d84eb0ea
commit e12027c4c1
8 changed files with 157 additions and 80 deletions

View file

@ -21,6 +21,7 @@ from fontTools.ttLib.tables._m_a_x_p import maxpFormat_0_5, maxpFormat_1_0_add
from fontTools.ttLib.tables._p_o_s_t import postFormat
from fontTools.ttLib.tables.O_S_2f_2 import OS2_format_1, OS2_format_2, OS2_format_5, panoseFormat
from fontTools.ttLib.tables._m_e_t_a import table__m_e_t_a
import fontTools.ttLib.tables._t_r_a_k as t_r_a_k
# from robofab.world import world, RFont, RGlyph, OpenFont, NewFont
# from robofab.objects.objectsRF import RFont, RGlyph, OpenFont, NewFont, RContour
@ -296,7 +297,10 @@ def genFontInfo(fontpath, outputType, withGlyphs=True):
version = v[0]
if version.lower() == 'version':
version = v[1]
version = '.'.join([str(int(v)) for v in version.split('.')])
try:
version = '.'.join([str(int(v)) for v in version.split('.')])
except:
version = nameDict['version']
info['version'] = version
if outputType is not OUTPUT_TYPE_GLYPHLIST:
@ -447,11 +451,11 @@ def genFontInfo(fontpath, outputType, withGlyphs=True):
if fsSelection & 0b0000000000001000: s.append('3: OUTLINED')
if fsSelection & 0b0000000000010000: s.append('4: STRIKEOUT')
if fsSelection & 0b0000000000100000: s.append('5: BOLD')
if fsSelection & 0b0000000010000000: s.append('6: REGULAR')
if fsSelection & 0b0000000100000000: s.append('7: USE_TYPO_METRICS')
if fsSelection & 0b0000001000000000: s.append('8: WWS')
if fsSelection & 0b0000010000000000: s.append('9: OBLIQUE')
os2['fsSelection_raw'] = fsSelection
if fsSelection & 0b0000000001000000: s.append('6: REGULAR')
if fsSelection & 0b0000000010000000: s.append('7: USE_TYPO_METRICS')
if fsSelection & 0b0000000100000000: s.append('8: WWS')
if fsSelection & 0b0000001000000000: s.append('9: OBLIQUE')
os2['fsSelection_raw'] = bin(fsSelection)
os2['fsSelection'] = s
@ -464,9 +468,25 @@ def genFontInfo(fontpath, outputType, withGlyphs=True):
v.decode('utf8')
meta[k] = v
except:
meta[k] = 'data:;base64,' + b64encode(v)
meta[k] = 'data:;base64,' + b64encode(v).decode('ascii')
info['meta'] = meta
if 'trak' in tt:
# Apple-specific table, linking size to tracking values.
# https://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6trak.html
trak = {}
table = tt['trak']
for direction in ("horiz", "vert"):
dataName = direction + "Data"
trackData = getattr(table, dataName, t_r_a_k.TrackData())
td = {}
for k, tableEntry in trackData.__dict__['_map'].items():
td[k] = { "nameIndex": tableEntry.nameIndex }
for k2 in tableEntry.keys():
td[k][str(k2)] = tableEntry[k2]
trak[dataName] = td
info['trak'] = trak
# rest of tables
for tname in tt.keys():
if tname not in info: