Ejemplo n.º 1
0
        public static void LoadSystemFonts(this InstalledFontCollection 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");
        }
Ejemplo n.º 2
0
        public static void LoadFontsFromFolder(this InstalledFontCollection fontCollection, string folder, bool recursive = false)
        {
            try
            {
                // 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":
                    case ".ttc":
                    case ".otc":
                    case ".woff":
                    case ".woff2":
                        fontCollection.AddFont(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);
                    }
                }
            }
            catch (DirectoryNotFoundException e)
            {
                return;
            }
        }
Ejemplo n.º 3
0
 public TextServices()
 {
     typefaceStore = new TypefaceStore();
     typefaceStore.FontCollection = InstalledFontCollection.GetSharedFontCollection(null);
     _glyphLayout = new GlyphLayout();
 }