Skip to content

@pdfa-lab/fontkit / fontkit

Variable: fontkit ​

const fontkit: object

Defined in: src/base.ts:52

The legacy factory entry point into the library.

Available both as a default import and as the named import fontkit.

Why Deprecated? ​

  • The fontkit.create factory relies on runtime structural probing to determine whether a byte stream is a TrueTypeFont, a TrueTypeCollection, or a DFont. This approach introduces two critical drawbacks:
  1. Ambiguity: It forces a vague union return type, requiring consumers to write manual type guards downstream.
  2. Security & Validation: Loading raw, unverified data from untrusted sources is strongly discouraged. Data integrity checks should happen before the parser layer, meaning the container format is already known.

For robust, typesafe applications, instantiate the specific format container classes directly instead of relying on this dynamic factory helper.

WOFFFont, WOFF2Font, TrueTypeCollection, or DFont directly.

Type Declaration ​

create ​

create: (bytes, postscriptName?) => TrueTypeFont<SFNTDirectory> | FontCollection | null

Create an instance of a font or a font collection.

For a FontCollection, you may specify the PostScript name of one of the fonts contained in the collection. Otherwise, you get the collection itself. You can then get the list of included fonts with the method getFonts.

If the font is a regular font program file and you specify a PostScript name, an attempt is made to get a font variation of that name. That is only possible if:

  1. The font has an fvarTable.fvar table.
  2. The font either has a CFF2 table, or it has both a gvar and glyf table.

The resolution may still fail if the requested variation is not present in the font.

Parameters ​

ParameterTypeDescription
bytesUint8Arraythe raw font byte
postscriptName?stringthe optional PostScript name

Returns ​

TrueTypeFont<SFNTDirectory> | FontCollection | null

the font or font collection

Deprecated ​

Use one of the designated class constructors TrueTypeFont, WOFFFont, WOFF2Font, TrueTypeCollection, DFont instead!

defaultLanguage ​

defaultLanguage: string = 'en'

The default language to use.

logErrors ​

logErrors: boolean = false

Set to true for verbose error logging.

setDefaultLanguage ​

setDefaultLanguage: (lang) => void

Parameters ​

ParameterTypeDefault value
langstring'en'

Returns ​

void