public static Typeface TrySetFontAttributes(FontAttributes fontAttribute, string fontName, Context context) { int index = fontName.IndexOf("_", StringComparison.Ordinal); if (index > 0) { fontName = fontName.Substring(0, index); } _fontName = fontName; Typeface tf = null; switch (fontAttribute) { case FontAttributes.None: tf = TrySetFont(fontName, context); break; case FontAttributes.Bold: tf = TrySetFont(fontName + "_bold", context); break; case FontAttributes.Italic: tf = TrySetFont(fontName + "_italic", context); break; } return tf; }
public Span() { _fontFamily = null; _fontAttributes = FontAttributes.None; _fontSize = Device.GetNamedSize(NamedSize.Default, typeof(Label), true); _font = Font.SystemFontOfSize(_fontSize); }
public async Task FontAttributesInitializeCorrectly(FontAttributes attributes, bool isBold, bool isItalic) { var entry = new EntryStub() { Text = "Test", Font = Font.OfSize("Arial", 10).WithAttributes(attributes) }; await ValidatePropertyInitValue(entry, () => entry.Font.FontAttributes.HasFlag(FontAttributes.Bold), GetNativeIsBold, isBold); await ValidatePropertyInitValue(entry, () => entry.Font.FontAttributes.HasFlag(FontAttributes.Italic), GetNativeIsItalic, isItalic); }
public void FontAttributes(string attributeString, FontAttributes result) { var xaml = @" <Label xmlns=""http://schemas.microsoft.com/dotnet/2021/maui"" xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"" FontAttributes=""" + result + @""" />"; var label = new Label().LoadFromXaml(xaml); Assert.AreEqual(result, label.FontAttributes); }
public static Style ToStyle(this FontAttributes attributes, Color textColor = null) { return(new Style { FontFamily = attributes.Family, FontItalic = attributes.Italic, FontSize = attributes.Size, TextColor = (textColor ?? Color.Black).ToSKColor(), FontWeight = (int)attributes.Weight, }); }
private static string GetFontName(string fontFamily, FontAttributes fontAttributes) { //var postfix = "Regular"; //var bold = fontAttributes.HasFlag(FontAttributes.Bold); //var italic = fontAttributes.HasFlag(FontAttributes.Italic); //if (bold && italic) { postfix = "BoldItalic"; } //else if (bold) { postfix = "Bold"; } //else if (italic) { postfix = "Italic"; } return("CALIBRI.ttf"); }
public static SizeF GetTextSize(string text, FontAttributes fontAttributes, TextAlignment alignment, LineBreakMode lineBreakMode, float maxWidth, float height = -1) { var tb = new TextBlock(); tb.AddText(text, fontAttributes.ToStyle()); tb.Alignment = alignment.ToTextAlignment(); tb.MaxWidth = maxWidth; tb.MaxLines = null; tb.Layout(); return(new SizeF(tb.MeasuredWidth, tb.MeasuredHeight)); }
public static TypefaceStyle ToAndroid(this FontAttributes attr) { if ((attr & FontAttributes.Italic) == FontAttributes.Italic) { return(TypefaceStyle.Italic); } if ((attr & FontAttributes.Bold) == FontAttributes.Bold) { return(TypefaceStyle.Bold); } return(TypefaceStyle.Normal); }
public override int GetHashCode() { int hash = Text?.GetHashCode() ?? -1; hash ^= BackgroundColor.GetHashCode(); hash ^= ForegroundColor.GetHashCode(); hash ^= FontAttributes.GetHashCode(); hash ^= FontSize.GetHashCode(); hash ^= Command?.GetHashCode() ?? -1; hash ^= CommandParameter?.GetHashCode() ?? -1; return(hash); }
protected override WPFLabel CreateView() { DefaultFont = new FontAttributes() { Family = "Segoe UI", Size = 12, Weight = Weight.Regular, Italic = false }; return(new WPFLabel()); }
private static string GetFontName(string fontFamily, FontAttributes fontAttributes) { if (fontAttributes.HasFlag(FontAttributes.Bold)) { return(fontAttributes.HasFlag(FontAttributes.Italic) ? $"{fontFamily}-BoldItalic" : $"{fontFamily}-Bold"); } return(fontAttributes.HasFlag(FontAttributes.Italic) ? $"{fontFamily}-Italic" : $"{fontFamily}"); }
private static Typeface GetTypeface(string fontName, FontAttributes font,Context ctx) { var fontPath = System.IO.Path.Combine("Fonts", fontName + ".ttf"); try { return Typeface.CreateFromAsset(ctx.Assets, fontPath); } catch (Exception) { Log.Error("OneDeezer", String.Format("Font {0} not found", fontName)); return Typeface.Default; } }
public override int GetHashCode() { unchecked { int hashCode = FontFamily != null?FontFamily.GetHashCode() : 0; hashCode = (hashCode * 397) ^ FontSize.GetHashCode(); hashCode = (hashCode * 397) ^ NamedSize.GetHashCode(); hashCode = (hashCode * 397) ^ FontAttributes.GetHashCode(); return(hashCode); } }
public void FontAttributes(string attributeString, FontAttributes result) { var xaml = @" <Label xmlns=""http://xamarin.com/schemas/2014/forms"" xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"" FontAttributes=""" + result + @""" />"; Device.PlatformServices = new MockPlatformServices(); var label = new Label().LoadFromXaml(xaml); Assert.AreEqual(result, label.FontAttributes); }
// Create boilerplate observation child detail label private Label ObservationDataLabel(string text, int fontSize, FontAttributes fontAttributes) { Label label = new Label() { Text = text, FontAttributes = fontAttributes, FontSize = fontSize, HorizontalOptions = LayoutOptions.StartAndExpand, VerticalOptions = LayoutOptions.Start }; return(label); }
public static Font ParseUIFont(string font) { FontAttributes fontAttrs = FontAttributes.None; // Logger.LogLine ("TEST PARSING"); if (font.Contains("font-weight: bold;")) { // Logger.LogLine ("Found Bold"); fontAttrs = FontAttributes.Bold; } return(new Font().WithAttributes(fontAttrs)); }
private static Typeface ToTypeFace(this string fontfamily, FontAttributes attr = FontAttributes.None) { fontfamily ??= String.Empty; (bool success, Typeface typeface)result = fontfamily.TryGetFromAssets(); if (result.success) { return(result.typeface); } else { TypefaceStyle style = ToTypefaceStyle(attr); return(Typeface.Create(fontfamily, style)); } }
public static void SetFont(this TextBlock textBlock, FontAttributes fontAttributes) { if (textBlock == null) { return; } textBlock.FontStyle = fontAttributes.Italic ? Windows.UI.Text.FontStyle.Italic : Windows.UI.Text.FontStyle.Normal; textBlock.FontSize = fontAttributes.Size; textBlock.FontWeight = new Windows.UI.Text.FontWeight { Weight = (ushort)fontAttributes.Weight }; textBlock.FontFamily = new Windows.UI.Xaml.Media.FontFamily(fontAttributes.Family); }
public static Font ParseUIFont(string font) { FontAttributes fontAttrs = FontAttributes.None; // Logger.LogLine ("TEST PARSING"); if (font.IndexOf("font-weight: bold;", StringComparison.Ordinal) != -1) { // Logger.LogLine ("Found Bold"); fontAttrs = FontAttributes.Bold; } return(new Font().WithAttributes(fontAttrs)); }
public LabelState(Label label) { HorizontalTextAlignment = label.HorizontalTextAlignment; VerticalTextAlignment = label.VerticalTextAlignment; FontFamily = label.FontFamily; FontSize = label.FontSize; FontAttributes = label.FontAttributes; Text = label.Text; HtmlText = label.HtmlText; AutoFit = label.AutoFit; Lines = label.Lines; FittedFontSize = label.FittedFontSize; SynchronizedFontSize = label.SynchronizedFontSize; }
public void SetAttributeTypeface(FontAttributes attribute, Typeface typeface) { FontFaceInfo item = this[attribute]; if (item == null) { item = new FontFaceInfo(this, typeface); _fontFaceList.Add(item); } if (item.TypeFace == null) { item.TypeFace = typeface; } }
void AddDetailLabel(LogoDetail detail, Color color, int fontSize = 18, FontAttributes fontAttributes = FontAttributes.Bold) { var label = new Label { Text = "", TextColor = color, HorizontalOptions = LayoutOptions.CenterAndExpand, FontFamily = "HelveticaNeue-Thin", FontSize = fontSize, FontAttributes = fontAttributes }; DetailLabels[detail] = label; stackLayoutInfo.Children.Add(label); }
FormattedString CreateFormatted(ContainerInline inlines, string family, FontAttributes attributes, TextDecorations textDecorations, Color foregroundColor, Color backgroundColor, float size, float lineHeight) { var fs = new FormattedString(); foreach (var inline in inlines) { var spans = CreateSpans(inline, family, attributes, textDecorations, foregroundColor, backgroundColor, size, lineHeight); foreach (var span in spans) { fs.Spans.Add(span); } } return(fs); }
private void SetFocusPointBoldness(int index, FocusPointItem fpi, bool resetAll) { //Sets MainFocusPoint and makes it bold for (int i = 0; i < FocusPointList.TemplatedItems.Count; i++) { FontAttributes fa = FontAttributes.None; if (i == index && !resetAll) { fa = FontAttributes.Bold; _vm.Practice.MainFocusPoint = fpi; } ((Label)FocusPointList.TemplatedItems[i].FindByName("FocusPointName")).FontAttributes = fa; } }
/// <summary> /// change the values of this font /// </summary> /// <param name="typeFace"></param> /// <param name="height"></param> /// <param name="style"></param> /// <param name="orientation"></param> public void SetValues(String typeFace, int height, FontAttributes style, int orientation, int charSet) { // Don't change the font name if the supplied name is empty string trimmedTypeFace = typeFace.Trim(); if (!String.IsNullOrEmpty(trimmedTypeFace)) { TypeFace = trimmedTypeFace; } Height = height; Style = style; Orientation = orientation; CharSet = charSet; }
internal static Typeface ToTypeFace(this string fontfamily, FontAttributes attr = FontAttributes.None) { fontfamily = fontfamily ?? String.Empty; var result = fontfamily.TryGetFromAssets(); if (result.success) { return(result.typeface); } else { var style = ToTypefaceStyle(attr); return(Typeface.Create(fontfamily, style)); } }
/// <summary> /// Constructor /// </summary> public SlideConfig(string title, string description, string icon, string backgroundColor, string titleTextColor = "#FFFFFF", string descriptionTextColor = "#FFFFFF", FontAttributes titleFontAttributes = FontAttributes.Bold, FontAttributes descriptionFontAttributes = FontAttributes.None, int titleFontSize = 24, int descriptionFontSize = 16) { Title = title; Description = description; Icon = icon; BackgroundColor = backgroundColor; TitleTextColor = titleTextColor; DescriptionTextColor = descriptionTextColor; TitleFontAttributes = titleFontAttributes; DescriptionFontAttributes = descriptionFontAttributes; TitleFontSize = titleFontSize; DescriptionFontSize = descriptionFontSize; }
public static WDrawing.FontStyle ToWindowsFontStyle(this FontAttributes self) { switch (self) { case FontAttributes.Bold: { return(WDrawing.FontStyle.Bold); } case FontAttributes.Italic: { return(WDrawing.FontStyle.Italic); } } return(WDrawing.FontStyle.Regular); }
static public UnityEngine.FontStyle ToUnityFontStyle(this FontAttributes attrs) { switch (attrs) { case FontAttributes.Bold: { return(UnityEngine.FontStyle.Bold); } case FontAttributes.Italic: { return(UnityEngine.FontStyle.Italic); } } return(UnityEngine.FontStyle.Normal); }
private void FixFontAtLocation(int location, NSMutableAttributedString text, string fontFamily, FontAttributes fontAttributes) { if (fontFamily == null) { return; } NSRange range; var font = ( UIFont )text.GetAttribute(UIStringAttributeKey.Font, location, out range); var newName = GetFontName(fontFamily, fontAttributes); font = UIFont.FromName(newName, font.PointSize); text.RemoveAttribute(UIStringAttributeKey.Font, range); text.AddAttribute(UIStringAttributeKey.Font, font, range); }
internal static Typeface ToTypeFace(this string fontfamily, FontAttributes attr = FontAttributes.None) { Typeface result; if (IsAssetFontFamily(fontfamily)) { result = Typeface.CreateFromAsset(Android.App.Application.Context.Assets, FontNameToFontFile(fontfamily)); } else { var style = ToTypefaceStyle(attr); result = Typeface.Create(fontfamily, style); } return(result); }
public static TFontAttributes ToPlatform(this FontAttributes fontAttribute) { TFontAttributes attributes = TFontAttributes.None; if (fontAttribute == FontAttributes.Italic) { attributes = attributes | TFontAttributes.Italic; } if (fontAttribute == FontAttributes.Bold) { attributes = attributes | TFontAttributes.Bold; } return(attributes); }
protected override TextView CreateView(Context context) { var textView = new TextView(context); if (DefaultColor == null) { DefaultFont = new FontAttributes { Italic = textView.Typeface.IsItalic, Size = 16, Weight = Weight.Regular }; DefaultColor = textView.CurrentTextColor.ToColor(); } return(textView); }
protected override bool CheckIfCustomFont (string fontFamily, FontAttributes attributes, out string fontFileName) { for (int i = 0; i < CustomFontFamily.Length; i++) { if (string.Equals(fontFamily, CustomFontFamily[i], StringComparison.InvariantCulture)){ var fontFamilyData = CustomFontFamilyData[i]; for (int j = 0; j < fontFamilyData.Length; j++) { var data = fontFamilyData[j]; if (data.Item1 == attributes){ fontFileName = data.Item2; return true; } } break; } } fontFileName = null; return false; }
public void SetLabelFont(double fontSize, FontAttributes attributes) { label.FontSize = fontSize; label.FontAttributes = attributes; }
static UIFont _ToUIFont(string family, float size, FontAttributes attributes) { var bold = (attributes & FontAttributes.Bold) != 0; var italic = (attributes & FontAttributes.Italic) != 0; if (family != null) { try { UIFont result; if (UIFont.FamilyNames.Contains(family) && Forms.IsiOS7OrNewer) { var descriptor = new UIFontDescriptor().CreateWithFamily(family); if (bold || italic) { var traits = (UIFontDescriptorSymbolicTraits)0; if (bold) traits = traits | UIFontDescriptorSymbolicTraits.Bold; if (italic) traits = traits | UIFontDescriptorSymbolicTraits.Italic; descriptor = descriptor.CreateWithTraits(traits); result = UIFont.FromDescriptor(descriptor, size); if (result != null) return result; } } result = UIFont.FromName(family, size); if (result != null) return result; } catch { Debug.WriteLine("Could not load font named: {0}", family); } } if (bold && italic) { var defaultFont = UIFont.SystemFontOfSize(size); if (!Forms.IsiOS7OrNewer) { // not sure how to make a font both bold and italic in iOS 6, default to bold return UIFont.BoldSystemFontOfSize(size); } var descriptor = defaultFont.FontDescriptor.CreateWithTraits(UIFontDescriptorSymbolicTraits.Bold | UIFontDescriptorSymbolicTraits.Italic); return UIFont.FromDescriptor(descriptor, 0); } if (bold) return UIFont.BoldSystemFontOfSize(size); if (italic) return UIFont.ItalicSystemFontOfSize(size); return UIFont.SystemFontOfSize(size); }
static UIFont ToUIFont(string family, float size, FontAttributes attributes) { var key = new ToUIFontKey(family, size, attributes); lock (ToUiFont) { UIFont value; if (ToUiFont.TryGetValue(key, out value)) return value; } var generatedValue = _ToUIFont(family, size, attributes); lock (ToUiFont) { UIFont value; if (!ToUiFont.TryGetValue(key, out value)) ToUiFont.Add(key, value = generatedValue); return value; } }
internal ToUIFontKey(string family, float size, FontAttributes attributes) { _family = family; _size = size; _attributes = attributes; }