Skip to content

RichTextBlock: TextReadingOrder and content-driven bidi are inert #24339

Open

Description

@MartinZikmund

What would you like to be added? 💡

TextReadingOrder is [NotImplemented] and TextAlignment.DetectFromContent always resolves to Left. RTL content is laid out left-to-right.

An explicit FlowDirection on the control or on a Run is honoured — what is missing is content-driven detection and full Unicode bidi reordering.

Why is this needed? 🤔

RTL languages render incorrectly rather than merely losing a feature, which makes this the most user-visible correctness gap left on the control.

Renderer 🎨

  • Skia
  • Native

For which platforms 📱💻🖥️

All platforms 🌍

Anything else we need to know? 💬

This is a pre-existing limitation of the Uno text engine rather than a regression of the port: TextBlock behaves the same way. Fixing it once would serve both.

Follow-up from the RichTextBlock deep-core port; recorded in specs/richtextblock-winui-port/port-validation-winui-2.4.0.md.

Activity

  1. added
    kind/enhancement
    triage/untriaged
    project/text 🔤
    on Sep 2, 2026
  2. mikernet commented on Nov 25, 2026

    @mikernet
    Contributor

    I'm taking this one. Status, what scoping and measuring on native WinUI found, and a question about the longer-term direction.

    Status. The work is a stack of PRs. In review order:

    1. test(richtextblock): Pin geometry and hit-testing against native WinUI #26724: tests that pin today's RichTextBlock geometry against native WinUI, so the engine change has a regression net.
    2. fix(text): Embed only differing runs and honor bidi controls #26726: bidi in UnicodeText. Only a run whose direction differs from its control's is embedded, bidi control characters in text are honored, and the buffers ICU keeps pointers to stay alive. Closes Latin text in a FlowDirection=RightToLeft TextBlock 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.
    3. fix(text): Default null highlighter brushes like WinUI #26725: default brushes for a TextHighlighter that sets none. Closes TextBlock TextHighlighter with no Background paints no highlight; WinUI falls back to the yellow TextControlHighlighterBackground #24747.
    4. 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 RichTextBlock needs from UnicodeText: resuming a paragraph on an overflow, trimming at another width, InlineUIContainer placeholders, and reading and drawing by line.
    5. Still to come: a fix for text containing U+001C–U+001E making the layout throw, the engine swap itself, TextReadingOrder, and the removal of ParsedText.

    Why RichTextBlock has no bidi. TextBlock, TextBox and RichEditBox lay out text with UnicodeText, which runs ICU's implementation of the Unicode Bidi Algorithm. RichTextBlock misses out because SkiaTextFormatter/SkiaTextLine bridge the ported BlockLayoutEngine onto the legacy ParsedText. That path guesses direction per segment through HarfBuzz and hard-codes IsBaseDirectionRightToLeft => false. So the fix is to move RichTextBlock's paragraphs onto UnicodeText; no new bidi implementation is needed.

    UnicodeText had bidi problems of its own, though, which the swap would have carried over. They are what #26726 fixes for every control that uses it.

    The swap, in the PR after #26727:

    • A new formatter on UnicodeText replaces SkiaTextFormatter/SkiaTextLine. The existing RichTextBlock tests are compared against a baseline from master at each step, and the TextBlock, TextBox and RichEditBox suites stay green, since they share the engine.
    • RichTextBlock behaves as TextReadingOrder.DetectFromContent. That is WinUI's default, measured for RichTextBlock and TextBlock; the generated stub's 0 (UseFlowDirection) was the Windows 8.1 default. TextAlignment.DetectFromContent works with it, and the public TextReadingOrder property follows in its own PR.
    • Afterwards, ParsedText and the legacy Run/Segment/RenderLine shaping code are deleted, about 3,000 lines.

    #24748 gets fixed by the swap instead of a separate patch: a right-to-left link will react where it is drawn. A fix in ParsedText alone would break the ported ParagraphNode paths (selection, GetPositionFromPoint, automation bounds), which currently rely on that mismatch. One correction to that issue, from clicking on native WinUI: a click on the empty space beside a line that holds only a Hyperlink does raise Click there, on either side, so "clicking empty space doesn't raise Click" isn't WinUI's behavior.

    RTL coordinates. The ported ParagraphNode/RichTextBlockView math follows WinUI's convention: a right-to-left element stays mirrored, the layout math is flow-relative, and the text drawing context mirrors back. UIElement.GetFlowDirectionTransform cancels the mirror for text surfaces instead, which only works for RichTextBlock today because the detected direction is always left-to-right. The swap follows WinUI: RichTextBlock and RichTextBlockOverflow stay mirrored, and one small helper mirrors back around the text paint and the engine's hit-tests. Measured on native WinUI:

    • an overflow lays out and mirrors by its master's FlowDirection, whatever its own is;
    • WinUI's RichTextBlock reports GetCharacterRect and GetPositionFromPoint on the wrong side of the line when the content's direction differs from FlowDirection and the alignment isn't the start. WinUI's TextBlock reports the same cases on the drawn text. I'm matching the drawn text.

    Longer term, which is where I'd like your input: I think the end state is the WinUI model for every text control.

    • One engine, UnicodeText, which this work completes.
    • One coordinate convention. WinUI's mirroring for every text control, with the mirror-back in one place at the engine boundary (draw, hit-test and rectangle queries) instead of the isMirroredTextSurface exception. The helper the swap adds is written so TextBlock and TextBox can use it unchanged.
    • One layout stack for TextBlock and RichTextBlock, as in WinUI.
      • TextBlockView is already ported but not used yet.
      • TextBlock has its own selection and hit-testing beside the ported TextSelectionManager.
      • Moving TextBlock onto PageNode/TextBlockView/TextSelectionManager would remove that duplication, and give TextBlock TextPointer and text-view automation parity.
      • It would keep a fast path for plain text, as WinUI does with DWriteLayout, so labels don't pay for the node tree.

    This issue only covers RichTextBlock. The rest would be separate PRs, and none of the PRs above depends on the answers. Before I plan them:

    • Is moving TextBlock onto the shared stack (the port notes call it "Stage 9") planned or in progress on your side?
    • That move would rewrite the measure, arrange and paint paths the open TextBlock performance PRs optimize. Should it wait until they are merged, and is there a benchmark it has to hold?
    • Any objection to WinUI's mirror convention as the target for all the text controls?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/skia/text ✏️kind/enhancementproject/text 🔤triage/untriaged

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions