sf

subset-font

Create a subset of a TrueType/OpenType/WOFF/WOFF2 font using the wasm build of harfbuzz/hb-subset

Showing:

Popularity

Downloads/wk

4.7K

GitHub Stars

12

Maintenance

Last Commit

3mos ago

Contributors

4

Package

Dependencies

4

License

BSD-3-Clause

Type Definitions

Tree-Shakeable

No?

Categories

Readme

subset-font

Create a subset font from an existing font in SFNT (TrueType/OpenType), WOFF, or WOFF2 format. Uses harfbuzzjs, which is a WebAssembly build of HarfBuzz.

const subsetFont = require('subset-font');

const mySfntFontBuffer = Buffer.from(/*...*/);

// Create a new font with only the characters required to render "Hello, world!" in WOFF2 format:
const subsetBuffer = await subsetFont(mySfntFontBuffer, 'Hello, world!', {
  targetFormat: 'woff2',
});

API

subsetFont(buffer, text, options): Promise<Buffer>

Asynchronously create a subset font as a Buffer instance, optionally converting it to another format.

Returns a promise that gets fulfilled with the subset font as a Buffer instance, or rejected with an error.

Options:

  • targetFormat - the format to output, can be either 'sfnt', 'woff', or 'woff2'.
  • preserveNameIds - an array of numbers specifying the extra name ids to preserve in the name table. By default the harfbuzz subsetter drops most of these. Use case described here.

For backwards compatibility reasons, 'truetype' is supported as an alias for 'sfnt'.

Why not use harfbuzzjs directly?

This middle-man module only really exists for convenience.

  • harfbuzzjs is deliberately low-level bindings for HarfBuzz. While very flexible, it means that you need a series of hard-to-get-right incantations to move data in and out of the WebAssembly heap and carry out a subsetting operation. See harfbuzz/harfbuzzjs#9.
  • The subsetting routines in HarfBuzz only support the SFNT (TrueType/OpenType) format. subset-font adds support for reading and writing WOFF and WOFF2 via the fontverter library.

Releases

Changelog

License

3-clause BSD license -- see the LICENSE file for details.

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100