Skip to content

Differences to Other fontkit Versions ​

Other Versions ​

There are a number of other versions of fontkit available:

Notable Differences ​

The most important differences are:

  • Fully Typed: Written from the ground up in TypeScript, eliminating the need for external @types/fontkit definitions.
  • Modernised Module Structure: Full API exposed via clean named exports (TrueTypeFont, TrueTypeCollection, other individual font classes, etc.), alongside a default export for backwards compatibility.
  • Static Format Identifiers: Font classes and font collections expose a static readonly objType (e.g., WOFF2Font.objType === font.objType) matching instance .objType properties to enable type-safe format checks without string literal guessing.
  • Strongly Typed Font Tables: Low-level font tables and structures (such as cmap, hmtx, OS2, or morx) have been refactored into strict, strongly typed interfaces and (discriminated) unions.
  • Modern Tooling & Zero Legacy Dependencies: Updated build pipelines, package exports, and test suites targeting modern Node.js runtime environments and ESM/CJS dual-package resolution.
  • Ported Bugfixes: All known bugfixes from the other fontkit versions have been ported to @pdfa-lab/fontkit.
  • Actively Maintained: This fork will receive regular dependency updates. Bugfixes and other pull requests are welcome!
  • Flexible Subset Streaming: You can use the new and simple encode() or the legacy encodeStream() method for subset serialisation.

Incompatibilities ​

An effort has been made to maintain maximum compatibility with upstream fontkit and other versions. The following known incompatibilities exist:

  • All tables in @pdfa-lab/fontkit are nullable! When you access a table, you always have to check whether it is actually present. The hand-crafted interfaces for other fontkit versions, suggest that some tables like CFF , OS/2, head, hhea, or post are always present, which is by no means guaranteed by the library. But the library contains methods that elegantly validate font features and cast at the same time so that you can safely access certain subsets of tables, see Font Type Narrowing!
  • The CommonJS module does not have a default export: You have to change const fontkit = require('@pdfa-lab/fontkit') to const { fontkit } = require('@pdfa-lab/fontkit').
  • The discriminating property objType is preferred over the deprecated type.