npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

subset-font

v2.4.0

Published

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

Downloads

32,793

Readme

subset-font

Create a subset font from an existing font in SFNT (TrueType/OpenType), WOFF, or WOFF2 format. When subsetting a variable font, you can also reduce the variation space at the individual axis level.

These operations are implemented using harfbuzzjs, which is a WebAssembly build of HarfBuzz.

Basic example

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',
});

Reducing the variation space

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',
  variationAxes: {
    // Pin the axis to 200:
    wght: 200,
    // Reduce the variation space, explicitly setting a new default value:
    GRAD: { min: -50, max: 50, default: 25 },
    // Reduce the variation space. A new default value will be inferred by clamping the old default to the new range:
    slnt: { min: -9, max: 0 },
    // The remaining axes will be kept as-is
  },
});

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.
  • variationAxes - an object specifying a full or partial instancing of variation axes in the font. Only works with variable fonts. See the example above.
  • noLayoutClosure - don't perform glyph closure for layout substitution (GSUB). Equivalent to hb-subset --no-layout-closure and pyftsubset --no-layout-closure.

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.