Font Object

This documentation for fontkit is created and provided by the Typogram team. It’s a third-party documentation intended to delve deeper into the fontkit API. For the most accurate information, refer to fontkit’s official documentation.

The Font object is central to Fontkit. It represents a font in your system or a font file.

Properties (Read-only)


  • Description: The PostScript name of the font. This is a unique identifier, often used in CSS and other contexts.

  • Type: String


  • Description: The full name of the font, typically including its weight or style.

  • Type: String


  • Description: The name of the font family to which this font belongs.

  • Type: String


  • Description: The specific style or weight of the font within its family (e.g., "Bold" or "Italic").

  • Type: String


  • Description: The copyright statement associated with the font.

  • Type: String


  • Description: The version string of the font.

  • Type: String


  • Description: The total number of glyphs in the font.

  • Type: Number


  • Description: A set of all Unicode characters covered by the font.

  • Type: Set of Numbers


  • Description: A list of OpenType feature tags available in the font.

  • Type: Array of Strings


  • Description: The number of font units per em. It's a foundational metric for a font, often set to values like 1000 or 2048.

  • Type: Number


  • Description: The font's ascent, which is the distance from the baseline to the top of the font's bounding box.

  • Type: Number


  • Description: The font's descent, which is the distance from the baseline to the bottom of the font's bounding box.

  • Type: Number


  • Description: The height of capital letters from the baseline.

  • Type: Number


  • Description: The height of lowercase letters, specifically the height of the letter 'x'.

  • Type: Number


  • Description: The recommended line gap or spacing between lines of text for this font.

  • Type: Number


  • Description: The position of the underline relative to the baseline.

  • Type: Number


  • Description: The thickness of the underline.

  • Type: Number


  • Description: The angle (in degrees) of the italic slant. Upright fonts have an italic angle of 0.

  • Type: Number


  • Description: The font's bounding box, which encompasses all glyphs in the font. It's an object with minX, minY, maxX, and maxY properties.

  • Type: Object


  • Description: Information about variable font axes if the font is a variable font. Each axis has properties like tag, name, min, default, and max.

  • Type: Array of Objects


  • Description: Named instances for variable fonts, such as predefined width or weight variations.

  • Type: Object


  • Description: An internal processor for the font's character map. Typically used internally by Fontkit.

  • Type: Object


  • Description: An internal engine for glyph layout. Typically used internally by Fontkit.

  • Type: Object


  • Description: An internal processor for handling font variations. Typically used internally by Fontkit.

  • Type: Object

Other Properties

Basic properties:



The type of the font, such as 'truetype', 'cff', etc.


The default language for the font, used when retrieving names and other language-specific details.


The readable stream from which the font is being read. Useful for reading binary data directly from the font file.


An object representing the coordinates for variable font instances. If the font is not variable, this property is null.


(Internal) Position of the directory within the font stream. Typically used internally by Fontkit for navigation purposes.


(Internal) A cache of parsed tables. Used internally by Fontkit to store tables that have been parsed.


(Internal) A cache of parsed glyphs. Used internally by Fontkit to store glyphs that have been read from the font.


The font's directory table, which provides an index to the rest of the tables in the font.

Font tables as properties:



Glyph Definition Table: Contains glyph class definitions, ligature caret lists, and glyph attachment positioning.


Glyph Positioning Table: Contains information about positioning glyphs in complex scripts or ligature adjustments.


Glyph Substitution Table: Defines glyph substitutions, such as ligatures, contextual alternates, etc.


OS/2 and Windows Specific Table: Contains metrics, glyph index ranges, style flags, and other font metadata.


Character to Glyph Index Mapping Table: Maps character codes to glyph indices.


Control Value Table: Contains values used by the fpgm table and the glyf table for hinting.


Font Program: Contains hinting instructions for the font.


Grid-fitting and Scan-conversion Procedure Table: Contains information for grid-fitting and anti-aliasing.


Glyph Data Table: Contains the outlines of the glyphs in the font.


Font Header Table: Contains global font information such as bounding box, version, etc.


Horizontal Header Table: Contains horizontal metrics and settings.


