WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit 4cdae1e

Browse files
authored
Merge pull request #21282 from unoplatform/mergify/bp/release/stable/6.2/pr-21257
fix(skia): TextBlock RenderTransform and FlowDirection issues (backport #21257)
2 parents ed0f22a + 35db6f7 commit 4cdae1e

File tree

3 files changed

+85
-22
lines changed

3 files changed

+85
-22
lines changed

src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml_Controls/Given_TextBlock.cs

Lines changed: 77 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,25 @@
1616
using Windows.System;
1717
using Windows.UI.Input.Preview.Injection;
1818
using FluentAssertions;
19-
using static Private.Infrastructure.TestServices;
2019
using System.Collections.Generic;
2120
using System.Drawing;
2221
using SamplesApp.UITests;
2322
using Uno.Disposables;
2423
using Uno.Extensions;
2524
using Uno.UI.Extensions;
26-
using Point = Windows.Foundation.Point;
27-
using Size = Windows.Foundation.Size;
2825
using Combinatorial.MSTest;
29-
26+
using Uno.UI.Helpers;
27+
using Microsoft.UI.Xaml.Markup;
3028

3129
#if __SKIA__
3230
using SkiaSharp;
3331
using Microsoft.UI.Xaml.Documents.TextFormatting;
3432
#endif
3533

34+
using Point = Windows.Foundation.Point;
35+
using Size = Windows.Foundation.Size;
36+
using static Private.Infrastructure.TestServices;
37+
3638
namespace Uno.UI.RuntimeTests.Tests.Windows_UI_Xaml_Controls
3739
{
3840
[TestClass]
@@ -986,6 +988,29 @@ public async Task When_Padding()
986988
ImageAssert.DoesNotHaveColorInRectangle(screenshot, new Rectangle(0, 0, 50, 50), Colors.Red);
987989
}
988990

991+
#if __SKIA__
992+
[TestMethod]
993+
public async Task When_RenderTransform_Rearrange()
994+
{
995+
var sut = new TextBlock()
996+
{
997+
Text = "AsdAsd",
998+
RenderTransform = new CompositeTransform { ScaleX = 2, ScaleY = 2 },
999+
};
1000+
1001+
await UITestHelper.Load(sut);
1002+
1003+
var a = sut.Visual.TransformMatrix;
1004+
1005+
sut.InvalidateArrange();
1006+
await UITestHelper.WaitForIdle();
1007+
1008+
var b = sut.Visual.TransformMatrix;
1009+
1010+
Assert.AreEqual(a, b, "Visual.TransformMatrix should remain unchanged after re-arrange.");
1011+
}
1012+
#endif
1013+
9891014
#if HAS_UNO // GetMouse is not available on WinUI
9901015
#region IsTextSelectionEnabled
9911016

@@ -1601,5 +1626,53 @@ public async Task When_IsTextSelectionEnabled_TouchScroll_Then_DoesNotAlterSelec
16011626
}
16021627
#endregion
16031628
#endif
1629+
1630+
#if __SKIA__
1631+
[TestMethod]
1632+
[GitHubWorkItem("https://github.com/unoplatform/uno/issues/21264")]
1633+
[DataRow("L")]
1634+
[DataRow("R")]
1635+
[DataRow("LL")]
1636+
[DataRow("LR")]
1637+
[DataRow("RL")]
1638+
[DataRow("RR")]
1639+
[DataRow("LLL")]
1640+
[DataRow("LLR")]
1641+
[DataRow("LRL")]
1642+
[DataRow("LRR")]
1643+
[DataRow("RLL")]
1644+
[DataRow("RLR")]
1645+
[DataRow("RRL")]
1646+
[DataRow("RRR")]
1647+
public async Task When_Layered_FlowDirection(string setup)
1648+
{
1649+
if (string.IsNullOrEmpty(setup) || setup.Any(c => c is not ('L' or 'R')))
1650+
{
1651+
throw new ArgumentException("setup must be a non-empty string containing only 'L' and 'R' characters");
1652+
}
1653+
1654+
FrameworkElement root = null;
1655+
var textblock = new TextBlock { Text = "Asd" };
1656+
1657+
// assign FlowDirection from in-most, and box each layer with border
1658+
// LLR: Border R > Border L > TextBlock L
1659+
foreach (var c in setup)
1660+
{
1661+
root = root is null ? textblock : new Border { Child = root };
1662+
root.FlowDirection = Parse(c);
1663+
}
1664+
1665+
await UITestHelper.Load(root);
1666+
1667+
Assert.AreEqual(1, textblock.Visual.TotalMatrix.M11);
1668+
1669+
FlowDirection Parse(char c) => c switch
1670+
{
1671+
'L' => FlowDirection.LeftToRight,
1672+
'R' => FlowDirection.RightToLeft,
1673+
_ => throw new InvalidOperationException()
1674+
};
1675+
}
1676+
#endif
16041677
}
16051678
}

