public static void LoadFontsFromFolder(this InstalledTypefaceCollection fontCollection, string folder)
        {
            if (!Directory.Exists(folder))
            {
                return;
            }
            //-------------------------------------

            // 1. font dir
            foreach (string file in Directory.GetFiles(folder))
            {
                //eg. this is our custom font folder
                string ext = Path.GetExtension(file).ToLower();
                switch (ext)
                {
                default: break;

                case ".ttf":
                case ".otf":
                    fontCollection.AddFontStreamSource(new FontFileStreamProvider(file));
                    break;
                }
            }

            //2. browse recursively; on Linux, fonts are organised in subdirectories
            foreach (string subfolder in Directory.GetDirectories(folder))
            {
                LoadFontsFromFolder(fontCollection, subfolder);
            }
        }
Ejemplo n.º 2
0
        public static void LoadFontsFromFolder(this InstalledTypefaceCollection fontCollection, string folder, bool recursive = false)
        {
            if (!Directory.Exists(folder))
            {
#if DEBUG
                System.Diagnostics.Debug.WriteLine("LoadFontsFromFolder, not found folder:" + folder);
#endif
                return;
            }
            //-------------------------------------

            // 1. font dir
            foreach (string file in Directory.GetFiles(folder))
            {
                //eg. this is our custom font folder
                string ext = Path.GetExtension(file).ToLower();
                switch (ext)
                {
                default: break;

                case ".ttc":
                case ".otc":
                case ".ttf":
                case ".otf":
                case ".woff":
                case ".woff2":
                    fontCollection.AddFontStreamSource(new FontFileStreamProvider(file));
                    break;
                }
            }

            //2. browse recursively; on Linux, fonts are organised in subdirectories
            if (recursive)
            {
                foreach (string subfolder in Directory.GetDirectories(folder))
                {
                    LoadFontsFromFolder(fontCollection, subfolder, recursive);
                }
            }
        }