Exemple #1
0
 private static void EnsureSystemFontCache()
 {
     if (FontResolver.gdiFontFamilyToFontFileMap != null)
     {
         return;
     }
     FontResolver.gdiFontFamilyToFontFileMap = new Dictionary <string, List <string> >();
     FontResolver.wpfFontFamilyToFontFileMap = new Dictionary <string, List <string> >();
     foreach (string str in Directory.GetFiles(FontEmbedder.SystemFontsDirectory))
     {
         foreach (Typeface typeface in (IEnumerable <Typeface>)FontEmbedder.GetTypefacesSafe(str))
         {
             bool   useGdiFontNames1         = true;
             string serializeFontFamilyName1 = FontEmbedder.GetSerializeFontFamilyName(typeface, useGdiFontNames1);
             bool   useGdiFontNames2         = false;
             string serializeFontFamilyName2 = FontEmbedder.GetSerializeFontFamilyName(typeface, useGdiFontNames2);
             FontResolver.StoreSystemFont(FontResolver.gdiFontFamilyToFontFileMap, serializeFontFamilyName1, str);
             FontResolver.StoreSystemFont(FontResolver.wpfFontFamilyToFontFileMap, serializeFontFamilyName2, str);
             if (serializeFontFamilyName1 != serializeFontFamilyName2)
             {
                 FontResolver.gdiToWpfSystemFontNameMap[serializeFontFamilyName1] = serializeFontFamilyName2;
                 FontResolver.wpfToGdiSystemFontNameMap[serializeFontFamilyName2] = serializeFontFamilyName1;
             }
         }
     }
 }
Exemple #2
0
 private static void AddFontFileToCache(string fontFile, Dictionary <string, List <KeyValuePair <Typeface, string> > > cache, bool useGdiFontNames, Dictionary <string, string> gdiFontNameMap, Dictionary <string, string> wpfFontNameMap)
 {
     foreach (string str in FontEmbedder.GetFontNamesInFile(fontFile, useGdiFontNames))
     {
         string     index      = FontFamilyHelper.EnsureFamilyName(str);
         FontFamily fontFamily = new FontFamily(fontFile + "#" + index);
         List <KeyValuePair <Typeface, string> > list;
         if (!cache.TryGetValue(str, out list))
         {
             list         = new List <KeyValuePair <Typeface, string> >();
             cache[index] = list;
         }
         foreach (Typeface key in (IEnumerable <Typeface>)FontEmbedder.GetTypefacesSafe(fontFile))
         {
             list.Add(new KeyValuePair <Typeface, string>(key, fontFamily.Source));
         }
     }
     if (gdiFontNameMap == null)
     {
         return;
     }
     foreach (Typeface typeface in (IEnumerable <Typeface>)FontEmbedder.GetTypefacesSafe(fontFile))
     {
         bool   useGdiFontNames1         = true;
         string serializeFontFamilyName1 = FontEmbedder.GetSerializeFontFamilyName(typeface, useGdiFontNames1);
         bool   useGdiFontNames2         = false;
         string serializeFontFamilyName2 = FontEmbedder.GetSerializeFontFamilyName(typeface, useGdiFontNames2);
         if (serializeFontFamilyName1 != serializeFontFamilyName2 && !string.IsNullOrEmpty(serializeFontFamilyName1) && !string.IsNullOrEmpty(serializeFontFamilyName2))
         {
             gdiFontNameMap[serializeFontFamilyName1] = serializeFontFamilyName2;
             wpfFontNameMap[serializeFontFamilyName2] = serializeFontFamilyName1;
         }
     }
 }
Exemple #3
0
 private static void RemoveFontFileFromCache(string fontFile, Dictionary <string, List <KeyValuePair <Typeface, string> > > cache, bool useGdiFontNames)
 {
     foreach (string familyName in FontEmbedder.GetFontNamesInFile(fontFile, useGdiFontNames))
     {
         string key = FontFamilyHelper.EnsureFamilyName(familyName);
         List <KeyValuePair <Typeface, string> > list;
         if (cache.TryGetValue(key, out list))
         {
             using (IEnumerator <Typeface> enumerator = FontEmbedder.GetTypefacesSafe(fontFile).GetEnumerator())
             {
                 while (enumerator.MoveNext())
                 {
                     Typeface typeface = enumerator.Current;
                     list.RemoveAll((Predicate <KeyValuePair <Typeface, string> >)(putativeTypeface => typeface == putativeTypeface.Key));
                 }
             }
             if (list.Count == 0)
             {
                 cache.Remove(key);
             }
         }
     }
 }
Exemple #4
0
        public static void CreateSystemFontFamiliesCache()
        {
            PerformanceUtility.StartPerformanceSequence(PerformanceEvent.FontCacheInitialization);
            Dictionary <string, SystemFontFamily> fontFileMap1 = new Dictionary <string, SystemFontFamily>();
            Dictionary <string, SystemFontFamily> fontFileMap2 = new Dictionary <string, SystemFontFamily>();

            foreach (string str in Directory.GetFiles(FontEmbedder.SystemFontsDirectory))
            {
                foreach (Typeface typeface in (IEnumerable <Typeface>)FontEmbedder.GetTypefacesSafe(str))
                {
                    bool useGdiFontNames1 = false;
                    FontEmbedder.StoreSystemFont(str, typeface, fontFileMap1, useGdiFontNames1);
                    bool useGdiFontNames2 = true;
                    FontEmbedder.StoreSystemFont(str, typeface, fontFileMap2, useGdiFontNames2);
                }
            }
            FontEmbedder.wpfFonts = (IEnumerable <SystemFontFamily>)Enumerable.ToList <SystemFontFamily>((IEnumerable <SystemFontFamily>)fontFileMap1.Values);
            SystemFontFamily systemFontFamily = new SystemFontFamily(new FontFamily("Portable User Interface"));

            fontFileMap2["Portable User Interface"] = systemFontFamily;
            FontEmbedder.gdiFonts = (IEnumerable <SystemFontFamily>)Enumerable.ToList <SystemFontFamily>((IEnumerable <SystemFontFamily>)fontFileMap2.Values);
            PerformanceUtility.EndPerformanceSequence(PerformanceEvent.FontCacheInitialization);
        }