| 58 | } |
| 59 | |
| 60 | async load() { |
| 61 | this.loading = true; |
| 62 | |
| 63 | const { postscriptName } = this.options; |
| 64 | |
| 65 | if (isDataUrl(this.src)) { |
| 66 | this.data = fontkit.create( |
| 67 | Buffer.from(this.src.split(',')[1], 'base64'), |
| 68 | postscriptName, |
| 69 | ); |
| 70 | } else if (BROWSER || isUrl(this.src)) { |
| 71 | const { headers, body, method = 'GET' } = this.options; |
| 72 | const data = await fetchFont(this.src, { method, body, headers }); |
| 73 | this.data = fontkit.create(data, postscriptName); |
| 74 | } else { |
| 75 | this.data = await new Promise((resolve, reject) => |
| 76 | fontkit.open(this.src, postscriptName, (err, data) => |
| 77 | err ? reject(err) : resolve(data), |
| 78 | ), |
| 79 | ); |
| 80 | } |
| 81 | |
| 82 | this.loading = false; |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | class Font { |