Files
genoffice/packages/font-metrics/tests/font-covering.test.ts
T
merrick-2002andGenOffice fe2e17403c Sync snapshot (2026-08-19) (#110)
- Improve Docs pagination, anchored-object fidelity, password protection, recovery safety, and multilingual font fallback
- Scale Sheets editing and saves for large workbooks with safer AI bulk operations, aggregation, undo, recovery, and richer visual fidelity
- Expand Slides fidelity with 3D rendering, SmartArt and WordArt improvements, pattern and texture fills, and resource cleanup
- Add AI PDF creation, text insertion, reading-position restore, safer atomic saves, and improved comments and page workflows
- Add Markdown math rendering and protect linked assets across save, conversion, and document lifecycle operations
- Read legacy DOC and PPT attachments locally and strengthen document package resource cleanup
- Document default-on usage analytics with a persistent Settings opt-out and a dedicated, tested privacy page

Co-authored-by: GenOffice <merrick-2002@users.noreply.github.com>
2026-08-19 20:14:50 +08:00

37 lines
1.3 KiB
TypeScript

import { describe, expect, it } from 'vitest'
import { findFontCovering } from '../src/font-locate'
/** Table tags of a standalone sfnt buffer */
function tableTags(font: Buffer): string[] {
const n = font.readUInt16BE(4)
const tags: string[] = []
for (let i = 0; i < n; i++) tags.push(font.toString('latin1', 12 + i * 16, 16 + i * 16))
return tags
}
describe('findFontCovering', () => {
it('returns null for empty text', () => {
expect(findFontCovering('')).toBeNull()
expect(findFontCovering('\n')).toBeNull()
})
it('finds an installed face covering plain Latin', () => {
const bytes = findFontCovering('Hello world')
if (bytes === null && process.platform === 'linux') return // fontless CI container
expect(bytes).not.toBeNull()
expect(tableTags(bytes!).some((t) => t === 'glyf' || t === 'CFF ')).toBe(true)
})
it('returns null for unassigned codepoints no real font maps', () => {
expect(findFontCovering('\u0378')).toBeNull()
})
it('never picks a color-emoji face', () => {
const bytes = findFontCovering('🦄')
if (bytes === null) return // expected on most machines: only color fonts map emoji
const tags = tableTags(bytes)
for (const color of ['sbix', 'COLR', 'CBDT', 'CBLC']) expect(tags).not.toContain(color)
})
})