internal static void ApplyFont(this Control self, IFontElement element)
 {
     self.FontSize   = element.FontSize;
     self.FontFamily = !string.IsNullOrEmpty(element.FontFamily) ? new FontFamily(element.FontFamily) : (FontFamily)WApplication.Current.Resources["ContentControlThemeFontFamily"];
     self.FontStyle  = element.FontAttributes.HasFlag(FontAttributes.Italic) ? FontStyle.Italic : FontStyle.Normal;
     self.FontWeight = element.FontAttributes.HasFlag(FontAttributes.Bold) ? FontWeights.Bold : FontWeights.Normal;
 }
 internal void ApplyTypographyScheme(IFontElement fontElement)
 {
     Font = fontElement?.ToUIFont();
     _typographyScheme.Subtitle1 = Font;
     TextFieldTypographyThemer.ApplyTypographyScheme(_typographyScheme, this);
     TextFieldTypographyThemer.ApplyTypographyScheme(_typographyScheme, _activeTextinputController);
 }
Exemple #3
0
 internal static void ApplyFont(this Control self, IFontElement element)
 {
     self.FontSize   = element.FontSize;
     self.FontFamily = FontService.GetWinFontFamily(element.FontFamily);
     self.FontStyle  = element.FontAttributes.HasFlag(FontAttributes.Italic) ? Windows.UI.Text.FontStyle.Italic : Windows.UI.Text.FontStyle.Normal;
     self.FontWeight = element.FontAttributes.HasFlag(FontAttributes.Bold) ? FontWeights.Bold : FontWeights.Normal;
 }
		internal static void ApplyFont(this Control self, IFontElement element)
		{
			self.FontSize = element.FontSize;
			self.FontFamily = !string.IsNullOrEmpty(element.FontFamily) ? new FontFamily(element.FontFamily) : (FontFamily)WApplication.Current.Resources["ContentControlThemeFontFamily"];
			self.FontStyle = element.FontAttributes.HasFlag(FontAttributes.Italic) ? FontStyle.Italic : FontStyle.Normal;
			self.FontWeight = element.FontAttributes.HasFlag(FontAttributes.Bold) ? FontWeights.Bold : FontWeights.Normal;
		}
 internal static void ApplyFont(this Control self, IFontElement element)
 {
     self.FontSize   = element.FontSize;
     self.FontFamily = element.FontFamily.ToFontFamily();
     self.FontStyle  = element.FontAttributes.HasFlag(FontAttributes.Italic) ? FontStyle.Italic : FontStyle.Normal;
     self.FontWeight = element.FontAttributes.HasFlag(FontAttributes.Bold) ? FontWeights.Bold : FontWeights.Normal;
 }
Exemple #6
0
        internal static Typeface ToTypeface(this IFontElement self)
        {
            if (self.IsDefault())
            {
                return(s_defaultTypeface ?? _DefaultTypeface_Get());
            }

            var      key = new Tuple <string, FontAttributes>(self.FontFamily, self.FontAttributes);
            Typeface result;

            if (Typefaces.TryGetValue(key, out result))
            {
                return(result);
            }

            if (self.FontFamily == null)
            {
                var style = ToTypefaceStyle(self.FontAttributes);
                result = Typeface.Create(_DefaultTypeface_Get(), style);
            }
            else if (LoadFromAssets.IsMatch(self.FontFamily))
            {
                result = Typeface.CreateFromAsset(AApplication.Context.Assets, FontNameToFontFile(self.FontFamily));
            }
            else
            {
                var style = ToTypefaceStyle(self.FontAttributes);
                result = Typeface.Create(self.FontFamily, style);
            }
            return(Typefaces[key] = result);
        }
Exemple #7
0
        internal static void ApplyFont(this Control self, IFontElement element)
        {
            self.FontSize = element.FontSize;

            if (!string.IsNullOrEmpty(element.FontFamily))
            {
                self.FontFamily = new FontFamily(element.FontFamily);
            }
            else
            {
                self.FontFamily = (FontFamily)System.Windows.Application.Current.Resources["FontFamilySemiBold"];
            }

            if (element.FontAttributes.HasFlag(FontAttributes.Italic))
            {
                self.FontStyle = FontStyles.Italic;
            }
            else
            {
                self.FontStyle = FontStyles.Normal;
            }

            if (element.FontAttributes.HasFlag(FontAttributes.Bold))
            {
                self.FontWeight = FontWeights.Bold;
            }
            else
            {
                self.FontWeight = FontWeights.Normal;
            }
        }
