Esempio n. 1
0
        private void PreBuildFonts(System.Windows.Media.FontFamily[] fonts, string cacheFilePath)
        {
            var b = new BackgroundWorker();

            b.DoWork += (sender, args) =>
            {
                System.Diagnostics.Debug.WriteLine("Preloading fonts");
                if (!Directory.Exists(Path.GetDirectoryName(cacheFilePath)))
                {
                    Directory.CreateDirectory(Path.GetDirectoryName(cacheFilePath));
                }

                if (File.Exists(cacheFilePath))
                {
                    try
                    {
                        using (var fs = new FileStream(cacheFilePath, FileMode.Open))
                            FontObject.ReadDictionaryFromStream(fs);
                    }
                    catch
                    {
                        File.Delete(cacheFilePath);
                    }
                }

                var okFonts = new List <FontObject>();
                foreach (System.Windows.Media.FontFamily font in fonts)
                {
                    try
                    {
                        var f = new FontObject(font);
                        if (f.GetStyledFontGeometryUsingCache() != null)
                        {
                            okFonts.Add(f);
                        }
                    }
                    catch { }
                }

                if (!File.Exists(cacheFilePath) || okFonts.Count != FontObject.GeometryCount)
                {
                    using (var fs = new FileStream(cacheFilePath, FileMode.Create))
                        FontObject.SaveDictionaryToStream(fs);
                }

                args.Result = okFonts.ToArray();
            };
            b.RunWorkerCompleted += (sender, args) =>
            {
                AllFonts = (FontObject[])args.Result;
                System.Diagnostics.Debug.WriteLine("Fonts preloaded");
                SubtitleFont = AllFonts.First(f => f.Font.ToString().ToLowerInvariant().Contains("impact"));
            };
            b.RunWorkerAsync();
        }
Esempio n. 2
0
        public virtual async Task LoadAsync(Dictionary <string, object> pageState, object navigationParam)
        {
            await Data.InitAsync();

            AllFonts = Data.Fonts;

            if (ApplicationData.Current.LocalSettings.Values.ContainsKey("Character"))
            {
                selectedCharacter = (char)ApplicationData.Current.LocalSettings.Values["Character"];
            }

            if (ApplicationData.Current.LocalSettings.Values.ContainsKey("Font"))
            {
                SelectedFont = AllFonts.First(f => f.Name == (string)ApplicationData.Current.LocalSettings.Values["Font"]);
            }
            else
            {
                selectedCharacter = '!';
                SelectedFont      = AllFonts.First(f => f.Name == "Segoe MDL2 Assets");
            }
        }