feat: add font conversion dependencies and test fixtures

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
2026-07-31 12:54:32 +02:00
co-authored by Claude Sonnet 5
parent 1eb391242f
commit b61e6e2df3
7 changed files with 170 additions and 0 deletions
+32
View File
@@ -0,0 +1,32 @@
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);
});
});