зеркало из https://github.com/DeGsoft/maui-linux.git
* [MacOS] Draft push test fix macOS test * Refactor * [Controls] Add repo test case #2204 * [Controls] Remove demo page * [iOS,macOS] Refactor FontExtensions * [iOS] Change visibility of shared method * [Controls] Cleanup test #2204
This commit is contained in:
Родитель
dd8ed7ee23
Коммит
d2f0794a37
|
@ -35,5 +35,7 @@
|
|||
</dict>
|
||||
<key>NSMainStoryboardFile</key>
|
||||
<string>Main</string>
|
||||
<key>ATSApplicationFontsPath</key>
|
||||
<string>Fonts</string>
|
||||
</dict>
|
||||
</plist>
|
||||
|
|
Двоичный файл не отображается.
Двоичные данные
Xamarin.Forms.ControlGallery.MacOS/Resources/Fonts/Roboto-BoldItalic.ttf
Executable file
Двоичные данные
Xamarin.Forms.ControlGallery.MacOS/Resources/Fonts/Roboto-BoldItalic.ttf
Executable file
Двоичный файл не отображается.
Двоичные данные
Xamarin.Forms.ControlGallery.MacOS/Resources/Fonts/Roboto-Italic.ttf
Executable file
Двоичные данные
Xamarin.Forms.ControlGallery.MacOS/Resources/Fonts/Roboto-Italic.ttf
Executable file
Двоичный файл не отображается.
Двоичные данные
Xamarin.Forms.ControlGallery.MacOS/Resources/Fonts/Roboto-Regular.ttf
Executable file
Двоичные данные
Xamarin.Forms.ControlGallery.MacOS/Resources/Fonts/Roboto-Regular.ttf
Executable file
Двоичный файл не отображается.
|
@ -115,7 +115,7 @@
|
|||
<Name>Xamarin.Forms.Maps</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\Xamarin.Forms.Platform\Xamarin.Forms.Platform.csproj">
|
||||
<Project>{67F9D3A8-F71E-4428-913F-C37AE82CDB24}</Project>
|
||||
<Project>{D31A6537-ED9C-4EBD-B231-A8D4FE44126A}</Project>
|
||||
<Name>Xamarin.Forms.Platform</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\Xamarin.Forms.Platform.MacOS\Xamarin.Forms.Platform.MacOS.csproj">
|
||||
|
@ -381,10 +381,25 @@
|
|||
<BundleResource Include="..\Xamarin.Forms.ControlGallery.iOS\Images\Vegetables%402x.jpg">
|
||||
<Link>Images\Vegetables%402x.jpg</Link>
|
||||
</BundleResource>
|
||||
<BundleResource Include="Resources\Fonts\Roboto-Bold.ttf">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</BundleResource>
|
||||
<BundleResource Include="Resources\Fonts\Roboto-BoldItalic.ttf">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</BundleResource>
|
||||
<BundleResource Include="Resources\Fonts\Roboto-Italic.ttf">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</BundleResource>
|
||||
<BundleResource Include="Resources\Fonts\Roboto-Regular.ttf">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</BundleResource>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<InterfaceDefinition Include="Main.storyboard" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="Resources\Fonts\" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildExtensionsPath)\Xamarin\Mac\Xamarin.Mac.CSharp.targets" />
|
||||
<Target Name="_VerifyBuildSignature" />
|
||||
</Project>
|
||||
|
|
|
@ -139,5 +139,12 @@
|
|||
<string>LaunchScreen</string>
|
||||
<key>XSAppIconAssets</key>
|
||||
<string>Assets.xcassets/AppIcon.appiconset</string>
|
||||
<key>UIAppFonts</key>
|
||||
<array>
|
||||
<string>Fonts/Roboto-Italic.ttf</string>
|
||||
<string>Fonts/Roboto-Bold.ttf</string>
|
||||
<string>Fonts/Roboto-Regular.ttf</string>
|
||||
<string>Fonts/Roboto-BoldItalic.ttf</string>
|
||||
</array>
|
||||
</dict>
|
||||
</plist>
|
||||
|
|
|
@ -302,6 +302,22 @@
|
|||
<BundleResource Include="Resources\xamarin_logo%403x.png" />
|
||||
<BundleResource Include="Resources\xamarin_logo%402x.png" />
|
||||
<BundleResource Include="Resources\xamarin_logo.png" />
|
||||
<BundleResource Include="..\Xamarin.Forms.ControlGallery.MacOS\Resources\Fonts\Roboto-Bold.ttf">
|
||||
<Link>Resources\Fonts\Roboto-Bold.ttf</Link>
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</BundleResource>
|
||||
<BundleResource Include="..\Xamarin.Forms.ControlGallery.MacOS\Resources\Fonts\Roboto-BoldItalic.ttf">
|
||||
<Link>Resources\Fonts\Roboto-BoldItalic.ttf</Link>
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</BundleResource>
|
||||
<BundleResource Include="..\Xamarin.Forms.ControlGallery.MacOS\Resources\Fonts\Roboto-Italic.ttf">
|
||||
<Link>Resources\Fonts\Roboto-Italic.ttf</Link>
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</BundleResource>
|
||||
<BundleResource Include="..\Xamarin.Forms.ControlGallery.MacOS\Resources\Fonts\Roboto-Regular.ttf">
|
||||
<Link>Resources\Fonts\Roboto-Regular.ttf</Link>
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</BundleResource>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
|
@ -368,5 +384,8 @@
|
|||
<Visible>false</Visible>
|
||||
</ImageAsset>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="Resources\Fonts\" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildExtensionsPath)\Xamarin\iOS\Xamarin.iOS.CSharp.targets" />
|
||||
</Project>
|
|
@ -0,0 +1,56 @@
|
|||
using Xamarin.Forms.CustomAttributes;
|
||||
using Xamarin.Forms.Internals;
|
||||
|
||||
#if UITEST
|
||||
using Xamarin.Forms.Core.UITests;
|
||||
using Xamarin.UITest;
|
||||
using NUnit.Framework;
|
||||
#endif
|
||||
|
||||
namespace Xamarin.Forms.Controls.Issues
|
||||
{
|
||||
#if UITEST
|
||||
[Category(UITestCategories.ManualReview)]
|
||||
#endif
|
||||
[Preserve(AllMembers = true)]
|
||||
[Issue(IssueTracker.Github, 2204, "Font aliasing and color aren't displayed correctly in MacOS without a retina display", PlatformAffected.macOS)]
|
||||
public class Issue2204 : TestContentPage
|
||||
{
|
||||
readonly string _fontFamilyMacOs = "Roboto";
|
||||
|
||||
protected override void Init()
|
||||
{
|
||||
var grid = new Grid
|
||||
{
|
||||
BackgroundColor = Color.FromHex("#32d2c8")
|
||||
};
|
||||
|
||||
grid.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto });
|
||||
grid.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto });
|
||||
grid.ColumnDefinitions.Add(new ColumnDefinition { Width = GridLength.Star });
|
||||
grid.ColumnDefinitions.Add(new ColumnDefinition { Width = GridLength.Star });
|
||||
|
||||
var layoutCustomFount = new StackLayout();
|
||||
var layoutDefaultFont = new StackLayout();
|
||||
var label = new Label { Text = "This 1st column uses a custom font, it should be different from the 2nd column, check the '9s' " };
|
||||
for (int i = 10; i < 20; i++)
|
||||
{
|
||||
AddToLayout(layoutCustomFount, i, _fontFamilyMacOs);
|
||||
AddToLayout(layoutDefaultFont, i, null);
|
||||
}
|
||||
grid.Children.Add(label, 0, 2, 0, 1);
|
||||
grid.Children.Add(layoutCustomFount, 0, 1);
|
||||
grid.Children.Add(layoutDefaultFont, 1, 1);
|
||||
Content = new ScrollView { Content = grid };
|
||||
}
|
||||
|
||||
static void AddToLayout(StackLayout layout, int i, string fontFamily)
|
||||
{
|
||||
var text = $"Xamarin Forms FontSize:{i}";
|
||||
layout.Children.Add(new Label { Text = text, FontSize = i, FontFamily = fontFamily, TextColor = Color.White });
|
||||
layout.Children.Add(new Label { Text = text, FontSize = i, FontFamily = fontFamily, FontAttributes = FontAttributes.Bold, TextColor = Color.White });
|
||||
layout.Children.Add(new Label { Text = text, FontSize = i, FontFamily = fontFamily, FontAttributes = FontAttributes.Italic, TextColor = Color.White });
|
||||
layout.Children.Add(new Label { Text = text, FontSize = i, FontFamily = fontFamily, FontAttributes = FontAttributes.Italic | FontAttributes.Bold, TextColor = Color.White });
|
||||
}
|
||||
}
|
||||
}
|
|
@ -886,6 +886,7 @@
|
|||
<Compile Include="$(MSBuildThisFileDirectory)Issue4138.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Issue4314.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Issue5172.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Issue2204.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="$(MSBuildThisFileDirectory)Bugzilla22229.xaml">
|
||||
|
|
|
@ -0,0 +1,62 @@
|
|||
using System.Diagnostics;
|
||||
using Xamarin.Forms.Internals;
|
||||
using AppKit;
|
||||
|
||||
namespace Xamarin.Forms.Platform.MacOS
|
||||
{
|
||||
public static partial class FontExtensions
|
||||
{
|
||||
static readonly string DefaultFontName = NSFont.SystemFontOfSize(12).FontName;
|
||||
|
||||
public static NSFont ToNSFont(this Font self) => ToNativeFont(self);
|
||||
|
||||
internal static NSFont ToNSFont(this IFontElement element) => ToNativeFont(element);
|
||||
|
||||
static NSFont _ToNativeFont(string family, float size, FontAttributes attributes)
|
||||
{
|
||||
NSFont defaultFont = NSFont.SystemFontOfSize(size);
|
||||
NSFont font = null;
|
||||
NSFontDescriptor descriptor = null;
|
||||
var bold = (attributes & FontAttributes.Bold) != 0;
|
||||
var italic = (attributes & FontAttributes.Italic) != 0;
|
||||
|
||||
if (family != null && family != DefaultFontName)
|
||||
{
|
||||
try
|
||||
{
|
||||
descriptor = new NSFontDescriptor().FontDescriptorWithFamily(family);
|
||||
font = NSFont.FromDescription(descriptor, size);
|
||||
|
||||
if (font == null)
|
||||
font = NSFont.FromFontName(family, size);
|
||||
}
|
||||
catch
|
||||
{
|
||||
Debug.WriteLine("Could not load font named: {0}", family);
|
||||
}
|
||||
}
|
||||
|
||||
//if we didn't found a Font or Descriptor for the FontFamily use the default one
|
||||
if (font == null)
|
||||
font = defaultFont;
|
||||
|
||||
if (descriptor == null)
|
||||
descriptor = defaultFont.FontDescriptor;
|
||||
|
||||
if (bold || italic)
|
||||
{
|
||||
var traits = (NSFontSymbolicTraits)0;
|
||||
if (bold)
|
||||
traits = traits | NSFontSymbolicTraits.BoldTrait;
|
||||
if (italic)
|
||||
traits = traits | NSFontSymbolicTraits.ItalicTrait;
|
||||
|
||||
var fontDescriptoWithTraits = descriptor.FontDescriptorWithSymbolicTraits(traits);
|
||||
|
||||
font = NSFont.FromDescription(fontDescriptoWithTraits, size);
|
||||
}
|
||||
|
||||
return font.ScreenFontWithRenderingMode(NSFontRenderingMode.AntialiasedIntegerAdvancements);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -182,9 +182,6 @@
|
|||
<Compile Include="..\Xamarin.Forms.Platform.iOS\Extensions\UIViewExtensions.cs">
|
||||
<Link>Extensions\UIViewExtensions.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\Xamarin.Forms.Platform.iOS\Renderers\FontExtensions.cs">
|
||||
<Link>Extensions\FontExtensions.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\Xamarin.Forms.Platform.iOS\Renderers\FormattedStringExtensions.cs">
|
||||
<Link>Extensions\FormattedStringExtensions.cs</Link>
|
||||
</Compile>
|
||||
|
@ -237,10 +234,14 @@
|
|||
<Link>VisualElementRenderer.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="Extensions\NSMenuExtensions.cs" />
|
||||
<Compile Include="Extensions\FontExtensions.cs" />
|
||||
<Compile Include="..\Xamarin.Forms.Platform.iOS\Extensions\FontExtensions.Shared.cs">
|
||||
<Link>Extensions\FontExtensions.Shared.cs</Link>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Xamarin.Forms.Platform\Xamarin.Forms.Platform.csproj">
|
||||
<Project>{67F9D3A8-F71E-4428-913F-C37AE82CDB24}</Project>
|
||||
<Project>{D31A6537-ED9C-4EBD-B231-A8D4FE44126A}</Project>
|
||||
<Name>Xamarin.Forms.Platform</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\Xamarin.Forms.Core\Xamarin.Forms.Core.csproj">
|
||||
|
|
|
@ -0,0 +1,103 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Xamarin.Forms.Internals;
|
||||
#if __MOBILE__
|
||||
using UIKit;
|
||||
using NativeFont = UIKit.UIFont;
|
||||
|
||||
namespace Xamarin.Forms.Platform.iOS
|
||||
#else
|
||||
using AppKit;
|
||||
using NativeFont = AppKit.NSFont;
|
||||
|
||||
namespace Xamarin.Forms.Platform.MacOS
|
||||
#endif
|
||||
{
|
||||
public static partial class FontExtensions
|
||||
{
|
||||
static readonly Dictionary<ToNativeFontFontKey, NativeFont> ToUiFont = new Dictionary<ToNativeFontFontKey, NativeFont>();
|
||||
|
||||
internal static bool IsDefault(this Span self)
|
||||
{
|
||||
return self.FontFamily == null && self.FontSize == Device.GetNamedSize(NamedSize.Default, typeof(Label), true) &&
|
||||
self.FontAttributes == FontAttributes.None;
|
||||
}
|
||||
|
||||
static NativeFont ToNativeFont(this IFontElement element)
|
||||
{
|
||||
var fontFamily = element.FontFamily;
|
||||
var fontSize = (float)element.FontSize;
|
||||
var fontAttributes = element.FontAttributes;
|
||||
return ToNativeFont(fontFamily, fontSize, fontAttributes, _ToNativeFont);
|
||||
}
|
||||
|
||||
static NativeFont ToNativeFont(this Font self)
|
||||
{
|
||||
var size = (float)self.FontSize;
|
||||
if (self.UseNamedSize)
|
||||
{
|
||||
switch (self.NamedSize)
|
||||
{
|
||||
case NamedSize.Micro:
|
||||
size = 12;
|
||||
break;
|
||||
case NamedSize.Small:
|
||||
size = 14;
|
||||
break;
|
||||
case NamedSize.Medium:
|
||||
size = 17; // as defined by iOS documentation
|
||||
break;
|
||||
case NamedSize.Large:
|
||||
size = 22;
|
||||
break;
|
||||
default:
|
||||
size = 17;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
var fontAttributes = self.FontAttributes;
|
||||
|
||||
return ToNativeFont(self.FontFamily, size, fontAttributes, _ToNativeFont);
|
||||
}
|
||||
|
||||
static NativeFont ToNativeFont(string family, float size, FontAttributes attributes, Func<string, float, FontAttributes, NativeFont> factory)
|
||||
{
|
||||
var key = new ToNativeFontFontKey(family, size, attributes);
|
||||
|
||||
lock (ToUiFont)
|
||||
{
|
||||
NativeFont value;
|
||||
if (ToUiFont.TryGetValue(key, out value))
|
||||
return value;
|
||||
}
|
||||
|
||||
var generatedValue = factory(family, size, attributes);
|
||||
|
||||
lock (ToUiFont)
|
||||
{
|
||||
NativeFont value;
|
||||
if (!ToUiFont.TryGetValue(key, out value))
|
||||
ToUiFont.Add(key, value = generatedValue);
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
struct ToNativeFontFontKey
|
||||
{
|
||||
internal ToNativeFontFontKey(string family, float size, FontAttributes attributes)
|
||||
{
|
||||
_family = family;
|
||||
_size = size;
|
||||
_attributes = attributes;
|
||||
}
|
||||
#pragma warning disable 0414 // these are not called explicitly, but they are used to establish uniqueness. allow it!
|
||||
string _family;
|
||||
float _size;
|
||||
FontAttributes _attributes;
|
||||
#pragma warning restore 0414
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,72 @@
|
|||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using Xamarin.Forms.Internals;
|
||||
using UIKit;
|
||||
|
||||
namespace Xamarin.Forms.Platform.iOS
|
||||
{
|
||||
public static partial class FontExtensions
|
||||
{
|
||||
static readonly string DefaultFontName = UIFont.SystemFontOfSize(12).Name;
|
||||
|
||||
public static UIFont ToUIFont(this Font self) => ToNativeFont(self);
|
||||
|
||||
internal static UIFont ToUIFont(this IFontElement element) => ToNativeFont(element);
|
||||
|
||||
static UIFont _ToNativeFont(string family, float size, FontAttributes attributes)
|
||||
{
|
||||
var bold = (attributes & FontAttributes.Bold) != 0;
|
||||
var italic = (attributes & FontAttributes.Italic) != 0;
|
||||
|
||||
if (family != null && family != DefaultFontName)
|
||||
{
|
||||
try
|
||||
{
|
||||
UIFont result = null;
|
||||
if (UIFont.FamilyNames.Contains(family))
|
||||
{
|
||||
var descriptor = new UIFontDescriptor().CreateWithFamily(family);
|
||||
|
||||
if (bold || italic)
|
||||
{
|
||||
var traits = (UIFontDescriptorSymbolicTraits)0;
|
||||
if (bold)
|
||||
traits = traits | UIFontDescriptorSymbolicTraits.Bold;
|
||||
if (italic)
|
||||
traits = traits | UIFontDescriptorSymbolicTraits.Italic;
|
||||
|
||||
descriptor = descriptor.CreateWithTraits(traits);
|
||||
result = UIFont.FromDescriptor(descriptor, size);
|
||||
if (result != null)
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
result = UIFont.FromName(family, size);
|
||||
if (result != null)
|
||||
return result;
|
||||
}
|
||||
catch
|
||||
{
|
||||
Debug.WriteLine("Could not load font named: {0}", family);
|
||||
}
|
||||
}
|
||||
|
||||
if (bold && italic)
|
||||
{
|
||||
var defaultFont = UIFont.SystemFontOfSize(size);
|
||||
|
||||
var descriptor = defaultFont.FontDescriptor.CreateWithTraits(UIFontDescriptorSymbolicTraits.Bold | UIFontDescriptorSymbolicTraits.Italic);
|
||||
return UIFont.FromDescriptor(descriptor, 0);
|
||||
}
|
||||
|
||||
if (italic)
|
||||
return UIFont.ItalicSystemFontOfSize(size);
|
||||
|
||||
if (bold)
|
||||
return UIFont.BoldSystemFontOfSize(size);
|
||||
|
||||
return UIFont.SystemFontOfSize(size);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,289 +0,0 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using Xamarin.Forms;
|
||||
using Xamarin.Forms.Internals;
|
||||
#if __MOBILE__
|
||||
using UIKit;
|
||||
namespace Xamarin.Forms.Platform.iOS
|
||||
#else
|
||||
using AppKit;
|
||||
using UIFont = AppKit.NSFont;
|
||||
|
||||
namespace Xamarin.Forms.Platform.MacOS
|
||||
#endif
|
||||
{
|
||||
public static class FontExtensions
|
||||
{
|
||||
|
||||
#if __MOBILE__
|
||||
static readonly string DefaultFontName = UIFont.SystemFontOfSize(12).Name;
|
||||
#else
|
||||
static readonly string DefaultFontName = UIFont.SystemFontOfSize(12).FontName;
|
||||
#endif
|
||||
|
||||
static readonly Dictionary<ToUIFontKey, UIFont> ToUiFont = new Dictionary<ToUIFontKey, UIFont>();
|
||||
#if __MOBILE__
|
||||
public static UIFont ToUIFont(this Font self)
|
||||
|
||||
#else
|
||||
public static UIFont ToNSFont(this Font self)
|
||||
#endif
|
||||
{
|
||||
var size = (float)self.FontSize;
|
||||
if (self.UseNamedSize)
|
||||
{
|
||||
switch (self.NamedSize)
|
||||
{
|
||||
case NamedSize.Micro:
|
||||
size = 12;
|
||||
break;
|
||||
case NamedSize.Small:
|
||||
size = 14;
|
||||
break;
|
||||
case NamedSize.Medium:
|
||||
size = 17; // as defined by iOS documentation
|
||||
break;
|
||||
case NamedSize.Large:
|
||||
size = 22;
|
||||
break;
|
||||
default:
|
||||
size = 17;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
var bold = self.FontAttributes.HasFlag(FontAttributes.Bold);
|
||||
var italic = self.FontAttributes.HasFlag(FontAttributes.Italic);
|
||||
|
||||
if (self.FontFamily != null && self.FontFamily != DefaultFontName)
|
||||
{
|
||||
try
|
||||
{
|
||||
#if __MOBILE__
|
||||
if (UIFont.FamilyNames.Contains(self.FontFamily))
|
||||
{
|
||||
var descriptor = new UIFontDescriptor().CreateWithFamily(self.FontFamily);
|
||||
|
||||
if (bold || italic)
|
||||
{
|
||||
var traits = (UIFontDescriptorSymbolicTraits)0;
|
||||
if (bold)
|
||||
traits = traits | UIFontDescriptorSymbolicTraits.Bold;
|
||||
if (italic)
|
||||
traits = traits | UIFontDescriptorSymbolicTraits.Italic;
|
||||
|
||||
descriptor = descriptor.CreateWithTraits(traits);
|
||||
return UIFont.FromDescriptor(descriptor, size);
|
||||
}
|
||||
}
|
||||
|
||||
return UIFont.FromName(self.FontFamily, size);
|
||||
|
||||
#else
|
||||
|
||||
var descriptor = new NSFontDescriptor().FontDescriptorWithFamily(self.FontFamily);
|
||||
|
||||
if (bold || italic)
|
||||
{
|
||||
var traits = (NSFontSymbolicTraits)0;
|
||||
if (bold)
|
||||
traits = traits | NSFontSymbolicTraits.BoldTrait;
|
||||
if (italic)
|
||||
traits = traits | NSFontSymbolicTraits.ItalicTrait;
|
||||
|
||||
descriptor = descriptor.FontDescriptorWithSymbolicTraits(traits);
|
||||
return NSFont.FromDescription(descriptor, size);
|
||||
}
|
||||
|
||||
return NSFont.FromFontName(self.FontFamily, size);
|
||||
#endif
|
||||
}
|
||||
catch
|
||||
{
|
||||
Debug.WriteLine("Could not load font named: {0}", self.FontFamily);
|
||||
}
|
||||
}
|
||||
if (bold && italic)
|
||||
{
|
||||
var defaultFont = UIFont.SystemFontOfSize(size);
|
||||
#if __MOBILE__
|
||||
var descriptor = defaultFont.FontDescriptor.CreateWithTraits(UIFontDescriptorSymbolicTraits.Bold | UIFontDescriptorSymbolicTraits.Italic);
|
||||
return UIFont.FromDescriptor(descriptor, 0);
|
||||
}
|
||||
if (italic)
|
||||
return UIFont.ItalicSystemFontOfSize(size);
|
||||
#else
|
||||
var descriptor = defaultFont.FontDescriptor.FontDescriptorWithSymbolicTraits(
|
||||
NSFontSymbolicTraits.BoldTrait |
|
||||
NSFontSymbolicTraits.ItalicTrait);
|
||||
|
||||
return NSFont.FromDescription(descriptor, 0);
|
||||
}
|
||||
if (italic)
|
||||
{
|
||||
Debug.WriteLine("Italic font requested, passing regular one");
|
||||
return NSFont.UserFontOfSize(size);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (bold)
|
||||
return UIFont.BoldSystemFontOfSize(size);
|
||||
|
||||
return UIFont.SystemFontOfSize(size);
|
||||
}
|
||||
|
||||
internal static bool IsDefault(this Span self)
|
||||
{
|
||||
return self.FontFamily == null && self.FontSize == Device.GetNamedSize(NamedSize.Default, typeof(Label), true) &&
|
||||
self.FontAttributes == FontAttributes.None;
|
||||
}
|
||||
|
||||
#if __MOBILE__
|
||||
internal static UIFont ToUIFont(this Label label)
|
||||
#else
|
||||
internal static UIFont ToNSFont(this Label label)
|
||||
#endif
|
||||
{
|
||||
var values = label.GetValues(Label.FontFamilyProperty, Label.FontSizeProperty, Label.FontAttributesProperty);
|
||||
return ToUIFont((string)values[0], (float)(double)values[1], (FontAttributes)values[2]) ??
|
||||
UIFont.SystemFontOfSize(UIFont.LabelFontSize);
|
||||
}
|
||||
|
||||
#if __MOBILE__
|
||||
internal static UIFont ToUIFont(this IFontElement element)
|
||||
#else
|
||||
internal static NSFont ToNSFont(this IFontElement element)
|
||||
#endif
|
||||
{
|
||||
return ToUIFont(element.FontFamily, (float)element.FontSize, element.FontAttributes);
|
||||
}
|
||||
|
||||
static UIFont _ToUIFont(string family, float size, FontAttributes attributes)
|
||||
{
|
||||
var bold = (attributes & FontAttributes.Bold) != 0;
|
||||
var italic = (attributes & FontAttributes.Italic) != 0;
|
||||
|
||||
if (family != null && family != DefaultFontName)
|
||||
{
|
||||
try
|
||||
{
|
||||
UIFont result;
|
||||
#if __MOBILE__
|
||||
if (UIFont.FamilyNames.Contains(family))
|
||||
{
|
||||
var descriptor = new UIFontDescriptor().CreateWithFamily(family);
|
||||
|
||||
if (bold || italic)
|
||||
{
|
||||
var traits = (UIFontDescriptorSymbolicTraits)0;
|
||||
if (bold)
|
||||
traits = traits | UIFontDescriptorSymbolicTraits.Bold;
|
||||
if (italic)
|
||||
traits = traits | UIFontDescriptorSymbolicTraits.Italic;
|
||||
|
||||
descriptor = descriptor.CreateWithTraits(traits);
|
||||
result = UIFont.FromDescriptor(descriptor, size);
|
||||
if (result != null)
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
result = UIFont.FromName(family, size);
|
||||
#else
|
||||
|
||||
var descriptor = new NSFontDescriptor().FontDescriptorWithFamily(family);
|
||||
|
||||
if (bold || italic)
|
||||
{
|
||||
var traits = (NSFontSymbolicTraits)0;
|
||||
if (bold)
|
||||
traits = traits | NSFontSymbolicTraits.BoldTrait;
|
||||
if (italic)
|
||||
traits = traits | NSFontSymbolicTraits.ItalicTrait;
|
||||
|
||||
descriptor = descriptor.FontDescriptorWithSymbolicTraits(traits);
|
||||
result = NSFont.FromDescription(descriptor, size);
|
||||
if (result != null)
|
||||
return result;
|
||||
}
|
||||
|
||||
result = NSFont.FromFontName(family, size);
|
||||
#endif
|
||||
if (result != null)
|
||||
return result;
|
||||
}
|
||||
catch
|
||||
{
|
||||
Debug.WriteLine("Could not load font named: {0}", family);
|
||||
}
|
||||
}
|
||||
|
||||
if (bold && italic)
|
||||
{
|
||||
var defaultFont = UIFont.SystemFontOfSize(size);
|
||||
|
||||
#if __MOBILE__
|
||||
var descriptor = defaultFont.FontDescriptor.CreateWithTraits(UIFontDescriptorSymbolicTraits.Bold | UIFontDescriptorSymbolicTraits.Italic);
|
||||
return UIFont.FromDescriptor(descriptor, 0);
|
||||
}
|
||||
if (italic)
|
||||
return UIFont.ItalicSystemFontOfSize(size);
|
||||
#else
|
||||
var descriptor = defaultFont.FontDescriptor.FontDescriptorWithSymbolicTraits(
|
||||
NSFontSymbolicTraits.BoldTrait |
|
||||
NSFontSymbolicTraits.ItalicTrait);
|
||||
|
||||
return NSFont.FromDescription(descriptor, 0);
|
||||
}
|
||||
if (italic)
|
||||
{
|
||||
var defaultFont = UIFont.SystemFontOfSize(size);
|
||||
var descriptor = defaultFont.FontDescriptor.FontDescriptorWithSymbolicTraits(NSFontSymbolicTraits.ItalicTrait);
|
||||
return NSFont.FromDescription(descriptor, 0);
|
||||
}
|
||||
#endif
|
||||
if (bold)
|
||||
return UIFont.BoldSystemFontOfSize(size);
|
||||
|
||||
return UIFont.SystemFontOfSize(size);
|
||||
}
|
||||
|
||||
static UIFont ToUIFont(string family, float size, FontAttributes attributes)
|
||||
{
|
||||
var key = new ToUIFontKey(family, size, attributes);
|
||||
|
||||
lock (ToUiFont)
|
||||
{
|
||||
UIFont value;
|
||||
if (ToUiFont.TryGetValue(key, out value))
|
||||
return value;
|
||||
}
|
||||
|
||||
var generatedValue = _ToUIFont(family, size, attributes);
|
||||
|
||||
lock (ToUiFont)
|
||||
{
|
||||
UIFont value;
|
||||
if (!ToUiFont.TryGetValue(key, out value))
|
||||
ToUiFont.Add(key, value = generatedValue);
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
struct ToUIFontKey
|
||||
{
|
||||
internal ToUIFontKey(string family, float size, FontAttributes attributes)
|
||||
{
|
||||
_family = family;
|
||||
_size = size;
|
||||
_attributes = attributes;
|
||||
}
|
||||
#pragma warning disable 0414 // these are not called explicitly, but they are used to establish uniqueness. allow it!
|
||||
string _family;
|
||||
float _size;
|
||||
FontAttributes _attributes;
|
||||
#pragma warning restore 0414
|
||||
}
|
||||
}
|
||||
}
|
|
@ -83,7 +83,6 @@
|
|||
<Compile Include="$(MSBuildThisFileDirectory)Renderers\DatePickerRenderer.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Renderers\EditorRenderer.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Renderers\EntryRenderer.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Renderers\FontExtensions.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Renderers\FormattedStringExtensions.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Renderers\FrameRenderer.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Renderers\ImageRenderer.cs" />
|
||||
|
@ -208,6 +207,8 @@
|
|||
<Compile Include="NativeValueConverterService.cs" />
|
||||
<Compile Include="NativeBindingService.cs" />
|
||||
<Compile Include="Extensions\AccessibilityExtensions.cs" />
|
||||
<Compile Include="Extensions\FontExtensions.cs" />
|
||||
<Compile Include="Extensions\FontExtensions.Shared.cs" />
|
||||
<Compile Include="Renderers\ButtonLayoutManager.cs" />
|
||||
<Compile Include="Renderers\IButtonLayoutRenderer.cs" />
|
||||
</ItemGroup>
|
||||
|
|
Загрузка…
Ссылка в новой задаче