Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Typesetter

The typesetter is responsible for layouting text on the screen or in a virtual space. It takes a label, which defines where it wants to appear (@see Label), and a font face that is used to display the text, and computes the actual position for each glyph. Its output is a vertex array, which describes the glyphs position and appearance on the screen/in the scene and which can be rendered using a LabelRenderPass.

Hierarchy

  • Typesetter

Index

Constructors

constructor

Properties

Static Private Readonly DELIMITERS

DELIMITERS: string = '\x0A ,.-/()[]<>'

Methods

Static Private advances

  • advances(label: Label, text?: string): Float32Array
  • Resolves a typed float array storing the advances of each of the label's characters.

    Parameters

    • label: Label

      Label to resolve advances for.

    • Optional text: string

      Text to compute advances for, if none is given, label.text is used.

    Returns Float32Array

    • A typed float array of all ordered character advances.

Static Private elideFragments

  • elideFragments(threshold: number, labelFragments: Fragment[], labelFragmentWidths: Float32Array, labelAdvances: Float32Array, labelKernings: Float32Array, reverse: boolean): [Fragment[], number[], number]
  • Creates a sub list of fragments that fit into threshold. The last fragment might be adjusted in order to cram as many characters as possible for the elide. Reverse flag can be used do start left or right.

    Parameters

    • threshold: number

      Threshold in typesetting space.

    • labelFragments: Fragment[]

      Pre-computed label fragments.

    • labelFragmentWidths: Float32Array

      Pre-accumulated widths of the label fragments.

    • labelAdvances: Float32Array

      Advances in order to reduce lookups.

    • labelKernings: Float32Array

      Kernings in order to reduce lookups.

    • reverse: boolean

      -If enabled, the right side elide fragments will be collected and adjusted. Left side otherwise.

    Returns [Fragment[], number[], number]

    • A new fragment, fragment-widths array for elide advancing, and overall width.

Static Private elideThresholds

  • elideThresholds(label: Label, ellipsisWidth: number): [number, number]
  • Computes the left and right side thresholds for elide computation.

    Parameters

    • label: Label

      Label to query elide mode and line width from.

    • ellipsisWidth: number

      Pre-computed width of the full ellipsis (t avoid re-computation).

    Returns [number, number]

    • The left and right thresholds intended for elide fragment retrieval.

Static Private fragmentWidths

  • fragmentWidths(fragments: Fragment[], advances: Float32Array, kernings: Float32Array): Float32Array
  • Compute fragment widths without kernings w.r.t. preceding and subsequent fragments.

    Parameters

    • fragments: Fragment[]

      -

    • advances: Float32Array

      -

    • kernings: Float32Array

      -

    Returns Float32Array

    -

Static Private fragments

  • fragments(label: Label): Fragment[]
  • Create array of word, delimiter, and line feed fragments. A fragment thereby denotes the start and exclusive end index as well as the type. The array is intended to favor maintainability over performance.

    Parameters

    • label: Label

      Label to create fragments for.

    Returns Fragment[]

    • Fragments, i.e., indices ranges and associated fragment type (word, linefeed, delimiter).

Static Private getMinMaxVertices

  • getMinMaxVertices(vertices: GlyphVertices, begin: number, end: number): [number, number, number, number, number, number]
  • Returns [minX, minY, minZ, maxX, maxY, maxZ] of the vertices coordinates, i.e., origins, origins + tangents, origins + ups, from which a bounding rectangle can be calculated.

    Parameters

    • vertices: GlyphVertices

      Glyph vertices to be transformed (expected untransformed, in typesetting space).

    • begin: number

      Vertex index to start alignment at.

    • end: number

      Vertex index to stop alignment at.

    Returns [number, number, number, number, number, number]

Static Private kernings

  • kernings(label: Label, text?: string): Float32Array
  • Resolves a typed float array storing the kernings of each of the label's characters.

    Parameters

    • label: Label

      Label to resolve kernings for.

    • Optional text: string

      Text to compute advances for, if none is given, label.text is used.

    Returns Float32Array

    • A typed float array of all ordered character kernings.

Static Private lineAnchorOffset

  • lineAnchorOffset(label: Label): number
  • Compute an initial line anchor w.r.t. the targeted anchoring.

    Parameters

    • label: Label

      Label to adjust the y-positions for.

    Returns number

Static Private minMax

  • minMax(currentMin: number, currentMax: number, values: number[]): vec2
  • Returns a vec2 [min, max] containing the minimum and the maximum of the given values.

    Parameters

    • currentMin: number

      the current minimum (e.g., initialized to +Infinity)

    • currentMax: number

      the current maximum (e.g., initialized to -Infinity)

    • values: number[]

      find the maximum and minimum of the given values

    Returns vec2

Static Private transform

  • Create and transform glyph vertices for rendering.

    Parameters

    • label: Label

      Label providing transform data, e.g., alignment and static transform.

    • vertices: GlyphVertices

      Glyph vertices to apply transformations to.

    • lines: Line[]

      Indices of glyph vertices on same lines to apply line-based transformations.

    Returns void

Static Private transformAlignment

  • transformAlignment(width: number, alignment: Alignment, vertices: undefined | GlyphVertices, begin: number, end: number): void
  • Adjusts the vertices for a line after typesetting (done due to line feed, word wrap, or end of line) w.r.t. the targeted line alignment.

    Parameters

    • width: number

      Width of the line (e.g., typesetting position at the end of the line in typesetting space).

    • alignment: Alignment

      Targeted alignment, e.g., left, center, or right.

    • vertices: undefined | GlyphVertices

      Glyph vertices for rendering to align the origins' x-components of (expected untransformed).

    • begin: number

      Vertex index to start alignment at.

    • end: number

      Vertex index to stop alignment at.

    Returns void

Static Private transformVertices

  • transformVertices(transform: mat4, vertices: undefined | GlyphVertices, begin: number, end: number): void
  • Computes origin, tangent, and up vector for every vertex of in the given range.

    Parameters

    • transform: mat4

      Transformation to apply to every vertex.

    • vertices: undefined | GlyphVertices

      Glyph vertices to be transformed (expected untransformed, in typesetting space).

    • begin: number

      Vertex index to start alignment at.

    • end: number

      Vertex index to stop alignment at.

    Returns void

Static typeset

  • Typesets the given label, transforming the vertices in-world, ready to be rendered.

    Parameters

    • label: Label

      The label that is to be typeset.

    • vertices: GlyphVertices

      in/out The glyph vertices, a prepared (optionally empty) vertex storage.

    Returns number

    • The number of glyphs that are actually typeset and setup as vertices.

Static Private updateRectangleMinMax

  • updateRectangleMinMax(currentRectangle: number[], newRectangle: number[]): void
  • Parameters

    • currentRectangle: number[]

      [minX, minY, minZ, maxX, maxY, maxZ] is updated in-place

    • newRectangle: number[]

      [minX, minY, minZ, maxX, maxY, maxZ] used to update currentRectangle

    Returns void

Static Private writeVertex

  • Configuring the vertex for a given glyph to be rendered. If no vertex is given or the glyph is not depictable, this method immediately exits at the beginning.

    Parameters

    • fontFace: FontFace

      Font face to be applied for setting up the vertex.

    • pen: vec2

      Typesetting position which is the not-yet-transformed position the glyph will be rendered at.

    • glyph: Glyph

      Glyph that is to be rendered/configured.

    • vertices: undefined | GlyphVertices

      Glyph vertex store required for rendering.

    • index: number

      Glyph vertex index for store manipulation.

    Returns void