From 67519498d85b59c15146d10db64f717feb752d3d Mon Sep 17 00:00:00 2001 From: Andreas Lind Date: Sun, 24 Mar 2024 09:22:45 +0100 Subject: [PATCH] Add docs --- README.md | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 2c3a169..5ea8fbf 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,23 @@ # subset-font -Create a subset font from an existing font in SFNT (TrueType/OpenType), WOFF, or WOFF2 format. Uses [`harfbuzzjs`](https://github.com/harfbuzz/harfbuzzjs), which is a WebAssembly build of [HarfBuzz](https://harfbuzz.github.io/). +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`](https://github.com/harfbuzz/harfbuzzjs), which is a WebAssembly build of [HarfBuzz](https://harfbuzz.github.io/). + +## Basic example + +```js +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 ```js const subsetFont = require('subset-font'); @@ -10,6 +27,15 @@ 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 + }, }); ``` @@ -25,6 +51,7 @@ 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](https://github.com/papandreou/subset-font/issues/7). +- `variationAxes` - an object specifying a full or partial instancing of variation axes in the font. Only works with variable fonts. See the example above. For backwards compatibility reasons, `'truetype'` is supported as an alias for `'sfnt'`.