Beispiel #1
0
 private void ApplyNativeFontStyle(FontStyle fontStyle)
 {
     if (fontStyle.ToString() == "Italic")
     {
         if (this.NativeFontWeight != null)
         {
             switch (this.NativeFontWeight.ToString())
             {
                 case "Black":
                     {
                         ((Android.Widget.TextView)this.NativeUIElement).SetTypeface(Android.Graphics.Typeface.Default, Android.Graphics.TypefaceStyle.BoldItalic);
                         break;
                     }
                 case "Bold":
                     {
                         ((Android.Widget.TextView)this.NativeUIElement).SetTypeface(Android.Graphics.Typeface.Default, Android.Graphics.TypefaceStyle.BoldItalic);
                         break;
                     }
                 case "ExtraBlack":
                     {
                         ((Android.Widget.TextView)this.NativeUIElement).SetTypeface(Android.Graphics.Typeface.Default, Android.Graphics.TypefaceStyle.BoldItalic);
                         break;
                     }
                 case "ExtraBold":
                     {
                         ((Android.Widget.TextView)this.NativeUIElement).SetTypeface(Android.Graphics.Typeface.Default, Android.Graphics.TypefaceStyle.BoldItalic);
                         break;
                     }
                 case "ExtraLight":
                     {
                         var tf = Android.Graphics.Typeface.Create("sans-serif" + "-light", Android.Graphics.TypefaceStyle.Normal);
                         ((Android.Widget.TextView)this.NativeUIElement).SetTypeface(tf, Android.Graphics.TypefaceStyle.Italic);
                         break;
                     }
                 case "Light":
                     {
                         var tf = Android.Graphics.Typeface.Create("sans-serif" + "-light", Android.Graphics.TypefaceStyle.Normal);
                         ((Android.Widget.TextView)this.NativeUIElement).SetTypeface(tf, Android.Graphics.TypefaceStyle.Italic);
                         break;
                     }
                 case "SemiBold":
                     {
                         ((Android.Widget.TextView)this.NativeUIElement).SetTypeface(Android.Graphics.Typeface.Default, Android.Graphics.TypefaceStyle.BoldItalic);
                         break;
                     }
                 case "Thin":
                     {
                         var tf = Android.Graphics.Typeface.Create("sans-serif" + "-thin", Android.Graphics.TypefaceStyle.Normal);
                         ((Android.Widget.TextView)this.NativeUIElement).SetTypeface(tf, Android.Graphics.TypefaceStyle.Italic);
                         break;
                     }
                 default:
                     {
                         ((Android.Widget.TextView)this.NativeUIElement).SetTypeface(Android.Graphics.Typeface.Default, Android.Graphics.TypefaceStyle.Italic);
                         break;
                     }
             }
         }
         else
         {
             ((Android.Widget.TextView)this.NativeUIElement).SetTypeface(Android.Graphics.Typeface.Default, Android.Graphics.TypefaceStyle.Italic);
         }
     }
     else
     {
         if (this.NativeFontWeight != null)
         {
             switch (this.NativeFontWeight.ToString())
             {
                 case "Black":
                     {
                         ((Android.Widget.TextView)this.NativeUIElement).SetTypeface(Android.Graphics.Typeface.Default, Android.Graphics.TypefaceStyle.Bold);
                         break;
                     }
                 case "Bold":
                     {
                         ((Android.Widget.TextView)this.NativeUIElement).SetTypeface(Android.Graphics.Typeface.Default, Android.Graphics.TypefaceStyle.Bold);
                         break;
                     }
                 case "ExtraBlack":
                     {
                         ((Android.Widget.TextView)this.NativeUIElement).SetTypeface(Android.Graphics.Typeface.Default, Android.Graphics.TypefaceStyle.Bold);
                         break;
                     }
                 case "ExtraBold":
                     {
                         ((Android.Widget.TextView)this.NativeUIElement).SetTypeface(Android.Graphics.Typeface.Default, Android.Graphics.TypefaceStyle.Bold);
                         break;
                     }
                 case "ExtraLight":
                     {
                         var tf = Android.Graphics.Typeface.Create("sans-serif" + "-light", Android.Graphics.TypefaceStyle.Normal);
                         ((Android.Widget.TextView)this.NativeUIElement).SetTypeface(tf, Android.Graphics.TypefaceStyle.Normal);
                         break;
                     }
                 case "Light":
                     {
                         var tf = Android.Graphics.Typeface.Create("sans-serif" + "-light", Android.Graphics.TypefaceStyle.Normal);
                         ((Android.Widget.TextView)this.NativeUIElement).SetTypeface(tf, Android.Graphics.TypefaceStyle.Normal);
                         break;
                     }
                 case "SemiBold":
                     {
                         ((Android.Widget.TextView)this.NativeUIElement).SetTypeface(Android.Graphics.Typeface.Default, Android.Graphics.TypefaceStyle.Bold);
                         break;
                     }
                 case "Thin":
                     {
                         var tf = Android.Graphics.Typeface.Create("sans-serif" + "-thin", Android.Graphics.TypefaceStyle.Normal);
                         ((Android.Widget.TextView)this.NativeUIElement).SetTypeface(tf, Android.Graphics.TypefaceStyle.Normal);
                         break;
                     }
                 default:
                     {
                         ((Android.Widget.TextView)this.NativeUIElement).SetTypeface(Android.Graphics.Typeface.Default, Android.Graphics.TypefaceStyle.Normal);
                         break;
                     }
             }
         }
         else
         {
             ((Android.Widget.TextView)this.NativeUIElement).SetTypeface(Android.Graphics.Typeface.Default, Android.Graphics.TypefaceStyle.Normal);
         }
     }
 }
        /// <summary>
        /// Get all font weights from a font style and return as array.
        /// </summary>
        /// <param name="font">The font to use</param>
        /// <param name="fontStyle">The font style</param>
        /// <returns>The array of font weights</returns>
        private FontWeight[] GetFontWeights(FontFamily font, FontStyle fontStyle)
        {
            List<FontWeight> list = new List<FontWeight>();
            var typeFaces = font.FamilyTypefaces.OrderBy(f => f.Style.ToString());

            foreach (FamilyTypeface face in typeFaces)
            {
                if (!list.Contains(face.Weight) && String.Equals(face.Style.ToString(), fontStyle.ToString()))
                {
                    list.Add(face.Weight);
                }
            }

            return (FontWeight[])list.ToArray();
        }