diff --git a/samples/ControlCatalog/Pages/DropDownPage.xaml b/samples/ControlCatalog/Pages/DropDownPage.xaml index 864d2be49c..7673294e46 100644 --- a/samples/ControlCatalog/Pages/DropDownPage.xaml +++ b/samples/ControlCatalog/Pages/DropDownPage.xaml @@ -27,6 +27,15 @@ + + + + + + + + + diff --git a/samples/ControlCatalog/Pages/DropDownPage.xaml.cs b/samples/ControlCatalog/Pages/DropDownPage.xaml.cs index edab5f1ceb..397f9f21e1 100644 --- a/samples/ControlCatalog/Pages/DropDownPage.xaml.cs +++ b/samples/ControlCatalog/Pages/DropDownPage.xaml.cs @@ -13,6 +13,9 @@ namespace ControlCatalog.Pages private void InitializeComponent() { AvaloniaXamlLoader.Load(this); + var fontDropDown = this.Find("fontDropDown"); + fontDropDown.Items = Avalonia.Media.FontFamily.SystemFontFamilies; + fontDropDown.SelectedIndex = 0; } } } diff --git a/src/Avalonia.Visuals/Media/FontFamily.cs b/src/Avalonia.Visuals/Media/FontFamily.cs index 0ba25e6c0d..5c152cd8a0 100644 --- a/src/Avalonia.Visuals/Media/FontFamily.cs +++ b/src/Avalonia.Visuals/Media/FontFamily.cs @@ -5,6 +5,7 @@ using System; using System.Collections.Generic; using System.Linq; using Avalonia.Media.Fonts; +using Avalonia.Platform; namespace Avalonia.Media { @@ -51,6 +52,12 @@ namespace Avalonia.Media /// public static FontFamily Default => new FontFamily(String.Empty); + /// + /// Represents all font families in the system. This can be an expensive call depending on platform implementation. + /// + public static IEnumerable SystemFontFamilies => + AvaloniaLocator.Current.GetService().InstalledFontNames.Select(name => new FontFamily(name)); + /// /// Gets the primary family name of the font family. /// diff --git a/src/Avalonia.Visuals/Platform/IPlatformRenderInterface.cs b/src/Avalonia.Visuals/Platform/IPlatformRenderInterface.cs index aacdef0538..3a1f79e32a 100644 --- a/src/Avalonia.Visuals/Platform/IPlatformRenderInterface.cs +++ b/src/Avalonia.Visuals/Platform/IPlatformRenderInterface.cs @@ -13,6 +13,11 @@ namespace Avalonia.Platform /// public interface IPlatformRenderInterface { + /// + /// Get all installed fonts in the system + /// + IEnumerable InstalledFontNames { get; } + /// /// Creates a formatted text implementation. /// diff --git a/src/Skia/Avalonia.Skia/PlatformRenderInterface.cs b/src/Skia/Avalonia.Skia/PlatformRenderInterface.cs index 9b10d74c64..8080c27831 100644 --- a/src/Skia/Avalonia.Skia/PlatformRenderInterface.cs +++ b/src/Skia/Avalonia.Skia/PlatformRenderInterface.cs @@ -19,6 +19,8 @@ namespace Avalonia.Skia { private GRContext GrContext { get; } + public IEnumerable InstalledFontNames => SKFontManager.Default.FontFamilies; + public PlatformRenderInterface() { var gl = AvaloniaLocator.Current.GetService(); diff --git a/src/Windows/Avalonia.Direct2D1/Direct2D1Platform.cs b/src/Windows/Avalonia.Direct2D1/Direct2D1Platform.cs index 3ec18dac5e..8412a65e23 100644 --- a/src/Windows/Avalonia.Direct2D1/Direct2D1Platform.cs +++ b/src/Windows/Avalonia.Direct2D1/Direct2D1Platform.cs @@ -41,6 +41,19 @@ namespace Avalonia.Direct2D1 public static SharpDX.DXGI.Device1 DxgiDevice { get; private set; } + public IEnumerable InstalledFontNames + { + get + { + var cache = Direct2D1FontCollectionCache.s_installedFontCollection; + var length = cache.FontFamilyCount; + for (int i = 0; i < length; i++) + { + var names = cache.GetFontFamily(i).FamilyNames; + yield return names.GetString(0); + } + } + } private static readonly object s_initLock = new object(); private static bool s_initialized = false; diff --git a/src/Windows/Avalonia.Direct2D1/Media/Direct2D1FontCollectionCache.cs b/src/Windows/Avalonia.Direct2D1/Media/Direct2D1FontCollectionCache.cs index d60aa15a5e..d93a59d384 100644 --- a/src/Windows/Avalonia.Direct2D1/Media/Direct2D1FontCollectionCache.cs +++ b/src/Windows/Avalonia.Direct2D1/Media/Direct2D1FontCollectionCache.cs @@ -7,7 +7,7 @@ namespace Avalonia.Direct2D1.Media internal static class Direct2D1FontCollectionCache { private static readonly ConcurrentDictionary s_cachedCollections; - private static readonly SharpDX.DirectWrite.FontCollection s_installedFontCollection; + internal static readonly SharpDX.DirectWrite.FontCollection s_installedFontCollection; static Direct2D1FontCollectionCache() { diff --git a/tests/Avalonia.UnitTests/MockPlatformRenderInterface.cs b/tests/Avalonia.UnitTests/MockPlatformRenderInterface.cs index f8ad7e63f2..0e2abb314d 100644 --- a/tests/Avalonia.UnitTests/MockPlatformRenderInterface.cs +++ b/tests/Avalonia.UnitTests/MockPlatformRenderInterface.cs @@ -9,6 +9,8 @@ namespace Avalonia.UnitTests { public class MockPlatformRenderInterface : IPlatformRenderInterface { + public IEnumerable InstalledFontNames => new string[0]; + public IFormattedTextImpl CreateFormattedText( string text, Typeface typeface, diff --git a/tests/Avalonia.Visuals.UnitTests/VisualTree/MockRenderInterface.cs b/tests/Avalonia.Visuals.UnitTests/VisualTree/MockRenderInterface.cs index 92c12c6b9e..fec0f0831a 100644 --- a/tests/Avalonia.Visuals.UnitTests/VisualTree/MockRenderInterface.cs +++ b/tests/Avalonia.Visuals.UnitTests/VisualTree/MockRenderInterface.cs @@ -8,6 +8,8 @@ namespace Avalonia.Visuals.UnitTests.VisualTree { class MockRenderInterface : IPlatformRenderInterface { + public IEnumerable InstalledFontNames => new string[0]; + public IFormattedTextImpl CreateFormattedText( string text, Typeface typeface,