@pdfa-lab/fontkit / FontkitAPI
Interface: FontkitAPI ​
Defined in: src/base.ts:39
The factory entry point into the library.
Available both as a default import and as the named import fontkit. Exception: The CommonJS bundle only has the named import fontkit.
Properties ​
create ​
create: (
bytes,postscriptName?) =>TrueTypeFont<SFNTDirectory> |FontCollection|null
Defined in: src/base.ts:130
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
TrueTypeFont, WOFFFont, WOFF2Font, TrueTypeCollection, DFont instead!
Deprecated ​
Use fontkit.loadFont or fontkit.loadFontCollection instead!
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.
The function is deprecated, because it forces users to check the type of the returned object. They will normally either expect a font or a font collection, but not both.
defaultLanguage ​
defaultLanguage:
string
Defined in: src/base.ts:48
The default language to use. Defaults to 'en'.
loadFont ​
loadFont: (
bytes,postscriptName?) =>TrueTypeFont
Defined in: src/base.ts:85
Load a font from raw input data. You can either load a TrueTypeFont, WOFF2Font, or @WOFFFont. Alternatively, you can pass a TrueTypeCollection or DFont along with the PostScript name of a font inside that collection.
That means: The second argument postscriptName is mandatory for a FontCollection and forbidden for a Font. Not following the calling convention will result in an exception!
The function throws an exception, if the input data is not in a recognised format.
Parameters ​
| Parameter | Type | Description |
|---|---|---|
bytes | Uint8Array | the raw input data for either a font file or a font collection |
postscriptName? | string | the PostScript name of the font in a collection |
Returns ​
loadFontCollection ​
loadFontCollection: (
bytes) =>FontCollection
Defined in: src/base.ts:97
Load a font collection from raw input data. You can either load a TrueTypeCollection or DFont.
The function throws an exception, if the input data is not in a recognised format.
Parameters ​
| Parameter | Type | Description |
|---|---|---|
bytes | Uint8Array | the raw input data for the font collection |
Returns ​
logErrors ​
logErrors:
boolean
Defined in: src/base.ts:43
Set to true for verbose error logging.
setDefaultLanguage ​
setDefaultLanguage: (
lang) =>void
Defined in: src/base.ts:55
Set the global default language.
Parameters ​
| Parameter | Type | Description |
|---|---|---|
lang | string | the language code |
Returns ​
void