Subset 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.
Fontkit can perform font subsetting, i.e. the process of creating a new font from an existing font where only the specified glyphs are included. This is useful to reduce the size of large fonts, such
Creating a Subset:
font.createSubset()
font.createSubset()
Description: Creates a new subset from the font.
Returns: A new
Subset
object.
Properties
subset.font
:
subset.font
:Type:
Font
Description: The original font from which the subset is derived. It provides a reference to the main font object, allowing access to all its properties, methods, and associated data.
subset.glyphEncoder
:
subset.glyphEncoder
:Type: Object or Encoder
Description: The encoder responsible for encoding the glyphs when creating the subset. This will often handle the conversion of glyph data into the required format for the subset.
subset.glyphs
:
subset.glyphs
:Type: Array of
Glyph
objectsDescription: An array containing all the glyphs that are included in the subset. Each glyph is an instance of the
Glyph
object, encapsulating its individual properties, metrics, and path data.
subset.mapping
:
subset.mapping
:Type: Object
Description: Represents the mapping between the glyphs in the original font and their corresponding entries in the subset. This ensures that when text is rendered using the subset, the correct glyphs are displayed.
Methods:
subset.includeGlyph(glyph)
subset.includeGlyph(glyph)
Description: Includes the given glyph in the subset.
Parameters:
glyph
: AGlyph
object or glyph ID to be included in the subset.
subset.encode()
subset.encode()
Description: Encodes the subset font.
Returns: A
Uint8Array
containing the encoded font data.
Example:
Last updated