Skip to content
TextLayout

TextLayout

Mojo struct 🡭

TextLayout

@memory_only
struct TextLayout

Text already shaped, kerned, line-broken and aligned, ready to be measured or drawn without doing that work again.

Pass a prepared layout to measure_layout and draw_layout. It retains the string, font, rotation, alignment, kerning, and ligature settings used to prepare it. Its anchor is relative, so it can be drawn at any (x, y).

The FontCache it was prepared against must be the one it is drawn with. The layout holds glyph indices resolved through that cache’s faces, not the outlines themselves.

Fields

  • text (String)
  • size (Float64)
  • family (String)
  • slant (FontSlant)
  • weight (FontWeight)
  • rotation (Float64)
  • align (TextAlign)
  • kerning (Bool)
  • ligatures (Bool)

Implemented traits

AnyType, Deinitable, Movable

Methods

__init__

fn def __init__(out self, var block: _BlockLayout, var text: String, size: Float64, var family: String, slant: FontSlant, weight: FontWeight, rotation: Float64, align: TextAlign, kerning: Bool, ligatures: Bool)

Args:

  • block (_BlockLayout)
  • text (String)
  • size (Float64)
  • family (String)
  • slant (FontSlant)
  • weight (FontWeight)
  • rotation (Float64)
  • align (TextAlign)
  • kerning (Bool)
  • ligatures (Bool)
  • self (Self)

Returns:

Self

has_ink

fn def has_ink(self) -> Bool

Whether anything would actually be drawn. False for an empty string, and for one that is only whitespace.

Args:

  • self (Self)

Returns:

Bool