@pdfa-lab/fontkit / Font
Interface: Font<TDirectory> ​
Defined in: src/font.ts:70
Baseline interface representing an unvalidated SFNT-based layout. Every table property is considered nullable by default. As a consequence, many properties are possibly undefined. You can avoid that by upcasting the font object with ["asOpenTypeFont"] to an OpenTypeFont, which guarantees the presence of the 8 core tables, and 0-2 outline tables.
This interface is mostly useless for application programming. You can normally just use TrueTypeFont as a type instead!
Extended by ​
Type Parameters ​
| Type Parameter | Default type |
|---|---|
TDirectory extends SFNTDirectory | SFNTDirectory |
Properties ​
avar ​
avar:
avar|null
Defined in: src/font.ts:324
Axis Variations Table. Modifies normalised coordinates across axes in variable fonts.
BASE ​
BASE:
BASE|null
Defined in: src/font.ts:235
Baseline Data Table. Sets alignment values dynamically shifting script baselines.
bsln ​
bsln:
bsln|null
Defined in: src/font.ts:330
Baseline Table. Provides baseline shift measurements for multi-script alignment.
CBLC ​
CBLC:
EBLC|null
Defined in: src/font.ts:211
Colour Bitmap Data Table. Variant containing colour bitmap raw data blocks.
cff ​
cff:
CFF1Font|null
Defined in: src/font.ts:183
PostScript Compact Font Format (CFF) Outline Table version 1.
CFF ​
**CFF **:
CFF1Font|null
Defined in: src/font.ts:188
Alternate PostScript Compact Font Format alias mapping.
CFF2 ​
CFF2:
CFF2Font|null
Defined in: src/font.ts:193
PostScript Compact Font Format (CFF) Outline Table version 2.
characterSet ​
characterSet:
number[] |undefined
Defined in: src/font.ts:468
An array of all of the unicode code points supported by the font.
cmap ​
cmap:
cmap|null
Defined in: src/font.ts:106
Character to Glyph Index Mapping Table. Maps characters to internal glyph indices.
COLR ​
COLR:
COLR|null
Defined in: src/font.ts:223
Colour Table. Outlines layering configurations for multi-coloured vector icon layouts.
copyright ​
copyright:
string|null
Defined in: src/font.ts:394
The font's copyright information, or null if not present.
CPAL ​
CPAL:
CPAL|null
Defined in: src/font.ts:229
Colour Palette Table. Maps index arrays declaring hex colours utilised by COLR elements.
cvt ​
**cvt **:
cvt|null
Defined in: src/font.ts:172
Control Value Table. Stores indexed control values used by TrueType instructions to maintain consistency when hinting glyphs.
defaultLanguage ​
readonlydefaultLanguage:string|null
Defined in: src/font.ts:607
The default language for strings to get from the font with getName().
See ​
directory ​
directory:
TDirectory
Defined in: src/font.ts:577
The structural binary wrapper tracking offset blocks and table pointers.
DSIG ​
DSIG:
DSIG|null
Defined in: src/font.ts:271
Digital Signature Table. Encapsulates cryptographic signatures validating binary authenticity.
EBLC ​
EBLC:
EBLC|null
Defined in: src/font.ts:205
Embedded Bitmap Data Table. Stores bitmap images for specific point sizes.
familyName ​
familyName:
string|null
Defined in: src/font.ts:384
The font's family name, e.g. "Helvetica", or null if not present.
feat ​
feat:
feat|null
Defined in: src/font.ts:336
Feature Name Table. Maps AAT feature selectors to localised string references.
fpgm ​
fpgm:
fpgm|null
Defined in: src/font.ts:154
Font Program Table. Contains low-level hints executing instruction sets across grid points.
fullName ​
fullName:
string|null
Defined in: src/font.ts:379
The font's full name, e.g. "Helvetica Bold", or null if not present.
fvar ​
fvar:
fvar|null
Defined in: src/font.ts:342
Font Variations Table. Declares design axes and instance configurations in variable fonts.
gasp ​
gasp:
gasp|null
Defined in: src/font.ts:277
Grid-fitting and Scan-conversion Procedure Table. Optimises text raster rendering constraints.
GDEF ​
GDEF:
GDEF|null
Defined in: src/font.ts:241
Glyph Definition Table. Categorises glyph types (e.g., base, ligature, mark) for layout alignment.
glyf ​
glyf:
glyph|null
Defined in: src/font.ts:178
Glyph Data Table. Describes TrueType glyph outlines, including contour coordinates, composite glyph components, and hinting instructions.
GPOS ​
GPOS:
GPOS|null
Defined in: src/font.ts:247
Glyph Positioning Table. Provides precise metric adjustments handling kerning and attachment marks.
GSUB ​
GSUB:
GSUB|null
Defined in: src/font.ts:253
Glyph Substitution Table. Supplies glyph substitutions for contextual alternates, ligatures, and script-specific rendering.
gvar ​
gvar:
gvar|null
Defined in: src/font.ts:348
Glyph Variations Table. Controls structural outline distortion transformations for variable glyphs.
hdmx ​
hdmx:
hdmx|null
Defined in: src/font.ts:283
Horizontal Device Metrics Table. Preserves explicit pixel width mappings optimising spacing.
head ​
head:
head|null
Defined in: src/font.ts:112
Font Header Table. Tracks global typographic metrics, scale grid bounds, and metadata.
hhea ​
hhea:
hhea|null
Defined in: src/font.ts:118
Horizontal Header Table. Stores global metric parameters for horizontal glyph layouts.
hmtx ​
hmtx:
hmtx|null
Defined in: src/font.ts:124
Horizontal Metrics Table. Contains advance widths and left side bearings for all glyphs.
HVAR ​
HVAR:
HVAR|null
Defined in: src/font.ts:265
Horizontal Variation Metrics Table. Adjusts advance metrics across design spaces in variable fonts.
JSTF ​
JSTF:
JSTF|null
Defined in: src/font.ts:259
Justification Table. Provides options for justification adjustments in complex scripts.
just ​
just:
just|null
Defined in: src/font.ts:354
Justification Table (just). Provides layout rules for line justification, glyph width deltas, and post-compensation actions in AAT typography.
kern ​
kern:
kern|null
Defined in: src/font.ts:288
Kerning Table. Contains traditional pairwise spacing adjustments.
layoutEngine ​
layoutEngine:
LayoutEngine
Defined in: src/font.ts:498
The shaping engine matching text scripts to font tables.
loca ​
loca:
loca|null
Defined in: src/font.ts:160
Index to Location Table. Maps local offsets for binary data streams resolving glyph outlines.
LTSH ​
LTSH:
LTSH|null
Defined in: src/font.ts:294
Linear Threshold Table. Sets pixel-per-em limits where scaling instructions degrade.
maxp ​
maxp:
maxp|null
Defined in: src/font.ts:130
Maximum Profile Table. Explicitly defines memory boundaries and total glyph count constraints.
morx ​
morx:
morx|null
Defined in: src/font.ts:360
Extended Glyph Metamorphosis Table. Powers state-machine transformations substituting AAT items.
name ​
name:
name|null
Defined in: src/font.ts:136
Naming Table. Contains multilingual string records for copyrights, families, and system IDs.
opbd ​
opbd:
opbd|null
Defined in: src/font.ts:366
Optical Bounds Table. Sets bounding limits to align glyphs based on visual centre points.
OS/2 ​
OS/2:
OS2|null
Defined in: src/font.ts:142
OS/2 and Windows Metrics Table. Contains subsystem configurations, weights, and unicode ranges.
PCLT ​
PCLT:
PCLT|null
Defined in: src/font.ts:300
PCL 5 Table. Contains metrics and command parameters for HP LaserJet compatibility.
post ​
post:
post|null
Defined in: src/font.ts:148
PostScript Table. Encapsulates printer operational bounds and memory-tracking metrics.
postscriptName ​
postscriptName:
string|Uint8Array<ArrayBufferLike> |null
Defined in: src/font.ts:374
The unique PostScript name for this font or null if not present.
Some broken fonts have PostScript names that cannot be decoded into a string. They are exposed as Uint8Array.
prep ​
prep:
prep|null
Defined in: src/font.ts:166
Control Value Program Table. Provides global instructions establishing variable outline alignment.
sbix ​
sbix:
sbix|null
Defined in: src/font.ts:217
Standard Bitmap Graphics Table. Embeds raster configurations (PNG/JPEG) directly within glyph IDs.
stream ​
stream:
DecodeStream
Defined in: src/font.ts:582
The raw input stream reading binary payload slices.
subfamilyName ​
subfamilyName:
string|null
Defined in: src/font.ts:389
The font's sub-family, e.g. "Bold", or null if not present.
variationProcessor ​
variationProcessor:
GlyphVariationProcessor|null
Defined in: src/font.ts:595
The processor responsible for calculating delta adjustments to glyph outlines along design variation axes. This is initialised when variation coordinates are applied, and is null for static fonts.
VDMX ​
VDMX:
VDMX|null
Defined in: src/font.ts:306
Vertical Device Metrics Table. Preserves explicit vertical pixel height mappings.
version ​
version:
string|null
Defined in: src/font.ts:399
The font's version number or null if not present.
vhea ​
vhea:
vhea|null
Defined in: src/font.ts:312
Vertical Header Table. Stores global metric parameters for vertical text directions.
vmtx ​
vmtx:
vmtx|null
Defined in: src/font.ts:318
Vertical Metrics Table. Contains advance heights and top side bearings for vertical layouts.
VORG ​
VORG:
VORG|null
Defined in: src/font.ts:199
Vertical Origin Table. Specifies vertical coordinate origins for dynamic metrics scaling.
Accessors ​
ascent ​
Get Signature ​
get ascent():
number|undefined
Defined in: src/font.ts:404
The font’s ascender.
Returns ​
number | undefined
availableFeatures ​
Get Signature ​
get availableFeatures(): keyof
Features[]
Defined in: src/font.ts:534
An array of all OpenType feature tags supported by the font.
Returns ​
keyof Features[]
bbox ​
Get Signature ​
get bbox():
Readonly<BoundingBox> |undefined
Defined in: src/font.ts:463
Deprecated ​
Use boundingBox instead!
Returns ​
Readonly<BoundingBox> | undefined
boundingBox ​
Get Signature ​
get boundingBox():
Readonly<BoundingBox> |undefined
Defined in: src/font.ts:458
The font’s bounding box, i.e. the box that encloses all glyphs in the font.
Returns ​
Readonly<BoundingBox> | undefined
capHeight ​
Get Signature ​
get capHeight():
number|undefined
Defined in: src/font.ts:436
The height of capital letters above the baseline. See here for more details.
Returns ​
number | undefined
descent ​
Get Signature ​
get descent():
number|undefined
Defined in: src/font.ts:409
The font’s descender.
Returns ​
number | undefined
italicAngle ​
Get Signature ​
get italicAngle():
number|undefined
Defined in: src/font.ts:430
If this is an italic font, the angle the cursor should be drawn at to match the font design.
Returns ​
number | undefined
lineGap ​
Get Signature ​
get lineGap():
number|undefined
Defined in: src/font.ts:414
The line gap, i.e. amount of space that should be included between lines.
Returns ​
number | undefined
numGlyphs ​
Get Signature ​
get numGlyphs():
number|undefined
Defined in: src/font.ts:447
The total count of glyph indexes present in the font mapping.
Returns ​
number | undefined
underlinePosition ​
Get Signature ​
get underlinePosition():
number|undefined
Defined in: src/font.ts:419
The offset from the normal underline position that should be used.
Returns ​
number | undefined
underlineThickness ​
Get Signature ​
get underlineThickness():
number|undefined
Defined in: src/font.ts:424
The weight of the underline that should be used.
Returns ​
number | undefined
unitsPerEm ​
Get Signature ​
get unitsPerEm():
number
Defined in: src/font.ts:453
The size of the font's internal coordinate grid in units per em. Defaults to 1000, if all other attempts to calculate the value fail.
Returns ​
number
xHeight ​
Get Signature ​
get xHeight():
number
Defined in: src/font.ts:442
The height of lowercase letters in the font. See here for more details.
Returns ​
number
Methods ​
asAATFont() ​
asAATFont():
AATFont|null
Defined in: src/font.ts:93
Attempts to view this font as an AATFont.
Returns ​
AATFont | null
the font with narrowed to an @{link AATFont} or `null if a required table is missing
asOpenTypeFont() ​
asOpenTypeFont():
OpenTypeFont|null
Defined in: src/font.ts:86
Attempts to view this font instance as a strict OpenType font layout. Returns null, if a structurally required table is missing.
See OpenTypeFont for usage instructions!
Returns ​
OpenTypeFont | null
the font with narrowed to an @{link OpenTypeFont} or `null if a required table is missing
asTrueTypeSubsetFont() ​
asTrueTypeSubsetFont():
TrueTypeSubsetFont|null
Defined in: src/font.ts:100
Attempts to view this font as an TrueTypeSubsetFont font.
Returns ​
TrueTypeSubsetFont | null
the font with narrowed to a @{link TrueTypeSubsetFont} or `null if a required table is missing
codePointsForGlyph() ​
codePointsForGlyph(
gid):number[]
Defined in: src/font.ts:529
Returns an array of alternative unicode mapping arrays tied to a specific glyph ID.
Parameters ​
| Parameter | Type |
|---|---|
gid | number |
Returns ​
number[]
createSubset() ​
createSubset():
Subset
Defined in: src/font.ts:572
Creates an empty layout subset utilising this font structure as its baseline data map.
Returns ​
getAvailableFeatures() ​
getAvailableFeatures(
script,language?): keyofFeatures[]
Defined in: src/font.ts:540
An array of all OpenType feature tags supported by the font for a given script and language.
Parameters ​
| Parameter | Type |
|---|---|
script | "Caucasian_Albanian" | "Arabic" | "Imperial_Aramaic" | "Armenian" | "Avestan" | "Balinese" | "Bamum" | "Bassa_Vah" | "Batak" | "Bengali" | "Bopomofo" | "Brahmi" | "Braille" | "Buginese" | "Buhid" | "Chakma" | "Canadian_Aboriginal" | "Carian" | "Cham" | "Cherokee" | "Coptic" | "Cypriot" | "Cyrillic" | "Devanagari" | "Deseret" | "Duployan" | "Egyptian_Hieroglyphs" | "Elbasan" | "Ethiopic" | "Georgian" | "Glagolitic" | "Gothic" | "Grantha" | "Greek" | "Gujarati" | "Gurmukhi" | "Hangul" | "Han" | "Hanunoo" | "Hebrew" | "Hiragana" | "Pahawh_Hmong" | "Katakana_Or_Hiragana" | "Old_Italic" | "Javanese" | "Kayah_Li" | "Katakana" | "Kharoshthi" | "Khmer" | "Khojki" | "Kannada" | "Kaithi" | "Tai_Tham" | "Lao" | "Latin" | "Lepcha" | "Limbu" | "Linear_A" | "Linear_B" | "Lisu" | "Lycian" | "Lydian" | "Mahajani" | "Mandaic" | "Manichaean" | "Mende_Kikakui" | "Meroitic_Cursive" | "Meroitic_Hieroglyphs" | "Malayalam" | "Modi" | "Mongolian" | "Mro" | "Meetei_Mayek" | "Myanmar" | "Old_North_Arabian" | "Nabataean" | "Nko" | "Ogham" | "Ol_Chiki" | "Old_Turkic" | "Oriya" | "Osmanya" | "Palmyrene" | "Pau_Cin_Hau" | "Old_Permic" | "Phags_Pa" | "Inscriptional_Pahlavi" | "Psalter_Pahlavi" | "Phoenician" | "Miao" | "Inscriptional_Parthian" | "Rejang" | "Runic" | "Samaritan" | "Old_South_Arabian" | "Saurashtra" | "Shavian" | "Sharada" | "Siddham" | "Khudawadi" | "Sinhala" | "Sora_Sompeng" | "Sundanese" | "Syloti_Nagri" | "Syriac" | "Tagbanwa" | "Takri" | "Tai_Le" | "New_Tai_Lue" | "Tamil" | "Tai_Viet" | "Telugu" | "Tifinagh" | "Tagalog" | "Thaana" | "Thai" | "Tibetan" | "Tirhuta" | "Ugaritic" | "Vai" | "Warang_Citi" | "Old_Persian" | "Cuneiform" | "Yi" | "Inherited" | "Common" | "Unknown" |
language? | string |
Returns ​
keyof Features[]
getGlyfTableStream() ​
getGlyfTableStream():
DecodeStream|null
Defined in: src/font.ts:588
Extracts a raw readable segment slice targeting vector outline definitions.
Returns ​
DecodeStream | null
getGlyph() ​
getGlyph(
glyph,characters?):Glyph|null
Defined in: src/font.ts:554
Returns a glyph object for the given glyph id. You can pass the array of code points this glyph represents for your use later, and it will be stored in the glyph object.
Parameters ​
| Parameter | Type | Description |
|---|---|---|
glyph | number | the glyph id |
characters? | readonly number[] | an array of code points this glyph represents |
Returns ​
Glyph | null
the corresponding glyph
glyphForCodePoint() ​
glyphForCodePoint(
codePoint):Glyph|null
Defined in: src/font.ts:485
Maps a single unicode code point to a Glyph object. Does not perform any advanced substitutions.
Parameters ​
| Parameter | Type | Description |
|---|---|---|
codePoint | number | the unicode code point |
Returns ​
Glyph | null
the corresponding glyph
glyphsForString() ​
glyphsForString(
str):Glyph[]
Defined in: src/font.ts:494
Returns an array of Glyph objects for the given string. This is only a static one-to-one mapping from characters to glyphs.
Parameters ​
| Parameter | Type | Description |
|---|---|---|
str | string | the string to encode |
Returns ​
Glyph[]
the corresponding glyphs
hasGlyphForCodePoint() ​
hasGlyphForCodePoint(
codePoint):boolean
Defined in: src/font.ts:476
Returns whether there is a glyph in the font for the given unicode code point.
Parameters ​
| Parameter | Type | Description |
|---|---|---|
codePoint | number | the unicode code point |
Returns ​
boolean
true if a glyph is available for the code point, false otherwise
hasTable() ​
hasTable<
K>(tag):boolean
Defined in: src/font.ts:76
Tests whether a certain table is present in the font file.
Type Parameters ​
| Type Parameter | Default type |
|---|---|
K extends string | string |
Parameters ​
| Parameter | Type | Description |
|---|---|---|
tag | "name" | "head" | "kern" | "opbd" | "loca" | "hmtx" | "cmap" | "hhea" | "maxp" | "OS/2" | "post" | "fpgm" | "prep" | "cvt " | "glyf" | "CFF " | "CFF2" | "VORG" | "EBLC" | "CBLC" | "sbix" | "COLR" | "CPAL" | "BASE" | "GDEF" | "GPOS" | "GSUB" | "JSTF" | "HVAR" | "DSIG" | "gasp" | "hdmx" | "LTSH" | "PCLT" | "VDMX" | "vhea" | "vmtx" | "avar" | "bsln" | "feat" | "fvar" | "gvar" | "just" | "morx" | K | the table name like cmap, OS/2, or hmtx |
Returns ​
boolean
layout() ​
layout(
str,userFeatures?,script?,language?,direction?):GlyphRun
Defined in: src/font.ts:511
Returns a GlyphRun object, which includes an array of Glyphs and GlyphPositions for the given string.
Parameters ​
| Parameter | Type | Description |
|---|---|---|
str | string | the string to encode |
userFeatures? | Features | keyof Features[] | an array of OpenType feature tags to be applied in addition to the default set. |
script? | OpenTypeTag | the script of the string |
language? | string | the language of the string |
direction? | BidiDirection | the writing direction for the string |
Returns ​
the rendered string as a GlyphRun
safeGetGlyph() ​
safeGetGlyph(
glyph,characters?):Glyph
Defined in: src/font.ts:563
Like getGlyph but falls back to the fallback glyph .notdef if the glyph cannot be resolved, because of missing tables.
Parameters ​
| Parameter | Type | Description |
|---|---|---|
glyph | number | the glyph id |
characters? | readonly number[] | an optional sequence of codepoints |
Returns ​
setDefaultLanguage() ​
setDefaultLanguage(
lang):void
Defined in: src/font.ts:614
Set the default language.
Parameters ​
| Parameter | Type |
|---|---|
lang | string | null |
Returns ​
void
See ​
stringsForGlyph() ​
stringsForGlyph(
gid):string[]
Defined in: src/font.ts:523
Returns an array of strings that map to the given glyph id.
Parameters ​
| Parameter | Type | Description |
|---|---|---|
gid | number | the glyph id |
Returns ​
string[]