コード例 #1
0
        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);
        }
コード例 #2
0
        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));
        }