fix(text): bundle Inter ExtraBold font

This commit is contained in:
Danila Poyarkov 2026-05-18 00:53:29 +03:00
parent 35eb749b70
commit 1ffc61cf50
4 changed files with 30 additions and 10 deletions

Binary file not shown.

View file

@ -61,6 +61,7 @@ const BUNDLED_FONTS: Record<string, string> = {
'Inter|Medium': '/Inter-Medium.ttf',
'Inter|SemiBold': '/Inter-SemiBold.ttf',
'Inter|Bold': '/Inter-Bold.ttf',
'Inter|ExtraBold': '/Inter-ExtraBold.ttf',
'Noto Naskh Arabic|Regular': '/NotoNaskhArabic-Regular.ttf'
}
@ -236,6 +237,16 @@ export class FontManager {
const localBuffer = await this.findLocalFont(family, style)
if (localBuffer) return this.registerAndCache(family, style, localBuffer)
const bundledUrl = BUNDLED_FONTS[cacheKey]
if (bundledUrl) {
try {
const buffer = await this.fetchBundledFont(bundledUrl)
if (buffer && !isVariableFont(buffer)) return this.registerAndCache(family, style, buffer)
} catch (e) {
console.warn(`Bundled font load failed for "${family}" ${style}:`, e)
}
}
if (typeof fetch !== 'undefined') {
try {
const buffer = await this.fetchGoogleFont(family, style)
@ -248,16 +259,6 @@ export class FontManager {
}
}
const bundledUrl = BUNDLED_FONTS[cacheKey]
if (bundledUrl) {
try {
const buffer = await this.fetchBundledFont(bundledUrl)
if (buffer && !isVariableFont(buffer)) return this.registerAndCache(family, style, buffer)
} catch (e) {
console.warn(`Bundled font load failed for "${family}" ${style}:`, e)
}
}
return null
}

BIN
public/Inter-ExtraBold.ttf Normal file

Binary file not shown.

View file

@ -184,6 +184,25 @@ describe('FontManager loaded font cache', () => {
expect(recording.registrations).toEqual([{ family: 'DownloadedCache', byteLength: 16 }])
expect(writes).toBe(0)
})
test('loads bundled Inter ExtraBold without network access', async () => {
const manager = new FontManager()
const recording = createRecordingProvider()
const originalFetch = globalThis.fetch
globalThis.fetch = (() => {
throw new Error('network disabled')
}) as typeof fetch
try {
manager.attachProvider({} as CanvasKit, recording.provider)
const data = await manager.loadFont('Inter', 'ExtraBold')
expect(data?.byteLength).toBeGreaterThan(0)
expect(recording.registrations).toEqual([{ family: 'Inter', byteLength: data?.byteLength }])
} finally {
globalThis.fetch = originalFetch
}
})
})
describe('collectFontKeys', () => {