Vixen
02b45cc4
csharp
public record class TextRun

One stretch of an element's text: one face, shaped and measured at one size.

No guide page documents this yet — the page shows what the code says about itself.

Remarks

A run is one face, and a line is a list of them. See TextLine: a string whose characters are not all in one font becomes several runs, and so would a rich text span carrying its own size. Everything on this type is about the one face, so a consumer that reaches for Font or Scale is asking a question only a run can answer — the line is where a mixed-font width or caret lives, because those can only be composed in pixels.

⚠ One line. Nothing here breaks a paragraph across lines, so a string wider than its element overflows it rather than wrapping — the measure function ignores the width it is offered. Vixen.Ui.Text already has the UAX#14 line breaker this needs and wrapping is the next piece of text work rather than a missing consideration; said here so that a long label overflowing reads as a known edge rather than as a layout bug.

The size is carried alongside the shaping rather than baked into it, because the shaping is shared: the cache returns the same ShapedText for the same string in the same font whatever size it is drawn at, and this is the per-element view of it.

Fields and properties (11)

  • public FontFace Font

    The face it was shaped with.

  • public ShapedText Shaped

    The glyphs, in design units.

  • public float Size

    The font size in pixels — what an em on this element measures.

  • public float Tracking

    letter-spacing in pixels, added after every typographic character. Zero for the overwhelming majority of text, and the code below is written so that zero costs nothing.

  • public float Leading

    The computed line-height in pixels, or NaN for the font's own recommendation. NaN rather than zero, because zero is a line height somebody might mean.

  • public int Start

    Where this run's text begins in the element's, as a UTF-16 index. Zero for a line that is one run, and what lets a caret index reach the run it belongs to.

  • public float Scale

    What multiplies a design unit to give a pixel.

  • public int Clusters

    How many typographic characters the line has, for tracking to be added between.

  • public float Width

    How wide the line is.

  • public float Height

    How tall one line of it is.

  • public float Baseline

    How far below the top of the line the baseline sits.

Methods (4)

  • public TextRun(FontFace Font, ShapedText Shaped, float Size, float Tracking = 0, float Leading = NaN, int Start = 0)

    One stretch of an element's text: one face, shaped and measured at one size.

  • public float CaretOffset(int index)

    How far along the run a caret index sits, in pixels.

  • public int CaretIndexAt(float x)

    Which caret index a distance from the run's start lands on.

  • public void Place(List<PositionedGlyph> into, float penX = 0)

    Places every glyph relative to the start of the line.

Used by (6)

  • DrawListBuilderVixen.Ui
  • FontFallbackTestsVixen.Ui.Tests
  • FontRegistryTestsVixen.Ui.Tests
  • TextLineVixen.Ui
  • TextTestsVixen.Ui.Tests
  • UiElementVixen.Ui