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.
2 of 5 tasks
|
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/text-bidi-embedding
branch
from
November 25, 2026 23:09
44c4434 to
6846e23
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: closes #25291, closes #26722, closes #26723; part of #24339 (epic: #26728)
PR Type:
🐞 Bugfix
What changed? 🚀
This changes how
UnicodeTextsets up bidi.UnicodeTextis the Skia text engine ofTextBlock,TextBox,PasswordBox(when it shows its password) andRichEditBox.RichTextBlockdoesn't use it yet, so it isn't affected. This is the second step of movingRichTextBlocktoUnicodeText(#24339).After this PR:
ubidi_close.ubidi_setParagot a level array that was rented from a pool and returned before the line loop read it again. ICU writes its resolved levels into that array and keeps reading it, so anything that rented the array in between changed the drawn order. I reproduced that with a test hook. A forced compacting GC alone didn't reproduce it.FlowDirectiondiffers from the control's is embedded, as on WinUI. In a right-to-left control, every right-to-left run used to get an explicit level, so all of the text became a right-to-left embedding. "Hello world." was drawn ".Hello world", and brackets were mirrored (Latin text in aFlowDirection=RightToLeftTextBlock is laid out as RTL on Skia: punctuation moves and brackets flip (WinUI keeps LTR order) #25291). Text now takes its direction from its own content.UnicodeTextpassed for every non-trivial layout. Now:Commit by commit:
Behavior change, per control
TextBlock,FlowDirection="RightToLeft", "Hello world."TextBox,FlowDirection="RightToLeft", "Hello world......"RichEditBox, right-to-left control, right-to-left paragraph, "Hello world......"RichEditBox, right-to-left control, default paragraphs: Latin; Hebrew with a number; a second paragraphTextBlock)TextBox,PasswordBoxandRichEditBoxTextBlock, paragraph starting with a right-to-left character, then an explicit right-to-leftRun: right-to-left mark + "abc ",Run"def", " gh"TextBlock, Latin-first paragraph, explicit left-to-rightRunTextBoxwhose text starts with a neutral, such as "(Hello)"The "measured" rows were checked on native WinUI, and in none of them does Uno now differ from WinUI where it didn't before.
Unchanged differences from WinUI:
RichEditBoxparagraph on a left-to-right base. So a right-to-left paragraph in a left-to-right control, and a Hebrew-first paragraph, read differently on Uno.RichEditBoxparagraphs; Uno doesn't.I left both for a follow-up.
Also unchanged:
Since the controls are honored in
TextBoxinput too, an override in typed or pasted text can now reorder what is displayed, as on WinUI: "invoice", U+202E and "txt.exe" display as "invoiceexe.txt".Validation
New tests read the visual order from the colour of each run's ink rather than from character rects.
Given_TextBlock_Bidi:When_Bidi_Buffers_Outlive_SetPara: Skia only, uses an internal hook. It overwrites the pooled level and map arrays a buffer returned too early would come back as.When_Rtl_TextBlock_Latin_Keeps_Period_At_End.When_Run_FlowDirection_Differs_From_Control: 2 rows.When_Bidi_Controls_In_Text: 5 rows.When_Differing_Run_Leaves_Control_Open: RLE, RLO, LRI, RLI, FSI.When_Differing_Run_In_Paragraph_Of_Its_Own_Direction: both directions.When_Differing_Run_Wraps: both directions, wrapped and trimmed. It checks the order of each line where lines break, or the line is trimmed, inside a differing run.When_Differing_Run_Ends_With_Spaces: Skia only, see above.When_Differing_Run_Spans_Paragraph_Separator.Other classes:
Given_TextBox.When_Rtl_TextBox_Latin_Keeps_Period_At_End.Given_RichEditBox.When_Rtl_RichEditBox_Latin_Keeps_Dots_At_End: 2 rows.Given_RichEditBox.When_Rtl_RichEditBox_Hebrew_Keeps_Ltr_Base: 2 rows. It runs on Skia Win32 and WinUI only, since it needs a font with Hebrew.Runtime, Skia Desktop (Win32):
TextBox,RichEditBoxright-to-left paragraph and right-to-left-control run rows;When_Differing_Run_In_Paragraph_Of_Its_Own_Direction;When_Differing_Run_Spans_Paragraph_Separator;When_Differing_Run_Wrapsrows.When_Run_FlowDirection_Differs_From_Control(LeftToRight);When_Differing_Run_Ends_With_Spaces;RichEditBoxdefault-paragraph rows.Given_RichTextBlock|Given_SkiaTextFormatter|Given_BlockLayoutEngine|Given_HyperlinkAutomation: 207 of 207, the same asmaster.Given_TextBlock|Given_TextBox|Given_RichEditBox|Given_PasswordBox: compared with amasterrun, no case went from pass to fail, and the 27 new cases pass. The 2 failures and 1 inconclusive case are the same as onmaster: input timing, a CRLF hit-test, and an accessibility client running.Runtime, native WinUI (WinAppSDK): the 25 cases that run there pass.
Runtime, Skia WebAssembly: the 25 cases that run there pass.
Cost. I timed
UnicodeTextconstruction with a temporary runtime test, alternatingmasterand this branch, while the PC was in use. Time is the minimum per batch, best of the rounds. Allocations are measured withGC.GetAllocatedBytesForCurrentThread.mastermasterRichEditBox-like paragraph, 238 characters, every run differingRichEditBox-like document, 2,380 characters in 10 paragraphs, every run differingCompile:
Uno.UIand the runtime tests build with analyzers and code style on, with no warning or error.PR Checklist ✅
Screenshots Compare Test Runresults.Behavior change:
FlowDirection="RightToLeft", left-to-right text in aTextBlock,TextBoxor revealedPasswordBoxkeeps its own reading order instead of being laid out as a right-to-left embedding. So does a right-to-left paragraph in a right-to-leftRichEditBox.RunwhoseFlowDirectiondiffers from the control's is embedded even in a paragraph that already has its direction.Each of these matches WinUI where measured, as listed in the table above.