Ejemplo n.º 1
0
        public static bool TryCreate(string path, out SystemFontRecord type)
        {
            type = default(SystemFontRecord);

            SystemFontType fontType;

            if (path.EndsWith(".ttf"))
            {
                fontType = SystemFontType.TrueType;
            }
            else if (path.EndsWith(".otf"))
            {
                fontType = SystemFontType.OpenType;
            }
            else if (path.EndsWith(".ttc"))
            {
                fontType = SystemFontType.TrueTypeCollection;
            }
            else if (path.EndsWith(".otc"))
            {
                fontType = SystemFontType.OpenTypeCollection;
            }
            else if (path.EndsWith(".pfb"))
            {
                fontType = SystemFontType.Type1;
            }
            else
            {
                return(false);
            }

            type = new SystemFontRecord(path, fontType);

            return(true);
        }
Ejemplo n.º 2
0
        public IEnumerable <SystemFontRecord> GetAllFonts()
        {
            var directories = new List <string>
            {
                "/usr/local/fonts",        // local
                "/usr/local/share/fonts",  // local shared
                "/usr/share/fonts",        // system
                "/usr/X11R6/lib/X11/fonts" // X
            };

            try
            {
                var folder = Environment.GetEnvironmentVariable("$HOME");

                if (!string.IsNullOrWhiteSpace(folder))
                {
                    directories.Add($"{folder}/.fonts");
                }
            }
            catch
            {
                // ignored
            }

            foreach (var directory in directories)
            {
                try
                {
                    if (!Directory.Exists(directory))
                    {
                        continue;
                    }
                }
                catch
                {
                    continue;
                }

                string[] files;

                try
                {
                    files = Directory.GetFiles(directory);
                }
                catch
                {
                    continue;
                }

                foreach (var file in files)
                {
                    if (SystemFontRecord.TryCreate(file, out var record))
                    {
                        yield return(record);
                    }
                }
            }
        }
Ejemplo n.º 3
0
        private bool TryGetTrueTypeFont(string name, SystemFontRecord record, out TrueTypeFontProgram font)
        {
            font = null;
            if (record.Type == SystemFontType.TrueType)
            {
                if (readFiles.Contains(record.Path))
                {
                    return(false);
                }

                return(TryReadFile(record.Path, true, name, out font));
            }

            return(false);
        }
Ejemplo n.º 4
0
        public IEnumerable <SystemFontRecord> GetAllFonts()
        {
            // TODO: Could use System.Drawing InstalledFontCollection to do this?

            var winDir = Environment.GetFolderPath(Environment.SpecialFolder.Windows);

            var fonts = Path.Combine(winDir, "Fonts");

            if (Directory.Exists(fonts))
            {
                var files = Directory.GetFiles(fonts);

                foreach (var file in files)
                {
                    if (SystemFontRecord.TryCreate(file, out var record))
                    {
                        yield return(record);
                    }
                }
            }

            var psFonts = Path.Combine(winDir, "PSFonts");

            if (Directory.Exists(psFonts))
            {
                var files = Directory.GetFiles(fonts);

                foreach (var file in files)
                {
                    if (SystemFontRecord.TryCreate(file, out var record))
                    {
                        yield return(record);
                    }
                }
            }
        }