diff --git a/Xamarin.Forms.ControlGallery.WindowsUniversal/Assets/Fonts/MaterialIconsOutlined-Regular.otf b/Xamarin.Forms.ControlGallery.WindowsUniversal/Assets/Fonts/MaterialIconsOutlined-Regular.otf new file mode 100644 index 00000000000..4ccd8ed30a2 Binary files /dev/null and b/Xamarin.Forms.ControlGallery.WindowsUniversal/Assets/Fonts/MaterialIconsOutlined-Regular.otf differ diff --git a/Xamarin.Forms.ControlGallery.WindowsUniversal/Xamarin.Forms.ControlGallery.WindowsUniversal.csproj b/Xamarin.Forms.ControlGallery.WindowsUniversal/Xamarin.Forms.ControlGallery.WindowsUniversal.csproj index 99e17b2d8aa..b36116c7a63 100644 --- a/Xamarin.Forms.ControlGallery.WindowsUniversal/Xamarin.Forms.ControlGallery.WindowsUniversal.csproj +++ b/Xamarin.Forms.ControlGallery.WindowsUniversal/Xamarin.Forms.ControlGallery.WindowsUniversal.csproj @@ -282,6 +282,7 @@ + diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue8606.cs b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue8606.cs new file mode 100644 index 00000000000..be422b4647e --- /dev/null +++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue8606.cs @@ -0,0 +1,73 @@ +using System; +using System.Collections.Generic; +using Xamarin.Forms.CustomAttributes; +using Xamarin.Forms.Internals; +#if UITEST +using Xamarin.UITest; +using NUnit.Framework; +using Xamarin.Forms.Core.UITests; +#endif + +namespace Xamarin.Forms.Controls.Issues +{ + [Preserve(AllMembers = true)] + [Issue(IssueTracker.Github, 8606, "[Bug] [UWP] FontIcons are not aligned correctly", PlatformAffected.UWP)] +#if UITEST + [Category(UITestCategories.Github5000)] + [Category(UITestCategories.ManualReview)] +#endif + public class Issue8606 : TestContentPage + { + protected override void Init() + { + var iconColor = Color.White; + List<(string fontFamily,string glyph,string familyShortName)> fontFamilyGlyphs = new List<(string,string,string)> + { + (GetFontFamily("fa-solid-900.ttf","Font Awesome 5 Free"), GetGlyph("f059"),"FaSolid"), + (GetFontFamily("ionicons.ttf","Ionicons"), GetGlyph("f142"),"Ionicons"), + (GetFontFamily("materialdesignicons-webfont.ttf","Material Design Icons"),GetGlyph("f625"),"Material old"), + (GetFontFamily("MaterialIconsOutlined-Regular.otf","Material Icons Outlined"), GetGlyph("e8fd"),"Material"), + }; + + List> affectedViewsCreators = new List> + { + (fontImageSource) => new Button { ImageSource = fontImageSource }, + (fontImageSource) => new ImageButton { WidthRequest=39,HeightRequest=39, Source = fontImageSource, BackgroundColor = Color.FromHex("#333333")}, + (fontImageSource) => new Frame{Content = new Image { Source = fontImageSource}, BorderColor=iconColor, Padding=0, } + }; + + var content = new StackLayout { }; + content.Children.Add(new Label { BackgroundColor = Color.Black, Padding = 12, TextColor = iconColor, Text = "Button, ImageButton and Image should use the same FontImageSourceHandler which should render centered." }); + + foreach (var (fontFamily, glyph, familyShortName) in fontFamilyGlyphs) + { + var fontImageSource = new FontImageSource { Size = 24, Color = iconColor, FontFamily = fontFamily, Glyph = glyph }; + var fontStackLayout = new StackLayout { }; + fontStackLayout.Children.Add(new Label { FontSize = 24, Text = familyShortName }); + var fontsStackLayout = new StackLayout { Orientation = StackOrientation.Horizontal, HorizontalOptions = LayoutOptions.Center }; + fontStackLayout.Children.Add(fontsStackLayout); + foreach (var affectedViewCreator in affectedViewsCreators) + { + var affectedView = affectedViewCreator(fontImageSource); + affectedView.VerticalOptions = LayoutOptions.Center; + fontsStackLayout.Children.Add(affectedView); + } + content.Children.Add(fontStackLayout); + } + + Content = content; + + } + + private string GetFontFamily(string fileName, string fontName) + { + return $"Assets/Fonts/{fileName}#{fontName}"; + } + + private static string GetGlyph(string codePoint) + { + int p = int.Parse(codePoint, System.Globalization.NumberStyles.HexNumber); + return char.ConvertFromUtf32(p); + } + } +} diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems index 0d53007f239..29158e68b95 100644 --- a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems +++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems @@ -53,6 +53,7 @@ Issue14801.xaml + Issue8804.xaml diff --git a/Xamarin.Forms.Platform.UAP/FontImageSourceHandler.cs b/Xamarin.Forms.Platform.UAP/FontImageSourceHandler.cs index 98b2decefa4..31d74ffa6f6 100755 --- a/Xamarin.Forms.Platform.UAP/FontImageSourceHandler.cs +++ b/Xamarin.Forms.Platform.UAP/FontImageSourceHandler.cs @@ -26,7 +26,7 @@ public sealed class FontImageSourceHandler : IImageSourceHandler, IIconElementHa { FontFamily = GetFontSource(fontsource), FontSize = (float)fontsource.Size, - HorizontalAlignment = CanvasHorizontalAlignment.Center, + HorizontalAlignment = CanvasHorizontalAlignment.Left, VerticalAlignment = CanvasVerticalAlignment.Center, Options = CanvasDrawTextOptions.Default }; @@ -42,9 +42,7 @@ public sealed class FontImageSourceHandler : IImageSourceHandler, IIconElementHa var iconcolor = (fontsource.Color != Color.Default ? fontsource.Color : Color.White).ToWindowsColor(); // offset by 1 as we added a 1 inset - var x = (float)layout.DrawBounds.X * -1; - - ds.DrawTextLayout(layout, x, 1f, iconcolor); + ds.DrawTextLayout(layout, 1f, 1f, iconcolor); } return Task.FromResult((Windows.UI.Xaml.Media.ImageSource)imageSource);