Horizontal Metrics Table: Contains metrics for each glyph's horizontal layout.


Index to Location Table: Contains offsets to each glyph in the glyf table.


Maximum Profile Table: Contains the maximum values for various font-wide parameters.


Naming Table: Contains names for various font attributes, including designer, copyright, etc.


PostScript Table: Contains information used for emulating PostScript fonts.


Control Value Program: Contains hinting instructions executed before processing any glyph in the font.



  • Description: Creates a Subset object, allowing you to create a new font containing only specified glyphs.

  • Returns: Subset object for further operations.


  • Description: Lists the OpenType layout features available in the font.

  • Returns: Array of available feature tags.


  • Description: If the font file contains multiple fonts, retrieves a specific one.

  • Parameters: Index or specific criteria for font selection.

  • Returns: Font object.


  • Description: Retrieves a glyph by its ID.

  • Parameters: Glyph ID.

  • Returns: Corresponding Glyph object.


  • Description: Returns a new Font object for the given variation.

  • Parameters: Variation criteria or name.

  • Returns: Variation data.


  • Description: Returns a new Font object for the given variation. This method is used to obtain a specific variation of the font based on the provided variation criteria.

  • Parameters: variation (Object) - An object specifying the variation criteria. The format of this object includes key-value pairs representing the variation axes. For example, { "wght": 400 } sets the weight of the font to 400.

  • Returns: Fontkit Font Object - A new font object that represents the specified variation of the original font.


let currentVariation = {
    "wght": 400
fkFont = fkFont.getVariation(currentVariation);


  • Description: Returns a Glyph object for a given Unicode code point.

  • Parameters: Unicode code point.

  • Returns: Corresponding Glyph object.


  • Description: Returns an array of Glyph objects for a given string.

  • Parameters: A string of characters.

  • Returns: Array of Glyph objects.


  • Description: Checks if the font has a glyph for the given Unicode code point.

  • Parameters: Unicode code point.

  • Returns: Boolean indicating presence of the glyph.

font.layout(text, features, script, language):

  • Description: This is used to lay out a string of text, returning a GlyphRun object. The features parameter is optional and can be used to turn on or off OpenType features. The script and language parameters can be used to set the script and language for shaping.

  • Parameters: A string of characters, and potentially additional layout parameters.

  • Returns: GlyphRun object.


  • Description: Retrieves the human-readable name for a specific name ID in the font.

  • Parameters: Name ID.

  • Returns: String representing the name.


  • Description: Sets the default language for the font, affecting layout operations.

  • Parameters: Language tag.

  • Returns: Void (changes are applied to the Font object).


  • Description: Retrieves strings that map to a specific glyph.

  • Parameters: Glyph ID or Glyph object.

  • Returns: Array of strings.


  • Description: (Internal) Decodes the directory structure of the font, which is a key part of its binary data.

  • Parameters: Typically involves references or offsets from the font file.

  • Returns: Decoded directory structure.


  • Description: (Internal) Decodes a specific table from the font's binary data.

  • Parameters: Table references or names from the font file.

  • Returns: Decoded table data.


  • Description: (Internal) Retrieves the base glyph for a particular character or code point.

  • Parameters: Usually a character or code point.

  • Returns: Corresponding base Glyph object.


  • Description: (Internal) Fetches a specific table from the font.

  • Parameters: Table name or reference.

  • Returns: Table data.


  • Description: (Internal) Retrieves a stream for reading a specific table from the font's binary data.

  • Parameters: Table name or reference.

  • Returns: Data stream for the specified table.

Layout a String and Access Glyphs:

const run = font.layout('Hello, Fontkit!');

// Iterate over each glyph in the GlyphRun to put together pathData
let pathData = '';
let x = 0;
let y = 0;
run.glyphs.forEach((glyph, index) => {
  console.log(`Glyph ID: ${}, Unicode: ${String.fromCodePoint(...glyph.codePoints)}`);
  const position = run.positions[index];
  if (glyph.path) {
    pathData += glyph.path
      .scale(1, -1)
      .translate(x + position.xOffset, y + position.yOffset)
    x += position.xAdvance;
    y += position.yAdvance;

Last updated