Exemple #8
0
        internal static Typeface ToTypeface(this IFontElement self)
        {
            if (self.IsDefault())
            {
                return(_sDefaultTypeface ?? (_sDefaultTypeface = Typeface.Default));
            }

            var key = new Tuple <string, FontAttributes>(self.FontFamily, self.FontAttributes);

            if (Typefaces.TryGetValue(key, out var result))
            {
                return(result);
            }

            if (self.FontFamily == null)
            {
                var style = ToTypefaceStyle(self.FontAttributes);
                result = Typeface.Create(Typeface.Default, style);
            }
            else if (IsAssetFontFamily(self.FontFamily))
            {
                result = Typeface.CreateFromAsset(Android.App.Application.Context.Assets, FontNameToFontFile(self.FontFamily));
            }
            else
            {
                var style = ToTypefaceStyle(self.FontAttributes);
                result = Typeface.Create(self.FontFamily, style);
            }

            return(Typefaces[key] = result);
        }
Exemple #9
0
 public static void ApplyTypographyScheme(IMaterialTextField textField, IFontElement fontElement)
 {
     textField.TextInput.Font             = fontElement?.ToUIFont();
     textField.TypographyScheme.Subtitle1 = textField.TextInput.Font;
     TextFieldTypographyThemer.ApplyTypographyScheme(textField.TypographyScheme, textField.TextInput);
     TextFieldTypographyThemer.ApplyTypographyScheme(textField.TypographyScheme, textField.ActiveTextInputController);
 }
Exemple #10
0
        public static void ApplyTypographyScheme(IMaterialTextField textField, IFontElement fontElement)
        {
            var containerScheme = textField.ContainerScheme;

            textField.TextInput.Font = fontElement?.ToUIFont();
            containerScheme.TypographyScheme.Subtitle1 = textField.TextInput.Font;
            ApplyContainerTheme(textField);
        }
Exemple #11
0
        static NativeFont ToNativeFont(this IFontElement element)
        {
            var fontFamily     = element.FontFamily;
            var fontSize       = (float)element.FontSize;
            var fontAttributes = element.FontAttributes;

            return(ToNativeFont(fontFamily, fontSize, fontAttributes, _ToNativeFont));
        }
Exemple #12
0
        internal static Typeface ToTypeface(this IFontElement self)
        {
            if (self.IsDefault())
            {
                return(s_defaultTypeface ?? (s_defaultTypeface = Typeface.Default));
            }

            return(ToTypeface(self.FontFamily, self.FontAttributes));
        }
Exemple #13
0
        internal static Typeface ToTypeface(this IFontElement self)
        {
            if (self.IsDefault())
            {
                return(Forms.FontManager.DefaultTypeface);
            }

            return(Forms.FontManager.GetTypeface(Font.OfSize(self.FontFamily, self.FontSize).WithAttributes(self.FontAttributes)));
        }
Exemple #14
0
 static public void SetFont(
     this UnityEngine.UI.Text self,
     IFontElement element)
 {
     if (self != null)
     {
         self.fontSize  = (int)element.FontSize;
         self.fontStyle = element.FontAttributes.ToUnityFontStyle();
     }
 }
