Repository navigation
This is a big release, modernizing the codebase, fixing plenty of bugs and making it more modular. Thanks to all the contributors who helped make it happen.
New targets
The minimum supported versions have been updated, but the requirements remain very conservative.
Node builds now target Node 22+.
The browser build targets Firefox 115+, Safari 16+, Chrome 120+.
ESM-only package
The package now exports only ECMAScript modules (ESM). Compatibility with CommonJS is preserved because the ESM loading via require() feature is enabled in supported Node.js versions.
Separate builds for Node.js and browsers
By leveraging the conditional exports feature, fontkit now ships different code for Node.js and browsers (or other JavaScript runtimes).
On Node.js, native compression (zlib, Brotli) is used, meaning less code is shipped and runtime execution is faster. In browsers, no Node.js-specific code is used or imported, and compression uses the efficient, tree-shakable fflate library.
Modular export
fontkit is a huge library accounting for a significant amount of shipped code in most applications that use it.
The main export still provides by default all font formats and shapers.
A new core export was introduced, allowing you to choose only the required features.
Below is an example that registers only TTFFont and ArabicShaper:
import * as fontkit from 'fontkit/core';
import { TTFFont } from 'fontkit/formats/TTFFont';
import { ArabicShaper } from 'fontkit/shapers/ArabicShaper';
fontkit.registerFormat(TTFFont);
fontkit.registerShaper(ArabicShaper);
const run = fontkit.create(buffer).layout('مرحبا');The main benefit is observed in browser builds where modern bundlers will discard unused code, but it can also be useful in serverless environments where cold start time is an important metric.
Plenty of bug fixes / improvements
New shapers, improved spec compliance, protection against malformed fonts, code cleanup (fewer dependencies). See below.
Full changelog:
- Return null for undecodable PostScript names instead of raw bytes, preventing a crash in PDFKit ([foliojs/pdfkit#1687](foliojs/pdfkit#1687))
- Add
registerShaperwith an optional scripts array overriding static script declarations, andfontkit/shapers/{ClassName}entry points with named shaper exports; core uses onlyDefaultShaperuntil specialized shapers are registered - Add a Myanmar shaper, ported from HarfBuzz
- Take the end-of-text transition of AAT morx state machines, so rearrangement and contextual substitution can act on the last glyphs like CoreText and HarfBuzz (#144, #147, #151)
- Rearrange glyphs in AAT morx tables only when the marked range holds every glyph the verb moves, like CoreText and HarfBuzz (#142, #143)
- Fix AAT glyph insertion: insert the marked glyph count, set the mark after inserting, skip the inserted glyphs, and limit how many glyphs a font can insert, like HarfBuzz (#171, #172, #173, #174)
- Stop AAT morx state machines that never advance after a bounded number of steps, like HarfBuzz (#175)
- Shape Tai Tham sakot followed by a consonant after vowel signs like HarfBuzz, instead of inserting a dotted circle
- Reverse right-to-left text, kern it in visual order and position its marks like HarfBuzz in fonts without GSUB, GPOS or morx (#39)
- Round HVAR advance deltas to whole units like HarfBuzz, so subsets of fonts with set variations no longer truncate advances such as 851.9999 to 851
- Fix glyphs in subsets of fonts with set variations: write the count of repeated flags at the end of a glyph, flatten composite glyphs, and take the left side bearings from the varied outlines
- Take the ascent, descent and line gap from the typo metrics when the font sets useTypoMetrics, like HarfBuzz, and fix the vhea structure, 16.16 table versions, and boxes of empty glyphs (#305, #306)
- Use non-default variation sequences when the variation selector also has default ones
- Add
fontkit/coreandfontkit/formats/{format}entry points with named format exports for explicit format registration, sharing state with the default entries - Remove the fast-deep-equal runtime dependency
- Decode the names of Windows symbol fonts (encoding ID 0) as UTF-16BE
- Ignore the advances of marks zeroed after GPOS when positioning attached marks
- Position marks like HarfBuzz in fonts without GPOS (#409)
- Fix canonical composition fallback, Arabic mark ordering, and positioning in fonts without GSUB
- Reorder combining marks like HarfBuzz, with its modified combining classes and Arabic modifier marks first
- Fix extra quadratic segments in TrueType contours with off-curve endpoints
- [BREAKING] Browser build is now ESM-only
- [BREAKING] Node build is now ESM-only
- [BREAKING] Node builds now targets Node 22+, Browser build targets Firefox 115+, Safari 16+, Chrome 120+
- Replace cache decorators with specialized lazy caching
- Fix crash when using TrueType font with empty glyphs (#353, #378, #303, #312). Based on #379
- Read hdmx device records at their padded size
- Encode subsets of fonts with set variations (#308)
- Map space and missing code points correctly with a legacy Mac cmap (#394)
- Keep a glyph's variation metrics stable when several composites use it
- Fix repha, pre-base vowel and dotted circle placement in the Universal Shaping Engine
- Return the requested code points for glyphs shared by several code points (#342) (#395)
- Map glyphs back to code points for cmap formats 6 and 10 (#392)
- Fix crash in the Universal Shaping Engine on characters outside a syllable, such as ZWNJ and ZWJ
- Size cmap format 10 glyph indices by entryCount (#391)
- Leave code points mapped to .notdef out of characterSet (#390)
- Fix glyph code point cache after composite decomposition (#387)
- Fix off-diagonal coefficients in composite glyph transforms (#388)
- Continue after the glyphs a lookup matched or inserted instead of applying it to them again (#383)
- Use native decompression lib in node. Replace tiny-inflate by fflate