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

Properties

Static Private DELIMITERS

DELIMITERS: string = ",.-/()[]<>"

Methods

Static Private advances

  • advances(label: Label, text?: undefined | 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: undefined | 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: Array<Fragment>, labelFragmentWidths: Float32Array, labelAdvances: Float32Array, labelKernings: Float32Array, reverse: boolean): [Array<Fragment>, Array<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: Array<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 [Array<Fragment>, Array<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: Array<Fragment>, advances: Float32Array, kernings: Float32Array): Float32Array
  • Compute fragment widths without kernings w.r.t. preceding and subsequent fragments.

    Parameters

    • fragments: Array<Fragment>

      -

    • advances: Float32Array

      -

    • kernings: Float32Array

      -

    Returns Float32Array

    -

Static Private fragments

  • 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 Array<Fragment>

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

Static Private kernings

  • kernings(label: Label, text?: undefined | 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: undefined | 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 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: Array<Line>

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

    Returns void

Static Private transformAlignment

  • transformAlignment(width: number, alignment: Alignment, vertices: GlyphVertices | undefined, 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: GlyphVertices | undefined

      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: GlyphVertices | undefined, 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: GlyphVertices | undefined

      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 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: GlyphVertices | undefined

      Glyph vertex store required for rendering.

    • index: number

      Glyph vertex index for store manipulation.

    Returns void