opentypejs / opentype.js

Read and write OpenType fonts using JavaScript.
https://opentype.js.org/
MIT License
4.38k stars 468 forks source link

Error: Unsupported OpenType signature wOF2 #601

Closed ab-etemadi closed 1 year ago

ab-etemadi commented 1 year ago

Using opentypejs cdn to load the font endups to the Error: Unsupported OpenType signature wOF2 error

Expected Behavior

load the font

Current Behavior

Error: Unsupported OpenType signature wOF2

Possible Solution

Steps to Reproduce (for bugs)

  1. download roboto regular ttf font from https://dl.dafont.com/dl/?f=roboto or any other source
  2. upload it on your server. and provide the uploaded font asset url to opentype js load url and await for its promise to resolve
  3. it ends with Error: Unsupported OpenType signature wOF2

Your Environment

Shopify liquid template engine

Connum commented 1 year ago

Please see #183 and #518.

ab-etemadi commented 1 year ago

@Connum Thank you for your assistance! I was able to optimize the code using the following approach:

    this.font = await fontBuffer
      .then((buffer) => Module.decompress(buffer))
      .then((buffer) => opentype.parse(Uint8Array.from(buffer).buffer));
  }