Options
All
  • Public
  • Public/Protected
  • All
Menu

Class FontFaceLoader

Transforms input raw data of a text-based font file to a font face (@see FontFace) specification. All referenced pages/glyph atlases will be loaded and setup as well. This is intended to be used directly by the FontFace and is not required to be exposed to webgl-operates public API.

Hierarchy

  • FontFaceLoader

Index

Methods

Static Protected findAscentAndDescentIfNoneProvided

  • findAscentAndDescentIfNoneProvided(fontFace: FontFace, size: number): void
  • Derives ascent and descent data for the font face. Since the computation is based on the available glyphs and not all of the font's glyphs might be included in the font face, the ascent/descent might be off (based on minimum y-offset).

    Parameters

    • fontFace: FontFace

      Font face to find ascent and/or descent for (if missing).

    • size: number

      Suggested size of the font face as read from the font file. Note that the actual size of the font face is determined by the sum of ascent and descent (which should equal the font files info size).

    Returns void

Static process

  • process(fontFace: FontFace, data: string, url: string, headless?: boolean): Promise<FontFace | undefined>
  • Asynchronously loads a fnt-file and referenced pages to create a font face from them.

    Parameters

    • fontFace: FontFace

      Font face object to transform data into.

    • data: string

      Font face data, probably fetched from an URL.

    • url: string

      Uniform resource locator string referencing the fnt-file that was loaded.

    • Default value headless: boolean = false

      Whether or not to enable headless mode. If enabled, pages are not loaded.

    Returns Promise<FontFace | undefined>

Static Protected processChar

  • processChar(stream: Array<string>, fontFace: FontFace): boolean
  • Parses the char fields for character id (code point), x, y, width, height, xoffset, yoffset, xadvance to store them in the font face as instances of Glyph. This relies on fontFace.base and fontFace.glyphTextureExtent, so execute processCommon() first.

    Parameters

    • stream: Array<string>

      The stream of the 'char' identifier.

    • fontFace: FontFace

      The font face in which the loaded glyph texture is stored.

    Returns boolean

Static Protected processCommon

  • processCommon(stream: Array<string>, fontFace: FontFace): boolean
  • Parses the common fields for lineHeight, base, ascent, descent, scaleW and scaleH to store them in the font face. If ascent and/or descent are not available, they can be computed using the largest y-offset (ascent = baseline - max_yoffset) and descent can be derived as well (descent = - fontsize + ascent).

    Parameters

    • stream: Array<string>

      The stream of the 'common' identifier.

    • fontFace: FontFace

      The font face in which the parsed values are stored.

    Returns boolean

Static Protected processInfo

  • processInfo(stream: Array<string>, fontFace: FontFace): boolean
  • Parses the info fields for padding values and stores them in the font face

    Parameters

    • stream: Array<string>

      The stream of the 'info' identifier.

    • fontFace: FontFace

      The font face in which the padding is stored.

    Returns boolean

Static Protected processKerning

  • processKerning(stream: Array<string>, fontFace: FontFace): boolean
  • Parses the kerning fields for first and second character and the amount, to store them in the font face.

    Parameters

    • stream: Array<string>

      The stream of the 'kerning' identifier.

    • fontFace: FontFace

      The font face in which the kerning tuples are stored.

    Returns boolean

Static Protected processPage

  • processPage(stream: Array<string>, fontFace: FontFace, url: string): Promise<void> | undefined
  • Parses a page to load the associated png-file, i.e., the glyph atlas.

    Parameters

    • stream: Array<string>

      The stream of the 'page' identifier.

    • fontFace: FontFace

      The font face in which the loaded glyph texture is stored.

    • url: string

      Uniform resource locator string referencing the fnt-file (used for base path retrieval).

    Returns Promise<void> | undefined

    • Promise for handling image load status.

Static Protected readKeyValuePairs

  • readKeyValuePairs(stream: Array<string>, mandatoryKeys: Array<string>, resultPairs: StringPairs): boolean
  • Parses to find key-value pairs for given mandatory keys.

    Parameters

    • stream: Array<string>

      The stream from which the pairs should be read.

    • mandatoryKeys: Array<string>

      The found pairs are only valid if the mandatory keys are found.

    • resultPairs: StringPairs

    Returns boolean

    • success