harfbuzzjs
    Preparing search index...

    Class Font

    An object representing a HarfBuzz font. A font represents a face at a specific size and with certain other parameters (pixels-per-em, variation settings) specified. Fonts are the primary input to the shaping process.

    Index

    Constructors

    Properties

    ptr: number

    Accessors

    Methods

    • Draws the outline that corresponds to a glyph in the specified font.

      The outline is returned by way of calls to the callbacks of the drawFuncs object, with drawData passed to them.

      Parameters

      • glyphId: number

        The glyph ID.

      • drawFuncs: DrawFuncs

        The DrawFuncs to draw to.

      • OptionaldrawData: unknown

        User data to pass to draw callbacks.

      Returns void

    • Draws the outline that corresponds to a glyph in the specified font.

      This is a newer name for Font.drawGlyph, that returns false if the font has no outlines for the glyph.

      The outline is returned by way of calls to the callbacks of the drawFuncs object, with drawData passed to them.

      Parameters

      • glyphId: number

        The glyph ID.

      • drawFuncs: DrawFuncs

        The DrawFuncs to draw to.

      • OptionaldrawData: unknown

        User data to pass to draw callbacks.

      Returns boolean

      true if the glyph was drawn, false otherwise.

    • Fetches the PNG image for a glyph.

      To get an optimally sized PNG blob, the PPEM values must be set on the font. If PPEM is unset, the blob returned will be the largest PNG available.

      Parameters

      • glyphId: number

        A glyph index.

      Returns Uint8Array<ArrayBufferLike> | undefined

      The PNG image for the glyph, or undefined if the glyph has no PNG image.

    • Fetches a list of the caret positions defined for a ligature glyph in the GDEF table of the font.

      Note that a ligature that is formed from n characters will have n-1 caret positions. The first character is not represented in the array, since its caret position is the glyph position.

      The positions returned by this function are 'unshaped', and will have to be fixed up for kerning that may be applied to the ligature glyph.

      Parameters

      • direction: Direction

        The text direction to use.

      • glyph: number

        The glyph to query.

      Returns number[]

      An array of caret positions.

    • Fetches the optical bound of a glyph positioned at the margin of text. The direction identifies which edge of the glyph to query.

      Parameters

      • lookupIndex: number

        Index of the feature lookup to query.

      • direction: Direction

        Edge of the glyph to query.

      • glyph: number

        A glyph id.

      Returns number

      Adjustment value. Negative values mean the glyph will stick out of the margin.

    • Fetches metrics value corresponding to metricsTag from the font.

      Parameters

      • metricsTag: number

        MetricsTag of metrics value you like to fetch.

      Returns number | undefined

      The metrics value, or undefined if not found in the font.

    • Fetches metrics value corresponding to metricsTag from the font, and synthesizes a value if the value is missing in the font.

      Parameters

      • metricsTag: number

        MetricsTag of metrics value you like to fetch.

      Returns number

      The metrics value.

    • Fetches metrics value corresponding to metricsTag from the font with the current font variation settings applied.

      Parameters

      • metricsTag: number

        MetricsTag of metrics value you like to fetch.

      Returns number

      The requested metric value.

    • Fetches horizontal metrics value corresponding to metricsTag from the font with the current font variation settings applied.

      Parameters

      • metricsTag: number

        MetricsTag of metrics value you like to fetch.

      Returns number

      The requested metric value.

    • Fetches vertical metrics value corresponding to metricsTag from the font with the current font variation settings applied.

      Parameters

      • metricsTag: number

        MetricsTag of metrics value you like to fetch.

      Returns number

      The requested metric value.

    • Fetches the glyph ID for a Unicode code point in the specified font, with an optional variation selector.

      If variationSelector is 0, it is equivalent to Font.nominalGlyph; otherwise it is equivalent to Font.variationGlyph.

      Parameters

      • unicode: number

        The Unicode code point to query.

      • variationSelector: number = 0

        A variation-selector code point.

      Returns number | undefined

      The glyph ID, or undefined if not found.

    • Return glyph extents.

      Parameters

      • glyphId: number

        ID of the requested glyph in the font.

      Returns GlyphExtents | undefined

      An object with xBearing, yBearing, width, and height, or undefined.

    • Return glyph ID from name.

      Parameters

      • name: string

        Name of the requested glyph in the font.

      Returns number | undefined

      The glyph ID, or undefined if not found.

    • Return glyph horizontal advance.

      Parameters

      • glyphId: number

        ID of the requested glyph in the font.

      Returns number

      The horizontal advance width.

    • Return glyph horizontal origin.

      Parameters

      • glyphId: number

        ID of the requested glyph in the font.

      Returns [number, number] | undefined

      [x, y] origin coordinates, or undefined if not available.

    • Return glyph name.

      Parameters

      • glyphId: number

        ID of the requested glyph in the font.

      Returns string

      The glyph name string.

    • Return a glyph as an SVG path string.

      Parameters

      • glyphId: number

        ID of the requested glyph in the font.

      Returns string

      SVG path data string.

    • Return glyph vertical advance.

      Parameters

      • glyphId: number

        ID of the requested glyph in the font.

      Returns number

      The vertical advance height.

    • Return glyph vertical origin.

      Parameters

      • glyphId: number

        ID of the requested glyph in the font.

      Returns [number, number] | undefined

      [x, y] origin coordinates, or undefined if not available.

    • Fetches the nominal glyph ID for a Unicode code point in the specified font.

      This version of the function should not be used to fetch glyph IDs for code points modified by variation selectors. For variation-selector support, use Font.variationGlyph or Font.glyph.

      Parameters

      • unicode: number

        The Unicode code point to query.

      Returns number | undefined

      The glyph ID, or undefined if not found.

    • Paints the glyph. This function is similar to Font.paintGlyphOrFail, but if painting a color glyph failed, it will fall back to painting an outline monochrome glyph.

      The painting instructions are returned by way of calls to the callbacks of the paintFuncs object, with paintData passed to them.

      If the font has color palettes, then paletteIndex selects the palette to use. If the font only has one palette, this will be 0.

      Parameters

      • glyphId: number

        The glyph ID.

      • paintFuncs: PaintFuncs

        The PaintFuncs to paint with.

      • OptionalpaintData: unknown

        User data to pass to paint callbacks.

      • paletteIndex: number = 0

        The index of the font's color palette to use.

      • foreground: Color = ...

        The foreground color, unpremultiplied.

      Returns void

    • Paints a color glyph.

      Succeeds if the glyph has color paint layers (COLRv0), a color paint graph (COLRv1), or a bitmap image that the font's callbacks render successfully. Returns false if the font has no color data for the glyph; the client can then fall back to Font.drawGlyphOrFail for the monochrome outline.

      The painting instructions are returned by way of calls to the callbacks of the paintFuncs object, with paintData passed to them.

      If the font has color palettes, then paletteIndex selects the palette to use. If the font only has one palette, this will be 0.

      Parameters

      • glyphId: number

        The glyph ID.

      • paintFuncs: PaintFuncs

        The PaintFuncs to paint with.

      • OptionalpaintData: unknown

        User data to pass to paint callbacks.

      • paletteIndex: number = 0

        The index of the font's color palette to use.

      • foreground: Color = ...

        The foreground color, unpremultiplied.

      Returns boolean

      true if the glyph was painted, false otherwise.

    • Set the font's scale factor, affecting the position values returned from shaping.

      Parameters

      • xScale: number

        Units to scale in the X dimension.

      • yScale: number

        Units to scale in the Y dimension.

      Returns void

    • Applies a list of font-variation settings to a font.

      Note that this overrides all existing variations set on the font. Axes not included in variations will be effectively set to their default values.

      Parameters

      • variations: Variation[]

        Array of variation settings to apply.

      Returns void

    • Create a sub font that inherits this font's properties.

      Returns Font

      A new Font object representing the sub font.

    • Fetches the glyph ID for a Unicode code point when followed by by the specified variation-selector code point, in the specified font.

      Parameters

      • unicode: number

        The Unicode code point to query.

      • variationSelector: number

        The variation-selector code point to query.

      Returns number | undefined

      The glyph ID, or undefined if not found.