コード例 #1
0
        public SystemFontFinder(TrueTypeFontParser trueTypeFontParser)
        {
            this.trueTypeFontParser = trueTypeFontParser;

            ISystemFontLister lister;

#if NETSTANDARD2_0
            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                lister = new WindowsSystemFontLister();
            }
            else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
            {
                lister = new MacSystemFontLister();
            }
            else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
            {
                lister = new LinuxSystemFontLister();
            }
            else
            {
                throw new NotSupportedException($"Unsupported operating system: {RuntimeInformation.OSDescription}.");
            }
#else
            lister = new WindowsSystemFontLister();
#endif

            availableFonts = new Lazy <IReadOnlyList <SystemFontRecord> >(() => lister.GetAllFonts().ToList());
        }
コード例 #2
0
        static SystemFontFinder()
        {
            var dict = new Dictionary <string, string[]>
            {
                { "Courier", new[] { "CourierNew", "CourierNewPSMT", "LiberationMono", "NimbusMonL-Regu" } },
                { "Courier-Bold", new[] { "CourierNewPS-BoldMT", "CourierNew-Bold", "LiberationMono-Bold", "NimbusMonL-Bold" } },
                { "Courier-Oblique", new[] { "CourierNewPS-ItalicMT", "CourierNew-Italic", "LiberationMono-Italic", "NimbusMonL-ReguObli" } },
                { "Courier-BoldOblique", new[] { "CourierNewPS-BoldItalicMT", "CourierNew-BoldItalic", "LiberationMono-BoldItalic", "NimbusMonL-BoldObli" } },
                { "Helvetica", new[] { "ArialMT", "Arial", "LiberationSans", "NimbusSanL-Regu" } },
                { "Helvetica-Bold", new[] { "Arial-BoldMT", "Arial-Bold", "LiberationSans-Bold", "NimbusSanL-Bold" } },
                { "Helvetica-BoldOblique", new[] { "Arial-BoldItalicMT", "Helvetica-BoldItalic", "LiberationSans-BoldItalic", "NimbusSanL-BoldItal" } },
                { "Helvetica-Oblique", new[] { "Arial-ItalicMT", "Arial-Italic", "Helvetica-Italic", "LiberationSans-Italic", "NimbusSanL-ReguItal" } },
                { "Times-Roman", new[] { "TimesNewRomanPSMT", "TimesNewRoman", "TimesNewRomanPS", "LiberationSerif", "NimbusRomNo9L-Regu" } },
                { "Times-Bold", new[] { "TimesNewRomanPS-BoldMT", "TimesNewRomanPS-Bold", "TimesNewRoman-Bold", "LiberationSerif-Bold", "NimbusRomNo9L-Medi" } },
                { "Times-Italic", new[] { "TimesNewRomanPS-ItalicMT", "TimesNewRomanPS-Italic", "TimesNewRoman-Italic", "LiberationSerif-Italic", "NimbusRomNo9L-ReguItal" } },
                { "TimesNewRomanPS-BoldItalicMT", new[] { "TimesNewRomanPS-BoldItalic", "TimesNewRoman-BoldItalic", "LiberationSerif-BoldItalic", "NimbusRomNo9L-MediItal" } },
                { "Symbol", new[] { "SymbolMT", "StandardSymL" } },
                { "ZapfDingbats", new[] { "ZapfDingbatsITC", "Dingbats", "MS-Gothic" } }
            };

            HashSet <string> names;

            try
            {
                names = Standard14.GetNames();
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException("Failed to load the Standard 14 fonts from the assembly's resources.", ex);
            }

            foreach (var name in names)
            {
                if (!dict.ContainsKey(name))
                {
                    var value = Standard14.GetMappedFontName(name);

                    if (dict.TryGetValue(value, out var subs))
                    {
                        dict[name] = subs;
                    }
                    else
                    {
                        dict[name] = new[] { value };
                    }
                }
            }

            NameSubstitutes = dict;

            ISystemFontLister lister;

#if NETSTANDARD2_0
            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                lister = new WindowsSystemFontLister();
            }
            else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
            {
                lister = new MacSystemFontLister();
            }
            else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
            {
                lister = new LinuxSystemFontLister();
            }
            else
            {
                throw new NotSupportedException($"Unsupported operating system: {RuntimeInformation.OSDescription}.");
            }
#else
            lister = new WindowsSystemFontLister();
#endif

            AvailableFonts = new Lazy <IReadOnlyList <SystemFontRecord> >(() => lister.GetAllFonts().ToList());
        }