fix(text): bundle Inter ExtraBold font
This commit is contained in:
parent
35eb749b70
commit
1ffc61cf50
BIN
packages/core/assets/Inter-ExtraBold.ttf
Normal file
BIN
packages/core/assets/Inter-ExtraBold.ttf
Normal file
Binary file not shown.
|
|
@ -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
BIN
public/Inter-ExtraBold.ttf
Normal file
Binary file not shown.
|
|
@ -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', () => {
|
||||
|
|
|
|||
Loading…
Reference in a new issue