Repository navigation
Conversation
ubidi_setPara keeps pointers to the text and the embedding levels it is given, writes the resolved levels back into that array, and ubidi_setLine and ubidi_getLevels read them again for every line. UnicodeText pinned both only for the setPara call and returned the level array to the shared pool before the line loop, so anything that rented the array in between changed the visual order of the text. Copy both into native memory owned by the bidi object and free it after ubidi_close.
In a right-to-left TextBlock, TextBox or RichEditBox, UnicodeText gave every right-to-left run the explicit level 1, which made all of the text a right-to-left embedding: "Hello world." was drawn as ".Hello world". WinUI embeds only an element whose direction differs from its parent's. A run with the control's direction now gets ICU's wildcard level 0, which takes its paragraph's level, detected from the first strong character, as left-to-right controls already did. A run whose direction differs keeps its explicit level.
UnicodeText passed ICU an embedding-levels array for every non-trivial layout, and ICU ignores LRE, RLE, LRO, RLO, PDF and the isolates when it gets one. WinUI honors them. Pass no array. When no run's direction differs from the control's, ICU reads the text as it is. When one does, ICU reads a copy with an LRE or RLE before that run and a PDF after it, the way WinUI embeds such an element, so the run's embedding and the text's own controls nest by the usual rules. A paragraph separator ends every embedding, so the run's embedding is opened again after each one inside the run. Indices are mapped between the text and the copy, through a pooled map, for the runs and the line reordering. As on WinUI, a differing run is now embedded even in a paragraph that already has its direction, and a control the run leaves open is closed by the run's PDF in place of the run's own embedding.
Add UnicodeTextOptions, an optional trailing parameter of the UnicodeText constructor whose default changes nothing, with ResumeIndex: where a previous layout of the same paragraph broke at its own width. The bidi resolution and the shaping still cover the whole text, so the resumed lines keep the paragraph's level and the joining across the break. The text before the index goes on lines that never wrap and end at the index, and FirstResumedLine is the first line after them.
Add TrimmingWidth, the width a line must fit for trimming when it differs from the width the text wraps at, and ForcedEllipsisLine, a line that gets an ellipsis even if it fits and ends the layout, as a paragraph ellipsis does. Lines before the resume index are never trimmed.
Add InlineContainers: when a caller sets it, each InlineUIContainer among the inlines takes one U+FFFC character, sized by what the caller measures, as RichEditBox images already do. U+FFFC breaks on both sides, so an object never splits a line inside it. A container before the resume index belongs to a previous layout and gets an empty placeholder without being measured.
Add line-scoped reads for callers that position each line themselves: a line's range, metrics and content edge (GetLineInfo), the character hit at an x on it (HitTestLine), the caret x of an index on it (GetCaretX), the caret stops around an index (GetCaretStop), the spans a range covers on it (GetRangeBoundsInLine) and its inline objects (GetInlineObjectsInLine).
Add DrawLines, which draws the given lines of a layout, each with its own offset and its own band for the fills and the caret, for callers that place each line themselves. Every element placed per line moves with its line: glyphs, decorations, character backgrounds, tab leaders, highlight and selection fills, high-contrast backplates, spell-check squiggles, the composition underline, inline images, list markers and the caret on the ending line. Draw is DrawLines over every line at the layout's own position.
|
Azure Pipelines: Successfully started running 1 pipeline(s). There may be pipelines that require an authorized user to comment /azp run to run. |
Contributor
|
Tick the box to add this pull request to the merge queue (same as
|
mikernet
force-pushed
the
dev/mikernet/unicodetext-line-options
branch
from
November 25, 2026 23:09
32ce174 to
256997c
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
GitHub Issue: part of #24339 (epic: #26728)
PR Type:
✨ Feature
What changed? 🚀
This gives
UnicodeText, the Skia text engine ofTextBlock,TextBox,PasswordBoxandRichEditBox, whatRichTextBlockneeds to lay out each paragraph with it: resuming a paragraph on an overflow, trimming at another width, hostingInlineUIContainers, reading one line at a time and drawing each line at its own position. It is the fourth step of movingRichTextBlocktoUnicodeText(#24339). It is stacked on #26726, so the first three commits in the diff are that PR's.Nothing uses the new options yet;
RichTextBlockstarts using them in the next PR. Each one is tested directly on the engine here.TextBlock,TextBox,PasswordBoxandRichEditBoxdon't set any of them, so their layout and drawing are unchanged.All the inputs go in one new trailing constructor parameter,
in UnicodeTextOptions options = default. Its default changes nothing, so no call site changes.Commit by commit:
ResumeIndex). An overflow continues a paragraph where the previous page broke it, at that page's width. The resumed layout still resolves bidi and shapes the whole paragraph, so the resumed lines keep the paragraph's direction and the joining across the break (an Arabic word broken in the middle keeps its joined forms). The text before the index goes on lines that never wrap and end at the index;FirstResumedLineis the first line after them. Those lines go through the same bidi index mapping as every other line, including the copy with embedding characters that fix(text): Embed only differing runs and honor bidi controls #26726 adds. An index where no line can start (inside a cluster, such as a surrogate pair, or between the two halves of a CRLF) throws.TrimmingWidth,ForcedEllipsisLine). A line can be trimmed at a width other than the one it wraps at, and a line that fits can get the paragraph's ellipsis because text after it won't be shown. Lines before the resume index are never trimmed, and a forced line before the first resumed line throws.InlineContainers). When the caller sets it, eachInlineUIContainertakes one U+FFFC character, sized by what the caller measures, asRichEditBoximages already do. U+FFFC breaks on both sides. A container before the resume index gets an empty placeholder and isn't measured, since the previous page laid it out.UnicodeText.Lines.cs: a line's range, metrics and content edge, the character hit at an x on it, the caret x of an index on it, the caret stops around an index, the spans a range covers on it, and its inline objects. A line reports its line break length and the whitespace before it asTextLinedoes; on a line that ends with an ellipsis, the trailing whitespace is 0.DrawLines, which draws the given lines, each moved by its own translation from where the layout puts it (zero draws it whereDrawdoes), and with its own band, given where the line is drawn, for its fills and caret. Everything the engine places per line moves with its line: glyphs, decorations, character backgrounds, tab leaders, highlight and selection fills, high-contrast backplates, spell-check squiggles, the composition underline, inline images, list markers and the caret on the ending line.Drawis nowDrawLinesover every line at the layout's own position.Cost for existing callers
I measured
UnicodeTextconstruction andDrawagainst #26726's branch, for a short ASCII label, an Arabic paragraph and a long wrapped paragraph, alternating the two builds over nine rounds (Skia Desktop, Release, the same benchmark source in both builds):Draw, #26726Draw, this PREach number is the fastest of 9 batches of 300 to 20,000 calls, with
GC.GetAllocatedBytesForCurrentThreadaround each batch. Construction compares the last two alternating rounds of each build;Drawcompares the fastest of nine rounds per build, because a busy PC moved its medians by up to 20% in both builds alike.The options record adds no allocation when it's left unset.
PR Checklist ✅
Given_UnicodeTextOptions(Skia only: it buildsUnicodeTextdirectly): resumed lines equal the full layout's line by line (clusters, glyph IDs, direction, x) for left-to-right, right-to-left, mixed text, a run whose direction differs from the control's, emergency breaks in Latin and Arabic, a right-to-left paragraph resumed at a Latin line, line breaks and tabs before and after the resume index, NoWrap, and a resume at the end of the text; every index of a text with a surrogate pair, a combining mark and a CRLF, which resumes where a line can start and throws elsewhere; trimming at another width and the forced ellipsis, also in a resumed layout; inline object placeholders; the line reads, round-tripped over every cluster, and the trailing whitespace and line break lengths;DrawLineswith a different offset for every line against each line drawn alone under a translated session, with and without high contrast; a band taller than the line, which the fills and the caret cover; andDrawLinesat the layout's own positions againstDrawfor aTextBlock, pixel for pixel.DrawLines, one mutation per element placed per line).RichTextBlockgroup (207 cases) and theTextBlock/TextBox/RichEditBox/PasswordBoxgroup (1,599 cases) give the same results as on fix(text): Embed only differing runs and honor bidi controls #26726's branch.Screenshots Compare Test Runresults.