import { describe, it, expect } from 'vitest'; import fs from 'node:fs/promises'; import path from 'node:path'; import opentype from 'opentype.js'; import * as fontkit from 'fontkit'; async function parseWithOpentype(fixtureName) { const buf = await fs.readFile(path.join(import.meta.dirname, '..', 'fixtures', fixtureName)); const ab = buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.byteLength); return opentype.parse(ab); } describe('font fixtures', () => { it('sample.otf parses as a CFF-flavored OpenType font', async () => { const font = await parseWithOpentype('sample.otf'); expect(font.outlinesFormat).toBe('cff'); expect(font.glyphs.length).toBe(1568); }); it('sample.ttf parses as a TrueType font with the same glyph count as sample.otf', async () => { const font = await parseWithOpentype('sample.ttf'); expect(font.outlinesFormat).toBe('truetype'); expect(font.glyphs.length).toBe(1568); }); it('sample.dfont is a valid dfont container with one embedded sfnt font', async () => { const buffer = await fs.readFile(path.join(import.meta.dirname, '..', 'fixtures', 'sample.dfont')); const dfont = fontkit.create(buffer); const sfntType = dfont.header.map.typeList.types.find((t) => t.name === 'sfnt'); expect(sfntType.refList).toHaveLength(1); }); });