TextEngine
Core text layout, line-wrapping, dimension measurement, and inline-content rendering engine.
Overview
TextEngine is the centralized subsystem responsible for measuring character widths, wrapping long text runs across multiple lines, aligning blocks horizontally/vertically, and laying out embedded inline spans (icons, textures, badges) alongside regular text.
Text and Content Measurement
Measurement methods compute line dimensions (measureLineWidth) and block heights (measureTextHeight) taking into account font ascent, descent, character code-points, and atomic inline spans. The minContentWidth method determines the minimum width required to display the longest word without clipping.
Line Wrapping
wrapLines() splits rich text across word boundaries to fit within a given maximum width (maxWidth). If single words exceed the available line width, they are broken at character boundaries to prevent line overflows.
Rendering and Inline Content
When rendering plain text runs, TextEngine delegates directly to RenderBackend. If inline spans exist, TextEngine computes exact coordinates for each atom and invokes its InlineContentRenderer with final screen bounds.
Measuring and Wrapping Rich Text
float maxWidth = 200.0f;
List<RichText> lines = TextEngine.wrapLines(context, richText, maxWidth);
float totalHeight = TextEngine.linesHeight(context, lines);
Drawing Aligned Text into Canvas
TextEngine.draw(context, richText, x, y, width, height, paint, transform,
Alignment.CENTER, Alignment.CENTER);
API
TextEngine::measureLineWidth(String)
measureLineWidth(String)
Measures line width using approximate glyph spacing without active backend.
| Parameter | Type | Description |
|---|---|---|
text |
String |
Text to measure. |
Returns float: Calculated line width in pixels..
TextEngine::minContentWidth(RichText)
minContentWidth(RichText)
Calculates the width of the longest unbreakable word in the rich text.
| Parameter | Type | Description |
|---|---|---|
text |
RichText |
Rich text to inspect. |
Returns float: Minimum content width in pixels..
TextEngine::measureLineWidth(RenderContext, String)
measureLineWidth(RenderContext, String)
Measures string width using active render backend font metrics.
| Parameter | Type | Description |
|---|---|---|
context |
RenderContext |
Active render context. |
text |
String |
Text string. |
Returns float: Line width in pixels..
TextEngine::measureLineWidth(RenderContext, RichText)
measureLineWidth(RenderContext, RichText)
Measures rich text width taking inline spans and fonts into account.
| Parameter | Type | Description |
|---|---|---|
context |
RenderContext |
Active render context. |
text |
RichText |
Rich text instance. |
Returns float: Maximum line width in pixels..
TextEngine::measureLineWidth(RichText)
measureLineWidth(RichText)
Measures rich text width using font faces embedded in runs.
| Parameter | Type | Description |
|---|---|---|
text |
RichText |
Rich text instance. |
Returns float: Line width in pixels..
TextEngine::measureTextHeight(RichText)
measureTextHeight(RichText)
Calculates total vertical height for all lines of rich text.
| Parameter | Type | Description |
|---|---|---|
text |
RichText |
Rich text instance. |
Returns float: Total text height in pixels..
TextEngine::measureTextHeight(RenderContext, RichText)
measureTextHeight(RenderContext, RichText)
Calculates rich text height using active render backend font metrics.
| Parameter | Type | Description |
|---|---|---|
context |
RenderContext |
Active render context. |
text |
RichText |
Rich text instance. |
Returns float: Text height in pixels..
TextEngine::wrapLines(RichText, float)
wrapLines(RichText, float)
Splits rich text into wrapped lines fitting within the specified maximum width.
| Parameter | Type | Description |
|---|---|---|
text |
RichText |
Rich text to wrap. |
maxWidth |
float |
Maximum line width. |
Returns List: List of wrapped rich text lines..
TextEngine::wrapLines(RenderContext, RichText, float)
wrapLines(RenderContext, RichText, float)
Wraps rich text using backend font measurements.
| Parameter | Type | Description |
|---|---|---|
context |
RenderContext |
Active render context. |
text |
RichText |
Rich text to wrap. |
maxWidth |
float |
Maximum line width. |
Returns List: List of wrapped rich text lines..
TextEngine::lineHeight(RichText)
lineHeight(RichText)
Calculates the height of a single rich text line based on runs and inline content.
| Parameter | Type | Description |
|---|---|---|
line |
RichText |
Line to evaluate. |
Returns float: Line height in pixels..
TextEngine::lineHeight(RenderContext, RichText)
lineHeight(RenderContext, RichText)
Calculates line height using active render context metrics.
| Parameter | Type | Description |
|---|---|---|
context |
RenderContext |
Active render context. |
line |
RichText |
Line to evaluate. |
Returns float: Line height in pixels..
TextEngine::linesHeight(List)
linesHeight(List)
Calculates the combined height of multiple wrapped lines.
| Parameter | Type | Description |
|---|---|---|
lines |
List |
List of rich text lines. |
Returns float: Combined height in pixels..
TextEngine::linesHeight(RenderContext, List)
linesHeight(RenderContext, List)
Calculates combined lines height using active render context.
| Parameter | Type | Description |
|---|---|---|
context |
RenderContext |
Active render context. |
lines |
List |
List of rich text lines. |
Returns float: Combined height in pixels..
TextEngine::draw(RenderContext, String, float, float, float, float, Paint, Transform, Alignment, Alignment)
draw(RenderContext, String, float, float, float, float, Paint, Transform, Alignment, Alignment)
Renders plain text aligned within the specified bounding box.
| Parameter | Type | Description |
|---|---|---|
context |
RenderContext |
Active render context. |
text |
String |
Text string. |
x |
float |
X coordinate. |
y |
float |
Y coordinate. |
width |
float |
Container width. |
height |
float |
Container height. |
paint |
Paint |
Paint styling. |
transform |
Transform |
Optional transform. |
horizontalAlignment |
Alignment |
Horizontal alignment. |
verticalAlignment |
Alignment |
Vertical alignment. |
TextEngine::draw(RenderContext, RichText, float, float, float, float, Paint, Transform, Alignment, Alignment)
draw(RenderContext, RichText, float, float, float, float, Paint, Transform, Alignment, Alignment)
Renders rich text with alignment and inline content support.
| Parameter | Type | Description |
|---|---|---|
context |
RenderContext |
Active render context. |
text |
RichText |
Rich text instance. |
x |
float |
X coordinate. |
y |
float |
Y coordinate. |
width |
float |
Container width. |
height |
float |
Container height. |
paint |
Paint |
Paint styling. |
transform |
Transform |
Optional transform. |
horizontalAlignment |
Alignment |
Horizontal alignment. |
verticalAlignment |
Alignment |
Vertical alignment. |
TextEngine::drawInline(DrawScope, RichText, float, float, float, float, Paint)
drawInline(DrawScope, RichText, float, float, float, float, Paint)
Lays out and draws rich text with inline content into a DrawScope.
| Parameter | Type | Description |
|---|---|---|
draw |
DrawScope |
Target draw scope. |
text |
RichText |
Rich text instance. |
x |
float |
X coordinate. |
y |
float |
Y coordinate. |
width |
float |
Container width. |
height |
float |
Container height. |
paint |
Paint |
Paint styling. |
TextEngine::drawInline(DrawScope, RichText, float, float, float, float, Paint, float)
drawInline(DrawScope, RichText, float, float, float, float, Paint, float)
Lays out and draws rich text into a DrawScope with visual vertical offset.
| Parameter | Type | Description |
|---|---|---|
draw |
DrawScope |
Target draw scope. |
text |
RichText |
Rich text instance. |
x |
float |
X coordinate. |
y |
float |
Y coordinate. |
width |
float |
Container width. |
height |
float |
Container height. |
paint |
Paint |
Paint styling. |
textVisualOffset |
float |
Vertical visual offset. |
TextEngine::usesPositionalBrush(RichText)
usesPositionalBrush(RichText)
Checks whether any text run in the rich text uses a coordinate-dependent brush.
| Parameter | Type | Description |
|---|---|---|
text |
RichText |
Rich text instance. |
Returns boolean: true if positional brush is present..
TextEngine::alignedStart(float, float, float, Alignment)
alignedStart(float, float, float, Alignment)
Calculates the starting coordinate of an item given available space and alignment.
| Parameter | Type | Description |
|---|---|---|
start |
float |
Base offset coordinate. |
available |
float |
Total available dimension. |
size |
float |
Item dimension. |
alignment |
Alignment |
Alignment mode. |
Returns float: Aligned start position..