public static object ValidateFontFamily(string fontFamilyList, SvgDocument doc, SvgFontManager fontManager) { // Split font family list on "," and then trim start and end spaces and quotes. var fontParts = (fontFamilyList ?? string.Empty).Split(new[] { ',' }).Select(fontName => fontName.Trim(new[] { '"', ' ', '\'' })); // Find a the first font that exists in the list of installed font families. // styles from IE get sent through as lowercase. foreach (var f in fontParts) { IEnumerable <SvgFontFace> fontFaces; if (doc != null && doc.FontDefns().TryGetValue(f, out fontFaces)) { return(fontFaces); } var family = fontManager.FindFont(f); if (family != null) { return(family); } } // No valid font family found from the list requested. return(System.Drawing.FontFamily.GenericSansSerif); }
public static object ValidateFontFamily(string fontFamilyList, SvgDocument doc) { // Split font family list on "," and then trim start and end spaces and quotes. var fontParts = (fontFamilyList ?? string.Empty).Split(new[] { ',' }).Select(fontName => fontName.Trim(new[] { '"', ' ', '\'' })); FontFamily family; IEnumerable <SvgFontFace> sFaces; // Find a the first font that exists in the list of installed font families. //styles from IE get sent through as lowercase. foreach (var f in fontParts) { if (doc != null && doc.FontDefns().TryGetValue(f, out sFaces)) { return(sFaces); } family = SvgFontManager.FindFont(f); if (family != null) { return(family); } #if !NETSTANDARD20 family = PrivateFonts.Families.FirstOrDefault(ff => string.Equals(ff.Name, f, StringComparison.OrdinalIgnoreCase)); if (family != null) { return(family); } #endif switch (f.ToLower()) { case "serif": return(System.Drawing.FontFamily.GenericSerif); case "sans-serif": return(System.Drawing.FontFamily.GenericSansSerif); case "monospace": return(System.Drawing.FontFamily.GenericMonospace); } } // No valid font family found from the list requested. return(System.Drawing.FontFamily.GenericSansSerif); }