Repository navigation
Description
Current behavior 🐛
On Skia, a TextBlock with FlowDirection="RightToLeft" lays out Latin-only text as a right-to-left paragraph. Trailing punctuation jumps to the other end, brackets are drawn mirrored, and a leading number moves to the end of the line:
| Text | Uno Skia (RTL) | WinUI 3 (RTL) |
|---|---|---|
Star a sample (Ctrl+Shift+D) to pin it here. |
.Star a sample )Ctrl+Shift+D( to pin it here |
Star a sample (Ctrl+Shift+D) to pin it here. |
Search samples (Ctrl+F) |
(Search samples )Ctrl+F |
Search samples (Ctrl+F) |
1,472 samples in 136 categories |
samples in 136 categories 1,472 |
1,472 samples in 136 categories |
Only the alignment flips in WinUI (the text sits against the right edge); the characters inside the line stay in reading order.
This is separate from #24904 (default alignment under RTL) and from #24339 (RichTextBlock / TextReadingOrder being inert). Here the visible glyph order inside a TextBlock is wrong, regardless of alignment.
Expected behavior 🎯
Same as WinUI: the paragraph direction comes from the first strong character of the content (TextReadingOrder.DetectFromContent behavior), falling back to FlowDirection only when the text has no strong character. Latin text stays left-to-right inside an RTL-flow TextBlock, and brackets are not mirrored.
Backed by a native WinUI 3 run of the same XAML (WinAppSDK head, FlowDirection=RightToLeft on the root): the strings above render exactly as in the right-hand column.
How to reproduce it (as minimally and precisely as possible) 🔬
- Create an Uno app (Skia renderer) and use this
MainPage.xamlcontent:<StackPanel Spacing="8" Padding="20"> <TextBlock FontSize="32" FlowDirection="LeftToRight" Text="Hello (world)" /> <TextBlock FontSize="32" FlowDirection="RightToLeft" Text="Hello (world)" /> <TextBlock FontSize="32" FlowDirection="LeftToRight" Text="1,472 samples in 136 categories" /> <TextBlock FontSize="32" FlowDirection="RightToLeft" Text="1,472 samples in 136 categories" /> </StackPanel>
- Run on Skia Desktop.
- Observe that the
RightToLeftblocks show)world( Helloandsamples in 136 categories 1,472(and are drawn left-aligned, see RightToLeftTextBlockdraws its text at the left edge with the defaultTextAlignment(WinUI draws it at the right) #24904) instead of the same glyph order as theLeftToRightblocks. - Run the same XAML on WinUI 3: the glyph order is identical in both blocks.
Runtime test (Uno.UI.RuntimeTests, Skia Desktop) that renders both blocks shrink-to-fit, so alignment cannot affect the result, and compares the pixels. It fails on current master for Hello (world) (2099 pixels differ) and 1,472 samples in 136 categories (4880 pixels differ):
[TestMethod]
[DataRow("Hello (world)")]
[DataRow("1,472 samples in 136 categories")]
public async Task When_Latin_Text_Under_RTL_Looks_Same_As_LTR(string text)
{
var ltr = Build(text, FlowDirection.LeftToRight);
var rtl = Build(text, FlowDirection.RightToLeft);
WindowHelper.WindowContent = new StackPanel { Children = { ltr, rtl } };
await WindowHelper.WaitForLoaded(ltr);
await WindowHelper.WaitForIdle();
var ltrShot = await UITestHelper.ScreenShot(ltr);
var rtlShot = await UITestHelper.ScreenShot(rtl);
await ltrShot.Populate();
await rtlShot.Populate();
var differing = 0;
for (var y = 0; y < ltrShot.Height; y++)
{
for (var x = 0; x < ltrShot.Width; x++)
{
if (ltrShot.GetPixel(x, y) != rtlShot.GetPixel(x, y))
{
differing++;
}
}
}
Assert.AreEqual(0, differing);
}
private static Border Build(string text, FlowDirection flowDirection) => new()
{
Background = new SolidColorBrush(Colors.White),
HorizontalAlignment = HorizontalAlignment.Left,
Child = new TextBlock { Text = text, FontSize = 32, FlowDirection = flowDirection, Foreground = new SolidColorBrush(Colors.Black) },
};Workaround 🔄
Set FlowDirection="LeftToRight" on Latin-only TextBlocks (which also changes their alignment).
Works on UWP/WinUI 🪟
Yes (verified on WinUI 3 / WinAppSDK).
Environment 🌍
Skia Desktop (Windows). The text path is shared, so other Skia heads are likely affected, but only Desktop was run.
NuGet package version(s) 📦
unoplatform/uno master at 951b7b4 (net11.0-desktop, Release).
Affected platforms 📱💻🖥️
Skia (verified on Desktop Windows).
IDE 🧰
No response
IDE version 🧠
No response
Relevant plugins 🔌
No response
Anything else we need to know? 💬
Root cause (source-backed, runtime result above): UnicodeText hands ICU an explicit embedding level for every run, and the level is derived from the run's FlowDirection, which defaults to the control's. Under RTL flow, every Latin run gets level 1 (an RTL embedding), so ICU never gets to detect the paragraph direction from the content, even though the paragraph is created with UBIDI_DEFAULT_RTL. The Latin text is then reordered and bracket-mirrored as RTL:
- Level assignment from
FlowDirection: UnicodeText.cs#L483-L486 CreateBiDiAndSetPara(..., embeddingLevels): UnicodeText.cs#L489- Run direction defaulting to the control's: UnicodeText.cs#L380
TextBlock.TextReadingOrder is still a [NotImplemented] stub, so there is also no way to opt in or out (#24339).
A possible fix is to only pass explicit embedding levels for runs whose FlowDirection was set explicitly and differs from the control's, and let ICU resolve the rest from the content.
Not confirmed: a related symptom was seen in a larger app where Shift rendered as Shfit (the fi pair) under RTL; the plain Shift string in the test above renders identically in LTR and RTL, so that one is not included here.
Activity