diff --git a/src/Controls/tests/TestCases.Android.Tests/snapshots/android/VerifyFontImageAreCenterAlign.png b/src/Controls/tests/TestCases.Android.Tests/snapshots/android/VerifyFontImageAreCenterAlign.png new file mode 100644 index 000000000000..272e4bb3b372 Binary files /dev/null and b/src/Controls/tests/TestCases.Android.Tests/snapshots/android/VerifyFontImageAreCenterAlign.png differ diff --git a/src/Controls/tests/TestCases.HostApp/Issues/Issue30004.cs b/src/Controls/tests/TestCases.HostApp/Issues/Issue30004.cs new file mode 100644 index 000000000000..f0f13b54101f --- /dev/null +++ b/src/Controls/tests/TestCases.HostApp/Issues/Issue30004.cs @@ -0,0 +1,20 @@ +namespace Maui.Controls.Sample.Issues; + +[Issue(IssueTracker.Github, 30004, "FontImageSource not center-aligned inside Image control", PlatformAffected.UWP)] +public class Issue30004 : ContentPage +{ + public Issue30004() + { + Content = new StackLayout() + { + Children = + { + new Label(){Text = "FontAwesome", AutomationId="FontImage", HorizontalOptions = LayoutOptions.Center, FontSize = 20, Margin = new Thickness(0, 20, 0, 20)}, + new Image() { Source = new FontImageSource() { FontFamily = "FA", Glyph = "\xf7a4", Color = Colors.Black, Size = 50}, Margin = 4, Background= Colors.Red, WidthRequest=100, HeightRequest=100, HorizontalOptions = LayoutOptions.Center}, + + new Label(){Text = "ionicons", HorizontalOptions = LayoutOptions.Center, VerticalOptions = LayoutOptions.Center, FontSize = 20, Margin = new Thickness(0, 20, 0, 20)}, + new Image() { Source = new FontImageSource() { FontFamily = "Ion",Glyph = "\uf47e", Color = Colors.Black, Size = 50}, Background= Colors.Red,WidthRequest=100, HeightRequest=100, HorizontalOptions = LayoutOptions.Center}, + } + }; + } +} \ No newline at end of file diff --git a/src/Controls/tests/TestCases.Mac.Tests/snapshots/mac/VerifyFontImageAreCenterAlign.png b/src/Controls/tests/TestCases.Mac.Tests/snapshots/mac/VerifyFontImageAreCenterAlign.png new file mode 100644 index 000000000000..f4c0c3d24a08 Binary files /dev/null and b/src/Controls/tests/TestCases.Mac.Tests/snapshots/mac/VerifyFontImageAreCenterAlign.png differ diff --git a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue30004.cs b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue30004.cs new file mode 100644 index 000000000000..4b0d6553e23d --- /dev/null +++ b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue30004.cs @@ -0,0 +1,21 @@ +using NUnit.Framework; +using UITest.Appium; +using UITest.Core; + +namespace Microsoft.Maui.TestCases.Tests.Issues; +public class Issue30004 : _IssuesUITest +{ + public override string Issue => "FontImageSource not center-aligned inside Image control"; + + public Issue30004(TestDevice device) + : base(device) + { } + + [Test] + [Category(UITestCategories.Image)] + public void VerifyFontImageAreCenterAlign() + { + App.WaitForElement("FontImage"); + VerifyScreenshot(); + } +} \ No newline at end of file diff --git a/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/ImageUITests_Source_FontImageSource_FontAwesome.png b/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/ImageUITests_Source_FontImageSource_FontAwesome.png index d6bf1ef6d0d0..e07ea4fcb8c0 100644 Binary files a/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/ImageUITests_Source_FontImageSource_FontAwesome.png and b/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/ImageUITests_Source_FontImageSource_FontAwesome.png differ diff --git a/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/ImageUITests_Source_FontImageSource_Ionicons.png b/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/ImageUITests_Source_FontImageSource_Ionicons.png index f2d99244e9d2..99e2d82f9b15 100644 Binary files a/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/ImageUITests_Source_FontImageSource_Ionicons.png and b/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/ImageUITests_Source_FontImageSource_Ionicons.png differ diff --git a/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/Issue21202Test.png b/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/Issue21202Test.png index 4c81a19de320..5f1ab03c9958 100644 Binary files a/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/Issue21202Test.png and b/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/Issue21202Test.png differ diff --git a/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/Issue22433_Default.png b/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/Issue22433_Default.png index 3b121c472ce4..152a869f145e 100644 Binary files a/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/Issue22433_Default.png and b/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/Issue22433_Default.png differ diff --git a/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/Issue22433_Layout.png b/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/Issue22433_Layout.png index 13e153d2ee57..d46ec1c29d81 100644 Binary files a/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/Issue22433_Layout.png and b/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/Issue22433_Layout.png differ diff --git a/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/Issue22433_Spacing.png b/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/Issue22433_Spacing.png index 8637899a5e82..f4120fe54481 100644 Binary files a/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/Issue22433_Spacing.png and b/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/Issue22433_Spacing.png differ diff --git a/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/ToolbarItemFontIconSourceChangesAtRunTime.png b/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/ToolbarItemFontIconSourceChangesAtRunTime.png index a4ad67fefb4e..2e3d85d26379 100644 Binary files a/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/ToolbarItemFontIconSourceChangesAtRunTime.png and b/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/ToolbarItemFontIconSourceChangesAtRunTime.png differ diff --git a/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/VerifyFontImageAreCenterAlign.png b/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/VerifyFontImageAreCenterAlign.png new file mode 100644 index 000000000000..d06c927fa784 Binary files /dev/null and b/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/VerifyFontImageAreCenterAlign.png differ diff --git a/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/VerifyFontImageWithFontColorGreen.png b/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/VerifyFontImageWithFontColorGreen.png index 9becee47aed2..cc9112dbc518 100644 Binary files a/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/VerifyFontImageWithFontColorGreen.png and b/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/VerifyFontImageWithFontColorGreen.png differ diff --git a/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/VerifyImageAspect_AspectFitWithImageSourceFromFontImage.png b/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/VerifyImageAspect_AspectFitWithImageSourceFromFontImage.png index d13b0cfe2588..a220bd3b8c95 100644 Binary files a/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/VerifyImageAspect_AspectFitWithImageSourceFromFontImage.png and b/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/VerifyImageAspect_AspectFitWithImageSourceFromFontImage.png differ diff --git a/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/VerifyImageAspect_CenterWithImageSourceFromFontImage.png b/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/VerifyImageAspect_CenterWithImageSourceFromFontImage.png index 69f402965cd4..7b3fe6c29e86 100644 Binary files a/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/VerifyImageAspect_CenterWithImageSourceFromFontImage.png and b/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/VerifyImageAspect_CenterWithImageSourceFromFontImage.png differ diff --git a/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/VerifyImageAspect_FillWithImageSourceFromFontImage.png b/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/VerifyImageAspect_FillWithImageSourceFromFontImage.png index 809438b58d9a..f282b7821de8 100644 Binary files a/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/VerifyImageAspect_FillWithImageSourceFromFontImage.png and b/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/VerifyImageAspect_FillWithImageSourceFromFontImage.png differ diff --git a/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios/VerifyFontImageAreCenterAlign.png b/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios/VerifyFontImageAreCenterAlign.png new file mode 100644 index 000000000000..359b2b77537c Binary files /dev/null and b/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios/VerifyFontImageAreCenterAlign.png differ diff --git a/src/Core/src/ImageSources/FontImageSourceService/FontImageSourceService.Windows.cs b/src/Core/src/ImageSources/FontImageSourceService/FontImageSourceService.Windows.cs index 43e818f42102..6af115b579ec 100644 --- a/src/Core/src/ImageSources/FontImageSourceService/FontImageSourceService.Windows.cs +++ b/src/Core/src/ImageSources/FontImageSourceService/FontImageSourceService.Windows.cs @@ -77,18 +77,18 @@ internal CanvasImageSource RenderImageSource(IFontImageSource imageSource, float }; var device = CanvasDevice.GetSharedDevice(); - using var layout = new CanvasTextLayout(device, imageSource.Glyph, textFormat, 0, 0); + using var layout = new CanvasTextLayout(device, imageSource.Glyph, textFormat, fontSize, fontSize); // add a 1px padding all around - var canvasWidth = (float)layout.DrawBounds.Width + 2; - var canvasHeight = (float)layout.DrawBounds.Height + 2; + var canvasWidth = (float)layout.LayoutBounds.Width + 2; + var canvasHeight = (float)layout.LayoutBounds.Height + 2; var canvasImageSource = new CanvasImageSource(device, canvasWidth, canvasHeight, dpi); using (var ds = canvasImageSource.CreateDrawingSession(UI.Colors.Transparent)) { // offset by 1px as we added a 1px padding - var x = (layout.DrawBounds.X * -1) + 1; - var y = (layout.DrawBounds.Y * -1) + 1; + var x = (layout.LayoutBounds.X * -1) + 1; + var y = (layout.LayoutBounds.Y * -1) + 1; ds.DrawTextLayout(layout, (float)x, (float)y, color); }