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);
            }
        }
Пример #2
0
 public static InstalledTypefaceCollection GetSharedTypefaceCollection(FirstInitFontCollectionDelegate initdel)
 {
     if (s_intalledTypefaces == null)
     {
         //first time
         s_intalledTypefaces = new InstalledTypefaceCollection();
         initdel(s_intalledTypefaces);
     }
     return(s_intalledTypefaces);
 }
        public static void LoadSystemFonts(this InstalledTypefaceCollection fontCollection)
        {
            // Windows system fonts
            LoadFontsFromFolder(fontCollection, "c:\\Windows\\Fonts");

            // These are reasonable places to look for fonts on Linux
            LoadFontsFromFolder(fontCollection, "/usr/share/fonts");
            LoadFontsFromFolder(fontCollection, "/usr/share/wine/fonts");
            LoadFontsFromFolder(fontCollection, "/usr/share/texlive/texmf-dist/fonts");
            LoadFontsFromFolder(fontCollection, "/usr/share/texmf/fonts");

            // OS X system fonts (https://support.apple.com/en-us/HT201722)
            LoadFontsFromFolder(fontCollection, "/System/Library/Fonts");
            LoadFontsFromFolder(fontCollection, "/Library/Fonts");
        }
Пример #4
0
        public static void LoadSystemFonts(this InstalledTypefaceCollection fontCollection, bool recursive = false)
        {
            if (CustomSystemFontListLoader != null)
            {
                CustomSystemFontListLoader(fontCollection);
                return;
            }
            // Windows system fonts
            LoadFontsFromFolder(fontCollection, "c:\\Windows\\Fonts");
            // These are reasonable places to look for fonts on Linux
            LoadFontsFromFolder(fontCollection, "/usr/share/fonts", true);
            LoadFontsFromFolder(fontCollection, "/usr/share/wine/fonts", true);
            LoadFontsFromFolder(fontCollection, "/usr/share/texlive/texmf-dist/fonts", true);
            LoadFontsFromFolder(fontCollection, "/usr/share/texmf/fonts", true);

            // OS X system fonts (https://support.apple.com/en-us/HT201722)

            LoadFontsFromFolder(fontCollection, "/System/Library/Fonts");
            LoadFontsFromFolder(fontCollection, "/Library/Fonts");
        }
Пример #5
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);
                }
            }
        }
Пример #6
0
 public static void SetAsSharedTypefaceCollection(InstalledTypefaceCollection installedTypefaceCollection)
 {
     s_intalledTypefaces = installedTypefaceCollection;
 }