Skip to content
TextRun

TextRun

Mojo struct 🡭

TextRun

@memory_only
struct TextRun

One piece of a label draw_text_runs draws: its text at its own size and slant, placed against the runs around it. A label that mixes sizes or slants – a variable in italic, a superscript at 70% – is a list of these and stays one label: one <text> element on SVG, one string to select, copy or announce.

dx moves the pen before the run, from where the previous run’s advance ended: a kern, negative to back up, which is how a fraction’s denominator gets under its numerator. dy is the run’s baseline relative to the label’s baseline, positive downward, so a superscript is negative and the run after it is back at 0. Both are in the label’s own frame, before rotation. They are <tspan>’s dx and dy, except that dy here names the run’s own baseline rather than a shift that carries on to the runs after it.

Fields

  • text (String)
  • size (Float64)
  • slant (FontSlant)
  • dx (Float64)
  • dy (Float64)

Implemented traits

AnyType, Copyable, Deinitable, ImplicitlyCopyable, Movable

Methods

__init__

fn def __init__(out self, text: String, size: Float64, slant: FontSlant = FontSlant.NORMAL, dx: Float64 = 0, dy: Float64 = 0)

One run of a label made of several.

Args:

  • text (String): The run’s text, one line.
  • size (Float64): Font size in pixels.
  • slant (FontSlant): Upright, italic or oblique.
  • dx (Float64): Pen shift before the run, from the previous run’s end.
  • dy (Float64): The run’s baseline, relative to the label’s; positive is downward, so a superscript is negative.
  • self (Self)

Returns:

Self