Lorp / samsa

Variable font inspector
https://lorp.github.io/samsa/
Apache License 2.0
243 stars 23 forks source link

Cannot read property 'axisOrdering' of undefined #49

Closed herrernst closed 4 years ago

herrernst commented 4 years ago

Thank you for your great tool! When trying Inter variable font from here: https://github.com/rsms/inter/blob/v3.14/docs/font-files/Inter.var.otf I get this:

Uncaught TypeError: Cannot read property 'axisOrdering' of undefined
    at (index):1504
    at Array.forEach (<anonymous>)
    at SamsaFont.vfLoaded [as callback] ((index):1490)
    at SamsaFont.parse (samsa-core.js:797)
    at new SamsaFont (samsa-core.js:2560)
    at FileReader.reader.onload ((index):3382)
(anonymous) @ (index):1504
vfLoaded @ (index):1490
SamsaFont.parse @ samsa-core.js:797
SamsaFont @ samsa-core.js:2560
reader.onload @ (index):3382
load (async)
(anonymous) @ (index):3377
Lorp commented 4 years ago

What tool was used to make this font? It is broken!

The STAT fielddesignAxisCount is 0 while axisValueCount is 11, and axisCount in the fvar table is 2. You can see these values for yourself by typing these into the console:

GLOBAL.vf.tables["STAT"].data.designAxisCount
GLOBAL.vf.tables["STAT"].data.axisValueCount
GLOBAL.vf.tables["fvar"].data.axisCount

From the OpenType spec:

designAxisCount — The number of design axis records. In a font with an 'fvar' table, this value must be greater than or equal to the axisCount value in the 'fvar' table. In all fonts, must be greater than zero if axisValueCount is greater than zero.

In other words, you have to re-declare any axes that are used in STAT as “designAxes”, even if they are identical to the variation axes already defined in the fvar table. Take a look at a TTX dump of another font with a STAT table.

Also, is there any reason you have an .otf extension rather than .ttf?

herrernst commented 4 years ago

Thanks for your feedback. I have no idea how this font was produced, I have no connection to it. So because the font is buggy, you can close this IMHO.

Lorp commented 4 years ago

Followups to rsms/inter#311

rsms commented 4 years ago

fonttools and ufo2ft produced that font so you will likely see a large number of other fonts with similar setup. (This has been fixed in source Inter with a pretty elaborate patch.)

rsms commented 4 years ago

Here’s a patched version in case you want to test https://github.com/rsms/inter/files/5100101/Inter-3.15-text-f7924a233e.zip

anthrotype commented 4 years ago

fonttools always sets the STAT designAxisCount to the fvar.axisCount. Are you sure the STAT table was not post-processed with some other tool maybe?

Lorp commented 4 years ago

Thanks @rsms. I’ll happily add some error handling to Samsa if the tool(chain) that made this font is widespread. So far however it is the only font I have ever seen with this error.