From f30ab27ae88507dea13e0a14af69dc861c9212f8 Mon Sep 17 00:00:00 2001 From: Sivamuthu Kumar Date: Tue, 5 Jun 2018 19:03:33 -0400 Subject: [PATCH] Fix macOS label renderer Italic Font attributes (#2729) fixes #2728 --- .../Issue2728.cs | 38 +++++++++++++++++++ ...rin.Forms.Controls.Issues.Shared.projitems | 1 + .../Renderers/FontExtensions.cs | 5 ++- 3 files changed, 42 insertions(+), 2 deletions(-) create mode 100644 Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue2728.cs diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue2728.cs b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue2728.cs new file mode 100644 index 000000000..008b6441a --- /dev/null +++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue2728.cs @@ -0,0 +1,38 @@ +using Xamarin.Forms.CustomAttributes; +using Xamarin.Forms.Internals; + +#if UITEST +using NUnit.Framework; +using Xamarin.UITest; +#endif + +namespace Xamarin.Forms.Controls.Issues +{ + [Preserve(AllMembers = true)] + [Issue(IssueTracker.Github, 2728, "[macOS] Label FontAttributes Italic is not working")] + public class Issue2728 : TestContentPage + { + protected override void Init() + { + var label = new Label { Text = "Hello Label", FontAttributes = FontAttributes.Italic }; + + Content = new StackLayout + { + Children = { + label + } + }; + } + + +#if UITEST + [Test] + public void Issue2728TestsItalicLabel () + { + RunningApp.WaitForElement(q => q.Text("Home")); + RunningApp.Screenshot ("Label rendererd with italic font"); + } +#endif + + } +} 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 81d1ddf8e..b51a96ea0 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 @@ -732,6 +732,7 @@ + diff --git a/Xamarin.Forms.Platform.iOS/Renderers/FontExtensions.cs b/Xamarin.Forms.Platform.iOS/Renderers/FontExtensions.cs index 2ddd11c8f..91aea71a5 100644 --- a/Xamarin.Forms.Platform.iOS/Renderers/FontExtensions.cs +++ b/Xamarin.Forms.Platform.iOS/Renderers/FontExtensions.cs @@ -231,8 +231,9 @@ namespace Xamarin.Forms.Platform.MacOS } if (italic) { - Debug.WriteLine("Italic font requested, passing regular one"); - return NSFont.UserFontOfSize(size); + var defaultFont = UIFont.SystemFontOfSize(size); + var descriptor = defaultFont.FontDescriptor.FontDescriptorWithSymbolicTraits(NSFontSymbolicTraits.ItalicTrait); + return NSFont.FromDescription(descriptor, 0); } #endif if (bold)