fonteditor-core
FontEditor core functions

Feature
Read and write sfnt font like ttf, woff, woff2, eot, svg, otf.
- sfnt parse
- read, write, transform fonts
- ttf (read and write)
- woff (read and write)
- woff2 (read and write)
- eot (read and write)
- svg (read and write)
- otf (only read and convert to ttf)
- ttf glyph adjust
- svg to glyph
Usage
import {Font} from 'fonteditor-core';
import fs from 'fs';
const buffer = fs.readFileSync('font.ttf');
const font = Font.create(buffer, {
type: 'ttf',
subset: [65, 66],
hinting: true,
kerning: true,
compound2simple: true,
inflate: undefined,
combinePath: false,
});
const fontObject = font.get();
console.log(Object.keys(fontObject));
const buffer = font.write({
type: 'woff',
hinting: false,
kerning: false,
writeZeroContoursGlyfData: false,
deflate: undefined,
support: {head: {}, hhea: {}}
});
fs.writeFileSync('font.woff', buffer);
font.toBase64({
type: 'ttf'
});
font.optimize()
font.compound2simple()
font.sort()
const result = font.find({
unicode: [65]
});
const result = font.find({
filter: function (glyf) {
return glyf.name === 'icon'
}
});
font.merge(font1, {
scale: 1
});
woff2
Notice: woff2 use wasm build of google woff2, before read and write woff2
, we should first call woff2.init()
.
import {Font, woff2} from 'fonteditor-core';
woff2.init().then(() => {
const font = Font.create(buffer, {
type: 'woff2'
});
const buffer = font.write({type: 'woff2'});
});
woff2.init('/assets/woff2.wasm').then(() => {
const font = Font.createEmpty();
const arrayBuffer = font.write({type: 'woff2'});
});
Demo
npm run dev
build
npm run build
test
npm run test
support
Node.js:>= 12.0
Browser: Chrome, Safari
Related
License
MIT © Fonteditor