Options
All
  • Public
  • Public/Protected
  • All
Menu

Measures the dimensions of text

Hierarchy

  • TextMeasurer

Index

Constructors

Properties

Methods

Constructors

Private constructor

  • new TextMeasurer(ctx: CanvasRenderingContext2D): TextMeasurer
  • Parameters

    • ctx: CanvasRenderingContext2D

    Returns TextMeasurer

Properties

Private Readonly ctx

ctx: CanvasRenderingContext2D

Canvas ctx used to measure text

Methods

measureLines

  • measureLines(lines: string[], lineSpacingPx: number, font: string): [Point, Point[]]
  • Get the total size of several lines and the individual size of each line

    Parameters

    • lines: string[]

      Array of lines of text to measure

    • lineSpacingPx: number

      Distance in pixels between the end of one line and the start of the next

    • font: string

      CSS font string representing the font to measure the text in. Should set at least font size and font-family.

    Returns [Point, Point[]]

    [total size, size of each line[]]; The total size is the combined size of each line plus the line spacing between each line, and each line's size is the size of the text without extra spacing

measureOneLine

  • measureOneLine(line: string, font: string): Point
  • Get the size of a single line

    Parameters

    • line: string
    • font: string

      CSS font string representing the font to measure the text in. Should set at least font size and font-family.

    Returns Point

Static new

  • Create a new TextMeasurer

    Returns Result<TextMeasurer, string>

    New Some(TextMeasurer) if construction succeeds, Err(message) if the construction fails

Generated using TypeDoc