Skip to main content

TextOptions and TextRun

Namespace: PinataLabs.Typography. Guides: Wrapping and alignment, Rich text.

TextOptions​

public class TextOptions

The settings that TextMeasurer and TextRenderer use to lay out text. A TextOptions object is mutable. Do not change one while another thread uses it.

Constructors​

ConstructorDescription
TextOptions(Font font)Options with font and the default value of every other property.
TextOptions(TextOptions options)A copy of options. The lists in it are copied too.

Properties​

PropertyTypeDefaultDescription
FontFont(required)The font of the text. Must not be null.
FallbackFontFamiliesIReadOnlyList<FontFamily>emptyFamilies to take glyphs from when the font has none. See Fallback fonts.
Dpifloat72The resolution, in dots per inch. Must not be negative. At 72, one point is one pixel.
OriginVector2(0, 0)The point that the text box is placed at.
WrappingLengthfloat-1The width of the text box in pixels (the height, for vertical text). Lines wrap at this length. -1 turns wrapping off.
WordBreakingWordBreakingStandardHow to break words that do not fit.
LineSpacingfloat1A multiple of the font's line height. Must not be 0.
TextDirectionTextDirectionAutoThe base direction of the text, as CSS direction. Auto finds it from the first strong character.
TabWidthfloat-1The width of a tab, as a number of spaces. -1 uses the font's tab glyph.
TextAlignmentTextAlignmentStartHow each line is placed in the text box.
TextJustificationTextJustificationNoneHow lines are stretched to the width of the box. Needs WrappingLength.
HorizontalAlignmentHorizontalAlignmentLeftWhich part of the text box is at Origin, horizontally.
VerticalAlignmentVerticalAlignmentTopWhich part of the text box is at Origin, vertically.
LayoutModeLayoutModeHorizontalTopBottomHorizontal lines or vertical columns. See Vertical text.
KerningModeKerningModeStandardWhether to apply kerning.
HintingModeHintingModeNoneWhether to apply TrueType hinting. See Hinting.
ColorFontSupportColorFontSupportMicrosoftColrFormatWhether to use color glyphs. See Color fonts.
FeatureTagsIReadOnlyList<Tag>emptyMore OpenType features to apply. See OpenType features.
TextRunsIReadOnlyList<TextRun>emptyRuns that style parts of the text.

TextRun​

public class TextRun

A part of the text with its own font, decorations or attributes. You can subclass it to carry your own data to a renderer.

MemberDescription
TextRun()Makes an empty run.
StartThe index of the first grapheme of the run. Inclusive.
EndThe index after the last grapheme of the run. Exclusive.
FontThe font of the run. null means TextOptions.Font.
TextAttributesNone, Subscript or Superscript.
TextDecorationsNone, or any combination of Underline, Strikeout and Overline.
Slice(ReadOnlySpan<char> text)The part of text that the run covers.

Start and End count graphemes, not char values. Text outside every run uses TextOptions.Font.

The library does not change your TextRun objects, so you can reuse them. It clamps Start and End to the grapheme count and drops runs that are empty after clamping. When runs overlap or nest, the run that is later in the list wins for the overlapping part, and the earlier run continues after it. The order of Start values does not matter.