( glyphtContext: FontContext['glyphtContext'], ttfBuffer: Uint8Array, )
| 15 | }; |
| 16 | |
| 17 | const deriveBaseName = async ( |
| 18 | glyphtContext: FontContext['glyphtContext'], |
| 19 | ttfBuffer: Uint8Array, |
| 20 | ): Promise<string> => { |
| 21 | const fontRefs = await glyphtContext.loadFonts([ttfBuffer]); |
| 22 | |
| 23 | try { |
| 24 | const [fontRef] = fontRefs; |
| 25 | |
| 26 | if (!fontRef) { |
| 27 | return 'font'; |
| 28 | } |
| 29 | |
| 30 | const family = normalizeKebabCase(fontRef.familyName); |
| 31 | const subFamily = normalizeKebabCase(fontRef.subfamilyName); |
| 32 | return `${family}-${subFamily}`; |
| 33 | } finally { |
| 34 | for (const fontRef of fontRefs) { |
| 35 | fontRef.destroy(); |
| 36 | } |
| 37 | } |
| 38 | }; |
| 39 | |
| 40 | /** |
| 41 | * Converts a font buffer into multiple webfont formats (TTF, WOFF, WOFF2). |
no test coverage detected