Exemple #15
0
        public static UIFont ToUIFont(this IFontElement fontElement)
        {
            var fontSize       = fontElement.FontSize;
            var fontAttributes = fontElement.FontAttributes;
            var fontFamily     = fontElement.FontFamily;

            return(fontFamily is null
                ? Font.SystemFontOfSize(fontSize, fontAttributes).ToUIFont()
                : Font.OfSize(fontFamily, fontSize).WithAttributes(fontAttributes).ToUIFont());
        }
        /*
         *      //
         *      // Static Methods
         *      //
         *      static UIFont _ToUIFont (string family, float size, FontAttributes attributes)
         *      {
         *              bool isBold = (attributes & FontAttributes.Bold) > FontAttributes.None;
         *              bool isItalic = (attributes & FontAttributes.Italic) > FontAttributes.None;
         *              if (family != null) {
         *                      try {
         *                              UIFont uIFont;
         *                              if (family.ToLower()=="monospace")
         *                                      family="Menlo";
         *                              if (family.ToLower()=="serif")
         *                                      family="Times New Roman";
         *                              if (family.ToLower()=="sans-serif")
         *                                      family="Arial";
         *
         *                              if (UIFont.FamilyNames.Contains (family)) {
         *                                      UIFontDescriptor uIFontDescriptor = new UIFontDescriptor ().CreateWithFamily (family);
         *                                      if (isBold | isItalic) {
         *                                              UIFontDescriptorSymbolicTraits uIFontDescriptorSymbolicTraits = UIFontDescriptorSymbolicTraits.ClassUnknown;
         *                                              if (isBold)
         *                                                      uIFontDescriptorSymbolicTraits |= UIFontDescriptorSymbolicTraits.Bold;
         *                                              if (isItalic)
         *                                                      uIFontDescriptorSymbolicTraits |= UIFontDescriptorSymbolicTraits.Italic;
         *                                              uIFontDescriptor = uIFontDescriptor.CreateWithTraits (uIFontDescriptorSymbolicTraits);
         *                                              uIFont = UIFont.FromDescriptor (uIFontDescriptor, size);
         *                                              if (uIFont != null)
         *                                                      return uIFont;
         *                                      }
         *                              }
         *                              //uIFont = UIFont.FromName (family, size);
         *                              uIFont = UIFont.FromName(family, size) ?? EmbeddedFont(family,size);
         *                              if (uIFont != null)
         *                                      return uIFont;
         *                      }
         *                      catch {
         *                      }
         *              }
         *              if (isBold & isItalic) {
         *                      UIFont uIFont2 = UIFont.SystemFontOfSize (size);
         *                      return UIFont.FromDescriptor (uIFont2.FontDescriptor.CreateWithTraits (UIFontDescriptorSymbolicTraits.Italic | UIFontDescriptorSymbolicTraits.Bold), 0);
         *              } else {
         *                      if (isBold)
         *                              return UIFont.BoldSystemFontOfSize (size);
         *                      return isItalic ? UIFont.ItalicSystemFontOfSize (size) : UIFont.SystemFontOfSize (size);
         *              }
         *      }
         */

        /*
         *      internal static bool IsDefault (this Span self)
         *      {
         *              return self.FontFamily == null && self.FontSize == Device.GetNamedSize (NamedSize.Default, typeof(Label), true) && self.FontAttributes == FontAttributes.None;
         *      }
         */

        /*
         *      static UIFont ToUIFont (string family, float size, FontAttributes attributes) {
         *              var key = new FontExtensions.FontKey (family, size, attributes);
         *              Dictionary<FontExtensions.FontKey, UIFont> dictionary = FontExtensions.UiFontCache;
         *              UIFont result;
         *              lock (dictionary) {
         *                      UIFont storedUiFont;
         *                      if (dictionary.TryGetValue (key, out storedUiFont)) {
         *                              result = storedUiFont;
         *                              return result;
         *                      }
         *              }
         *              UIFont newUiFont = FontExtensions._ToUIFont (family, size, attributes);
         *              dictionary = FontExtensions.UiFontCache;
         *              lock (dictionary) {
         *                      UIFont uIFont3;
         *                      if (!dictionary.TryGetValue (key, out uIFont3)) {
         *                              // only add if we're really sure it's no there!
         *                              dictionary.Add (key, uIFont3 = newUiFont);
         *                      }
         *                      result = uIFont3;
         *              }
         *              return result;
         *      }
         */

        /*
         *      internal static UIFont ToUIFont (this IFontElement element)
         *      {
         *              return FontExtensions.ToUIFont (element.FontFamily, (float)element.FontSize, element.FontAttributes);
         *      }
         */

        internal static UIFont ToUIFont(this IFontElement element)
        {
            //object[] values = label.GetValues (Label.FontFamilyProperty, Label.FontSizeProperty, Label.FontAttributesProperty);
            //var family = (string)label.GetValue (Label.FontFamilyProperty);
            //var size = (double)label.GetValue (Label.FontSizeProperty);
            //if (size < 0)
            //	size = UIFont.LabelFontSize;
            //var attr = (FontAttributes)label.GetValue (Label.FontAttributesProperty);
            //return FontExtensions.ToUIFont (family, (float)size, attr) ?? UIFont.SystemFontOfSize (UIFont.LabelFontSize);
            return(BestFont(element.FontFamily, (nfloat)element.FontSize, (element.FontAttributes & FontAttributes.Bold) != 0, (element.FontAttributes & FontAttributes.Italic) != 0));
        }
