Exemple #1
0
        protected override void LoadSystemFonts()
        {
            if (m_LoadSystemFonts_CalledOnce)
            {
                return;
            }
            m_LoadSystemFonts_CalledOnce = true;


            FontFamily[] families = new InstalledFontCollection().Families;
            if (families != null &&
                families.Length > 0)
            {
                return;
            }


#if PORTABLE || SILVERLIGHT
            string[] names = Enum.GetNames(typeof(System.Environment.SpecialFolder));
            foreach (string name in names)
            {
                if (string.Compare(name, "Fonts") == 0)
                {
                    base.LoadSystemFonts();
                    return;
                }
            }
#endif


            String fontsDir = null;
#if !WINDOWS_PHONE && !WINDOWS_PHONE_7 && !WINDOWS_PHONE_71
#if NET40 || ANDROID || __IOS__
            //  NET40 or higher
            fontsDir = Environment.GetFolderPath(Environment.SpecialFolder.Fonts);
#else
#if SILVERLIGHT && !WINDOWS_PHONE && !WINDOWS_PHONE_7 && !WINDOWS_PHONE_71
            try
            {
                fontsDir = Environment.GetFolderPath(Environment.SpecialFolder.System);

                // get parent of System folder to have Windows folder
                IO.DirectoryInfo dirWindowsFolder = new IO.DirectoryInfo(Environment.GetFolderPath(Environment.SpecialFolder.System));

                // Concatenate Fonts folder onto Windows folder.
                fontsDir = IO.Path.Combine(dirWindowsFolder.Parent.FullName, "Fonts");
            }
            catch
            {
                fontsDir = null;
            }
#else
            PlatformID pid = Environment.OSVersion.Platform;
            if (pid == PlatformID.Win32NT)
            {
                // get parent of System folder to have Windows folder
                IO.DirectoryInfo dirWindowsFolder = IO.Directory.GetParent(Environment.GetFolderPath(Environment.SpecialFolder.System));
                if (dirWindowsFolder != null)
                {
                    // Concatenate Fonts folder onto Windows folder.
                    fontsDir = IO.Path.Combine(dirWindowsFolder.FullName, "Fonts");
                }
            }
            else if (pid == PlatformID.Unix)
            {
                //Path.Combine(home, ".fonts");
                fontsDir = "usr/share/fonts/truetype";
            }
#if !WINDOWS_PHONE && !WINDOWS_PHONE_7 && !WINDOWS_PHONE_71
            else if (pid == PlatformID.MacOSX)
            {
                //  Path.Combine(home, "Library", "Fonts");
                fontsDir = "Library/Fonts";
            }
#endif
#endif
#endif
#endif

            if (!string.IsNullOrEmpty(fontsDir) &&
                IO.Directory.Exists(fontsDir))
            {
                InstalledFontCollection.LoadCache();
                {
                    try
                    {
                        InstalledFontCollection.AddFontFiles(fontsDir, true);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.ToString());
                    }
                }
                InstalledFontCollection.SaveCache();
            }


            //  Load additional font files (if no any system fonts loaded) and set default params
            //???   if ((new InstalledFontCollection()).Families.Length == 0)
            {
#if SILVERLIGHT || WINDOWS_PHONE || WINDOWS_PHONE_7 || WINDOWS_PHONE_71 || ANDROID || __IOS__
                Alt.Sketch.Config.Font_NoAntiAliasMaxSize = 5;
#endif

                InstalledFontCollection.AddFontFiles("AltData/Fonts");
                InstalledFontCollection.AddFontFiles("AltData/Fonts/Open-Sans");
            }
        }