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 ?? "").Split(new[] { ',' }).Select(fontName => fontName.Trim(new[] { '"', ' ', '\'' })); var families = System.Drawing.FontFamily.Families; 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.FontDefns().TryGetValue(f, out sFaces)) return sFaces; family = families.FirstOrDefault(ff => ff.Name.ToLower() == f.ToLower()); if (family != null) return family; switch (f) { 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; }
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[] { '"', ' ', '\'' })); var families = System.Drawing.FontFamily.Families; Func <FontFamily, bool> getFamily; 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); } getFamily = new Func <FontFamily, bool>(ff => string.Equals(ff.Name, f, StringComparison.OrdinalIgnoreCase)); family = families.FirstOrDefault(getFamily); if (family != null) { return(family); } family = PrivateFonts.Families.FirstOrDefault(getFamily); if (family != null) { return(family); } 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); }