In a JS environment I want to list the a font's 'font features' so that I can set them with font-feature-settings css.
Is there a better alternative than opentype.js?
In a JS environment I want to list the a font's 'font features' so that I can set them with font-feature-settings css.
Is there a better alternative than opentype.js?
Font features can be extracted from the GSUB
table.
Here is a simple example listing the font feature names from
import opentype from 'opentype.js'
async function listFontFeatures()
{
const font = await opentype.load("C:\\Windows\\Fonts\\arial.ttf");
const featureNames = [...Array.from(new Set(font.tables.gsub.features.map((f: any) => f.tag)))]
for (const name of featureNames)
console.log(name);
}
listFontFeatures();
This displays the 4 char font feature codes :
c2sc calt ccmp dlig dnom fina frac init isol liga lnum locl medi numr onum
Human readable names can be looked up from here
I've created an opentype.features.js npm package, which does more than opentype.js, with respect to listing font features.
Along with listing the feature tags, it also lists the feature descriptions and option labels.
Example output:
...,{"tag":"cv13","description":"Cap B-hook alt","options":["Lowercase style"]},...