Skip to content
text_run_anchors

text_run_anchors

Mojo function 🡭

text_run_anchors

fn def text_run_anchors(x: Float64, y: Float64, runs: List[TextRun], family: String = "Sans", weight: FontWeight = FontWeight.NORMAL, rotation: Float64 = 0, align: TextAlign = TextAlign.LEFT, *, mut cache: FontCache) -> List[FPoint]

Where each run of draw_text_runs(x, y, runs, ...) lands: the anchor draw_text takes for that run drawn alone, with TextAlign.LEFT and the same rotation. One entry per run, in order.

The pen starts at the label’s origin; each run moves it by its dx, takes the pen as its left end, and advances it by its own measured advance. Where the pen ends is the label’s width, and align shifts every run by none, half or all of it, as draw_text shifts a line by its advance. Each run’s (pen, dy) is then rotated about (x, y), clockwise on screen. A run with no text moves nothing and takes the pen where it stands.

This is the layout the raster, PDF and bounds backends share. The SVG backend writes the offsets into <tspan>s and the viewer’s font metrics decide the advances and the alignment, as they do for a single run.

Args:

  • x (Float64): Anchor x, sub-pixel: the label’s left end for TextAlign.LEFT.
  • y (Float64): Anchor y, sub-pixel: the label’s baseline.
  • runs (List[TextRun]): The label’s runs, in reading order.
  • family (String): Font family name or generic alias, shared by every run.
  • weight (FontWeight): Normal or bold, shared by every run.
  • rotation (Float64): Radians about the anchor.
  • align (TextAlign): Horizontal alignment of the whole label.
  • cache (FontCache): Shared font cache to measure through.

Returns:

List[FPoint]: One anchor per run, in runs order.

Raises:

Error: No font could be resolved for family.