Browse Source
Conflicts: src/Markup/Avalonia.Markup.Xaml/PortableXaml/AvaloniaDefaultTypeConverters.cspull/1560/head
37 changed files with 1375 additions and 121 deletions
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,179 @@ |
|||
// Copyright (c) The Avalonia Project. All rights reserved.
|
|||
// Licensed under the MIT license. See licence.md file in the project root for full license information.
|
|||
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using Avalonia.Media.Fonts; |
|||
|
|||
namespace Avalonia.Media |
|||
{ |
|||
public class FontFamily |
|||
{ |
|||
/// <summary>
|
|||
/// Initializes a new instance of the <see cref="T:Avalonia.Media.FontFamily" /> class.
|
|||
/// </summary>
|
|||
/// <param name="name">The name of the <see cref="FontFamily"/>.</param>
|
|||
/// <exception cref="T:System.ArgumentNullException">name</exception>
|
|||
public FontFamily(string name) |
|||
{ |
|||
Contract.Requires<ArgumentNullException>(name != null); |
|||
|
|||
FamilyNames = new FamilyNameCollection(new[] { name }); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Initializes a new instance of the <see cref="T:Avalonia.Media.FontFamily" /> class.
|
|||
/// </summary>
|
|||
/// <param name="names">The names of the <see cref="FontFamily"/>.</param>
|
|||
/// <exception cref="T:System.ArgumentNullException">name</exception>
|
|||
public FontFamily(IEnumerable<string> names) |
|||
{ |
|||
Contract.Requires<ArgumentNullException>(names != null); |
|||
|
|||
FamilyNames = new FamilyNameCollection(names); |
|||
} |
|||
|
|||
/// <inheritdoc />
|
|||
/// <summary>
|
|||
/// Initializes a new instance of the <see cref="T:Avalonia.Media.FontFamily" /> class.
|
|||
/// </summary>
|
|||
/// <param name="name">The name of the <see cref="T:Avalonia.Media.FontFamily" />.</param>
|
|||
/// <param name="source">The source of font resources.</param>
|
|||
public FontFamily(string name, Uri source) : this(name) |
|||
{ |
|||
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; |
|||
|
|||
/// <summary>
|
|||
/// Gets the family names.
|
|||
/// </summary>
|
|||
/// <value>
|
|||
/// The family familyNames.
|
|||
/// </value>
|
|||
public FamilyNameCollection FamilyNames { 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
|
|||
/// </summary>
|
|||
/// <param name="fontFamily"></param>
|
|||
public static implicit operator FontFamily(string fontFamily) |
|||
{ |
|||
return new FontFamily(fontFamily); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Parses a <see cref="T:Avalonia.Media.FontFamily"/> string.
|
|||
/// </summary>
|
|||
/// <param name="s">The <see cref="T:Avalonia.Media.FontFamily"/> string.</param>
|
|||
/// <returns></returns>
|
|||
/// <exception cref="ArgumentException">
|
|||
/// Specified family is not supported.
|
|||
/// </exception>
|
|||
public static FontFamily Parse(string s) |
|||
{ |
|||
if (string.IsNullOrEmpty(s)) |
|||
{ |
|||
throw new ArgumentException("Specified family is not supported."); |
|||
} |
|||
|
|||
var segments = s.Split('#'); |
|||
|
|||
switch (segments.Length) |
|||
{ |
|||
case 1: |
|||
{ |
|||
var names = segments[0].Split(',') |
|||
.Select(x => x.Trim()) |
|||
.Where(x => !string.IsNullOrWhiteSpace(x)); |
|||
return new FontFamily(names); |
|||
} |
|||
|
|||
case 2: |
|||
{ |
|||
return new FontFamily(segments[1], new Uri(segments[0], UriKind.RelativeOrAbsolute)); |
|||
} |
|||
|
|||
default: |
|||
{ |
|||
throw new ArgumentException("Specified family is not supported."); |
|||
} |
|||
} |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Returns a <see cref="string" /> that represents this instance.
|
|||
/// </summary>
|
|||
/// <returns>
|
|||
/// A <see cref="string" /> that represents this instance.
|
|||
/// </returns>
|
|||
public override string ToString() |
|||
{ |
|||
if (Key != null) |
|||
{ |
|||
return Key + "#" + FamilyNames; |
|||
} |
|||
|
|||
return FamilyNames.ToString(); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Returns a hash code for this instance.
|
|||
/// </summary>
|
|||
/// <returns>
|
|||
/// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.
|
|||
/// </returns>
|
|||
public override int GetHashCode() |
|||
{ |
|||
unchecked |
|||
{ |
|||
var hash = (int)2186146271; |
|||
|
|||
hash = (hash * 15768619) ^ FamilyNames.GetHashCode(); |
|||
|
|||
if (Key != null) |
|||
{ |
|||
hash = (hash * 15768619) ^ Key.GetHashCode(); |
|||
} |
|||
|
|||
return hash; |
|||
} |
|||
} |
|||
|
|||
public override bool Equals(object obj) |
|||
{ |
|||
if (!(obj is FontFamily other)) |
|||
{ |
|||
return false; |
|||
} |
|||
|
|||
if (Key != null) |
|||
{ |
|||
return other.FamilyNames.Equals(FamilyNames) && other.Key.Equals(Key); |
|||
} |
|||
|
|||
return other.FamilyNames.Equals(FamilyNames); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,131 @@ |
|||
// Copyright (c) The Avalonia Project. All rights reserved.
|
|||
// Licensed under the MIT license. See licence.md file in the project root for full license information.
|
|||
|
|||
using System; |
|||
using System.Collections; |
|||
using System.Collections.Generic; |
|||
using System.Collections.ObjectModel; |
|||
using System.Linq; |
|||
|
|||
namespace Avalonia.Media.Fonts |
|||
{ |
|||
using System.Text; |
|||
|
|||
public class FamilyNameCollection : IEnumerable<string> |
|||
{ |
|||
/// <summary>
|
|||
/// Initializes a new instance of the <see cref="FamilyNameCollection"/> class.
|
|||
/// </summary>
|
|||
/// <param name="familyNames">The family names.</param>
|
|||
/// <exception cref="ArgumentException">familyNames</exception>
|
|||
public FamilyNameCollection(IEnumerable<string> familyNames) |
|||
{ |
|||
Contract.Requires<ArgumentNullException>(familyNames != null); |
|||
|
|||
var names = new List<string>(familyNames); |
|||
|
|||
if (names.Count == 0) throw new ArgumentException($"{nameof(familyNames)} must not be empty."); |
|||
|
|||
Names = new ReadOnlyCollection<string>(names); |
|||
|
|||
PrimaryFamilyName = Names.First(); |
|||
|
|||
HasFallbacks = Names.Count > 1; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Gets the primary family name.
|
|||
/// </summary>
|
|||
/// <value>
|
|||
/// The primary family name.
|
|||
/// </value>
|
|||
public string PrimaryFamilyName { get; } |
|||
|
|||
/// <summary>
|
|||
/// Gets a value indicating whether fallbacks are defined.
|
|||
/// </summary>
|
|||
/// <value>
|
|||
/// <c>true</c> if fallbacks are defined; otherwise, <c>false</c>.
|
|||
/// </value>
|
|||
public bool HasFallbacks { get; } |
|||
|
|||
/// <summary>
|
|||
/// Gets the internal collection of names.
|
|||
/// </summary>
|
|||
/// <value>
|
|||
/// The names.
|
|||
/// </value>
|
|||
internal ReadOnlyCollection<string> Names { get; } |
|||
|
|||
/// <inheritdoc />
|
|||
/// <summary>
|
|||
/// Returns an enumerator that iterates through the collection.
|
|||
/// </summary>
|
|||
/// <returns>
|
|||
/// An enumerator that can be used to iterate through the collection.
|
|||
/// </returns>
|
|||
public IEnumerator<string> GetEnumerator() |
|||
{ |
|||
return Names.GetEnumerator(); |
|||
} |
|||
|
|||
/// <inheritdoc />
|
|||
/// <summary>
|
|||
/// Returns an enumerator that iterates through a collection.
|
|||
/// </summary>
|
|||
/// <returns>
|
|||
/// An <see cref="T:System.Collections.IEnumerator"></see> object that can be used to iterate through the collection.
|
|||
/// </returns>
|
|||
IEnumerator IEnumerable.GetEnumerator() |
|||
{ |
|||
return GetEnumerator(); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Returns a <see cref="string" /> that represents this instance.
|
|||
/// </summary>
|
|||
/// <returns>
|
|||
/// A <see cref="string" /> that represents this instance.
|
|||
/// </returns>
|
|||
public override string ToString() |
|||
{ |
|||
var builder = new StringBuilder(); |
|||
|
|||
for (var index = 0; index < Names.Count; index++) |
|||
{ |
|||
builder.Append(Names[index]); |
|||
|
|||
if (index == Names.Count - 1) break; |
|||
|
|||
builder.Append(", "); |
|||
} |
|||
|
|||
return builder.ToString(); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Returns a hash code for this instance.
|
|||
/// </summary>
|
|||
/// <returns>
|
|||
/// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.
|
|||
/// </returns>
|
|||
public override int GetHashCode() |
|||
{ |
|||
return ToString().GetHashCode(); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Determines whether the specified <see cref="object" />, is equal to this instance.
|
|||
/// </summary>
|
|||
/// <param name="obj">The <see cref="object" /> to compare with this instance.</param>
|
|||
/// <returns>
|
|||
/// <c>true</c> if the specified <see cref="object" /> is equal to this instance; otherwise, <c>false</c>.
|
|||
/// </returns>
|
|||
public override bool Equals(object obj) |
|||
{ |
|||
if (!(obj is FamilyNameCollection other)) return false; |
|||
|
|||
return other.ToString().Equals(ToString()); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,106 @@ |
|||
// Copyright (c) The Avalonia Project. All rights reserved.
|
|||
// Licensed under the MIT license. See licence.md file in the project root for full license information.
|
|||
|
|||
using System; |
|||
using System.Linq; |
|||
|
|||
namespace Avalonia.Media.Fonts |
|||
{ |
|||
/// <summary>
|
|||
/// Represents an identifier for a <see cref="IFontFamily"/>
|
|||
/// </summary>
|
|||
public class FontFamilyKey |
|||
{ |
|||
/// <summary>
|
|||
/// Creates a new instance of <see cref="FontFamilyKey"/> and extracts <see cref="Location"/> and <see cref="FileName"/> from given <see cref="Uri"/>
|
|||
/// </summary>
|
|||
/// <param name="source"></param>
|
|||
public FontFamilyKey(Uri source) |
|||
{ |
|||
if (source == null) throw new ArgumentNullException(nameof(source)); |
|||
|
|||
if (source.AbsolutePath.Contains(".ttf")) |
|||
{ |
|||
var filePathWithoutExtension = source.AbsolutePath.Replace(".ttf", string.Empty); |
|||
var fileNameWithoutExtension = filePathWithoutExtension.Split('.').Last(); |
|||
FileName = fileNameWithoutExtension + ".ttf"; |
|||
Location = new Uri(source.OriginalString.Replace("." + FileName, string.Empty), UriKind.RelativeOrAbsolute); |
|||
} |
|||
else |
|||
{ |
|||
Location = source; |
|||
} |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Location of stored font asset that belongs to a <see cref="IFontFamily"/>
|
|||
/// </summary>
|
|||
public Uri Location { get; } |
|||
|
|||
/// <summary>
|
|||
/// Optional filename for a font asset that belongs to a <see cref="IFontFamily"/>
|
|||
/// </summary>
|
|||
public string FileName { get; } |
|||
|
|||
/// <summary>
|
|||
/// Returns a hash code for this instance.
|
|||
/// </summary>
|
|||
/// <returns>
|
|||
/// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.
|
|||
/// </returns>
|
|||
public override int GetHashCode() |
|||
{ |
|||
unchecked |
|||
{ |
|||
var hash = (int)2166136261; |
|||
|
|||
if (Location != null) |
|||
{ |
|||
hash = (hash * 16777619) ^ Location.GetHashCode(); |
|||
} |
|||
|
|||
if (FileName != null) |
|||
{ |
|||
hash = (hash * 16777619) ^ FileName.GetHashCode(); |
|||
} |
|||
|
|||
return hash; |
|||
} |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Determines whether the specified <see cref="object" />, is equal to this instance.
|
|||
/// </summary>
|
|||
/// <param name="obj">The <see cref="object" /> to compare with this instance.</param>
|
|||
/// <returns>
|
|||
/// <c>true</c> if the specified <see cref="object" /> is equal to this instance; otherwise, <c>false</c>.
|
|||
/// </returns>
|
|||
public override bool Equals(object obj) |
|||
{ |
|||
if (!(obj is FontFamilyKey other)) return false; |
|||
|
|||
if (Location != other.Location) return false; |
|||
|
|||
if (FileName != other.FileName) return false; |
|||
|
|||
return true; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Returns a <see cref="string" /> that represents this instance.
|
|||
/// </summary>
|
|||
/// <returns>
|
|||
/// A <see cref="string" /> that represents this instance.
|
|||
/// </returns>
|
|||
public override string ToString() |
|||
{ |
|||
if (FileName == null) return Location.PathAndQuery; |
|||
|
|||
var builder = new UriBuilder(Location); |
|||
|
|||
builder.Path += "." + FileName; |
|||
|
|||
return builder.ToString(); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,72 @@ |
|||
// Copyright (c) The Avalonia Project. All rights reserved.
|
|||
// Licensed under the MIT license. See licence.md file in the project root for full license information.
|
|||
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Reflection; |
|||
using Avalonia.Platform; |
|||
|
|||
namespace Avalonia.Media.Fonts |
|||
{ |
|||
public static class FontFamilyLoader |
|||
{ |
|||
private static readonly IAssetLoader s_assetLoader; |
|||
|
|||
static FontFamilyLoader() |
|||
{ |
|||
s_assetLoader = AvaloniaLocator.Current.GetService<IAssetLoader>(); |
|||
} |
|||
|
|||
public static IEnumerable<Uri> LoadFontAssets(FontFamilyKey fontFamilyKey) |
|||
{ |
|||
return fontFamilyKey.FileName != null |
|||
? GetFontAssetsByFileName(fontFamilyKey.Location, fontFamilyKey.FileName) |
|||
: GetFontAssetsByLocation(fontFamilyKey.Location); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Searches for font assets at a given location and returns a quanity of found assets
|
|||
/// </summary>
|
|||
/// <param name="location"></param>
|
|||
/// <returns></returns>
|
|||
private static IEnumerable<Uri> GetFontAssetsByLocation(Uri location) |
|||
{ |
|||
var availableAssets = s_assetLoader.GetAssets(location); |
|||
|
|||
var matchingAssets = availableAssets.Where(x => x.absolutePath.EndsWith(".ttf")); |
|||
|
|||
return matchingAssets.Select(x => GetAssetUri(x.absolutePath, x.assembly)); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Searches for font assets at a given location and only accepts assets that fit to a given filename expression.
|
|||
/// <para>File names can target multiple files with * wildcard. For example "FontFile*.ttf"</para>
|
|||
/// </summary>
|
|||
/// <param name="location"></param>
|
|||
/// <param name="fileName"></param>
|
|||
/// <returns></returns>
|
|||
private static IEnumerable<Uri> GetFontAssetsByFileName(Uri location, string fileName) |
|||
{ |
|||
var availableResources = s_assetLoader.GetAssets(location); |
|||
|
|||
var compareTo = location.AbsolutePath + "." + fileName.Split('*').First(); |
|||
|
|||
var matchingResources = |
|||
availableResources.Where(x => x.absolutePath.Contains(compareTo) && x.absolutePath.EndsWith(".ttf")); |
|||
|
|||
return matchingResources.Select(x => GetAssetUri(x.absolutePath, x.assembly)); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Returns a <see cref="Uri"/> for a font asset that follows the resm scheme
|
|||
/// </summary>
|
|||
/// <param name="absolutePath"></param>
|
|||
/// <param name="assembly"></param>
|
|||
/// <returns></returns>
|
|||
private static Uri GetAssetUri(string absolutePath, Assembly assembly) |
|||
{ |
|||
return new Uri("resm:" + absolutePath + "?assembly=" + assembly.GetName().Name, UriKind.RelativeOrAbsolute); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,20 @@ |
|||
using System; |
|||
using System.ComponentModel; |
|||
using System.Globalization; |
|||
using Avalonia.Media; |
|||
|
|||
namespace Avalonia.Markup.Xaml.Converters |
|||
{ |
|||
public class FontFamilyTypeConverter : TypeConverter |
|||
{ |
|||
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType) |
|||
{ |
|||
return sourceType == typeof(string); |
|||
} |
|||
|
|||
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) |
|||
{ |
|||
return FontFamily.Parse((string)value); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,74 @@ |
|||
using System.Collections.Concurrent; |
|||
using Avalonia.Media; |
|||
using SkiaSharp; |
|||
|
|||
namespace Avalonia.Skia |
|||
{ |
|||
internal class SKTypefaceCollection |
|||
{ |
|||
private readonly ConcurrentDictionary<FontKey, SKTypeface> _cachedTypefaces = |
|||
new ConcurrentDictionary<FontKey, SKTypeface>(); |
|||
|
|||
public void AddTypeFace(SKTypeface typeface) |
|||
{ |
|||
var key = new FontKey(typeface.FamilyName, (SKFontStyleWeight)typeface.FontWeight, typeface.FontSlant); |
|||
|
|||
_cachedTypefaces.TryAdd(key, typeface); |
|||
} |
|||
|
|||
public SKTypeface GetTypeFace(Typeface typeface) |
|||
{ |
|||
SKFontStyleSlant skStyle = SKFontStyleSlant.Upright; |
|||
|
|||
switch (typeface.Style) |
|||
{ |
|||
case FontStyle.Italic: |
|||
skStyle = SKFontStyleSlant.Italic; |
|||
break; |
|||
|
|||
case FontStyle.Oblique: |
|||
skStyle = SKFontStyleSlant.Oblique; |
|||
break; |
|||
} |
|||
|
|||
var key = new FontKey(typeface.FontFamily.Name, (SKFontStyleWeight)typeface.Weight, skStyle); |
|||
|
|||
return _cachedTypefaces.TryGetValue(key, out var skTypeface) ? skTypeface : TypefaceCache.Default; |
|||
} |
|||
|
|||
private struct FontKey |
|||
{ |
|||
public readonly string Name; |
|||
public readonly SKFontStyleSlant Slant; |
|||
public readonly SKFontStyleWeight Weight; |
|||
|
|||
public FontKey(string name, SKFontStyleWeight weight, SKFontStyleSlant slant) |
|||
{ |
|||
Name = name; |
|||
Slant = slant; |
|||
Weight = weight; |
|||
} |
|||
|
|||
public override int GetHashCode() |
|||
{ |
|||
int hash = 17; |
|||
hash = hash * 31 + Name.GetHashCode(); |
|||
hash = hash * 31 + (int)Slant; |
|||
hash = hash * 31 + (int)Weight; |
|||
|
|||
return hash; |
|||
} |
|||
|
|||
public override bool Equals(object other) |
|||
{ |
|||
return other is FontKey ? Equals((FontKey)other) : false; |
|||
} |
|||
|
|||
private bool Equals(FontKey other) |
|||
{ |
|||
return Name == other.Name && Slant == other.Slant && |
|||
Weight == other.Weight; |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,53 @@ |
|||
using System.Collections.Concurrent; |
|||
using Avalonia.Media; |
|||
using Avalonia.Media.Fonts; |
|||
using Avalonia.Platform; |
|||
using SkiaSharp; |
|||
|
|||
namespace Avalonia.Skia |
|||
{ |
|||
internal static class SKTypefaceCollectionCache |
|||
{ |
|||
private static readonly ConcurrentDictionary<FontFamilyKey, SKTypefaceCollection> s_cachedCollections; |
|||
|
|||
static SKTypefaceCollectionCache() |
|||
{ |
|||
s_cachedCollections = new ConcurrentDictionary<FontFamilyKey, SKTypefaceCollection>(); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Gets the or add typeface collection.
|
|||
/// </summary>
|
|||
/// <param name="fontFamily">The font family.</param>
|
|||
/// <returns></returns>
|
|||
public static SKTypefaceCollection GetOrAddTypefaceCollection(FontFamily fontFamily) |
|||
{ |
|||
return s_cachedCollections.GetOrAdd(fontFamily.Key, x => CreateCustomFontCollection(fontFamily)); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Creates the custom font collection.
|
|||
/// </summary>
|
|||
/// <param name="fontFamily">The font family.</param>
|
|||
/// <returns></returns>
|
|||
private static SKTypefaceCollection CreateCustomFontCollection(FontFamily fontFamily) |
|||
{ |
|||
var fontAssets = FontFamilyLoader.LoadFontAssets(fontFamily.Key); |
|||
|
|||
var typeFaceCollection = new SKTypefaceCollection(); |
|||
|
|||
var assetLoader = AvaloniaLocator.Current.GetService<IAssetLoader>(); |
|||
|
|||
foreach (var asset in fontAssets) |
|||
{ |
|||
var assetStream = assetLoader.Open(asset); |
|||
|
|||
var typeface = SKTypeface.FromStream(assetStream); |
|||
|
|||
typeFaceCollection.AddTypeFace(typeface); |
|||
} |
|||
|
|||
return typeFaceCollection; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,67 @@ |
|||
using SharpDX; |
|||
using SharpDX.DirectWrite; |
|||
|
|||
namespace Avalonia.Direct2D1.Media |
|||
{ |
|||
/// <summary>
|
|||
/// Resource FontFileEnumerator.
|
|||
/// </summary>
|
|||
public class DWriteResourceFontFileEnumerator : CallbackBase, FontFileEnumerator |
|||
{ |
|||
private readonly Factory _factory; |
|||
private readonly FontFileLoader _loader; |
|||
private readonly DataStream _keyStream; |
|||
private FontFile _currentFontFile; |
|||
|
|||
/// <summary>
|
|||
/// Initializes a new instance of the <see cref="DWriteResourceFontFileEnumerator"/> class.
|
|||
/// </summary>
|
|||
/// <param name="factory">The factory.</param>
|
|||
/// <param name="loader">The loader.</param>
|
|||
/// <param name="key">The key.</param>
|
|||
public DWriteResourceFontFileEnumerator(Factory factory, FontFileLoader loader, DataPointer key) |
|||
{ |
|||
_factory = factory; |
|||
_loader = loader; |
|||
_keyStream = new DataStream(key.Pointer, key.Size, true, false); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Advances to the next font file in the collection. When it is first created, the enumerator is positioned before the first element of the collection and the first call to MoveNext advances to the first file.
|
|||
/// </summary>
|
|||
/// <returns>
|
|||
/// the value TRUE if the enumerator advances to a file; otherwise, FALSE if the enumerator advances past the last file in the collection.
|
|||
/// </returns>
|
|||
/// <unmanaged>HRESULT IDWriteFontFileEnumerator::MoveNext([Out] BOOL* hasCurrentFile)</unmanaged>
|
|||
bool FontFileEnumerator.MoveNext() |
|||
{ |
|||
bool moveNext = _keyStream.RemainingLength != 0; |
|||
|
|||
if (!moveNext) return false; |
|||
|
|||
_currentFontFile?.Dispose(); |
|||
|
|||
_currentFontFile = new FontFile(_factory, _keyStream.PositionPointer, 4, _loader); |
|||
|
|||
_keyStream.Position += 4; |
|||
|
|||
return true; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Gets a reference to the current font file.
|
|||
/// </summary>
|
|||
/// <value></value>
|
|||
/// <returns>a reference to the newly created <see cref="SharpDX.DirectWrite.FontFile"/> object.</returns>
|
|||
/// <unmanaged>HRESULT IDWriteFontFileEnumerator::GetCurrentFontFile([Out] IDWriteFontFile** fontFile)</unmanaged>
|
|||
FontFile FontFileEnumerator.CurrentFontFile |
|||
{ |
|||
get |
|||
{ |
|||
((IUnknown)_currentFontFile).AddReference(); |
|||
|
|||
return _currentFontFile; |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,84 @@ |
|||
using System; |
|||
using SharpDX; |
|||
using SharpDX.DirectWrite; |
|||
|
|||
namespace Avalonia.Direct2D1.Media |
|||
{ |
|||
/// <summary>
|
|||
/// This FontFileStream implem is reading data from a <see cref="DataStream"/>.
|
|||
/// </summary>
|
|||
public class DWriteResourceFontFileStream : CallbackBase, FontFileStream |
|||
{ |
|||
private readonly DataStream _stream; |
|||
|
|||
/// <summary>
|
|||
/// Initializes a new instance of the <see cref="DWriteResourceFontFileStream"/> class.
|
|||
/// </summary>
|
|||
/// <param name="stream">The stream.</param>
|
|||
public DWriteResourceFontFileStream(DataStream stream) |
|||
{ |
|||
_stream = stream; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Reads a fragment from a font file.
|
|||
/// </summary>
|
|||
/// <param name="fragmentStart">When this method returns, contains an address of a reference to the start of the font file fragment. This parameter is passed uninitialized.</param>
|
|||
/// <param name="fileOffset">The offset of the fragment, in bytes, from the beginning of the font file.</param>
|
|||
/// <param name="fragmentSize">The size of the file fragment, in bytes.</param>
|
|||
/// <param name="fragmentContext">When this method returns, contains the address of</param>
|
|||
/// <remarks>
|
|||
/// Note that ReadFileFragment implementations must check whether the requested font file fragment is within the file bounds. Otherwise, an error should be returned from ReadFileFragment. {{DirectWrite}} may invoke <see cref="SharpDX.DirectWrite.FontFileStream"/> methods on the same object from multiple threads simultaneously. Therefore, ReadFileFragment implementations that rely on internal mutable state must serialize access to such state across multiple threads. For example, an implementation that uses separate Seek and Read operations to read a file fragment must place the code block containing Seek and Read calls under a lock or a critical section.
|
|||
/// </remarks>
|
|||
/// <unmanaged>HRESULT IDWriteFontFileStream::ReadFileFragment([Out, Buffer] const void** fragmentStart,[None] __int64 fileOffset,[None] __int64 fragmentSize,[Out] void** fragmentContext)</unmanaged>
|
|||
void FontFileStream.ReadFileFragment(out IntPtr fragmentStart, long fileOffset, long fragmentSize, out IntPtr fragmentContext) |
|||
{ |
|||
lock (this) |
|||
{ |
|||
fragmentContext = IntPtr.Zero; |
|||
|
|||
_stream.Position = fileOffset; |
|||
|
|||
fragmentStart = _stream.PositionPointer; |
|||
} |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Releases a fragment from a file.
|
|||
/// </summary>
|
|||
/// <param name="fragmentContext">A reference to the client-defined context of a font fragment returned from {{ReadFileFragment}}.</param>
|
|||
/// <unmanaged>void IDWriteFontFileStream::ReleaseFileFragment([None] void* fragmentContext)</unmanaged>
|
|||
void FontFileStream.ReleaseFileFragment(IntPtr fragmentContext) |
|||
{ |
|||
// Nothing to release. No context are used
|
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Obtains the total size of a file.
|
|||
/// </summary>
|
|||
/// <returns>the total size of the file.</returns>
|
|||
/// <remarks>
|
|||
/// Implementing GetFileSize() for asynchronously loaded font files may require downloading the complete file contents. Therefore, this method should be used only for operations that either require a complete font file to be loaded (for example, copying a font file) or that need to make decisions based on the value of the file size (for example, validation against a persisted file size).
|
|||
/// </remarks>
|
|||
/// <unmanaged>HRESULT IDWriteFontFileStream::GetFileSize([Out] __int64* fileSize)</unmanaged>
|
|||
long FontFileStream.GetFileSize() |
|||
{ |
|||
return _stream.Length; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Obtains the last modified time of the file.
|
|||
/// </summary>
|
|||
/// <returns>
|
|||
/// the last modified time of the file in the format that represents the number of 100-nanosecond intervals since January 1, 1601 (UTC).
|
|||
/// </returns>
|
|||
/// <remarks>
|
|||
/// The "last modified time" is used by DirectWrite font selection algorithms to determine whether one font resource is more up to date than another one.
|
|||
/// </remarks>
|
|||
/// <unmanaged>HRESULT IDWriteFontFileStream::GetLastWriteTime([Out] __int64* lastWriteTime)</unmanaged>
|
|||
long FontFileStream.GetLastWriteTime() |
|||
{ |
|||
return 0; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,99 @@ |
|||
using System.Collections.Generic; |
|||
using Avalonia.Media.Fonts; |
|||
using Avalonia.Platform; |
|||
using SharpDX; |
|||
using SharpDX.DirectWrite; |
|||
|
|||
namespace Avalonia.Direct2D1.Media |
|||
{ |
|||
using System; |
|||
|
|||
internal class DWriteResourceFontLoader : CallbackBase, FontCollectionLoader, FontFileLoader |
|||
{ |
|||
private readonly List<DWriteResourceFontFileStream> _fontStreams = new List<DWriteResourceFontFileStream>(); |
|||
private readonly List<DWriteResourceFontFileEnumerator> _enumerators = new List<DWriteResourceFontFileEnumerator>(); |
|||
private readonly DataStream _keyStream; |
|||
|
|||
/// <summary>
|
|||
/// Initializes a new instance of the <see cref="DWriteResourceFontLoader"/> class.
|
|||
/// </summary>
|
|||
/// <param name="factory">The factory.</param>
|
|||
/// <param name="fontAssets"></param>
|
|||
public DWriteResourceFontLoader(Factory factory, IEnumerable<Uri> fontAssets) |
|||
{ |
|||
var factory1 = factory; |
|||
|
|||
var assetLoader = AvaloniaLocator.Current.GetService<IAssetLoader>(); |
|||
|
|||
foreach (var asset in fontAssets) |
|||
{ |
|||
var assetStream = assetLoader.Open(asset); |
|||
|
|||
var dataStream = new DataStream((int)assetStream.Length, true, true); |
|||
|
|||
assetStream.CopyTo(dataStream); |
|||
|
|||
dataStream.Position = 0; |
|||
|
|||
_fontStreams.Add(new DWriteResourceFontFileStream(dataStream)); |
|||
} |
|||
|
|||
// Build a Key storage that stores the index of the font
|
|||
_keyStream = new DataStream(sizeof(int) * _fontStreams.Count, true, true); |
|||
|
|||
for (int i = 0; i < _fontStreams.Count; i++) |
|||
{ |
|||
_keyStream.Write(i); |
|||
} |
|||
|
|||
_keyStream.Position = 0; |
|||
|
|||
// Register the
|
|||
factory1.RegisterFontFileLoader(this); |
|||
factory1.RegisterFontCollectionLoader(this); |
|||
} |
|||
|
|||
|
|||
/// <summary>
|
|||
/// Gets the key used to identify the FontCollection as well as storing index for fonts.
|
|||
/// </summary>
|
|||
/// <value>The key.</value>
|
|||
public DataStream Key => _keyStream; |
|||
|
|||
/// <summary>
|
|||
/// Creates a font file enumerator object that encapsulates a collection of font files. The font system calls back to this interface to create a font collection.
|
|||
/// </summary>
|
|||
/// <param name="factory">Pointer to the <see cref="SharpDX.DirectWrite.Factory"/> object that was used to create the current font collection.</param>
|
|||
/// <param name="collectionKey">A font collection key that uniquely identifies the collection of font files within the scope of the font collection loader being used. The buffer allocated for this key must be at least the size, in bytes, specified by collectionKeySize.</param>
|
|||
/// <returns>
|
|||
/// a reference to the newly created font file enumerator.
|
|||
/// </returns>
|
|||
/// <unmanaged>HRESULT IDWriteFontCollectionLoader::CreateEnumeratorFromKey([None] IDWriteFactory* factory,[In, Buffer] const void* collectionKey,[None] int collectionKeySize,[Out] IDWriteFontFileEnumerator** fontFileEnumerator)</unmanaged>
|
|||
FontFileEnumerator FontCollectionLoader.CreateEnumeratorFromKey(Factory factory, DataPointer collectionKey) |
|||
{ |
|||
var enumerator = new DWriteResourceFontFileEnumerator(factory, this, collectionKey); |
|||
|
|||
_enumerators.Add(enumerator); |
|||
|
|||
return enumerator; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Creates a font file stream object that encapsulates an open file resource.
|
|||
/// </summary>
|
|||
/// <param name="fontFileReferenceKey">A reference to a font file reference key that uniquely identifies the font file resource within the scope of the font loader being used. The buffer allocated for this key must at least be the size, in bytes, specified by fontFileReferenceKeySize.</param>
|
|||
/// <returns>
|
|||
/// a reference to the newly created <see cref="SharpDX.DirectWrite.FontFileStream"/> object.
|
|||
/// </returns>
|
|||
/// <remarks>
|
|||
/// The resource is closed when the last reference to fontFileStream is released.
|
|||
/// </remarks>
|
|||
/// <unmanaged>HRESULT IDWriteFontFileLoader::CreateStreamFromKey([In, Buffer] const void* fontFileReferenceKey,[None] int fontFileReferenceKeySize,[Out] IDWriteFontFileStream** fontFileStream)</unmanaged>
|
|||
FontFileStream FontFileLoader.CreateStreamFromKey(DataPointer fontFileReferenceKey) |
|||
{ |
|||
var index = SharpDX.Utilities.Read<int>(fontFileReferenceKey.Pointer); |
|||
|
|||
return _fontStreams[index]; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,65 @@ |
|||
using System.Collections.Concurrent; |
|||
using Avalonia.Media; |
|||
using Avalonia.Media.Fonts; |
|||
|
|||
namespace Avalonia.Direct2D1.Media |
|||
{ |
|||
internal static class Direct2D1FontCollectionCache |
|||
{ |
|||
private static readonly ConcurrentDictionary<FontFamilyKey, SharpDX.DirectWrite.FontCollection> s_cachedCollections; |
|||
private static readonly SharpDX.DirectWrite.Factory s_factory; |
|||
private static readonly SharpDX.DirectWrite.FontCollection s_installedFontCollection; |
|||
|
|||
static Direct2D1FontCollectionCache() |
|||
{ |
|||
s_cachedCollections = new ConcurrentDictionary<FontFamilyKey, SharpDX.DirectWrite.FontCollection>(); |
|||
|
|||
s_factory = AvaloniaLocator.Current.GetService<SharpDX.DirectWrite.Factory>(); |
|||
|
|||
s_installedFontCollection = s_factory.GetSystemFontCollection(false); |
|||
} |
|||
|
|||
public static SharpDX.DirectWrite.TextFormat GetTextFormat(Typeface typeface) |
|||
{ |
|||
var fontFamily = typeface.FontFamily; |
|||
var fontCollection = GetOrAddFontCollection(fontFamily); |
|||
var fontFamilyName = FontFamily.Default.Name; |
|||
|
|||
// Should this be cached?
|
|||
foreach (var familyName in fontFamily.FamilyNames) |
|||
{ |
|||
if (!fontCollection.FindFamilyName(familyName, out _)) |
|||
{ |
|||
continue; |
|||
} |
|||
|
|||
fontFamilyName = familyName; |
|||
|
|||
break; |
|||
} |
|||
|
|||
return new SharpDX.DirectWrite.TextFormat( |
|||
s_factory, |
|||
fontFamilyName, |
|||
fontCollection, |
|||
(SharpDX.DirectWrite.FontWeight)typeface.Weight, |
|||
(SharpDX.DirectWrite.FontStyle)typeface.Style, |
|||
SharpDX.DirectWrite.FontStretch.Normal, |
|||
(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); |
|||
|
|||
var fontLoader = new DWriteResourceFontLoader(s_factory, assets); |
|||
|
|||
return new SharpDX.DirectWrite.FontCollection(s_factory, fontLoader, fontLoader.Key); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,91 @@ |
|||
// Copyright (c) The Avalonia Project. All rights reserved.
|
|||
// Licensed under the MIT license. See licence.md file in the project root for full license information.
|
|||
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using Avalonia.Media; |
|||
using Avalonia.Media.Fonts; |
|||
using Xunit; |
|||
|
|||
namespace Avalonia.Visuals.UnitTests.Media |
|||
{ |
|||
public class FontFamilyTests |
|||
{ |
|||
[Fact] |
|||
public void Exception_Should_Be_Thrown_If_Name_Is_Null() |
|||
{ |
|||
Assert.Throws<ArgumentNullException>(() => new FontFamily((string)null)); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Exception_Should_Be_Thrown_If_Names_Is_Null() |
|||
{ |
|||
Assert.Throws<ArgumentNullException>(() => new FontFamily((IEnumerable<string>)null)); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Should_Implicitly_Convert_String_To_FontFamily() |
|||
{ |
|||
FontFamily fontFamily = "Arial"; |
|||
|
|||
Assert.Equal(new FontFamily("Arial"), fontFamily); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Should_Be_Equal() |
|||
{ |
|||
var fontFamily = new FontFamily("Arial"); |
|||
|
|||
Assert.Equal(new FontFamily("Arial"), fontFamily); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Parse_Parses_FontFamily_With_Name() |
|||
{ |
|||
var fontFamily = FontFamily.Parse("Courier New"); |
|||
|
|||
Assert.Equal("Courier New", fontFamily.Name); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Parse_Parses_FontFamily_With_Names() |
|||
{ |
|||
var fontFamily = FontFamily.Parse("Courier New, Times New Roman"); |
|||
|
|||
Assert.Equal("Courier New", fontFamily.Name); |
|||
|
|||
Assert.Equal(2, fontFamily.FamilyNames.Count()); |
|||
|
|||
Assert.Equal("Times New Roman", fontFamily.FamilyNames.Last()); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Parse_Parses_FontFamily_With_Resource_Folder() |
|||
{ |
|||
var source = new Uri("resm:Avalonia.Visuals.UnitTests#MyFont"); |
|||
|
|||
var key = new FontFamilyKey(source); |
|||
|
|||
var fontFamily = FontFamily.Parse(source.OriginalString); |
|||
|
|||
Assert.Equal("MyFont", fontFamily.Name); |
|||
|
|||
Assert.Equal(key, fontFamily.Key); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Parse_Parses_FontFamily_With_Resource_Filename() |
|||
{ |
|||
var source = new Uri("resm:Avalonia.Visuals.UnitTests.MyFont.ttf#MyFont"); |
|||
|
|||
var key = new FontFamilyKey(source); |
|||
|
|||
var fontFamily = FontFamily.Parse(source.OriginalString); |
|||
|
|||
Assert.Equal("MyFont", fontFamily.Name); |
|||
|
|||
Assert.Equal(key, fontFamily.Key); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,33 @@ |
|||
// Copyright (c) The Avalonia Project. All rights reserved.
|
|||
// Licensed under the MIT license. See licence.md file in the project root for full license information.
|
|||
|
|||
using System; |
|||
using System.Linq; |
|||
using Avalonia.Media.Fonts; |
|||
using Xunit; |
|||
|
|||
namespace Avalonia.Visuals.UnitTests.Media.Fonts |
|||
{ |
|||
public class FamilyNameCollectionTests |
|||
{ |
|||
[Fact] |
|||
public void Exception_Should_Be_Thrown_If_Names_Is_Null() |
|||
{ |
|||
Assert.Throws<ArgumentNullException>(() => new FamilyNameCollection(null)); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Exception_Should_Be_Thrown_If_Names_Is_Empty() |
|||
{ |
|||
Assert.Throws<ArgumentException>(() => new FamilyNameCollection(Enumerable.Empty<string>())); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Should_Be_Equal() |
|||
{ |
|||
var familyNames = new FamilyNameCollection(new[] { "Arial", "Times New Roman" }); |
|||
|
|||
Assert.Equal(new FamilyNameCollection(new[] { "Arial", "Times New Roman" }), familyNames); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,42 @@ |
|||
// Copyright (c) The Avalonia Project. All rights reserved.
|
|||
// Licensed under the MIT license. See licence.md file in the project root for full license information.
|
|||
|
|||
using System; |
|||
using Avalonia.Media.Fonts; |
|||
using Xunit; |
|||
|
|||
namespace Avalonia.Visuals.UnitTests.Media.Fonts |
|||
{ |
|||
public class FontFamilyKeyTests |
|||
{ |
|||
[Fact] |
|||
public void Exception_Should_Be_Thrown_If_Source_Is_Null() |
|||
{ |
|||
Assert.Throws<ArgumentNullException>(() => new FontFamilyKey(null)); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Should_Initialize_With_Location() |
|||
{ |
|||
var source = new Uri("resm:Avalonia.Visuals.UnitTests#MyFont"); |
|||
|
|||
var fontFamilyKey = new FontFamilyKey(source); |
|||
|
|||
Assert.Equal(new Uri("resm:Avalonia.Visuals.UnitTests"), fontFamilyKey.Location); |
|||
|
|||
Assert.Null(fontFamilyKey.FileName); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Should_Initialize_With_Location_And_Filename() |
|||
{ |
|||
var source = new Uri("resm:Avalonia.Visuals.UnitTests.MyFont.ttf#MyFont"); |
|||
|
|||
var fontFamilyKey = new FontFamilyKey(source); |
|||
|
|||
Assert.Equal(new Uri("resm:Avalonia.Visuals.UnitTests"), fontFamilyKey.Location); |
|||
|
|||
Assert.Equal("MyFont.ttf", fontFamilyKey.FileName); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,81 @@ |
|||
// Copyright (c) The Avalonia Project. All rights reserved.
|
|||
// Licensed under the MIT license. See licence.md file in the project root for full license information.
|
|||
|
|||
using System; |
|||
using System.Linq; |
|||
using Avalonia.Media.Fonts; |
|||
using Avalonia.UnitTests; |
|||
using Xunit; |
|||
|
|||
namespace Avalonia.Visuals.UnitTests.Media.Fonts |
|||
{ |
|||
using System.Diagnostics; |
|||
|
|||
public class FontFamilyLoaderTests |
|||
{ |
|||
private const string FontName = "#MyFont"; |
|||
private const string Assembly = "?assembly=Avalonia.Visuals.UnitTests"; |
|||
private const string AssetLocation = "resm:Avalonia.Visuals.UnitTests.Assets"; |
|||
|
|||
private readonly IDisposable _testApplication; |
|||
|
|||
public FontFamilyLoaderTests() |
|||
{ |
|||
const string AssetMyFontRegular = AssetLocation + ".MyFont-Regular.ttf" + Assembly + FontName; |
|||
const string AssetMyFontBold = AssetLocation + ".MyFont-Bold.ttf" + Assembly + FontName; |
|||
const string AssetYourFont = AssetLocation + ".YourFont.ttf" + Assembly + FontName; |
|||
|
|||
var fontAssets = new[] |
|||
{ |
|||
(AssetMyFontRegular, "AssetData"), |
|||
(AssetMyFontBold, "AssetData"), |
|||
(AssetYourFont, "AssetData") |
|||
}; |
|||
|
|||
_testApplication = StartWithResources(fontAssets); |
|||
} |
|||
|
|||
~FontFamilyLoaderTests() |
|||
{ |
|||
_testApplication.Dispose(); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Should_Load_Single_FontAsset() |
|||
{ |
|||
const string FontAsset = AssetLocation + ".MyFont-Regular.ttf" + Assembly + FontName; |
|||
|
|||
var source = new Uri(FontAsset, UriKind.RelativeOrAbsolute); |
|||
|
|||
var key = new FontFamilyKey(source); |
|||
|
|||
var fontAssets = FontFamilyLoader.LoadFontAssets(key); |
|||
|
|||
Assert.Single(fontAssets); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Should_Load_Matching_Assets() |
|||
{ |
|||
var source = new Uri(AssetLocation + ".MyFont-*.ttf" + Assembly + FontName, UriKind.RelativeOrAbsolute); |
|||
|
|||
var key = new FontFamilyKey(source); |
|||
|
|||
var fontAssets = FontFamilyLoader.LoadFontAssets(key).ToArray(); |
|||
|
|||
foreach (var fontAsset in fontAssets) |
|||
{ |
|||
Debug.WriteLine(fontAsset); |
|||
} |
|||
|
|||
Assert.Equal(2, fontAssets.Length); |
|||
} |
|||
|
|||
private static IDisposable StartWithResources(params (string, string)[] assets) |
|||
{ |
|||
var assetLoader = new MockAssetLoader(assets); |
|||
var services = new TestServices(assetLoader: assetLoader, platform: new AppBuilder().RuntimePlatform); |
|||
return UnitTestApplication.Start(services); |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue