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; } } } }
public string ResolveFont(string fontFamilySource, object fontStretch, object fontStyle, object fontWeight, IDocumentContext documentContext) { string fontFamilyPath = FontEmbedder.GetFontFamilyPath(fontFamilySource); FontFamily fontFamily = FontEmbedder.MakeDesignTimeFontReference(new FontFamily(fontFamilySource), documentContext); Dictionary <string, List <KeyValuePair <Typeface, string> > > dictionary; if (string.IsNullOrEmpty(fontFamilyPath)) { FontResolver.EnsureSystemFontCached(fontFamilySource); dictionary = this.useGdiFontNames ? FontResolver.gdiFontFamilyLookup : FontResolver.wpfFontFamilyLookup; } else { Uri uri = documentContext.MakeDesignTimeUri(new Uri(fontFamilyPath, UriKind.RelativeOrAbsolute)); if (!uri.IsAbsoluteUri) { return(fontFamilySource); } string localPath = uri.LocalPath; if (Microsoft.Expression.Framework.Documents.PathHelper.FileExists(localPath) && !localPath.EndsWith(".zip", StringComparison.OrdinalIgnoreCase)) { return(FontEmbedder.MakeSilverlightFontReference(this.GetCachedFont(localPath) + FontEmbedder.GetFontFamilySpecifier(fontFamilySource))); } if (!this.projectFontFamilyLookup.TryGetValue(Path.GetDirectoryName(uri.LocalPath), out dictionary)) { int num = fontFamilySource.IndexOf(";component", StringComparison.OrdinalIgnoreCase); if (num != -1 && fontFamilySource.StartsWith("/", StringComparison.OrdinalIgnoreCase)) { IFontResolver resolverForComponent = this.GetFontResolverForComponent(fontFamilySource.Substring(1, num - 1)); if (resolverForComponent != null && resolverForComponent != this) { return(resolverForComponent.ResolveFont(fontFamilySource, fontStretch, fontStyle, fontWeight, documentContext)); } } return(fontFamilySource); } } string fontNameFromSource = FontEmbedder.GetFontNameFromSource(fontFamily); List <KeyValuePair <Typeface, string> > list; if (dictionary.TryGetValue(fontNameFromSource, out list)) { string path = (string)null; FontResolver.FontMatch fontMatch1 = (FontResolver.FontMatch)null; foreach (KeyValuePair <Typeface, string> keyValuePair in list) { FontResolver.FontMatch fontMatch2 = new FontResolver.FontMatch(keyValuePair.Key, fontStretch, fontStyle, fontWeight); if (fontMatch1 == null || fontMatch2.CompareTo((object)fontMatch1) > 0) { path = keyValuePair.Value; fontMatch1 = fontMatch2; } } fontFamilySource = FontEmbedder.MakeSilverlightFontReference(Path.GetFullPath(path)); } return(fontFamilySource); }
private static void EnsureSystemFontCached(string fontSource) { FontResolver.EnsureSystemFontCache(); bool useGdiFontNames1 = true; FontResolver.StoreFontLookup(FontResolver.gdiFontFamilyLookup, FontResolver.gdiFontFamilyToFontFileMap, fontSource, useGdiFontNames1); bool useGdiFontNames2 = false; FontResolver.StoreFontLookup(FontResolver.wpfFontFamilyLookup, FontResolver.wpfFontFamilyToFontFileMap, fontSource, useGdiFontNames2); }
public void AddProjectFont(string fontItemPath) { string directoryName = Path.GetDirectoryName(fontItemPath); Dictionary <string, List <KeyValuePair <Typeface, string> > > cache; if (!this.projectFontFamilyLookup.TryGetValue(directoryName, out cache)) { cache = new Dictionary <string, List <KeyValuePair <Typeface, string> > >(); this.projectFontFamilyLookup[directoryName] = cache; } FontResolver.AddFontFileToCache(this.GetCachedFont(fontItemPath), cache, this.useGdiFontNames, this.gdiToWpfProjectFontNameMap, this.wpfToGdiProjectFontNameMap); }
private string ConvertFontName(string sourceName, Dictionary <string, string> systemFontNameMap, Dictionary <string, string> projectFontNameMap) { if (string.IsNullOrEmpty(sourceName)) { return(sourceName); } FontResolver.EnsureSystemFontCache(); string str; if (!systemFontNameMap.TryGetValue(sourceName, out str) && !projectFontNameMap.TryGetValue(sourceName, out str)) { str = sourceName; } return(str); }
public void RemoveProjectFont(string fontItemPath) { string directoryName = Path.GetDirectoryName(fontItemPath); Dictionary <string, List <KeyValuePair <Typeface, string> > > cache; if (!this.projectFontFamilyLookup.TryGetValue(directoryName, out cache)) { return; } FontResolver.RemoveFontFileFromCache(this.GetCachedFont(fontItemPath), cache, this.useGdiFontNames); if (cache.Count != 0) { return; } this.projectFontFamilyLookup.Remove(directoryName); }
private static void StoreFontLookup(Dictionary <string, List <KeyValuePair <Typeface, string> > > fontFamilyLookup, Dictionary <string, List <string> > fontFamilyToFontFileMap, string fontSource, bool useGdiFontNames) { if (fontFamilyLookup.ContainsKey(fontSource)) { return; } string serializeFontFamilyName = FontEmbedder.GetSerializeFontFamilyName(new FontFamily(fontSource), useGdiFontNames); List <string> list; if (!fontFamilyToFontFileMap.TryGetValue(serializeFontFamilyName, out list)) { return; } foreach (string fontFile in list) { FontResolver.AddFontFileToCache(fontFile, fontFamilyLookup, useGdiFontNames, (Dictionary <string, string>)null, (Dictionary <string, string>)null); } }