Options
All
  • Public
  • Public/Protected
  • All
Menu

Represents a font in the RFN font format. This is a raster font format, so all text metrics are in pixels.

Hierarchy

  • Font

Index

Constructors

constructor

  • new Font(fileName: string): Font
  • Construct a new Font from a given font file. The font is usable immediately, but text will not be rendered until it loads completely.

    Parameters

    • fileName: string

      SphereFS path of an RFN format font file.

    Returns Font

Properties

fileName

fileName: string

SphereFS path of the file from which this Font was constructed.

height

height: number

Height of a line of text as rendered using this font, in pixels.

Static Default

Default: Font

The default font provided by the engine.

Methods

drawText

  • drawText(surface: Surface, x: number, y: number, text: string, color?: Color, wrapWidth?: number): void
  • Render text to a surface using this font.

    Parameters

    • surface: Surface

      The surface on which to render.

    • x: number

      X coordinate where the text will be drawn.

    • y: number

      Y coordinate where the text will be drawn.

    • text: string

      Text string to render.

    • Optional color: Color

      Color of the text.

    • Optional wrapWidth: number

      If the text is wider than wrapWidth in pixels, it will be wrapped to multiple lines automatically.

    Returns void

getTextSize

  • getTextSize(text: string, wrapWidth: number): Size2D
  • Get the width and height of a text as drawn with this font when using word wrapping.

    Parameters

    • text: string

      The text to be measured.

    • wrapWidth: number

      Maximum width at which to wrap the text, in pixels.

    Returns Size2D

    A Size2D object with the measured width and height of the text.

heightOf

  • heightOf(text: string, wrapWidth?: number): number
  • Get the height of a text as drawn with this font using a given wrapWidth.

    Parameters

    • text: string

      The text to be measured.

    • Optional wrapWidth: number

      The maximum width at which to wrap the text, in pixels.

    Returns number

widthOf

  • widthOf(text: string): number
  • Get the width of a single line of text as drawn with this font.

    Parameters

    • text: string

      The text to be measured.

    Returns number

    The width of the text when rendered, in pixels.

wordWrap

  • wordWrap(text: string, wrapWidth: number): string[]
  • Split a text into multiple lines by applying word wrapping and newlines.

    Parameters

    • text: string

      The text string to process.

    • wrapWidth: number

      The maximum width at which to wrap the text, in pixels.

    Returns string[]

    An array of strings, with each string being a new line of text.

Static fromFile

  • fromFile(fileName: string): Promise<Font>
  • Load a font in the background and construct a new Font for it once it's ready.

    async

    Parameters

    • fileName: string

      SphereFS path of an RFN format font file.

    Returns Promise<Font>

    A promise for a newly constructed Font object.

Legend

  • Module
  • Object literal
  • Variable
  • Function
  • Function with type parameter
  • Index signature
  • Type alias
  • Type alias with type parameter
  • Enumeration
  • Enumeration member
  • Property
  • Method
  • Interface
  • Interface with type parameter
  • Constructor
  • Property
  • Method
  • Index signature
  • Class
  • Class with type parameter
  • Constructor
  • Property
  • Method
  • Accessor
  • Index signature
  • Inherited constructor
  • Inherited property
  • Inherited method
  • Inherited accessor
  • Protected property
  • Protected method
  • Protected accessor
  • Private property
  • Private method
  • Private accessor
  • Static property
  • Static method

Generated using TypeDoc