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);
        }
        internal void CopyOther(FontTypefaceCacheItem other)
        {
            if (other == null || other == this)
            {
                return;
            }

            this._fontFamily = other._fontFamily;
            this._fontFaceList.AddRange(other._fontFaceList);

            // update parent
            foreach (FontFaceInfo item in _fontFaceList)
            {
                item.ParentItem = this;
            }
        }
        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));
        }
 public FontFaceInfo(FontTypefaceCacheItem parentItem, Typeface typeFace)
 {
     _parentItem = parentItem;
     _typeFace   = typeFace;
 }
 public bool RemoveItem(FontTypefaceCacheItem item)
 {
     return(_items.Remove(item));
 }