Back to API Reference
Class

TextProcessor

sealed

Processes Unicode text through script analysis, BiDi reordering, shaping, and layout.

Remarks

TextProcessor is the main entry point for the text processing pipeline. It orchestrates multiple Unicode algorithms to produce correctly shaped and positioned glyphs. Processing pipeline: Parsing — converts UTF-16 to codepoints Script analysis (UAX #24) — identifies script per codepoint BiDi algorithm (UAX #9) — determines text direction and reordering Itemization — splits text into runs by script, direction, and font Shaping — converts codepoints to positioned glyphs via HarfBuzz Line breaking (UAX #14) — determines line break opportunities Layout — positions glyphs according to alignment settings Performance: The processor caches intermediate results. Use invalidation methods only when necessary to avoid redundant processing.

Example

csharp
public bool HasValidFirstPassData{ get }

Gets a value indicating whether valid first pass data (parsing, BiDi, shaping) is available.

public bool HasValidPositionedGlyphs{ get }

Gets a value indicating whether valid positioned glyphs are available.

public float ResultWidth{ get }

Gets the actual width of the laid out text.

public float ResultHeight{ get }

Gets the actual height of the laid out text.

public ReadOnlySpan<PositionedGlyph> PositionedGlyphs{ get }

Gets the positioned glyphs ready for rendering.

[ctor]public TextProcessor(UniTextBuffers uniTextBuffers)

Initializes a new instance of the TextProcessor class.

public void SetFontProvider(UniTextFontProvider provider)

Sets the font provider used for font lookup and glyph metrics.

public void InvalidateFirstPassData()

Invalidates all cached processing data, forcing a complete reprocess on next call.

public void InvalidateLayoutData()

Invalidates cached layout data while preserving shaping results.

public void InvalidatePositionedGlyphs()

Invalidates cached glyph positions while preserving line break data.

public void EnsureFirstPass(ReadOnlySpan<char> text, TextProcessSettings settings)

Ensures the first pass processing (parsing, BiDi, shaping) is complete.

public bool CanReuseLines(float width, float fontSize, bool wordWrap)

Determines whether cached line data can be reused for the specified parameters.

public bool CanReusePositions(float maxHeight, HorizontalAlignment hAlign, VerticalAlignment vAlign)

Determines whether cached glyph positions can be reused for the specified parameters.

public void EnsureLines(float width, float fontSize, bool wordWrap)

Ensures line breaking is complete for the specified parameters.

public void EnsurePositions(TextProcessSettings settings)

Ensures final glyph positioning is complete for the specified settings.

public float GetUnwrappedWidth()

Gets the total width of all text runs without line wrapping.

public float GetPreferredWidth(float fontSize)

Gets the preferred width for the text at the specified font size.

public float GetPreferredHeight(float fontSize, float lineSpacing)

Gets the preferred height for the text at the specified font size.

public float GetMaxLineWidth()

Gets the maximum width among all lines, considering explicit line breaks.

public float FindOptimalFontSize(float minSize, float maxSize, float targetWidth, float targetHeight, TextProcessSettings baseSettings)

Finds the optimal font size to fit text within the specified dimensions.

public void ForceRelayout(ReadOnlySpan<float> cpWidths)

Forces a complete relayout using custom codepoint widths.

public void ForceReposition()

Forces recalculation of glyph positions while preserving line breaks.

public readonly UniTextBuffers buf

The buffer container holding all intermediate and final processing results.

public LineHeightDelegate OnCalculateLineHeight

Invoked for each line during layout to allow modifiers to adjust line height.

public Action Parsed

Occurs after text parsing completes but before shaping.

public Action Shaped

Occurs after text shaping completes.

public Action LayoutComplete

Occurs after layout calculation completes.

See Also