- Gate ingest rendering until required faces and script fallbacks resolve - Key CanvasKit artifacts by font registration generation and invalidate affected nodes - Load character-aware remote subsets with cumulative coverage and exact render aliases - Use BCP-47 language hints for shaping and CJK fallback order - Keep baked .fig glyphs as an exhaustion-only fallback
71 lines
2.3 KiB
TypeScript
71 lines
2.3 KiB
TypeScript
import { describe, expect, test } from 'bun:test'
|
|
|
|
import { SceneGraph } from '@open-pencil/core'
|
|
import { fontManager, textNeededFallbackScripts } from '@open-pencil/core/text'
|
|
|
|
function pageId(graph: SceneGraph): string {
|
|
return graph.getPages()[0].id
|
|
}
|
|
|
|
describe('font fallback coverage indexing', () => {
|
|
test('detects supplementary-plane Han code points', async () => {
|
|
const family = `SupplementaryHan_${Date.now()}`
|
|
const data = await Bun.file('public/Inter-Regular.ttf').arrayBuffer()
|
|
fontManager.markLoaded(family, 'Regular', data)
|
|
const graph = new SceneGraph()
|
|
const node = graph.createNode('TEXT', pageId(graph), {
|
|
text: 'A𠀀B',
|
|
fontFamily: family,
|
|
fontWeight: 400
|
|
})
|
|
|
|
expect(textNeededFallbackScripts(node)).toContain('cjk-sc')
|
|
})
|
|
|
|
test('uses BCP-47 language hints for Han fallback selection', async () => {
|
|
const family = `LanguageHint_${Date.now()}`
|
|
const data = await Bun.file('public/Inter-Regular.ttf').arrayBuffer()
|
|
fontManager.markLoaded(family, 'Regular', data)
|
|
const graph = new SceneGraph()
|
|
const node = graph.createNode('TEXT', pageId(graph), {
|
|
text: '骨骨',
|
|
textLanguage: 'ja-JP',
|
|
fontFamily: family,
|
|
fontWeight: 400,
|
|
styleRuns: [
|
|
{
|
|
start: 1,
|
|
length: 1,
|
|
style: { textLanguage: 'zh-Hant-TW' }
|
|
}
|
|
]
|
|
})
|
|
|
|
expect(textNeededFallbackScripts(node)).toEqual(['cjk-jp', 'cjk-tc'])
|
|
})
|
|
|
|
test('uses UTF-16 style-run indices after a surrogate pair', async () => {
|
|
const cjkData = await Bun.file('tests/fixtures/fonts/NotoSansSC-Regular.ttf').arrayBuffer()
|
|
const latinData = await Bun.file('public/Inter-Regular.ttf').arrayBuffer()
|
|
const cjkFamily = `CJKRunBase_${Date.now()}`
|
|
const latinFamily = `CJKRunOverride_${Date.now()}`
|
|
fontManager.markLoaded(cjkFamily, 'Regular', cjkData)
|
|
fontManager.markLoaded(latinFamily, 'Regular', latinData)
|
|
const graph = new SceneGraph()
|
|
const node = graph.createNode('TEXT', pageId(graph), {
|
|
text: '😀你',
|
|
fontFamily: cjkFamily,
|
|
fontWeight: 400,
|
|
styleRuns: [
|
|
{
|
|
start: 2,
|
|
length: 1,
|
|
style: { fontFamily: latinFamily }
|
|
}
|
|
]
|
|
})
|
|
|
|
expect(textNeededFallbackScripts(node)).toContain('cjk-sc')
|
|
})
|
|
})
|