From e50f2d269a9ca870c5c3334fad9e76542d1ef480 Mon Sep 17 00:00:00 2001 From: Benedikt Schroeder Date: Thu, 24 May 2018 01:29:25 +0200 Subject: [PATCH] Removed IFontFamily Some code style fixes --- src/Avalonia.Visuals/Media/FontFamily.cs | 41 +++++++++++++++---- src/Avalonia.Visuals/Media/IFontFamily.cs | 35 ---------------- src/Avalonia.Visuals/Media/Typeface.cs | 4 +- .../SKTypefaceCollectionCache.cs | 4 +- .../Media/Direct2D1FontCollectionCache.cs | 17 +++++--- 5 files changed, 47 insertions(+), 54 deletions(-) delete mode 100644 src/Avalonia.Visuals/Media/IFontFamily.cs diff --git a/src/Avalonia.Visuals/Media/FontFamily.cs b/src/Avalonia.Visuals/Media/FontFamily.cs index d7b7edd96f..a4b4f5085a 100644 --- a/src/Avalonia.Visuals/Media/FontFamily.cs +++ b/src/Avalonia.Visuals/Media/FontFamily.cs @@ -8,7 +8,7 @@ using Avalonia.Media.Fonts; namespace Avalonia.Media { - public class FontFamily : IFontFamily + public class FontFamily { /// /// Initializes a new instance of the class. @@ -45,17 +45,34 @@ namespace Avalonia.Media Key = new FontFamilyKey(source); } + /// + /// Represents the default font family + /// public static FontFamily Default => new FontFamily("Courier New"); + /// + /// Gets the primary family name of the font family. + /// + /// + /// The primary name of the font family. + /// public string Name => FamilyNames.PrimaryFamilyName; - - FamilyNameCollection IFontFamily.FamilyNames => FamilyNames; - FontFamilyKey IFontFamily.Key => Key; - - internal FamilyNameCollection FamilyNames { get; } + /// + /// Gets the family names. + /// + /// + /// The family familyNames. + /// + public FamilyNameCollection FamilyNames { get; } - internal FontFamilyKey Key { get; } + /// + /// Gets the key for associated assets. + /// + /// + /// The family familyNames. + /// + public FontFamilyKey Key { get; } /// /// Implicit conversion of string to FontFamily @@ -76,7 +93,10 @@ namespace Avalonia.Media /// public static FontFamily Parse(string s) { - if (string.IsNullOrEmpty(s)) throw new ArgumentException("Specified family is not supported."); + if (string.IsNullOrEmpty(s)) + { + throw new ArgumentException("Specified family is not supported."); + } var segments = s.Split('#'); @@ -143,7 +163,10 @@ namespace Avalonia.Media public override bool Equals(object obj) { - if (!(obj is FontFamily other)) return false; + if (!(obj is FontFamily other)) + { + return false; + } if (Key != null) { diff --git a/src/Avalonia.Visuals/Media/IFontFamily.cs b/src/Avalonia.Visuals/Media/IFontFamily.cs deleted file mode 100644 index b6a5201bf5..0000000000 --- a/src/Avalonia.Visuals/Media/IFontFamily.cs +++ /dev/null @@ -1,35 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace Avalonia.Media -{ - using Avalonia.Media.Fonts; - - public interface IFontFamily - { - /// - /// Gets the name of the font family. - /// - /// - /// The name of the font family. - /// - string Name { get; } - - /// - /// Gets the family names. - /// - /// - /// The family familyNames. - /// - FamilyNameCollection FamilyNames { get; } - - /// - /// Gets the key for associated assets. - /// - /// - /// The family familyNames. - /// - FontFamilyKey Key { get; } - } -} diff --git a/src/Avalonia.Visuals/Media/Typeface.cs b/src/Avalonia.Visuals/Media/Typeface.cs index 1c619f5f5c..40e98d1565 100644 --- a/src/Avalonia.Visuals/Media/Typeface.cs +++ b/src/Avalonia.Visuals/Media/Typeface.cs @@ -15,7 +15,7 @@ namespace Avalonia.Media /// The font style. /// The font weight. public Typeface( - IFontFamily fontFamily, + FontFamily fontFamily, double fontSize = 12, FontStyle style = FontStyle.Normal, FontWeight weight = FontWeight.Normal) @@ -55,7 +55,7 @@ namespace Avalonia.Media /// /// Gets the font family. /// - public IFontFamily FontFamily { get; } + public FontFamily FontFamily { get; } /// /// Gets the size of the font in DIPs. diff --git a/src/Skia/Avalonia.Skia/SKTypefaceCollectionCache.cs b/src/Skia/Avalonia.Skia/SKTypefaceCollectionCache.cs index f8ee62f1f2..dc533cbf3c 100644 --- a/src/Skia/Avalonia.Skia/SKTypefaceCollectionCache.cs +++ b/src/Skia/Avalonia.Skia/SKTypefaceCollectionCache.cs @@ -20,7 +20,7 @@ namespace Avalonia.Skia /// /// The font family. /// - public static SKTypefaceCollection GetOrAddTypefaceCollection(IFontFamily fontFamily) + public static SKTypefaceCollection GetOrAddTypefaceCollection(FontFamily fontFamily) { return s_cachedCollections.GetOrAdd(fontFamily.Key, x => CreateCustomFontCollection(fontFamily)); } @@ -30,7 +30,7 @@ namespace Avalonia.Skia /// /// The font family. /// - private static SKTypefaceCollection CreateCustomFontCollection(IFontFamily fontFamily) + private static SKTypefaceCollection CreateCustomFontCollection(FontFamily fontFamily) { var fontAssets = FontFamilyLoader.LoadFontAssets(fontFamily.Key); diff --git a/src/Windows/Avalonia.Direct2D1/Media/Direct2D1FontCollectionCache.cs b/src/Windows/Avalonia.Direct2D1/Media/Direct2D1FontCollectionCache.cs index 0c69d9932e..4199c73c54 100644 --- a/src/Windows/Avalonia.Direct2D1/Media/Direct2D1FontCollectionCache.cs +++ b/src/Windows/Avalonia.Direct2D1/Media/Direct2D1FontCollectionCache.cs @@ -19,11 +19,6 @@ namespace Avalonia.Direct2D1.Media s_installedFontCollection = s_factory.GetSystemFontCollection(false); } - public static SharpDX.DirectWrite.FontCollection GetOrAddFontCollection(IFontFamily fontFamily) - { - return fontFamily.Key == null ? s_installedFontCollection : s_cachedCollections.GetOrAdd(fontFamily.Key, CreateFontCollection); - } - public static SharpDX.DirectWrite.TextFormat GetTextFormat(Typeface typeface) { var fontFamily = typeface.FontFamily; @@ -33,8 +28,13 @@ namespace Avalonia.Direct2D1.Media // Should this be cached? foreach (var familyName in fontFamily.FamilyNames) { - if (!fontCollection.FindFamilyName(familyName, out _)) continue; + if (!fontCollection.FindFamilyName(familyName, out _)) + { + continue; + } + fontFamilyName = familyName; + break; } @@ -48,6 +48,11 @@ namespace Avalonia.Direct2D1.Media (float)typeface.FontSize); } + private static SharpDX.DirectWrite.FontCollection GetOrAddFontCollection(FontFamily fontFamily) + { + return fontFamily.Key == null ? s_installedFontCollection : s_cachedCollections.GetOrAdd(fontFamily.Key, CreateFontCollection); + } + private static SharpDX.DirectWrite.FontCollection CreateFontCollection(FontFamilyKey key) { var assets = FontFamilyLoader.LoadFontAssets(key);