foliojs / fontkit

An advanced font engine for Node and the browser
1.44k stars 210 forks source link

Implementation question: availableFeatures #314

Open borriglione opened 1 year ago

borriglione commented 1 year ago

Hello,

thanks for this great engine/tool.

With:

  console.log('font.availableFeatures', font.availableFeatures)
  font.availableFeatures [
    'aalt', 'c2sc', 'case', 'dnom',
    'frac', 'lnum', 'mgrk', 'numr',
    'onum', 'ordn', 'pnum', 'rlig',
    'sinf', 'smcp', 'ss01', 'ss02',
    'ss03', 'ss04', 'ss05', 'ss10',
    'ss11', 'ss12', 'ss14', 'ss15',
    'ss16', 'ss17', 'ss18', 'ss19',
    'ss20', 'subs', 'sups', 'tnum',
    'cpsp', 'kern', 'mark', 'mkmk'
  ]

I get all available features for this font. Is there a way to determine which feature has which kind of unicode characters = alternative/available glyhps?

I would like to have an output:

[
  aalt: [['U+0040', 'U+0042'],
...
  ss11: ['U+0111'],
...
]
devongovett commented 1 year ago

Not really. These things map to complicated state machines that may highly depend on context of the surrounding glyphs. Mapping this backward to generate all of the possible unicode characters that might be involved in a given feature would be quite complicated. I haven't thought deeply enough about it to say whether it's impossible, but it would definitely be hard.