Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 20 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue30004.cs
Original file line number Diff line number Diff line change
@@ -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},
}
};
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -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();
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Loading