Repository navigation
Description
What would you like to be added? 💡
One text model for TextBlock, RichTextBlock, TextBox, PasswordBox and RichEditBox on Skia, the one WinUI has: a single engine with real Unicode bidi, WinUI's right-to-left coordinate convention for every text control, and one layout stack shared by TextBlock and RichTextBlock. I'm doing the work as a series of PRs, listed here in review order so they are easy to follow. Each PR stands on its own and can be taken when it's ready.
Phase 1. RichTextBlock on UnicodeText, with bidi (#24339)
RichTextBlock is the last control on the legacy ParsedText engine, which has no bidi. This phase moves it to UnicodeText, the engine the other controls use, and fixes that engine's own bidi problems on the way.
- test(richtextblock): Pin geometry and hit-testing against native WinUI #26724: tests that pin today's
RichTextBlockgeometry against native WinUI, as the regression net for the engine change. - fix(text): Embed only differing runs and honor bidi controls #26726:
UnicodeTextembeds only a run whose direction differs from its control's, honors bidi control characters, and keeps the buffers ICU points into alive. Closes Latin text in aFlowDirection=RightToLeftTextBlock is laid out as RTL on Skia: punctuation moves and brackets flip (WinUI keeps LTR order) #25291, Bidi control characters (RLO, RLE, PDF, isolates) in text are ignored on Skia #26722 and Skia text: ICU's bidi object reads a pooled array after it was returned to the pool #26723. - fix(text): Default null highlighter brushes like WinUI #26725: default brushes for a
TextHighlighterthat sets none. Closes TextBlock TextHighlighter with no Background paints no highlight; WinUI falls back to the yellow TextControlHighlighterBackground #24747. - feat(text): Let UnicodeText resume, trim, host objects and draw by line #26727, stacked on fix(text): Embed only differing runs and honor bidi controls #26726: what
RichTextBlockneeds fromUnicodeText: resuming a paragraph on an overflow, trimming at another width,InlineUIContainerplaceholders, and reading and drawing by line. - Text containing U+001C–U+001E makes the layout throw (issue and PR to come).
- The swap:
RichTextBlockparagraphs are laid out byUnicodeText, andRichTextBlockandRichTextBlockOverflowstay mirrored in right-to-left, as in WinUI. Fixes RightToLeftRichTextBlock: clicking a drawnHyperlinkdoes nothing, hit-testing ignores the RTL alignment flip #24748. - The public
RichTextBlock.TextReadingOrderproperty. Closes RichTextBlock: TextReadingOrder and content-driven bidi are inert #24339. - Removal of
ParsedTextand the legacyRun/Segment/RenderLineshaping code, about 3,000 lines.
#26724, #26725 and #26726 are independent of each other. #26727 needs #26726, and the rest need all four.
Phase 2. One coordinate convention for every text control
WinUI mirrors a right-to-left element, and its text layout code is written for that mirrored space. Uno cancels the mirror for text controls (isMirroredTextSurface in UIElement.GetFlowDirectionTransform) and has each feature compensate, which is where bugs like #24748 come from. Phase 1 puts RichTextBlock on WinUI's convention, with one small helper that mirrors back at the engine boundary. This phase does the same for TextBlock, TextBox, PasswordBox and RichEditBox, and deletes the exception.
- Design, then PRs (to be listed).
Phase 3. TextBlock on the shared layout stack
In WinUI, TextBlock and RichTextBlock share one layout stack. In Uno, the ported stack (BlockLayoutEngine, PageNode, ParagraphNode, TextSelectionManager) serves RichTextBlock only, TextBlockView is ported but unused, and TextBlock has its own selection, hit-testing and automation code beside it. This phase moves TextBlock onto the shared stack, which removes that duplication and gives TextBlock TextPointer support, text-view automation and TextReadingOrder.
Plain text keeps a fast path, as WinUI's TextBlock does, so a label doesn't pay for the node tree. A benchmark of plain TextBlock measure, arrange and paint gates every PR of this phase: it must not regress.
- Design, then PRs (to be listed).
Why is this needed? 🤔
- Right-to-left and mixed-direction text is wrong in places where the controls disagree with WinUI and with each other:
RichTextBlockhas no bidi at all (RichTextBlock: TextReadingOrder and content-driven bidi are inert #24339), hyperlinks in a right-to-leftRichTextBlockdon't react where they are drawn (RightToLeftRichTextBlock: clicking a drawnHyperlinkdoes nothing, hit-testing ignores the RTL alignment flip #24748), and Latin text in a right-to-leftTextBlockorTextBoxwas laid out as right-to-left (Latin text in aFlowDirection=RightToLeftTextBlock is laid out as RTL on Skia: punctuation moves and brackets flip (WinUI keeps LTR order) #25291). - Two engines and two conventions cost twice. A fix in one control doesn't reach the other, and code ported from WinUI runs in a coordinate space it wasn't written for.
- WinUI parity. With the same model as WinUI, its layout, selection and automation code runs as ported, and later WinUI changes port mechanically.
For which platforms 📱💻🖥️
All platforms 🌍
Anything else we need to know? 💬
- Every behavior is measured on native WinUI before it is matched, and each PR lists what was measured. Where WinUI contradicts itself, the PR says so. The one case so far: WinUI's
RichTextBlockreportsGetCharacterRectandGetPositionFromPointon the wrong side of a line when the content's direction differs fromFlowDirectionand the alignment isn't the start, while itsTextBlockreports the same cases on the drawn text. I match the drawn text. - Related work by others: fix(textblock): Align right-to-left text relative to FlowDirection #26699 (right-to-left alignment in
TextBlock) and Skia: right-to-left text that ends with a number/Latin run is shaped in the wrong direction (bidi runs collected in visual order, consumed as logical) #25979 (bidi runs consumed in the wrong order).
Is this the direction you want? 👍
I've settled the three points below myself, so the work isn't waiting on anyone, and each is the WinUI-parity choice. If you agree, a 👍 on this issue is enough. If you see a problem with one of them, or have work in progress it would collide with, tell me before that phase gets far.
- WinUI's mirror convention for every text control (phase 2). A right-to-left text control stays mirrored like any other element, and the text is mirrored back in one place at the engine boundary. I chose it because the layout, selection and automation code ported from WinUI is written for that space, and because the current exception has to be compensated for in every feature that reads a text coordinate.
TextBlockon the shared layout stack (phase 3). The port notes call this "Stage 9". If someone has already started on it, I'd rather build on that than duplicate it.- Performance and ordering for phase 3. It rewrites the measure, arrange and paint paths that the open
TextBlockperformance PRs optimize. I'm designing it to keep those optimizations whichever merges first, with a fast path for plain text and a benchmark that gates every PR. If Add a cross-platform performance benchmark suite with CI tracking #26516 (the benchmark suite) lands, that benchmark goes into it. If you'd rather phase 3 waits until those PRs are merged, or there is a benchmark you want it to hold, say which.
Activity