Exemple #17
0
        public static Font ToFont(this IFontElement element, double?defaultSize = null)
        {
            var size = element.FontSize;

            if (defaultSize.HasValue && (size <= 0 || double.IsNaN(size)))
            {
                size = defaultSize.Value;
            }

            return(Font.OfSize(element.FontFamily, size, enableScaling: element.FontAutoScalingEnabled).WithAttributes(element.FontAttributes));
        }
Exemple #18
0
        internal static Typeface ToTypeface(this IFontElement self)
        {
            if (self.IsDefault())
            {
                return(CompatServiceProvider.FontManager.DefaultTypeface);
            }

            var font = Font.OfSize(self.FontFamily, self.FontSize).WithAttributes(self.FontAttributes);

            return(CompatServiceProvider.FontManager.GetTypeface(font));
        }
 public MaterialTextField(IMaterialEntryRenderer element, IFontElement fontElement)
 {
     VisualElement.VerifyVisualFlagEnabled();
     ClearButtonMode            = UITextFieldViewMode.Never;
     _activeTextinputController = new MTextInputControllerFilled(this);
     TextInsetsMode             = TextInputTextInsetsMode.IfContent;
     _typographyScheme          = CreateTypographyScheme();
     _colorScheme = (SemanticColorScheme)CreateColorScheme();
     ApplyTypographyScheme(fontElement);
     ApplyTheme(element);
 }
Exemple #20
0
        static bool OnChanged(BindableObject bindable)
        {
            if (GetCancelEvents(bindable))
            {
                return(false);
            }

            IFontElement fontElement = (IFontElement)bindable;

            SetCancelEvents(bindable, true);
            bindable.SetValue(FontProperty, fontElement.ToFont());

            SetCancelEvents(bindable, false);
            return(true);
        }
        //public static void ApplyFont(this TextElement self, Font font)
        //{
        //	self.FontSize = font.UseNamedSize ? GetFontSize(font.NamedSize) : font.FontSize;

        //	if (!string.IsNullOrEmpty(font.FontFamily))
        //		self.FontFamily = new FontFamily(new Uri("pack://application:,,,/"), font.FontFamily);
        //	else
        //		self.FontFamily = (FontFamily)Avalonia.Application.Current.Resources["FontFamilyNormal"];

        //	if (font.FontAttributes.HasFlag(FontAttributes.Italic))
        //		self.FontStyle = FontStyles.Italic;
        //	else
        //		self.FontStyle = FontStyles.Normal;

        //	if (font.FontAttributes.HasFlag(FontAttributes.Bold))
        //		self.FontWeight = FontWeights.Bold;
        //	else
        //		self.FontWeight = FontWeights.Normal;
        //}

        internal static void ApplyFont(this Control self, IFontElement element)
        {
            //self.FontSize = element.FontSize;

            //if (!string.IsNullOrEmpty(element.FontFamily))
            //	self.FontFamily = new FontFamily(new Uri("pack://application:,,,/"), element.FontFamily);
            //else
            //	self.FontFamily = (FontFamily)Avalonia.Application.Current.Resources["FontFamilySemiBold"];

            //if (element.FontAttributes.HasFlag(FontAttributes.Italic))
            //	self.FontStyle = FontStyles.Italic;
            //else
            //	self.FontStyle = FontStyles.Normal;

            //if (element.FontAttributes.HasFlag(FontAttributes.Bold))
            //	self.FontWeight = FontWeights.Bold;
            //else
            //	self.FontWeight = FontWeights.Normal;
        }
