فهرست منبع

Removed IFontFamily
Some code style fixes

Benedikt Schroeder 7 سال پیش
والد
کامیت
e50f2d269a

+ 32 - 9
src/Avalonia.Visuals/Media/FontFamily.cs

@@ -8,7 +8,7 @@ using Avalonia.Media.Fonts;
 
 namespace Avalonia.Media
 {
-    public class FontFamily : IFontFamily
+    public class FontFamily
     {
         /// <summary>
         /// Initializes a new instance of the <see cref="T:Avalonia.Media.FontFamily" /> class.
@@ -45,17 +45,34 @@ namespace Avalonia.Media
             Key = new FontFamilyKey(source);
         }
 
+        /// <summary>
+        /// Represents the default font family
+        /// </summary>
         public static FontFamily Default => new FontFamily("Courier New");
 
+        /// <summary>
+        /// Gets the primary family name of the font family.
+        /// </summary>
+        /// <value>
+        /// The primary name of the font family.
+        /// </value>
         public string Name => FamilyNames.PrimaryFamilyName;
-      
-        FamilyNameCollection IFontFamily.FamilyNames => FamilyNames;
 
-        FontFamilyKey IFontFamily.Key => Key;
-
-        internal FamilyNameCollection FamilyNames { get; }
+        /// <summary>
+        /// Gets the family names.
+        /// </summary>
+        /// <value>
+        /// The family familyNames.
+        /// </value>
+        public FamilyNameCollection FamilyNames { get; }
 
-        internal FontFamilyKey Key { get; }
+        /// <summary>
+        /// Gets the key for associated assets.
+        /// </summary>
+        /// <value>
+        /// The family familyNames.
+        /// </value>
+        public FontFamilyKey Key { get; }
 
         /// <summary>
         /// Implicit conversion of string to FontFamily
@@ -76,7 +93,10 @@ namespace Avalonia.Media
         /// </exception>
         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)
             {

+ 0 - 35
src/Avalonia.Visuals/Media/IFontFamily.cs

@@ -1,35 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Text;
-
-namespace Avalonia.Media
-{
-    using Avalonia.Media.Fonts;
-
-    public interface IFontFamily
-    {
-        /// <summary>
-        /// Gets the name of the font family.
-        /// </summary>
-        /// <value>
-        /// The name of the font family.
-        /// </value>
-        string Name { get; }
-
-        /// <summary>
-        /// Gets the family names.
-        /// </summary>
-        /// <value>
-        /// The family familyNames.
-        /// </value>
-        FamilyNameCollection FamilyNames { get; }
-
-        /// <summary>
-        /// Gets the key for associated assets.
-        /// </summary>
-        /// <value>
-        /// The family familyNames.
-        /// </value>
-        FontFamilyKey Key { get; }
-    }
-}

+ 2 - 2
src/Avalonia.Visuals/Media/Typeface.cs

@@ -15,7 +15,7 @@ namespace Avalonia.Media
         /// <param name="style">The font style.</param>
         /// <param name="weight">The font weight.</param>
         public Typeface(
-            IFontFamily fontFamily, 
+            FontFamily fontFamily, 
             double fontSize = 12, 
             FontStyle style = FontStyle.Normal,
             FontWeight weight = FontWeight.Normal)
@@ -55,7 +55,7 @@ namespace Avalonia.Media
         /// <summary>
         /// Gets the font family.
         /// </summary>
-        public IFontFamily FontFamily { get; }
+        public FontFamily FontFamily { get; }
 
         /// <summary>
         /// Gets the size of the font in DIPs.

+ 2 - 2
src/Skia/Avalonia.Skia/SKTypefaceCollectionCache.cs

@@ -20,7 +20,7 @@ namespace Avalonia.Skia
         /// </summary>
         /// <param name="fontFamily">The font family.</param>
         /// <returns></returns>
-        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
         /// </summary>
         /// <param name="fontFamily">The font family.</param>
         /// <returns></returns>
-        private static SKTypefaceCollection CreateCustomFontCollection(IFontFamily fontFamily)
+        private static SKTypefaceCollection CreateCustomFontCollection(FontFamily fontFamily)
         {
             var fontAssets = FontFamilyLoader.LoadFontAssets(fontFamily.Key);
 

+ 11 - 6
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);