@pdfa-lab/fontkit / fontkit
Variable: fontkit ​
constfontkit: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.createfactory 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:
- Ambiguity: It forces a vague union return type, requiring consumers to write manual type guards downstream.
- 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:
- The font has an fvarTable.fvar table.
- The font either has a CFF2 table, or it has both a gvar and
glyftable.
The resolution may still fail if the requested variation is not present in the font.
Parameters ​
| Parameter | Type | Description |
|---|---|---|
bytes | Uint8Array | the raw font byte |
postscriptName? | string | the 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 ​
| Parameter | Type | Default value |
|---|---|---|
lang | string | 'en' |
Returns ​
void