Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
subset-font
Advanced tools
Create a subset of a TTF/WOFF/WOFF2 font using the wasm build of harfbuzz/hb-subset
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.
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',
});
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
},
});
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'
.
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.subset-font
adds support for reading and writing WOFF and WOFF2 via the fontverter
library.3-clause BSD license -- see the LICENSE
file for details.
FAQs
Create a subset of a TTF/WOFF/WOFF2 font using the wasm build of harfbuzz/hb-subset
We found that subset-font demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.