Пример #1
0
        /// <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);
        }
        /// <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);

                if (assetStream == null)
                {
                    throw new InvalidOperationException("Asset could not be loaded.");
                }

                var typeface = SKTypeface.FromStream(assetStream);

                if (typeface == null)
                {
                    throw new InvalidOperationException("Typeface could not be loaded.");
                }

                if (!typeface.FamilyName.Contains(fontFamily.Name))
                {
                    continue;
                }

                var key = new Typeface(fontFamily, typeface.FontSlant.ToAvalonia(),
                                       (FontWeight)typeface.FontWeight, (FontStretch)typeface.FontWidth);

                typeFaceCollection.AddTypeface(key, typeface);
            }

            return(typeFaceCollection);
        }