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 FontTypefaceCacheItem AddItem(FontTypefaceCacheItem item, FontAttributes attribute) { if (item == null || string.IsNullOrEmpty(item.FontFamily)) { return(item); } string fontFamily = item.FontFamily; FontTypefaceCacheItem existent = this[fontFamily]; if (existent == null) { try { Typeface typeface = Typeface.CreateFromAsset(Forms.Context.Assets, fontFamily + ".ttf"); item.SetAttributeTypeface(attribute, typeface); _items.Add(item); } catch { // Font not found System.Diagnostics.Debug.WriteLine("Font not found(Add Item): " + fontFamily); } } return(existent == null ? item : existent); }