# fonteditor-core

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

Latest version **2.6.3** (published 2025-08-27) · 0 weekly downloads

## Install

```sh
npm install fonteditor-core
pnpm add fonteditor-core
yarn add fonteditor-core
bun add fonteditor-core
```

## Health

**Score 50/100 (C)** — status: stable.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: stale.

## Facts

| | |
|---|---|
| Version | 2.6.3 |
| Published | 2025-08-27 |
| First published | 2015-07-21 |
| Weekly downloads | 0 |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 1.5 MB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 386 |
| Maintainers | junmer, kekee000, asd123freedom |
| Keywords | sfnt, font, editor, ttf, woff, woff2, svg, eot, otf |

## Links

- npm: https://www.npmjs.com/package/fonteditor-core
- Repository: https://github.com/kekee000/fonteditor-core
- Issues: https://github.com/kekee000/fonteditor-core/issues
- npm.io page: https://npm.io/package/fonteditor-core

## Dependencies (1)

- [@xmldom/xmldom](https://npm.io/package/@xmldom/xmldom.md) ^0.8.3

## Alternatives

- [@fortawesome/react-fontawesome](https://npm.io/package/@fortawesome/react-fontawesome.md) — 2.2M weekly downloads
- [roboto-fontface](https://npm.io/package/roboto-fontface.md) — 196.0K weekly downloads
- [@react-native-vector-icons/common](https://npm.io/package/@react-native-vector-icons/common.md) — 150.4K weekly downloads
- [@procore/core-icons](https://npm.io/package/@procore/core-icons.md) — 4.6K weekly downloads
- [@react-md/material-icons](https://npm.io/package/@react-md/material-icons.md) — 1.6K weekly downloads

## Recent versions

- 2.6.3 (latest) — 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
- … 56 more at https://npm.io/package/fonteditor-core/versions

## README

# fonteditor-core

**FontEditor core functions**

[![NPM version][npm-image]][npm-url]
[![Downloads][downloads-image]][npm-url]

## 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

```javascript
// 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_USAGE.md).

```javascript
// 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()`.

```javascript
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

## Related

- [fonteditor](https://github.com/ecomfe/fonteditor)
- [fontmin](https://github.com/ecomfe/fontmin)
- [fonteditor online](https://kekee000.github.io/fonteditor/index.html)

## License

MIT © Fonteditor

[downloads-image]: http://img.shields.io/npm/dm/fonteditor-core.svg
[npm-url]: https://npmjs.org/package/fonteditor-core
[npm-image]: http://img.shields.io/npm/v/fonteditor-core.svg

[travis-url]: https://travis-ci.org/kekee000/fonteditor-core
[travis-image]: http://img.shields.io/travis/kekee000/fonteditor-core.svg

---
_Source: https://npm.io/package/fonteditor-core · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
