/// <summary> /// Add an icon /// </summary> /// <typeparam name="T">Generic type to be used. This type must implement IExtendedHtmlString</typeparam> /// <param name="html">Current html element</param> /// <param name="icon">Icon to be rendered</param> /// <param name="size">[Optional] Icon size</param> /// <param name="htmlAttributes">[Optional] Extra html attributes</param> /// <returns>Html element with icon added</returns> /// <exception cref="FontAwesomeVersionException"> /// Thrown when a valid FontAwesome /// icon library version is not selected /// </exception> public static T AddIcon <T>(this T html, EFontAwesomeIcon icon, EFontAwesomeIconSize size = EFontAwesomeIconSize.Normal, object htmlAttributes = null) where T : IExtendedHtmlString { string prefix; if (WebExtrasSettings.FontAwesomeVersion == EFontAwesomeVersion.V3) { prefix = "icon-"; } else if (WebExtrasSettings.FontAwesomeVersion == EFontAwesomeVersion.V4) { prefix = "fa fa-"; } else { throw new FontAwesomeVersionException(); } List <string> cssClasses = new List <string> { prefix + icon.ToString().ToLowerInvariant().Replace("_", "-") }; if (size != EFontAwesomeIconSize.Normal) { cssClasses.Add(prefix + size.GetStringValue()); } html = AddIcon(html, cssClasses, htmlAttributes); return(html); }
/// <summary> /// Create a icon only link /// </summary> /// <param name="html">Current HTML helper object</param> /// <param name="icon">Icon to display</param> /// <param name="result">Link action</param> /// <param name="htmlAttributes">[Optional] Extra HTML attributes</param> /// <returns>A icon only link</returns> public static IExtendedHtmlString Hyperlink(this HtmlHelper html, EFontAwesomeIcon icon, ActionResult result, object htmlAttributes = null) { string link = WebExtrasMvcUtilT4.GetUrl(html, result); return(new BootstrapIconlink(icon, link, htmlAttributes)); }
/// <summary> /// Creates a new System.Windows.Media.Geometry of a specified FontAwesomeIcon. /// </summary> /// <param name="icon">The FontAwesome icon to be drawn.</param> /// <param name="width">The width of the SVG.</param> /// <param name="height">The height of the SVG</param> /// <returns>A new System.Windows.Media.Geometry</returns> public static Geometry CreateGeometry(this EFontAwesomeIcon icon, out int width, out int height) { if (icon.GetSvg(out var strPath, out width, out height)) { return(Geometry.Parse(strPath)); } return(null); }
/// <summary> /// Creates a new System.Windows.Media.FormattedText of a specified FontAwesomeIcon and foreground System.Windows.Media.Brush. /// </summary> /// <param name="icon">The FontAwesome icon to be drawn.</param> /// <param name="foregroundBrush">The System.Windows.Media.Brush to be used as the foreground.</param> /// <param name="emSize">The font size in em.</param> /// <returns>A new System.Windows.Media.FormattedText</returns> public static FormattedText CreateFormattedText(this EFontAwesomeIcon icon, Brush foregroundBrush, double emSize = 100) { return(new FormattedText(icon.GetUnicode(), CultureInfo.InvariantCulture, FlowDirection.LeftToRight, icon.GetTypeFace(), emSize, foregroundBrush) { TextAlignment = TextAlignment.Center, }); }
/// <summary> /// Creates a new System.Windows.Media.FormattedText of a specified FontAwesomeIcon and foreground System.Windows.Media.Brush. /// </summary> /// <param name="icon">The FontAwesome icon to be drawn.</param> /// <param name="foregroundBrush">The System.Windows.Media.Brush to be used as the foreground.</param> /// <param name="emSize">The font size in em.</param> /// <param name="flowDirection">The flow direction of the font</param> /// <param name="textFormattingMode">The text formatting mode of the font</param> /// <param name="numberSubstitution">The number substitution of the font.</param> /// <returns>A new System.Windows.Media.FormattedText</returns> public static FormattedText CreateFormattedText(this EFontAwesomeIcon icon, Brush foregroundBrush, double emSize, FlowDirection flowDirection, TextFormattingMode textFormattingMode, NumberSubstitution numberSubstitution) { return(new FormattedText(icon.GetUnicode(), CultureInfo.InvariantCulture, flowDirection, icon.GetTypeFace(), emSize, foregroundBrush, numberSubstitution, textFormattingMode)); }
/// <summary> /// Constructor /// </summary> /// <param name="icon">Icon to be displayed as the hypelink</param> /// <param name="url">Link URL</param> /// <param name="htmlAttributes">[Optional Extra HTML attributes</param> public BootstrapIconlink(EFontAwesomeIcon icon, string url, object htmlAttributes = null) : base(string.Empty, url, htmlAttributes) { CssClasses.Add("icon-only-link"); m_icon = BootstrapUtil.CreateIcon(icon); PrependTags.Add(m_icon); }
/// <summary> /// Creates a new System.Windows.Media.Drawing of a specified FontAwesomeIcon and foreground System.Windows.Media.Brush. /// This will use the Font for the Drawing creation. /// </summary> /// <param name="icon">The FontAwesome icon to be drawn.</param> /// <param name="foregroundBrush">The System.Windows.Media.Brush to be used as the foreground.</param> /// <param name="emSize">The font size in em.</param> /// <returns>A new System.Windows.Media.Drawing</returns> public static Drawing CreateDrawing(this EFontAwesomeIcon icon, Brush foregroundBrush, double emSize = 100) { var visual = new DrawingVisual(); using (var drawingContext = visual.RenderOpen()) { drawingContext.DrawText(icon.CreateFormattedText(foregroundBrush, emSize), new Point(0, 0)); } return(visual.Drawing); }
public MenuItem(string title, EFontAwesomeIcon icon, List <MenuItem> children = null) { Title = title; Icon = icon; if (children != null) { Children.AddRange(children); } }
/// <summary> /// Get the Font Awesome label of an icon /// </summary> public static string GetLabel(this EFontAwesomeIcon icon) { var info = icon.GetInformationAttribute <FontAwesomeInformationAttribute>(); if (info == null) { return(null); } return(info.Label); }
/// <summary> /// Get the Font Awesome Style of an icon /// </summary> public static EFontAwesomeStyle GetStyle(this EFontAwesomeIcon icon) { var info = icon.GetInformationAttribute <FontAwesomeInformationAttribute>(); if (info == null) { return(EFontAwesomeStyle.None); } return(info.Style); }
/// <summary> /// Get the Unicode of an icon /// </summary> public static string GetUnicode(this EFontAwesomeIcon icon) { var info = icon.GetInformationAttribute <FontAwesomeInformationAttribute>(); if (info == null) { return(char.ConvertFromUtf32(0)); } return(char.ConvertFromUtf32(info.Unicode)); }
/// <summary> /// Creates a new System.Windows.Media.Drawing of a specified FontAwesomeIcon. /// This will use the SVG for the Drawing creation. /// </summary> /// <param name="icon">The FontAwesome icon to be drawn.</param> /// <param name="brush">The Brush with which to fill the Geometry. This is optional, and can be null. If the brush is null, no fill is drawn.</param> /// <param name="pen">The Pen with which to stroke the Geometry. This is optional, and can be null. If the pen is null, no stroke is drawn.</param> /// <returns>A new System.Windows.Media.Drawing</returns> public static Drawing CreateDrawing(this EFontAwesomeIcon icon, Brush brush, Pen pen) { var visual = new DrawingVisual(); using (var drawingContext = visual.RenderOpen()) { if (icon.GetSvg(out var strPath, out var width, out var height)) { drawingContext.DrawGeometry(brush, pen, Geometry.Parse(strPath)); } } return(visual.Drawing); }
/// <summary> /// Get the Typeface of an icon /// </summary> public static Typeface GetTypeFace(this EFontAwesomeIcon icon) { switch (icon.GetStyle()) { case EFontAwesomeStyle.Regular: return(Fonts.RegularTypeface); case EFontAwesomeStyle.Solid: return(Fonts.SolidTypeface); case EFontAwesomeStyle.Brands: return(Fonts.BrandsTypeface); } return(Fonts.RegularTypeface); }
/// <summary> /// Get the FontFamily of an icon /// </summary> public static FontFamily GetFontFamily(this EFontAwesomeIcon icon) { switch (icon.GetStyle()) { case EFontAwesomeStyle.Regular: return(Fonts.RegularFontFamily); case EFontAwesomeStyle.Solid: return(Fonts.SolidFontFamily); case EFontAwesomeStyle.Brands: return(Fonts.BrandsFontFamily); } return(Fonts.RegularFontFamily); }
/// <summary> /// Creates a new System.Windows.Shapes.Path of a specified FontAwesomeIcon and foreground System.Windows.Media.Brush. /// </summary> /// <param name="icon">The FontAwesome icon to be drawn.</param> /// <param name="foregroundBrush">The System.Windows.Media.Brush to be used as the foreground.</param> /// <param name="emSize">The font size in em.</param> /// <returns>A new System.Windows.Shapes.Path</returns> public static Path CreatePath(this EFontAwesomeIcon icon, Brush foregroundBrush, double emSize = 100) { if (icon.GetSvg(out var strPath, out var width, out var height)) { return(new Path { Data = Geometry.Parse(strPath), Width = width, Height = height, Fill = foregroundBrush }); } return(null); }
/// <summary> /// Creates a new System.Windows.Media.ImageSource of a specified FontAwesomeIcon and foreground System.Windows.Media.Brush. /// </summary> /// <param name="icon">The FontAwesome icon to be drawn.</param> /// <param name="foregroundBrush">The System.Windows.Media.Brush to be used as the foreground.</param> /// <param name="emSize">The font size in em.</param> /// <returns>A new System.Windows.Media.ImageSource</returns> public static Path CreatePath(EFontAwesomeIcon icon, Brush foregroundBrush, double emSize = 100) { Path path = null; if (icon.GetSvg(out var strPath, out var width, out var height)) { path = new Path(); path.Data = Geometry.Parse(strPath); path.Width = width; path.Height = height; path.Fill = foregroundBrush; } return(path); }
/// <summary> /// Get the SVG path of an icon /// </summary> public static bool GetSvg(this EFontAwesomeIcon icon, out string path, out int width, out int height) { path = string.Empty; width = -1; height = -1; if (FontAwesomeInternal.Information.TryGetValue(icon, out var info) && info.Svg != null) { path = info.Svg.Path; width = info.Svg.Width; height = info.Svg.Height; return(true); } return(false); }
/// <summary> /// Creates a new System.Windows.Media.ImageSource of a specified FontAwesomeIcon and foreground System.Windows.Media.Brush. /// </summary> /// <param name="icon">The FontAwesome icon to be drawn.</param> /// <param name="foregroundBrush">The System.Windows.Media.Brush to be used as the foreground.</param> /// <param name="emSize">The font size in em.</param> /// <returns>A new System.Windows.Media.ImageSource</returns> public static ImageSource CreateImageSource(EFontAwesomeIcon icon, Brush foregroundBrush, double emSize = 100) { var visual = new DrawingVisual(); using (var drawingContext = visual.RenderOpen()) { drawingContext.DrawText( new FormattedText(icon.GetUnicode(), CultureInfo.InvariantCulture, FlowDirection.LeftToRight, icon.GetTypeFace(), emSize, foregroundBrush) { TextAlignment = TextAlignment.Center }, new Point(0, 0)); } return(new DrawingImage(visual.Drawing)); }
public EverythingResult(QueryResultItem item, EFontAwesomeIcon icon) : base( item.ResultType != ResultType.Directory ? item.Name : Path.GetFileName(item.FullPath), item.FullPath ) { _item = item; FontAwesomeIcon = icon; Options.Add(new RunAsAdminOption(item.FullPath)); if (item.ResultType == ResultType.File) { Options.Add(new OpenLocationOption(item.FullPath)); } }
/// <summary> /// Creates a Bootstrap Font-Awesome icon /// </summary> /// <param name="icon">Icon to be rendered</param> /// <param name="size">Icon size</param> /// <param name="htmlAttributes">Extra HTML attributes</param> /// <returns>A Bootstrap icon</returns> /// <exception cref="FontAwesomeVersionException">Thrown when a valid FontAwesome /// icon library version is not selected</exception> public static IHtmlComponent CreateIcon(EFontAwesomeIcon icon, EFontAwesomeIconSize size = EFontAwesomeIconSize.Normal, object htmlAttributes = null) { NameValueCollection attrsDictionary = WebExtrasUtil.AnonymousObjectToHtmlAttributes(htmlAttributes); List <string> cssClasses = new List <string>(); if (attrsDictionary.ContainsKey("class")) { cssClasses.AddRange(attrsDictionary["class"].Split(' ')); attrsDictionary.Remove("class"); } string prefix; switch (WebExtrasSettings.FontAwesomeVersion) { case EFontAwesomeVersion.V3: prefix = "icon-"; break; case EFontAwesomeVersion.V4: prefix = "fa fa-"; break; default: throw new FontAwesomeVersionException(); } cssClasses.Add(prefix + icon.ToString().ToLowerInvariant().Replace("_", "-")); if (size != EFontAwesomeIconSize.Normal) { cssClasses.Add(prefix + size.GetStringValue()); } HtmlComponent i = new HtmlComponent(EHtmlTag.I); i.CssClasses.AddRange(cssClasses); foreach (string key in attrsDictionary.Keys) { i.Attributes[key] = attrsDictionary[key]; } return(i); }
/// <summary> /// Get the Typeface of an icon /// </summary> public static Typeface GetTypeFace(this EFontAwesomeIcon icon) { var info = icon.GetInformationAttribute <FontAwesomeInformationAttribute>(); if (info == null) { return(Fonts.RegularTypeface); } return(info.Style switch { EFontAwesomeStyle.Regular => Fonts.RegularTypeface, EFontAwesomeStyle.Solid => Fonts.SolidTypeface, EFontAwesomeStyle.Brands => Fonts.BrandsTypeface, _ => null, });
/// <summary>Get the SVG path of an icon</summary> public static bool GetSvg(this EFontAwesomeIcon icon, out string path, out int width, out int height) { path = string.Empty; width = -1; height = -1; FontAwesomeSvgInformationAttribute informationAttribute = icon.GetInformationAttribute <FontAwesomeSvgInformationAttribute>(); if (informationAttribute == null) { return(false); } path = informationAttribute.Path; width = informationAttribute.Width; height = informationAttribute.Height; return(true); }
private static void ContentChanged(DependencyObject sender, DependencyPropertyChangedEventArgs evt) { if (!(sender is ContentControl)) { return; } ContentControl contentControl = (ContentControl)sender; if (!(evt.NewValue is EFontAwesomeIcon)) { return; } EFontAwesomeIcon newValue = (EFontAwesomeIcon)evt.NewValue; contentControl.FontFamily = newValue.GetFontFamily(); contentControl.Content = newValue.GetUnicode(); }
/// <summary> /// Get the FontFamily of an icon /// </summary> public static FontFamily GetFontFamily(this EFontAwesomeIcon icon) { var info = icon.GetInformationAttribute <FontAwesomeInformationAttribute>(); if (info == null) { return(Fonts.RegularFontFamily); } switch (info.Style) { case EFontAwesomeStyle.Regular: return(Fonts.RegularFontFamily); case EFontAwesomeStyle.Solid: return(Fonts.SolidFontFamily); case EFontAwesomeStyle.Brands: return(Fonts.BrandsFontFamily); } return(null); }
/// <summary> /// Get the Typeface of an icon /// </summary> public static Typeface GetTypeFace(this EFontAwesomeIcon icon) { var info = icon.GetInformationAttribute <FontAwesomeInformationAttribute>(); if (info == null) { return(Fonts.RegularTypeface); } switch (info.Style) { case EFontAwesomeStyle.Regular: return(Fonts.RegularTypeface); case EFontAwesomeStyle.Solid: return(Fonts.SolidTypeface); case EFontAwesomeStyle.Brands: return(Fonts.BrandsTypeface); } return(null); }
/// <summary> /// Get the SVG path of an icon /// </summary> public static bool GetSvg(this EFontAwesomeIcon icon, out string[] path, out int width, out int height) { path = null; width = -1; height = -1; var svgInfo = icon.GetInformationAttribute <FontAwesomeSvgInformationAttribute>(); if (svgInfo == null) { return(false); } path = svgInfo.Path; width = svgInfo.Width; height = svgInfo.Height; return(true); }
internal static T GetInformationAttribute <T>(this EFontAwesomeIcon icon) where T : class { if (icon == EFontAwesomeIcon.None) { return(null); } MemberInfo[] member = typeof(EFontAwesomeIcon).GetMember(icon.ToString()); if (member.Length == 0) { throw new Exception("EFontAwesomeIcon not found."); } object[] customAttributes = member[0].GetCustomAttributes(typeof(T), false); if (customAttributes.Length == 0) { throw new Exception("FontAwesomeInformationAttribute not found."); } return(customAttributes[0] as T); }
private static void ContentChanged(DependencyObject sender, DependencyPropertyChangedEventArgs evt) { // If target is not a ContenControl just ignore: Awesome.Content property can only be set on a ContentControl element if (!(sender is ContentControl)) { return; } ContentControl target = (ContentControl)sender; // If value is not a FontAwesomeIcon just ignore: Awesome.Content property can only be set to a FontAwesomeIcon value if (!(evt.NewValue is EFontAwesomeIcon)) { return; } EFontAwesomeIcon symbolIcon = (EFontAwesomeIcon)evt.NewValue; target.FontFamily = symbolIcon.GetFontFamily(); target.Content = symbolIcon.GetUnicode(); }
public static T GetInformationAttribute <T>(this EFontAwesomeIcon icon) where T : class { if (icon == EFontAwesomeIcon.None) { return(null); } var memInfo = typeof(EFontAwesomeIcon).GetMember(icon.ToString()); if (memInfo.Length == 0) { throw new Exception("EFontAwesomeIcon not found."); } var attributes = memInfo[0].GetCustomAttributes(typeof(T), false) .ToList(); if (!attributes.Any()) { throw new Exception("FontAwesomeInformationAttribute not found."); } return(attributes[0] as T); }
/// <summary> /// Renders a Bootstrap Font-Awesome icon /// </summary> /// <param name="html">Current Html helper object</param> /// <param name="icon">Icon to be rendered</param> /// <param name="size">Icon size</param> /// <param name="htmlAttributes">Extra HTML attributes</param> /// <returns>A Bootstrap icon</returns> /// <exception cref="FontAwesomeVersionException"> /// Thrown when a valid FontAwesome /// icon library version is not selected /// </exception> public static IExtendedHtmlStringLegacy Icon(this HtmlHelper html, EFontAwesomeIcon icon, EFontAwesomeIconSize size = EFontAwesomeIconSize.Normal, object htmlAttributes = null) { return(BootstrapUtil.CreateIcon(icon, size, htmlAttributes).ToHtmlElement()); }