I'm beginning work on an editor that allows you to play with variable fonts, however a very simple problem stumped me:
Variable fonts have variation axes which allow you modify the visual properties of the typeface. A simple one is weight, which allows you to go from light to black weight, for example.
The problem is that I don't know beforehand which variation axes are available in the font, so I can't dynamically display the correct sliders for the font.
Is there programmatic way in JavaScript to find the variation axes of variable fonts?
What have I tried you ask? Well, I've built this:
https://method.ac/font-tester/
The relevant code is this:
input.addEventListener("input", function(){
text.style["font-variation-settings"] = "'wght' " + input.value;
})
But what I'm really looking to solve is something like...
var fontAxes = [how?];
fontAxes.forEach(axis => {
var input = document.createElement("input");
// customize input
input.addEventListener("input", function(){
// change axis
})
})
wght). The code is currently in theremasteredbranch of github.com/Pomax/Font.js but will replace master in a few days when I add in the remaining parsing for the common table format and add in the text measurement functionality that the original Font.js was for.