Exemple #1
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 #2
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);
             }
         }
     }
 }