Fontkit is an advanced, cross-platform font engine designed for both Node.js and browser environments, currently stable at version 2.0.4. It offers comprehensive support for numerous font formats, including TrueType, OpenType, WOFF, WOFF2, and TrueType Collections. Its core capabilities encompass accurate character-to-glyph mapping, supporting advanced substitution features like ligatures, alongside robust glyph metrics and layout functionalities such as kerning. The library deeply integrates with OpenType (GSUB, GPOS) and Apple Advanced Typography (AAT) features, providing tools for extracting glyph vector paths for SVG conversion, handling color emoji glyphs (via SBIX and COLR tables), and supporting AAT variation glyphs for dynamic design control. A significant differentiator is its efficient font subsetting mechanism, which enables developers to create optimized font files containing only the necessary glyphs. The 2.0.0 release marked a substantial modernization, migrating from Node.js-specific `Buffer` usage to `Uint8Array` and `TextDecoder`, significantly enhancing its browser compatibility and changing the subset encoding API from streaming to a direct `Uint8Array` return. It is notably used as a core component within the PDFKit library.
npm install fontkitVerified import paths — ran on the pinned version, not inferred.
Demonstrates opening a font, laying out text, extracting SVG paths for individual glyphs, and creating/encoding a font subset, saving it to a new file.
Migrate any direct `Buffer` manipulations to use `Uint8Array` and `TextEncoder`/`TextDecoder` as appropriate for text encoding/decoding.
Replace calls to `subset.encodeStream()` with `subset.encode()`. Handle the returned `Uint8Array` directly instead of piping it through a stream.
Remove `iconv-lite` from your project dependencies if it was only used for `fontkit`. `fontkit` now handles encodings internally using standard Web APIs.
In browser environments, use `fontkit.create(buffer)` with a `Uint8Array` obtained from fetching font data (e.g., `fetch().arrayBuffer()`). Ensure your build process (e.g., Webpack, Rollup) is configured to use the browser-specific build of `fontkit` if it's not automatically picked up.
Ensure you are using the browser build of `fontkit` if in the browser. For Node.js, ensure your environment correctly defines `Buffer` or update your code to use `Uint8Array` where `Buffer` was previously expected, especially if migrating from pre-v2 `fontkit` versions.
Replace `subset.encodeStream()` with `subset.encode()`. The new method returns a `Uint8Array` directly, so adjust your subsequent code to handle a `Uint8Array` instead of a stream.
In browser environments, you must load font data as an `ArrayBuffer` (e.g., via `fetch`) and then use `fontkit.create(new Uint8Array(arrayBuffer))` to instantiate the font object.
No dependency data recorded yet.