using FastReport.Fonts;
using System;
using System.Drawing;
using System.Globalization;
using System.IO;
using System.Reflection;

namespace FastReport.Utils
{
    public static partial class Config
    {
        private static Export.Email.EmailSettings FEmailSettings = new Export.Email.EmailSettings();
        private static readonly TrueTypeCollection FFontCollection = new TrueTypeCollection();

        /// <summary>
        /// Gets or sets the settings for the "Send Email" window.
        /// </summary>
        public static Export.Email.EmailSettings EmailSettings
        {
            get { return FEmailSettings; }
            set { FEmailSettings = value; }
        }


        /// <summary>
        /// Get access to font collection
        /// </summary>
        public static TrueTypeCollection FontCollection
        {
            get { return FFontCollection; }
        }

#if SKIA
        private static CharacterMatcher characterMatcher = new CharacterMatcher();
        
        private class CharacterMatcher : Topten.RichTextKit.ICharacterMatcher
        {
            public CharacterMatcher()
            {
            }

            SkiaSharp.SKFontManager _fontManager = SkiaSharp.SKFontManager.Default;

            /// <inheritdoc />
            public SkiaSharp.SKTypeface MatchCharacter(string familyName, int weight, int width, SkiaSharp.SKFontStyleSlant slant, string[] bcp47, int character)
            {
                // check private fonts
                foreach (FontFamily f in PrivateFontCollection.Families)
                {
                    SkiaSharp.SKTypeface t = f.GetTypeface(FontStyle.Regular);
                    if (t.ContainsGlyph(character))
                        return t;
                }

                return _fontManager.MatchCharacter(familyName, weight, width, slant, bcp47, character);
            }
        }
#endif

        private static void ProcessMainAssembly()
        {
            new AssemblyInitializer();
#if !FRCORE
            new AssemblyInitializerDesignExt();
#endif
            new AssemblyInitializerBaseExt();
        }

    }
}