public IGlyphTypefaceImpl CreateGlyphTypeface(Typeface typeface) { var fontFamily = typeface.FontFamily; if (fontFamily.IsDefault) { fontFamily = _defaultTypeface.FontFamily; } if (fontFamily !.Key == null) { return(null); } var fontAssets = FontFamilyLoader.LoadFontAssets(fontFamily.Key); var asset = fontAssets.First(); var assetLoader = AvaloniaLocator.Current.GetService <IAssetLoader>(); if (assetLoader == null) { throw new NotSupportedException("IAssetLoader is not registered."); } var stream = assetLoader.Open(asset); return(new HarfBuzzGlyphTypefaceImpl(stream)); }
/// <summary> /// Creates the custom font collection. /// </summary> /// <param name="fontFamily">The font family.</param> /// <returns>SKTypefaceCollection.</returns> /// <exception cref="InvalidOperationException">Asset could not be loaded.</exception> /// <exception cref="InvalidOperationException">Asset could not be loaded.</exception> 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); if (assetStream == null) { throw new InvalidOperationException("Asset could not be loaded."); } var typeface = SKTypeface.FromStream(assetStream); if (typeface == null) { return(null); } if (typeface.FamilyName != fontFamily.Name) { continue; } var key = new Typeface(fontFamily, typeface.FontSlant.ToAvalonia(), (FontWeight)typeface.FontWeight); typeFaceCollection.AddTypeface(key, typeface); } return(typeFaceCollection); }
private static FontCollection CreateFontCollection(FontFamilyKey key) { var assets = FontFamilyLoader.LoadFontAssets(key); var fontLoader = new DWriteResourceFontLoader(Direct2D1Platform.DirectWriteFactory, assets); return(new FontCollection(Direct2D1Platform.DirectWriteFactory, fontLoader, fontLoader.Key)); }
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)); }
/// <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); }
/// <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 skTypeface = SKTypeface.FromStream(assetStream); var typeface = new Typeface(fontFamily, (FontWeight)skTypeface.FontWeight, (FontStyle)skTypeface.FontSlant); var entry = new TypefaceCollectionEntry(typeface, skTypeface); typeFaceCollection.AddEntry(skTypeface.FamilyName, new FontKey(typeface.Weight, typeface.Style), entry); } return(typeFaceCollection); }