public FontTypefaceCacheItem AddItem(string fontFamily, FontAttributes attribute) { if (string.IsNullOrEmpty(fontFamily)) { return(null); } else if (!fontFamily.Contains("-")) { fontFamily += "-Regular"; } FontTypefaceCacheItem newItem = this.AddItem(new FontTypefaceCacheItem(fontFamily), attribute); if (newItem != null) { Typeface typeface = newItem.GetTypeface(attribute); try { if (typeface == null) { newItem.SetAttributeTypeface(attribute, Typeface.CreateFromAsset(Forms.Context.Assets, fontFamily + ".ttf")); } } catch { //Font not found System.Diagnostics.Debug.WriteLine("Font not found(Add Family): " + fontFamily); } } return(newItem); }
public Typeface GetTypeFaceForFontFamily(string fontFamily, FontAttributes attribute, bool addNewIfNotFound) { FontTypefaceCacheItem item = this[fontFamily]; if (item == null) { if (addNewIfNotFound) { item = this.AddItem(fontFamily, attribute); } } if (item == null) { return(null); } return(item.GetTypeface(attribute)); }