diff --git a/src/SamplesApp/SamplesApp.UITests/Windows_UI_Xaml_Controls/TextBlockTests/TextBlockTests.cs b/src/SamplesApp/SamplesApp.UITests/Windows_UI_Xaml_Controls/TextBlockTests/TextBlockTests.cs
index e57e182d7c71..c708b28d1136 100644
--- a/src/SamplesApp/SamplesApp.UITests/Windows_UI_Xaml_Controls/TextBlockTests/TextBlockTests.cs
+++ b/src/SamplesApp/SamplesApp.UITests/Windows_UI_Xaml_Controls/TextBlockTests/TextBlockTests.cs
@@ -360,12 +360,7 @@ public void When_MaxLines_Changed_On_Stack_Container()
var rectAfter = _app.GetLogicalRect(stackTextBlockName);
var textBlockHeight = rectAfter.Height;
- var actualNumberOfLines = (int)Math.Ceiling(textBlockHeight / lineHeight);
- Assert.IsTrue(actualNumberOfLines == numberOfLines,
- "Results \n" +
- $"Expected Number of lines: {numberOfLines}. \n" +
- $"Actual Number of lines:{actualNumberOfLines}. \n" +
- $"Line height: {lineHeight}. \n");
+ textBlockHeight.Should().BeApproximately(lineHeight * numberOfLines, 0.5f * lineHeight);
}
[Test]
@@ -390,12 +385,7 @@ public void When_MaxLines_Changed_On_Grid_Container()
var rectAfter = _app.GetLogicalRect(gridTextBlockName);
var textBlockHeight = rectAfter.Height;
- var actualNumberOfLines = (int)Math.Ceiling(textBlockHeight / lineHeight);
- Assert.IsTrue(actualNumberOfLines == numberOfLines,
- "Results \n" +
- $"Expected Number of lines: {numberOfLines}. \n" +
- $"Actual Number of lines:{actualNumberOfLines}. \n" +
- $"Line height: {lineHeight}. \n");
+ textBlockHeight.Should().BeApproximately(lineHeight * numberOfLines, 0.5f * lineHeight);
}
[Test]
diff --git a/src/SamplesApp/UITests.Shared/Assets/Fonts/BravuraText.ttf b/src/SamplesApp/UITests.Shared/Assets/Fonts/BravuraText.ttf
new file mode 100644
index 000000000000..3a9b330a2453
Binary files /dev/null and b/src/SamplesApp/UITests.Shared/Assets/Fonts/BravuraText.ttf differ
diff --git a/src/SamplesApp/UITests.Shared/UITests.Shared.projitems b/src/SamplesApp/UITests.Shared/UITests.Shared.projitems
index 64187ccf22b5..3d23a2cf7327 100644
--- a/src/SamplesApp/UITests.Shared/UITests.Shared.projitems
+++ b/src/SamplesApp/UITests.Shared/UITests.Shared.projitems
@@ -9646,6 +9646,7 @@
+
@@ -9841,4 +9842,4 @@
-
\ No newline at end of file
+
diff --git a/src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml_Controls/Given_AutoSuggestBox.cs b/src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml_Controls/Given_AutoSuggestBox.cs
index 6d619b299fc3..a332be2297d7 100644
--- a/src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml_Controls/Given_AutoSuggestBox.cs
+++ b/src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml_Controls/Given_AutoSuggestBox.cs
@@ -58,8 +58,6 @@ public async Task When_SymbolIcon_Verify_Size()
#if __WASM__
Assert.AreEqual(new Size(13, 12), new Size(tbBounds.Width, tbBounds.Height));
-#elif __ANDROID__
- Assert.AreEqual(new Size(12, 14), new Size(tbBounds.Width, tbBounds.Height));
#else
// 12, 12 is the right behavior here.
Assert.AreEqual(new Size(12, 12), new Size(tbBounds.Width, tbBounds.Height));
diff --git a/src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml_Controls/Given_TextBlock.cs b/src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml_Controls/Given_TextBlock.cs
index 3031dcb8f7bd..0ed21a4ecb02 100644
--- a/src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml_Controls/Given_TextBlock.cs
+++ b/src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml_Controls/Given_TextBlock.cs
@@ -19,6 +19,7 @@
using static Private.Infrastructure.TestServices;
using System.Collections.Generic;
using System.Drawing;
+using SamplesApp.UITests;
using Uno.Disposables;
using Uno.Extensions;
using Point = Windows.Foundation.Point;
@@ -733,6 +734,44 @@ public async Task When_SolidColorBrush_With_Opacity()
ImageAssert.HasColorInRectangle(bitmap, new System.Drawing.Rectangle(0, 0, bitmap.Width, bitmap.Height), Colors.Red.WithOpacity(.5));
}
+
+ [TestMethod]
+ [UnoWorkItem("https://github.com/unoplatform/uno/issues/6528")]
+ public async Task When_Font_padding()
+ {
+ TextBlock tb1, tb2;
+ var sp = new StackPanel
+ {
+ Children =
+ {
+ new Border
+ {
+ BorderThickness = new Thickness(1),
+ BorderBrush = new SolidColorBrush(Microsoft.UI.Colors.Green),
+ Child = tb1 = new TextBlock
+ {
+ Text = "Default Font"
+ }
+ },
+ new Border
+ {
+ BorderThickness = new Thickness(1),
+ BorderBrush = new SolidColorBrush(Microsoft.UI.Colors.Red),
+ Child = tb2 = new TextBlock
+ {
+ FontFamily = new FontFamily("ms-appx:///Assets/Fonts/BravuraText.ttf"),
+ Text = "Bravura Font"
+ }
+ }
+ }
+ };
+
+ await UITestHelper.Load(sp);
+
+ // The 2 fonts don't have the same exact ascents and descents, so they're not supposed to be equal, just mostly the same
+ Assert.AreEqual(tb1.ActualHeight, tb2.ActualHeight, 7);
+ }
+
[TestMethod]
[RunsOnUIThread]
public async Task When_TextWrapping_Changed()
diff --git a/src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml_Controls/Given_TextBox.cs b/src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml_Controls/Given_TextBox.cs
index a25f8b786c71..ecaee68da426 100644
--- a/src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml_Controls/Given_TextBox.cs
+++ b/src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml_Controls/Given_TextBox.cs
@@ -1151,5 +1151,41 @@ private static async Task LoadZeroSizeTextBoxAsync(Style style)
await WindowHelper.WaitForIdle(); // Needed to account for lifecycle differences on mobile
return textBox;
}
+
+ [TestMethod]
+ [UnoWorkItem("https://github.com/unoplatform/uno/issues/6528")]
+ public async Task When_Font_padding()
+ {
+ TextBox tb1, tb2;
+ var sp = new StackPanel
+ {
+ Children =
+ {
+ new Border
+ {
+ BorderThickness = new Thickness(1),
+ BorderBrush = new SolidColorBrush(Microsoft.UI.Colors.Green),
+ Child = tb1 = new TextBox
+ {
+ Text = "Default Font"
+ }
+ },
+ new Border
+ {
+ BorderThickness = new Thickness(1),
+ BorderBrush = new SolidColorBrush(Microsoft.UI.Colors.Red),
+ Child = tb2 = new TextBox
+ {
+ FontFamily = new FontFamily("ms-appx:///Assets/Fonts/BravuraText.ttf"),
+ Text = "Bravura Font"
+ }
+ }
+ }
+ };
+
+ await UITestHelper.Load(sp);
+
+ Assert.AreEqual(tb1.ActualHeight, tb2.ActualHeight, 2);
+ }
}
}
diff --git a/src/Uno.UI/UI/Xaml/Controls/TextBlock/TextBlock.Android.cs b/src/Uno.UI/UI/Xaml/Controls/TextBlock/TextBlock.Android.cs
index 1946204c78a0..b37fe0676191 100644
--- a/src/Uno.UI/UI/Xaml/Controls/TextBlock/TextBlock.Android.cs
+++ b/src/Uno.UI/UI/Xaml/Controls/TextBlock/TextBlock.Android.cs
@@ -630,6 +630,7 @@ private Size UpdateLayout(Size availableSize, bool exactWidth = false)
MakeLayout(desiredWidth);
}
+ // More details on font metric calculations here: https://medium.com/androiddevelopers/fixing-font-padding-in-compose-text-768cd232425b
var lineCount = Layout.LineCount;
var measuredHeight = Layout.GetLineTop(lineCount);
if (_lineHeight != 0 && _addedSpacing > 0)
@@ -723,7 +724,7 @@ private void MakeLayout(int width, int maxLines = int.MaxValue)
1,
_addedSpacing = GetSpacingAdd(_paint),
_metrics,
- true,
+ false,
_ellipsize,
width
);
@@ -740,7 +741,7 @@ private void MakeLayout(int width, int maxLines = int.MaxValue)
1,
_addedSpacing = GetSpacingAdd(_paint),
_metrics,
- true,
+ false,
_ellipsize,
width
);
diff --git a/src/Uno.UI/UI/Xaml/Controls/TextBox/TextBoxView.Android.cs b/src/Uno.UI/UI/Xaml/Controls/TextBox/TextBoxView.Android.cs
index 4434466b2161..0eb51672fffe 100644
--- a/src/Uno.UI/UI/Xaml/Controls/TextBox/TextBoxView.Android.cs
+++ b/src/Uno.UI/UI/Xaml/Controls/TextBox/TextBoxView.Android.cs
@@ -42,6 +42,7 @@ public TextBoxView(TextBox owner)
this.SetBackgroundColor(Colors.Transparent);
//Remove default native padding.
this.SetPadding(0, 0, 0, 0);
+ SetIncludeFontPadding(false);
if (FeatureConfiguration.TextBox.HideCaret)
{