fonteditor-core

fonts (ttf, woff, woff2, eot, svg, otf) parse, write, transform, glyph adjust.

71 个版本
安装
npm install fonteditor-core
yarn add fonteditor-core
pnpm add fonteditor-core
bun add fonteditor-core
README

fonteditor-core

FontEditor core functions

NPM version Downloads

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
  • ESM compatibility for modern bundlers (Webpack, Rollup, Vite, Next.js, etc.)
  • TypeScript support with type definitions

Usage

// read font file
import {createFont} from 'fonteditor-core';
import fs from 'fs';

const buffer = fs.readFileSync('font.ttf');
// read font data, support format:
// - for ttf, otf, woff, woff2, support ArrayBuffer, Buffer
// - for svg, support string or Document(parsed svg)
const font = createFont(buffer, {
    // support ttf, woff, woff2, eot, otf, svg
    type: 'ttf',
    // only read `a`, `b` glyphs
    subset: [65, 66],
    // read font hinting tables, default false
    hinting: true,
    // read font kerning tables, default false
    kerning: true,
    // transform ttf compound glyph to simple
    compound2simple: true,
    // inflate function for woff
    inflate: undefined,
    // for svg path
    combinePath: false,
});
const fontObject = font.get();
console.log(Object.keys(fontObject));

/* => [ 'version',
  'numTables',
  'searchRenge',
  'entrySelector',
  'rengeShift',
  'head',
  'maxp',
  'glyf',
  'cmap',
  'name',
  'hhea',
  'post',
  'OS/2',
  'fpgm',
  'cvt',
  'prep'
]
*/

// write font file
const buffer = font.write({
    // support ttf, woff, woff2, eot, svg
    type: 'woff',
    // save font hinting tables, default false
    hinting: false,
    // save font kerning tables, default false
    kerning: false,
    // write glyf data when simple glyph has no contours, default false
    writeZeroContoursGlyfData: false,
    // deflate function for woff, eg. pako.deflate
    deflate: undefined,
    // for user to overwrite head.xMin, head.xMax, head.yMin, head.yMax, hhea etc.
    support: {head: {}, hhea: {}}
});
fs.writeFileSync('font.woff', buffer);

// to base64 str
font.toBase64({
    // support ttf, woff, woff2, eot, svg
    type: 'ttf'
});

// optimize glyphs
font.optimize()

// compound2simple
font.compound2simple()

// sort glyphs
font.sort()

// find glyphs
const result = font.find({
  unicode: [65]
});

const result = font.find({
  filter: function (glyf) {
    return glyf.name === 'icon'
  }
});

// merge another font object
font.merge(font1, {
  scale: 1
});

Modern ES Module Usage

This library supports both CommonJS and ES Modules. For detailed information on using with modern bundlers, please see ESM_USAGE.md.

// ESM import
import fonteditorCore, { createFont, woff2 } from 'fonteditor-core';

createFont(buffer, options);

woff2

Notice: woff2 use wasm build of google woff2, before read and write woff2, we should first call woff2.init().

import {createFont, woff2} from 'fonteditor-core';

// in nodejs
woff2.init().then(() => {
    // read woff2
    const font =  createFont(buffer, {
      type: 'woff2'
    });
    // write woff2
    const buffer = font.write({type: 'woff2'});
});

// in browser
woff2.init('/assets/woff2.wasm').then(() => {
    // read woff2
    const font = createFont();
    // write woff2
    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

License

MIT © Fonteditor

版本列表
2.6.3 2025-08-27
2.6.2 2025-08-01
2.6.1 2025-07-12
2.6.0 2025-07-12
2.5.4 2025-07-11
2.5.2 2025-07-11
2.5.1 2025-07-10
2.5.0 2025-07-09
2.4.1 2024-07-17
2.4.0 2024-04-17
2.3.3 2024-03-04
2.3.2 2023-11-13
2.3.1 2023-10-15
2.3.0 2023-08-31
2.2.2 2023-08-30
2.2.1 2023-08-30
2.2.0 2023-08-23
2.1.11 2023-01-06
2.1.10 2022-11-09
2.1.9 2022-10-12
2.1.8 2021-06-30
2.1.7 2021-05-17
2.1.6 2021-04-01
2.1.5 2020-11-10
2.1.4 2020-10-26
2.1.3 2020-10-14
2.1.2 2020-09-17
2.1.1 2020-03-02
2.1.0 2020-03-02
2.0.7 2019-11-09
2.0.6 2019-11-01
2.0.5 2019-10-30
2.0.4 2019-10-24
2.0.3 2019-10-19
2.0.2 2019-10-19
2.0.1 2019-10-17
1.0.5 2018-06-01
1.0.4 2018-06-01
1.0.3 2018-05-31
1.0.2 2017-10-17
1.0.1 2017-10-17
0.0.40 2017-10-17
0.0.39 2017-10-17
0.0.38 2017-10-17
0.0.37 2017-03-30
0.0.36 2017-02-21
0.0.35 2017-02-21
0.0.34 2017-02-21
0.0.33 2016-08-23
0.0.32 2016-07-07
0.0.31 2016-07-07
0.0.30 2016-07-04
0.0.26 2016-07-04
0.0.25 2016-07-04
0.0.24 2016-07-04
0.0.23 2016-06-20
0.0.22 2016-06-17
0.0.21 2016-04-17
0.0.20 2016-04-17
0.0.19 2016-04-15
0.0.17 2016-04-08
0.0.16 2016-04-06
0.0.15 2016-03-29
0.0.9 2016-03-29
0.0.8 2016-01-28
0.0.6 2016-01-05
0.0.5 2016-01-05
0.0.4 2015-12-23
0.0.3 2015-07-27
0.0.2 2015-07-24
0.0.1 2015-07-21