src/Uno.UI/UI/Xaml/Controls/TextBlock/TextBlock.skia.cs

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -109,21 +109,13 @@ private void UpdateSelectionRendering()
109109
}
110110
}
111111

112-
private void ApplyFlowDirection(float width)
113-
{
114-
Visual.TransformMatrix = FlowDirection == FlowDirection.RightToLeft
115-
? new Matrix4x4(new Matrix3x2(-1.0f, 0.0f, 0.0f, 1.0f, width, 0.0f))
116-
: Matrix4x4.Identity;
117-
}
118-
119112
protected override Size ArrangeOverride(Size finalSize)
120113
{
121114
var padding = Padding;
122115
var availableSizeWithoutPadding = finalSize.Subtract(padding);
123116
var arrangedSize = Inlines.Arrange(availableSizeWithoutPadding);
124117
Visual.Compositor.InvalidateRender(Visual);
125118
_lastInlinesArrangeWithPadding = arrangedSize.Add(padding);
126-
ApplyFlowDirection((float)finalSize.Width);
127119

128120
var result = base.ArrangeOverride(finalSize);
129121
UpdateIsTextTrimmed();
@@ -156,15 +148,6 @@ internal float GetComputedLineHeight()
156148
}
157149
}
158150

159-
internal override void OnPropertyChanged2(DependencyPropertyChangedEventArgs args)
160-
{
161-
base.OnPropertyChanged2(args);
162-
if (args.Property == FlowDirectionProperty)
163-
{
164-
ApplyFlowDirection((float)this.RenderSize.Width);
165-
}
166-
}
167-
168151
private int GetCharacterIndexAtPoint(Point point, bool extended = false) => Inlines.GetIndexAt(point, false, extended);
169152

170153
// Invalidate Inlines measure and repaint text when any IBlock properties used during measuring change:

src/Uno.UI/UI/Xaml/UIElement.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,14 @@ private void Initialize()
102102

103103
#if SUPPORTS_RTL
104104
internal Matrix3x2 GetFlowDirectionTransform()
105-
=> ShouldMirrorVisual() ? new Matrix3x2(-1.0f, 0.0f, 0.0f, 1.0f, (float)RenderSize.Width, 0.0f) : Matrix3x2.Identity;
105+
{
106+
var inMirroredSubtree = ShouldMirrorVisual();
107+
var isMirroredTextBlock = this is TextBlock { FlowDirection: FlowDirection.RightToLeft };
108+
109+
return inMirroredSubtree ^ isMirroredTextBlock
110+
? new Matrix3x2(-1.0f, 0.0f, 0.0f, 1.0f, (float)RenderSize.Width, 0.0f)
111+
: Matrix3x2.Identity;
112+
}
106113

107114
private bool ShouldMirrorVisual()
108115
{

0 commit comments

Comments
 (0)