private static (bool success, Typeface typeface) TryGetFromAssets(this string fontName) { //First check Alias (bool hasFontAlias, string fontPostScriptName) = FontRegistrar.HasFont(fontName); if (hasFontAlias) { return(true, Typeface.CreateFromFile(fontPostScriptName)); } bool isAssetFont = IsAssetFontFamily(fontName); if (isAssetFont) { return(LoadTypefaceFromAsset(fontName)); } var folders = new[] { "", "Fonts/", "fonts/", }; //copied text FontFile fontFile = FontFile.FromString(fontName); if (!string.IsNullOrWhiteSpace(fontFile.Extension)) { (bool hasFont, string fontPath) = FontRegistrar.HasFont(fontFile.FileNameWithExtension()); if (hasFont) { return(true, Typeface.CreateFromFile(fontPath)); } } else { foreach (string ext in FontFile.Extensions) { string formated = fontFile.FileNameWithExtension(ext); (bool hasFont, string fontPath) = FontRegistrar.HasFont(formated); if (hasFont) { return(true, Typeface.CreateFromFile(fontPath)); } foreach (string folder in folders) { formated = $"{folder}{fontFile.FileNameWithExtension()}#{fontFile.PostScriptName}"; (bool success, Typeface typeface)result = LoadTypefaceFromAsset(formated); if (result.success) { return(result); } } } } return(false, null); }
private static string CleanseFontName(string fontName) { //First check Alias (bool hasFontAlias, string fontPostScriptName) = FontRegistrar.HasFont(fontName); if (hasFontAlias) { return(fontPostScriptName); } FontFile fontFile = FontFile.FromString(fontName); if (!string.IsNullOrWhiteSpace(fontFile.Extension)) { (bool hasFont, string filePath) = FontRegistrar.HasFont(fontFile.FileNameWithExtension()); if (hasFont) { return(filePath ?? fontFile.PostScriptName); } } else { foreach (string ext in FontFile.Extensions) { string formated = fontFile.FileNameWithExtension(ext); (bool hasFont, string filePath) = FontRegistrar.HasFont(formated); if (hasFont) { return(filePath); } } } return(fontFile.PostScriptName); }