diff --git a/CHANGELOG.md b/CHANGELOG.md index f5dd419..3316e57 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,11 @@ +# 2.1.4 + - Removed ResourceDictionary(FontAwesome5Dictionary.xaml) + - Added new function for Font saving and loading to Fonts class. + - fonts now get saved to temporary directory and referenced from there to prevent memory leak +# 2.1.3 +- Added ImageSourceSvgConverter +- Made the Font Families adjustable on the static Fonts class +- Introduced a new ReosurceDictionary (FontAwesome5Dictionary.xaml) to prevent memory leaks # 2.1.2 - Fixed issue #31 # 2.1.1 diff --git a/README.md b/README.md index 54a6d62..768b7af 100644 --- a/README.md +++ b/README.md @@ -12,9 +12,8 @@ Font Awesome: https://github.com/FortAwesome/Font-Awesome #### Installation -```Install-Package FontAwesome5``` +1. Install the FontAwesome5 NuGet Package: ```Install-Package FontAwesome5``` -https://www.nuget.org/packages/FontAwesome5 #### Usage XAML @@ -22,6 +21,8 @@ The usage is the same like the version from charri, just the FontAwesomeIcon enu https://github.com/charri/Font-Awesome-WPF/blob/master/README-WPF.md#usage-xaml + + #### Usage XAML SVG The SvgAwesome can be used like the ImageAwesome. @@ -44,6 +45,10 @@ The SvgAwesome can be used like the ImageAwesome. https://github.com/charri/Font-Awesome-WPF/blob/master/README-WPF.md#imagesourceconverter +#### ImageSourceSvgConverter + +This is the same like the *ImageSourceConverter*, except it does use the Svg information to draw the icon instead of the font. + #### LabelConverter Gets the Label/Name of a EFontAwesomeIcon. The converter parameter can contain a format string, where {0} is the label/name and {1} is the style. diff --git a/src/Examples/FontAwesome5.Net40.Example/MainWindow.xaml b/src/Examples/FontAwesome5.Net40.Example/MainWindow.xaml index 7d83935..26dca4f 100644 --- a/src/Examples/FontAwesome5.Net40.Example/MainWindow.xaml +++ b/src/Examples/FontAwesome5.Net40.Example/MainWindow.xaml @@ -7,110 +7,95 @@ xmlns:fa5="http://schemas.fontawesome.com/icons/" mc:Ignorable="d" Title="FontAwesome5.Net40.Example" SizeToContent="WidthAndHeight"> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - + + + + + + + + + + + + + + + - - + - - - + + - - + + - - + + - - + + - - + + - - - + + + diff --git a/src/Examples/FontAwesome5.Net40.Example/ViewModels/MainWindowViewModel.cs b/src/Examples/FontAwesome5.Net40.Example/ViewModels/MainWindowViewModel.cs index 34f568c..a4dd68b 100644 --- a/src/Examples/FontAwesome5.Net40.Example/ViewModels/MainWindowViewModel.cs +++ b/src/Examples/FontAwesome5.Net40.Example/ViewModels/MainWindowViewModel.cs @@ -45,10 +45,6 @@ public MainWindowViewModel() public List FlipOrientations { get; set; } = new List(); public List AllIcons { get; set; } = new List(); - public string SVGText => $""; - public string ImageText => $""; - public string FontText => $""; - public event PropertyChangedEventHandler PropertyChanged; } } diff --git a/src/Examples/FontAwesome5.NetCore.Example/App.xaml b/src/Examples/FontAwesome5.NetCore.Example/App.xaml index 52adbea..a59f229 100644 --- a/src/Examples/FontAwesome5.NetCore.Example/App.xaml +++ b/src/Examples/FontAwesome5.NetCore.Example/App.xaml @@ -4,6 +4,6 @@ xmlns:local="clr-namespace:FontAwesome5.NetCore30" StartupUri="MainWindow.xaml"> - - + + diff --git a/src/Examples/FontAwesome5.NetCore.Example/FodyWeavers.xsd b/src/Examples/FontAwesome5.NetCore.Example/FodyWeavers.xsd index 2f1b8aa..221aeb8 100644 --- a/src/Examples/FontAwesome5.NetCore.Example/FodyWeavers.xsd +++ b/src/Examples/FontAwesome5.NetCore.Example/FodyWeavers.xsd @@ -31,6 +31,16 @@ Used to control if equality checks should use the static Equals method resolved from the base class. + + + Used to turn off build warnings from this weaver. + + + + + Used to turn off build warnings about mismatched On_PropertyName_Changed methods. + + diff --git a/src/Examples/FontAwesome5.NetCore.Example/FontAwesome5.NetCore.Example.csproj b/src/Examples/FontAwesome5.NetCore.Example/FontAwesome5.NetCore.Example.csproj index adde02b..b6bb663 100644 --- a/src/Examples/FontAwesome5.NetCore.Example/FontAwesome5.NetCore.Example.csproj +++ b/src/Examples/FontAwesome5.NetCore.Example/FontAwesome5.NetCore.Example.csproj @@ -7,7 +7,7 @@ - + diff --git a/src/Examples/FontAwesome5.NetCore.Example/MainWindow.xaml b/src/Examples/FontAwesome5.NetCore.Example/MainWindow.xaml index 5182c89..8d527e9 100644 --- a/src/Examples/FontAwesome5.NetCore.Example/MainWindow.xaml +++ b/src/Examples/FontAwesome5.NetCore.Example/MainWindow.xaml @@ -5,112 +5,98 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:FontAwesome5.NetCore30.Example" xmlns:fa5="http://schemas.fontawesome.com/icons/" + xmlns:fontawesome5="clr-namespace:FontAwesome5;assembly=FontAwesome5" mc:Ignorable="d" Title="FontAwesome5.NetCore.Example" Height="632" Width="883"> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + - - - - - - - - - - - - - + + + - - + + - - - + + - - + + - - + + - - - - - - - - - + + + + diff --git a/src/Examples/FontAwesome5.NetCore.Example/MainWindow.xaml.cs b/src/Examples/FontAwesome5.NetCore.Example/MainWindow.xaml.cs index 5cefb97..4753c73 100644 --- a/src/Examples/FontAwesome5.NetCore.Example/MainWindow.xaml.cs +++ b/src/Examples/FontAwesome5.NetCore.Example/MainWindow.xaml.cs @@ -12,19 +12,20 @@ using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; + using FontAwesome5.NetCore30.Example.ViewModels; namespace FontAwesome5.NetCore30.Example { - /// - /// Interaction logic for MainWindow.xaml - /// - public partial class MainWindow : Window + /// + /// Interaction logic for MainWindow.xaml + /// + public partial class MainWindow : Window + { + public MainWindow() { - public MainWindow() - { - DataContext = new MainWindowViewModel(); - InitializeComponent(); - } + DataContext = new MainWindowViewModel(); + InitializeComponent(); } + } } diff --git a/src/Examples/FontAwesome5.NetCore.Example/ViewModels/MainWindowViewModel.cs b/src/Examples/FontAwesome5.NetCore.Example/ViewModels/MainWindowViewModel.cs index 66c845e..4cbef9d 100644 --- a/src/Examples/FontAwesome5.NetCore.Example/ViewModels/MainWindowViewModel.cs +++ b/src/Examples/FontAwesome5.NetCore.Example/ViewModels/MainWindowViewModel.cs @@ -1,4 +1,5 @@ using FontAwesome5.Extensions; + using System; using System.Collections.Generic; using System.ComponentModel; @@ -9,45 +10,41 @@ namespace FontAwesome5.NetCore30.Example.ViewModels { - public class MainWindowViewModel : INotifyPropertyChanged + public class MainWindowViewModel : INotifyPropertyChanged + { + public MainWindowViewModel() { - public MainWindowViewModel() - { - AllIcons = Enum.GetValues(typeof(EFontAwesomeIcon)).Cast() - .OrderBy(i => i.GetStyle()).ThenBy(i => i.GetLabel()).ToList(); - AllIcons.Remove(EFontAwesomeIcon.None); - SelectedIcon = AllIcons.First(); - - FlipOrientations = Enum.GetValues(typeof(EFlipOrientation)).Cast().ToList(); - SpinDuration = 5; - PulseDuration = 5; - - FontSize = 30; - Rotation = 0; - - Visibilities = Enum.GetValues(typeof(Visibility)).Cast().ToList(); - Visibility = Visibility.Visible; - } - - public Visibility Visibility { get; set; } - public EFontAwesomeIcon SelectedIcon { get; set; } - - public bool SpinIsEnabled { get; set; } - public double SpinDuration { get; set; } - public bool PulseIsEnabled { get; set; } - public double PulseDuration { get; set; } - public EFlipOrientation FlipOrientation { get; set; } - public double FontSize { get; set; } - public double Rotation { get; set; } - - public List Visibilities { get; set; } = new List(); - public List FlipOrientations { get; set; } = new List(); - public List AllIcons { get; set; } = new List(); - - public string SVGText => $""; - public string ImageText => $""; - public string FontText => $""; - - public event PropertyChangedEventHandler PropertyChanged; + AllIcons = Enum.GetValues(typeof(EFontAwesomeIcon)).Cast() + .OrderBy(i => i.GetStyle()).ThenBy(i => i.GetLabel()).ToList(); + AllIcons.Remove(EFontAwesomeIcon.None); + SelectedIcon = AllIcons.First(); + + FlipOrientations = Enum.GetValues(typeof(EFlipOrientation)).Cast().ToList(); + SpinDuration = 5; + PulseDuration = 5; + + FontSize = 30; + Rotation = 0; + + Visibilities = Enum.GetValues(typeof(Visibility)).Cast().ToList(); + Visibility = Visibility.Visible; } + + public Visibility Visibility { get; set; } + public EFontAwesomeIcon SelectedIcon { get; set; } + + public bool SpinIsEnabled { get; set; } + public double SpinDuration { get; set; } + public bool PulseIsEnabled { get; set; } + public double PulseDuration { get; set; } + public EFlipOrientation FlipOrientation { get; set; } + public double FontSize { get; set; } + public double Rotation { get; set; } + + public List Visibilities { get; set; } = new List(); + public List FlipOrientations { get; set; } = new List(); + public List AllIcons { get; set; } = new List(); + + public event PropertyChangedEventHandler PropertyChanged; + } } diff --git a/src/Examples/FontAwesome5.UWP.Example/App.xaml b/src/Examples/FontAwesome5.UWP.Example/App.xaml index 781f3f2..a5518f4 100644 --- a/src/Examples/FontAwesome5.UWP.Example/App.xaml +++ b/src/Examples/FontAwesome5.UWP.Example/App.xaml @@ -3,5 +3,7 @@ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="using:FontAwesome5.UWP.Example"> + + diff --git a/src/FontAwesome5.Net/Converters/ImageSourceSvgConverter.cs b/src/FontAwesome5.Net/Converters/ImageSourceSvgConverter.cs new file mode 100644 index 0000000..7592d8d --- /dev/null +++ b/src/FontAwesome5.Net/Converters/ImageSourceSvgConverter.cs @@ -0,0 +1,44 @@ +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Text; +using System.Windows.Data; +using System.Windows.Markup; +using System.Windows.Media; + +using FontAwesome5.Extensions; + +namespace FontAwesome5.Converters +{ + /// + /// Converts a FontAwesomIcon to an ImageSource. Use the ConverterParameter to pass the Brush. + /// + public class ImageSourceSvgConverter : MarkupExtension, IValueConverter + { + public override object ProvideValue(IServiceProvider serviceProvider) + { + return this; + } + + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + if (value is not EFontAwesomeIcon) + { + return null; + } + + if (parameter is not Brush brush) + { + brush = Brushes.Black; + } + + return ((EFontAwesomeIcon)value).CreateImageSource(brush, new Pen()); + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + throw new NotImplementedException(); + } + } +} diff --git a/src/FontAwesome5.Net/Extensions/EFontAwesomeIconsExtensions.cs b/src/FontAwesome5.Net/Extensions/EFontAwesomeIconsExtensions.cs index c3cdccf..7551e44 100644 --- a/src/FontAwesome5.Net/Extensions/EFontAwesomeIconsExtensions.cs +++ b/src/FontAwesome5.Net/Extensions/EFontAwesomeIconsExtensions.cs @@ -9,130 +9,141 @@ namespace FontAwesome5.Extensions { - public static class EFontAwesomeIconsExtensions + public static class EFontAwesomeIconsExtensions + { + /// + /// Creates a new System.Windows.Media.ImageSource of a specified FontAwesomeIcon and foreground System.Windows.Media.Brush. + /// + /// The FontAwesome icon to be drawn. + /// The System.Windows.Media.Brush to be used as the foreground. + /// The font size in em. + /// A new System.Windows.Media.ImageSource + public static ImageSource CreateImageSource(this EFontAwesomeIcon icon, Brush foregroundBrush, double emSize = 100) { - /// - /// Creates a new System.Windows.Media.ImageSource of a specified FontAwesomeIcon and foreground System.Windows.Media.Brush. - /// - /// The FontAwesome icon to be drawn. - /// The System.Windows.Media.Brush to be used as the foreground. - /// The font size in em. - /// A new System.Windows.Media.ImageSource - public static ImageSource CreateImageSource(this EFontAwesomeIcon icon, Brush foregroundBrush, double emSize = 100) - { - return new DrawingImage(icon.CreateDrawing(foregroundBrush, emSize)); - } + return new DrawingImage(icon.CreateDrawing(foregroundBrush, emSize)); + } - /// - /// 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. - /// - /// The FontAwesome icon to be drawn. - /// The System.Windows.Media.Brush to be used as the foreground. - /// The font size in em. - /// A new System.Windows.Media.Drawing - 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; - } + /// + /// Creates a new System.Windows.Media.ImageSource of a specified FontAwesomeIcon and foreground System.Windows.Media.Brush. + /// + /// The FontAwesome icon to be drawn. + /// The System.Windows.Media.Brush to be used as the foreground. + /// A new System.Windows.Media.ImageSource + public static ImageSource CreateImageSource(this EFontAwesomeIcon icon, Brush foregroundBrush, Pen pen) + { + return new DrawingImage(icon.CreateDrawing(foregroundBrush, pen)); + } - /// - /// Creates a new System.Windows.Media.Drawing of a specified FontAwesomeIcon. - /// This will use the SVG for the Drawing creation. - /// - /// The FontAwesome icon to be drawn. - /// The Brush with which to fill the Geometry. This is optional, and can be null. If the brush is null, no fill is drawn. - /// The Pen with which to stroke the Geometry. This is optional, and can be null. If the pen is null, no stroke is drawn. - /// A new System.Windows.Media.Drawing - 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; - } + /// + /// 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. + /// + /// The FontAwesome icon to be drawn. + /// The System.Windows.Media.Brush to be used as the foreground. + /// The font size in em. + /// A new System.Windows.Media.Drawing + 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; + } - /// - /// Creates a new System.Windows.Media.FormattedText of a specified FontAwesomeIcon and foreground System.Windows.Media.Brush. - /// - /// The FontAwesome icon to be drawn. - /// The System.Windows.Media.Brush to be used as the foreground. - /// The font size in em. - /// A new System.Windows.Media.FormattedText - public static FormattedText CreateFormattedText(this EFontAwesomeIcon icon, Brush foregroundBrush, double emSize = 100) + /// + /// Creates a new System.Windows.Media.Drawing of a specified FontAwesomeIcon. + /// This will use the SVG for the Drawing creation. + /// + /// The FontAwesome icon to be drawn. + /// The Brush with which to fill the Geometry. This is optional, and can be null. If the brush is null, no fill is drawn. + /// The Pen with which to stroke the Geometry. This is optional, and can be null. If the pen is null, no stroke is drawn. + /// A new System.Windows.Media.Drawing + 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)) { - return new FormattedText(icon.GetUnicode(), CultureInfo.InvariantCulture, FlowDirection.LeftToRight, - icon.GetTypeFace(), emSize, foregroundBrush) - { - TextAlignment = TextAlignment.Center, - }; + drawingContext.DrawGeometry(brush, pen, Geometry.Parse(strPath)); } + } + return visual.Drawing; + } - /// - /// Creates a new System.Windows.Media.FormattedText of a specified FontAwesomeIcon and foreground System.Windows.Media.Brush. - /// - /// The FontAwesome icon to be drawn. - /// The System.Windows.Media.Brush to be used as the foreground. - /// The font size in em. - /// The flow direction of the font - /// The text formatting mode of the font - /// The number substitution of the font. - /// A new System.Windows.Media.FormattedText - 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); - } + /// + /// Creates a new System.Windows.Media.FormattedText of a specified FontAwesomeIcon and foreground System.Windows.Media.Brush. + /// + /// The FontAwesome icon to be drawn. + /// The System.Windows.Media.Brush to be used as the foreground. + /// The font size in em. + /// A new System.Windows.Media.FormattedText + 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, + }; + } - /// - /// Creates a new System.Windows.Shapes.Path of a specified FontAwesomeIcon and foreground System.Windows.Media.Brush. - /// - /// The FontAwesome icon to be drawn. - /// The System.Windows.Media.Brush to be used as the foreground. - /// The font size in em. - /// A new System.Windows.Shapes.Path - 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; - } + /// + /// Creates a new System.Windows.Media.FormattedText of a specified FontAwesomeIcon and foreground System.Windows.Media.Brush. + /// + /// The FontAwesome icon to be drawn. + /// The System.Windows.Media.Brush to be used as the foreground. + /// The font size in em. + /// The flow direction of the font + /// The text formatting mode of the font + /// The number substitution of the font. + /// A new System.Windows.Media.FormattedText + 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); + } - /// - /// Creates a new System.Windows.Media.Geometry of a specified FontAwesomeIcon. - /// - /// The FontAwesome icon to be drawn. - /// The width of the SVG. - /// The height of the SVG - /// A new System.Windows.Media.Geometry - public static Geometry CreateGeometry(this EFontAwesomeIcon icon, out int width, out int height) + /// + /// Creates a new System.Windows.Shapes.Path of a specified FontAwesomeIcon and foreground System.Windows.Media.Brush. + /// + /// The FontAwesome icon to be drawn. + /// The System.Windows.Media.Brush to be used as the foreground. + /// The font size in em. + /// A new System.Windows.Shapes.Path + 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 { - if (icon.GetSvg(out var strPath, out width, out height)) - { - return Geometry.Parse(strPath); - } - return null; - } + Data = Geometry.Parse(strPath), + Width = width, + Height = height, + Fill = foregroundBrush + }; + } + return null; + } + + /// + /// Creates a new System.Windows.Media.Geometry of a specified FontAwesomeIcon. + /// + /// The FontAwesome icon to be drawn. + /// The width of the SVG. + /// The height of the SVG + /// A new System.Windows.Media.Geometry + 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; } + } } diff --git a/src/FontAwesome5.Net/FontAwesome5.Net.csproj b/src/FontAwesome5.Net/FontAwesome5.Net.csproj index 1dc661d..40174e2 100644 --- a/src/FontAwesome5.Net/FontAwesome5.Net.csproj +++ b/src/FontAwesome5.Net/FontAwesome5.Net.csproj @@ -30,10 +30,6 @@ - - - - diff --git a/src/FontAwesome5.Net/Fonts.cs b/src/FontAwesome5.Net/Fonts.cs index 23887f6..a43aac2 100644 --- a/src/FontAwesome5.Net/Fonts.cs +++ b/src/FontAwesome5.Net/Fonts.cs @@ -1,6 +1,9 @@ using System; using System.Collections.Generic; +using System.IO; using System.Linq; +using System.Reflection; +using System.Resources; using System.Text; using System.Threading.Tasks; using System.Windows; @@ -8,35 +11,83 @@ namespace FontAwesome5 { - /// - /// Provides FontFamilies and Typefaces of FontAwesome5. - /// - public static class Fonts + /// + /// Provides FontFamilies and Typefaces of FontAwesome5. + /// + public static class Fonts + { + static Fonts() + { + var path = Path.GetTempPath(); + SaveFontFilesToDirectory(path); + LoadFromDirectory(path); + } + + public static void LoadFromResource() { - /// - /// FontAwesome5 Regular FontFamily - /// - public static readonly FontFamily RegularFontFamily = new FontFamily(new Uri("pack://application:,,,/FontAwesome5.Net;component/"), "./Fonts/#Font Awesome 5 Free Regular"); - /// - /// FontAwesome5 Solid FontFamily - /// - public static readonly FontFamily SolidFontFamily = new FontFamily(new Uri("pack://application:,,,/FontAwesome5.Net;component/"), "./Fonts/#Font Awesome 5 Free Solid"); - /// - /// FontAwesome5 Brands FontFamily - /// - public static readonly FontFamily BrandsFontFamily = new FontFamily(new Uri("pack://application:,,,/FontAwesome5.Net;component/"), "./Fonts/#Font Awesome 5 Brands Regular"); - - /// - /// FontAwesome5 Regular Typeface - /// - public static readonly Typeface RegularTypeface = new Typeface(RegularFontFamily, FontStyles.Normal, FontWeights.Normal, FontStretches.Normal); - /// - /// FontAwesome5 Solid Typeface - /// - public static readonly Typeface SolidTypeface = new Typeface(SolidFontFamily, FontStyles.Normal, FontWeights.Normal, FontStretches.Normal); - /// - /// FontAwesome5 Brands Typeface - /// - public static readonly Typeface BrandsTypeface = new Typeface(BrandsFontFamily, FontStyles.Normal, FontWeights.Normal, FontStretches.Normal); + RegularFontFamily = new FontFamily(new Uri("pack://application:,,,/FontAwesome5.Net;component/"), "./Fonts/#Font Awesome 5 Free Regular"); + SolidFontFamily = new FontFamily(new Uri("pack://application:,,,/FontAwesome5.Net;component/"), "./Fonts/#Font Awesome 5 Free Solid"); + BrandsFontFamily = new FontFamily(new Uri("pack://application:,,,/FontAwesome5.Net;component/"), "./Fonts/#Font Awesome 5 Brands Regular"); + } + + public static void LoadFromDirectory(string path) + { + RegularFontFamily = new FontFamily(new Uri($"file:///{path}", UriKind.Absolute), "./#Font Awesome 5 Free Regular"); + SolidFontFamily = new FontFamily(new Uri($"file:///{path}", UriKind.Absolute), "./#Font Awesome 5 Free Solid"); + BrandsFontFamily = new FontFamily(new Uri($"file:///{path}", UriKind.Absolute), "./#Font Awesome 5 Brands Regular"); } + + public static void SaveFontFilesToDirectory(string path) + { + var resManager = new ResourceManager("FontAwesome5.Net.g", Assembly.GetExecutingAssembly()); + WriteResourceToFile(resManager, $"Fonts/Font Awesome 5 Free-Solid-900.otf", Path.Combine(path, "Font Awesome 5 Free-Solid-900.otf")); + WriteResourceToFile(resManager, $"Fonts/Font Awesome 5 Free-Regular-400.otf", Path.Combine(path, "Font Awesome 5 Free-Regular-400.otf")); + WriteResourceToFile(resManager, $"Fonts/Font Awesome 5 Brands-Regular-400.otf", Path.Combine(path, "Font Awesome 5 Brands-Regular-400.otf")); + } + + private static void WriteResourceToFile(ResourceManager resManager, string resourceName, string fileName) + { + if (File.Exists(fileName)) + { + return; + } + + using (var res = resManager.GetStream(Uri.EscapeUriString(resourceName).ToLowerInvariant())) + { + using (var file = new FileStream(fileName, FileMode.Create, FileAccess.Write)) + { + res.CopyTo(file); + } + } + } + + /// + /// FontAwesome5 Regular FontFamily + /// + public static FontFamily RegularFontFamily; + + /// + /// FontAwesome5 Solid FontFamily + /// + public static FontFamily SolidFontFamily; + + /// + /// FontAwesome5 Brands FontFamily + /// + public static FontFamily BrandsFontFamily; + + + /// + /// FontAwesome5 Regular Typeface + /// + public static Typeface RegularTypeface => new Typeface(RegularFontFamily, FontStyles.Normal, FontWeights.Normal, FontStretches.Normal); + /// + /// FontAwesome5 Solid Typeface + /// + public static Typeface SolidTypeface => new Typeface(SolidFontFamily, FontStyles.Normal, FontWeights.Normal, FontStretches.Normal); + /// + /// FontAwesome5 Brands Typeface + /// + public static Typeface BrandsTypeface => new Typeface(BrandsFontFamily, FontStyles.Normal, FontWeights.Normal, FontStretches.Normal); + } } diff --git a/src/FontAwesome5.Net/ImageAwesome.cs b/src/FontAwesome5.Net/ImageAwesome.cs index 4e6bede..c9cd5f2 100644 --- a/src/FontAwesome5.Net/ImageAwesome.cs +++ b/src/FontAwesome5.Net/ImageAwesome.cs @@ -259,7 +259,7 @@ private static void OnIconPropertyChanged(DependencyObject d, DependencyProperty return; } - imageAwesome.SetValue(SourceProperty, imageAwesome.Icon.CreateImageSource(imageAwesome.Foreground)); + imageAwesome.SetValue(SourceProperty, imageAwesome.Icon.CreateImageSource(imageAwesome.Foreground, new Pen())); } diff --git a/src/FontAwesome5.UWP/Fonts.cs b/src/FontAwesome5.UWP/Fonts.cs index 0ac4b5e..f0b67fd 100644 --- a/src/FontAwesome5.UWP/Fonts.cs +++ b/src/FontAwesome5.UWP/Fonts.cs @@ -1,23 +1,30 @@ -using Windows.UI.Xaml.Media; +using System; +using System.IO; +using System.Reflection; + +using Windows.UI.Xaml; +using Windows.UI.Xaml.Media; namespace FontAwesome5 { + /// + /// Provides FontFamilies and Typefaces of FontAwesome5. + /// + public static class Fonts + { + /// + /// FontAwesome5 Regular FontFamily + /// + public static FontFamily RegularFontFamily = new FontFamily("ms-appx:///FontAwesome5.UWP/Fonts/Font Awesome 5 Free-Regular-400.otf#Font Awesome 5 Free"); + + /// + /// FontAwesome5 Solid FontFamily + /// + public static FontFamily SolidFontFamily = new FontFamily("ms-appx:///FontAwesome5.UWP/Fonts/Font Awesome 5 Free-Solid-900.otf#Font Awesome 5 Free"); + /// - /// Provides FontFamilies and Typefaces of FontAwesome5. + /// FontAwesome5 Brands FontFamily /// - public static class Fonts - { - /// - /// FontAwesome5 Regular FontFamily - /// - public static readonly FontFamily RegularFontFamily = new FontFamily("ms-appx:///FontAwesome5.UWP/Fonts/Font Awesome 5 Free-Regular-400.otf#Font Awesome 5 Free"); - /// - /// FontAwesome5 Solid FontFamily - /// - public static readonly FontFamily SolidFontFamily = new FontFamily("ms-appx:///FontAwesome5.UWP/Fonts/Font Awesome 5 Free-Solid-900.otf#Font Awesome 5 Free"); - /// - /// FontAwesome5 Brands FontFamily - /// - public static readonly FontFamily BrandsFontFamily = new FontFamily("ms-appx:///FontAwesome5.UWP/Fonts/Font Awesome 5 Brands-Regular-400.otf#Font Awesome 5 Brands"); - } + public static FontFamily BrandsFontFamily = new FontFamily("ms-appx:///FontAwesome5.UWP/Fonts/Font Awesome 5 Brands-Regular-400.otf#Font Awesome 5 Brands"); + } } diff --git a/src/FontAwesome5/FontAwesome5.csproj b/src/FontAwesome5/FontAwesome5.csproj index 00ff9d1..9769568 100644 --- a/src/FontAwesome5/FontAwesome5.csproj +++ b/src/FontAwesome5/FontAwesome5.csproj @@ -1,7 +1,7 @@  - netstandard1.4;net40 + netstandard1.4;netstandard2.1;net40;net5.0 Codinion Martin Topfstedt true diff --git a/src/NuGet/FontAwesome5.nuspec b/src/NuGet/FontAwesome5.nuspec index 065c3e9..38fa1db 100644 --- a/src/NuGet/FontAwesome5.nuspec +++ b/src/NuGet/FontAwesome5.nuspec @@ -1,79 +1,89 @@  - - FontAwesome5 - $version$ - - WPF (.Net and .Net Core) and UWP controls for the iconic SVG, font, and CSS toolkit Font Awesome 5. - For examples https://github.com/MartinTopfstedt/FontAwesome5 - Font-Awesome Version: 5.15.3 - - Codinion - MIT - https://github.com/MartinTopfstedt/FontAwesome5 - icon.png - false - fontawesome fontawesome5 - Copyright © 2019 Codinion - - - + + FontAwesome5 + $version$ + + WPF (.Net and .Net Core) and UWP controls for the iconic SVG, font, and CSS toolkit Font Awesome 5. + For examples https://github.com/MartinTopfstedt/FontAwesome5 + Font-Awesome Version: 5.15.3 + + Codinion + MIT + https://github.com/MartinTopfstedt/FontAwesome5 + icon.png + false + fontawesome fontawesome5 + Copyright © 2019 Codinion + + + - - - - + + + + - - - - - - - + + + + - - - - - - - + + + + - - - - - - - + + + + + + + - - - - - - - + + + + + + + - - - - - - - + + + + + + + - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Tools/FontAwesome5.Generator/FontAwesome5.Generator.csproj b/src/Tools/FontAwesome5.Generator/FontAwesome5.Generator.csproj index f32a314..03c7baa 100644 --- a/src/Tools/FontAwesome5.Generator/FontAwesome5.Generator.csproj +++ b/src/Tools/FontAwesome5.Generator/FontAwesome5.Generator.csproj @@ -58,7 +58,7 @@ true - true + false @@ -80,7 +80,6 @@ -