(family: string, axes: string[], value: number[])
| 114 | } |
| 115 | |
| 116 | async function getTtfFont(family: string, axes: string[], value: number[]): Promise<ArrayBuffer> { |
| 117 | const familyParam = axes.join(",") + "@" + value.join(","); |
| 118 | |
| 119 | // Get css style sheet with user agent Mozilla/5.0 Firefox/1.0 to ensure TTF is returned |
| 120 | const cssCall = await fetch(`https://fonts.googleapis.com/css2?family=${family}:${familyParam}&display=swap`, { |
| 121 | headers: { |
| 122 | "User-Agent": "Mozilla/5.0 Firefox/1.0", |
| 123 | }, |
| 124 | }); |
| 125 | |
| 126 | const css = await cssCall.text(); |
| 127 | const ttfUrl = css.match(/url\(([^)]+)\)/)?.[1]; |
| 128 | |
| 129 | return await fetch(ttfUrl).then((res) => res.arrayBuffer()); |
| 130 | } |
no test coverage detected