Exemple #22
0
        internal static Typeface ToTypeface(this IFontElement self)
        {
            var      key = new Tuple <string, FontAttributes>(self.FontFamily, self.FontAttributes);
            Typeface result;

            if (Typefaces.TryGetValue(key, out result))
            {
                return(result);
            }

            var style = TypefaceStyle.Normal;

            if ((self.FontAttributes & (FontAttributes.Bold | FontAttributes.Italic)) == (FontAttributes.Bold | FontAttributes.Italic))
            {
                style = TypefaceStyle.BoldItalic;
            }
            else if ((self.FontAttributes & FontAttributes.Bold) != 0)
            {
                style = TypefaceStyle.Bold;
            }
            else if ((self.FontAttributes & FontAttributes.Italic) != 0)
            {
                style = TypefaceStyle.Italic;
            }

            if (self.FontFamily != null)
            {
                result = Typeface.Create(self.FontFamily, style);
            }
            else
            {
                result = Typeface.Create(Typeface.Default, style);
            }

            Typefaces[key] = result;
            return(result);
        }
Exemple #23
0
        internal static void ApplyFont(this Control self, IFontElement element)
        {
            self.FontSize = element.FontSize;

            self.FontFamily = element.FontFamily.ToFontFamily();

            if (element.FontAttributes.HasFlag(FontAttributes.Italic))
            {
                self.FontStyle = FontStyles.Italic;
            }
            else
            {
                self.FontStyle = FontStyles.Normal;
            }

            if (element.FontAttributes.HasFlag(FontAttributes.Bold))
            {
                self.FontWeight = FontWeights.Bold;
            }
            else
            {
                self.FontWeight = FontWeights.Normal;
            }
        }
Exemple #24
0
 internal static bool IsDefault(this IFontElement self)
 {
     return(string.IsNullOrWhiteSpace(Application.DefaultFontFamily) && Application.FontSize_Get == null && self.FontFamily == null && self.FontSize == Device.GetNamedSize(NamedSize.Default, typeof(Label), true) && self.FontAttributes == FontAttributes.None);
 }
 internal static bool IsDefault(this IFontElement self)
 {
     return(self.FontFamily == null && self.FontSize == Device.GetNamedSize(NamedSize.Default, typeof(Label), true) && self.FontAttributes == FontAttributes.None);
 }
Exemple #26
0
 public ReadOnlyMaterialTextField(IMaterialEntryRenderer element, IFontElement fontElement) : base(element, fontElement)
 {
     string[] actions = { "copy:", "select:", "selectAll:" };
     _enableActions = new HashSet <string>(actions);
 }
Exemple #27
0
 public static Typeface ToTypeface(this IFontElement self, IFontManager fontManager)
 => self.ToFont().ToTypeface(fontManager);
Exemple #28
0
		internal static void ApplyFont(this Control self, IFontElement element)
		{
			self.FontSize = element.FontSize;

			if (!string.IsNullOrEmpty(element.FontFamily))
				self.FontFamily = new FontFamily(element.FontFamily);
			else
				self.FontFamily = (FontFamily)System.Windows.Application.Current.Resources["PhoneFontFamilySemiBold"];

			if (element.FontAttributes.HasFlag(FontAttributes.Italic))
				self.FontStyle = FontStyles.Italic;
			else
				self.FontStyle = FontStyles.Normal;

			if (element.FontAttributes.HasFlag(FontAttributes.Bold))
				self.FontWeight = FontWeights.Bold;
			else
				self.FontWeight = FontWeights.Normal;
		}
Exemple #29
0
 internal static UIFont ToUIFont(this IFontElement self)
 => CompatServiceProvider.FontManager.GetFont(Font.OfSize(self.FontFamily, self.FontSize).WithAttributes(self.FontAttributes));
 public static UIFont ToUIFont(this IFontElement element)
 {
     return(ToUIFont(element.FontFamily, (float)element.FontSize, element.FontAttributes));
 }
Exemple #31
0
 public MaterialTextField(IMaterialEntryRenderer element, IFontElement fontElement)
 {
     ContainerScheme = new ContainerScheme();
     MaterialTextManager.Init(element, this, fontElement);
 }
Exemple #32
0
 internal void ApplyTypographyScheme(IFontElement fontElement) =>
 MaterialTextManager.ApplyTypographyScheme(this, fontElement);