0

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?

Tom
  • 6,325
  • 4
  • 31
  • 55

2 Answers2

0

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

Tom
  • 6,325
  • 4
  • 31
  • 55
0

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"]},...

Tom
  • 6,325
  • 4
  • 31
  • 55