foliojs / fontkit

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

fonkit 2.0.0 create from ArrayBuffer returns empty `variationAxes` and null parameters #330

Open sulram opened 3 months ago

sulram commented 3 months ago

I'm trying to use fontkit 2.0.0 with a variable font... The first issue was that loading the buffer directly like this:

(async () => {
  try {
    const response = await fetch('/font.woff2')
    const buffer = await response.arrayBuffer()
    font = fontkit.create(buffer)
    console.log(font, font.namedVariations, font.variationAxes)
    generateSvgText()
  } catch (err) {
      console.error(err);
  }
})();

was returning

TypeError: First argument to DataView constructor must be an ArrayBuffer
    at new DataView (<anonymous>)
    at new DecodeStream (fontkit.js?v=18e2d3af:4122:17)
    at Module.$d636bc798e7178db$export$185802fd694ee1f5 (fontkit.js?v=18e2d3af:5242:29)`

Changing this line to font = fontkit.create(new Uint8Array(buffer)) works. But that is not documented anywhere.

The problem I'm facing now is that the font comes with many null parameters, and variationAxes and namedVariations are empty objects.

I've tested with the same fonts that works on this fontkit (1.8.0) demo:

Anyone having problems with Variable Fonts when changing from 1.8.0 to 2.0.0?

Thanks in advance

markmartirosian commented 3 months ago

I see the same issue. Thank you for the workaround tip @sulram.