feat: add font conversion dependencies and test fixtures
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -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);
|
||||
});
|
||||
});
|
||||
Vendored
+15
@@ -0,0 +1,15 @@
|
||||
# Font fixture attribution
|
||||
|
||||
`sample.otf` and `sample.ttf` are the Regular weight of
|
||||
[Source Code Pro](https://github.com/adobe-fonts/source-code-pro) by Adobe,
|
||||
licensed under the SIL Open Font License 1.1 (see that repo's
|
||||
`LICENSE.md`). Both are the same font family deliberately, so tests can
|
||||
assert glyph-count fidelity (1568 glyphs) across otf/ttf/woff conversions
|
||||
of "the same font" rather than comparing unrelated files.
|
||||
|
||||
`sample.dfont` is `Tests/ttx/data/TestDFONT.dfont` from
|
||||
[fonttools/fonttools](https://github.com/fonttools/fonttools), MIT
|
||||
licensed. It is a small (3.5KB) fixture containing one real embedded
|
||||
`sfnt` TrueType resource (7 glyphs) — used to exercise this project's
|
||||
dfont-container extraction code without needing a large real-world
|
||||
font suitcase.
|
||||
Vendored
BIN
Binary file not shown.
|
After Width: | Height: | Size: 3.4 KiB |
Vendored
BIN
Binary file not shown.
Vendored
BIN
Binary file not shown.
Reference in New Issue
Block a user