Options
All
  • Public
  • Public/Protected
  • All
Menu

Class TextFormatter

Hierarchy

  • TextFormatter

Index

Properties

Static DEBUG

DEBUG: boolean = false

To enable logging for this class. Set Vex.Flow.TextFormatter.DEBUG to true.

Accessors

fontSizeInPixels

  • get fontSizeInPixels(): number
  • this.size is specified in points. Convert to pixels.

    Returns number

localHeightCache

  • get localHeightCache(): Record<string, undefined | yExtent>
  • Returns Record<string, undefined | yExtent>

maxHeight

  • get maxHeight(): number
  • Returns number

Methods

getGlyphMetrics

  • getGlyphMetrics(character: string): FontGlyph
  • The glyphs table is indexed by the character (e.g., 'C', '@'). See: robotoslab_glyphs.ts & petalumascript_glyphs.ts.

    Parameters

    • character: string

    Returns FontGlyph

getResolution

  • getResolution(): number
  • Returns number

getWidthForCharacterInEm

  • getWidthForCharacterInEm(c: string): number
  • Retrieve the character's advanceWidth as a fraction of an em unit. For the space character ' ' as defined in the: petalumascript_glyphs.ts: 250 advanceWidth in the 1000 unitsPerEm font returns 0.25. robotoslab_glyphs.ts: 509 advanceWidth in the 2048 unitsPerEm font returns 0.2485.

    Parameters

    • c: string

    Returns number

getWidthForTextInEm

  • getWidthForTextInEm(text: string): number
  • Retrieve the total width of text in em units.

    Parameters

    • text: string

    Returns number

getWidthForTextInPx

  • getWidthForTextInPx(text: string): number
  • The width of the text (in em) is scaled by the font size (in px).

    Parameters

    • text: string

    Returns number

getYForCharacterInPx

  • getYForCharacterInPx(c: string): yExtent
  • Retrieve the character's y bounds (ymin, ymax) and height.

    Parameters

    • c: string

    Returns yExtent

getYForStringInPx

  • getYForStringInPx(str: string): yExtent
  • Parameters

    • str: string

    Returns yExtent

setFontSize

updateCacheKey

  • updateCacheKey(): void
  • Create a hash with the current font data, so we can cache computed widths.

    Returns void

updateParams

Static create

  • Call TextFormatter.registerInfo(info) to register font information before using this method.

    This method creates a formatter for the font that most closely matches the requested font. We compare font family, bold, and italic attributes. This method will return a fallback formatter if there are no matches.

    Parameters

    Returns TextFormatter

Static getFontFamilies

Static getInfo

  • Parameters

    • fontFamily: string

      used as a key to the font registry.

    Returns undefined | TextFormatterInfo

    the same info object that was passed in via TextFormatter.registerInfo(info)

Static registerInfo

  • Apps may register their own fonts and metrics, and those metrics will be available to the app for formatting.

    Metrics can be generated from a font file using fontgen_text.js in the tools/fonts directory.

    Parameters

    Returns void