From 24f21f2b608ce98cdf45d849c1a875d3d254c8d0 Mon Sep 17 00:00:00 2001 From: Martin Topfstedt Date: Wed, 14 Jul 2021 21:06:16 +0200 Subject: [PATCH 1/4] fix #35 --- CHANGELOG.md | 4 + Font-Awesome | 2 +- README.md | 26 +- .../FontAwesome5.NetCore.Example/App.xaml | 8 +- .../MainWindow.xaml | 192 +++++++------- .../FontAwesome5.UWP.Example/App.xaml | 8 +- .../Converters/ImageSourceSvgConverter.cs | 44 ++++ .../Extensions/EFontAwesomeIconsExtensions.cs | 241 +++++++++--------- src/FontAwesome5.Net/FontAwesome5.Net.csproj | 4 - .../FontAwesome5Dictionary.xaml | 6 + src/FontAwesome5.Net/Fonts.cs | 108 ++++++-- src/FontAwesome5.Net/ImageAwesome.cs | 2 +- src/FontAwesome5.UWP/FontAwesome5.UWP.csproj | 6 + .../FontAwesome5Dictionary.xaml | 6 + src/FontAwesome5.UWP/Fonts.cs | 88 +++++-- src/FontAwesome5/FontAwesome5.csproj | 2 +- src/NuGet/FontAwesome5.nuspec | 153 ++++++----- .../FontAwesome5.Generator.csproj | 3 +- 18 files changed, 568 insertions(+), 335 deletions(-) create mode 100644 src/FontAwesome5.Net/Converters/ImageSourceSvgConverter.cs create mode 100644 src/FontAwesome5.Net/FontAwesome5Dictionary.xaml create mode 100644 src/FontAwesome5.UWP/FontAwesome5Dictionary.xaml diff --git a/CHANGELOG.md b/CHANGELOG.md index f5dd419..8ae5d00 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +# 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/Font-Awesome b/Font-Awesome index d79d85c..d8db3d0 160000 --- a/Font-Awesome +++ b/Font-Awesome @@ -1 +1 @@ -Subproject commit d79d85c3fad85ad1885e87ed558f4afd6fce8289 +Subproject commit d8db3d032d22e7a5e21f3b40905b7867be19bb02 diff --git a/README.md b/README.md index 54a6d62..bf8fc19 100644 --- a/README.md +++ b/README.md @@ -12,9 +12,23 @@ Font Awesome: https://github.com/FortAwesome/Font-Awesome #### Installation -```Install-Package FontAwesome5``` - -https://www.nuget.org/packages/FontAwesome5 +1. Install the FontAwesome5 NuGet Package: ```Install-Package FontAwesome5``` +2. Add the FontAwesome5 ReosurceDictionary to your App.xaml +``` + + + + + + + + + +``` #### Usage XAML @@ -22,6 +36,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 +60,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.NetCore.Example/App.xaml b/src/Examples/FontAwesome5.NetCore.Example/App.xaml index 52adbea..c4a228a 100644 --- a/src/Examples/FontAwesome5.NetCore.Example/App.xaml +++ b/src/Examples/FontAwesome5.NetCore.Example/App.xaml @@ -4,6 +4,10 @@ xmlns:local="clr-namespace:FontAwesome5.NetCore30" StartupUri="MainWindow.xaml"> - - + + + + + + diff --git a/src/Examples/FontAwesome5.NetCore.Example/MainWindow.xaml b/src/Examples/FontAwesome5.NetCore.Example/MainWindow.xaml index 5182c89..621d8c0 100644 --- a/src/Examples/FontAwesome5.NetCore.Example/MainWindow.xaml +++ b/src/Examples/FontAwesome5.NetCore.Example/MainWindow.xaml @@ -5,112 +5,114 @@ 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.UWP.Example/App.xaml b/src/Examples/FontAwesome5.UWP.Example/App.xaml index 781f3f2..be11834 100644 --- a/src/Examples/FontAwesome5.UWP.Example/App.xaml +++ b/src/Examples/FontAwesome5.UWP.Example/App.xaml @@ -3,5 +3,11 @@ 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/FontAwesome5Dictionary.xaml b/src/FontAwesome5.Net/FontAwesome5Dictionary.xaml new file mode 100644 index 0000000..5d995e7 --- /dev/null +++ b/src/FontAwesome5.Net/FontAwesome5Dictionary.xaml @@ -0,0 +1,6 @@ + + pack://application:,,,/FontAwesome5.Net;component/./Fonts/#Font Awesome 5 Free Regular + pack://application:,,,/FontAwesome5.Net;component/./Fonts/#Font Awesome 5 Free Solid + pack://application:,,,/FontAwesome5.Net;component/./Fonts/#Font Awesome 5 Brands Regular + \ No newline at end of file diff --git a/src/FontAwesome5.Net/Fonts.cs b/src/FontAwesome5.Net/Fonts.cs index 23887f6..4c542a6 100644 --- a/src/FontAwesome5.Net/Fonts.cs +++ b/src/FontAwesome5.Net/Fonts.cs @@ -8,35 +8,91 @@ namespace FontAwesome5 { + /// + /// Provides FontFamilies and Typefaces of FontAwesome5. + /// + public static class Fonts + { /// - /// Provides FontFamilies and Typefaces of FontAwesome5. + /// FontAwesome5 Regular FontFamily /// - public static class Fonts + public static FontFamily RegularFontFamily { - /// - /// 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"); + set { _regularFontFamily = value; } + get + { + if (_regularFontFamily != null) + { + return _regularFontFamily; + } + else if (Application.Current.Resources["FontAwesome5Regular"] is FontFamily resource) + { + return resource; + } - /// - /// 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); + return RegularFontFamilyResource; + } } + private static FontFamily _regularFontFamily; + public static FontFamily RegularFontFamilyResource = new FontFamily(new Uri("pack://application:,,,/FontAwesome5.Net;component/"), "./Fonts/#Font Awesome 5 Free Regular"); + + /// + /// FontAwesome5 Solid FontFamily + /// + public static FontFamily SolidFontFamily + { + set { _solidFontFamily = value; } + get + { + if (_solidFontFamily != null) + { + return _solidFontFamily; + } + else if (Application.Current.Resources["FontAwesome5Solid"] is FontFamily resource) + { + return resource; + } + + return SolidFontFamilyResource; + } + } + private static FontFamily _solidFontFamily; + public static FontFamily SolidFontFamilyResource = new FontFamily(new Uri("pack://application:,,,/FontAwesome5.Net;component/"), "./Fonts/#Font Awesome 5 Free Solid"); + + /// + /// FontAwesome5 Brands FontFamily + /// + public static FontFamily BrandsFontFamily + { + set { _brandsFontFamily = value; } + get + { + if (_brandsFontFamily != null) + { + return _brandsFontFamily; + } + else if (Application.Current.Resources["FontAwesome5Brands"] is FontFamily resource) + { + return resource; + } + + return BrandsFontFamilyResource; + } + } + private static FontFamily _brandsFontFamily; + public static FontFamily BrandsFontFamilyResource = new FontFamily(new Uri("pack://application:,,,/FontAwesome5.Net;component/"), "./Fonts/#Font Awesome 5 Brands Regular"); + + /// + /// 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/FontAwesome5.UWP.csproj b/src/FontAwesome5.UWP/FontAwesome5.UWP.csproj index 812927b..34ac83a 100644 --- a/src/FontAwesome5.UWP/FontAwesome5.UWP.csproj +++ b/src/FontAwesome5.UWP/FontAwesome5.UWP.csproj @@ -160,6 +160,12 @@ + + + MSBuild:Compile + Designer + + 14.0 diff --git a/src/FontAwesome5.UWP/FontAwesome5Dictionary.xaml b/src/FontAwesome5.UWP/FontAwesome5Dictionary.xaml new file mode 100644 index 0000000..8b20001 --- /dev/null +++ b/src/FontAwesome5.UWP/FontAwesome5Dictionary.xaml @@ -0,0 +1,6 @@ + + ms-appx:///FontAwesome5.UWP/Fonts/Font Awesome 5 Free-Regular-400.otf#Font Awesome 5 Free + ms-appx:///FontAwesome5.UWP/Fonts/Font Awesome 5 Free-Solid-900.otf#Font Awesome 5 Free + ms-appx:///FontAwesome5.UWP/Fonts/Font Awesome 5 Brands-Regular-400.otf#Font Awesome 5 Brands + \ No newline at end of file diff --git a/src/FontAwesome5.UWP/Fonts.cs b/src/FontAwesome5.UWP/Fonts.cs index 0ac4b5e..ee1a4fc 100644 --- a/src/FontAwesome5.UWP/Fonts.cs +++ b/src/FontAwesome5.UWP/Fonts.cs @@ -1,23 +1,81 @@ -using Windows.UI.Xaml.Media; +using Windows.UI.Xaml; +using Windows.UI.Xaml.Media; namespace FontAwesome5 { + /// + /// Provides FontFamilies and Typefaces of FontAwesome5. + /// + public static class Fonts + { /// - /// Provides FontFamilies and Typefaces of FontAwesome5. + /// FontAwesome5 Regular FontFamily /// - public static class Fonts + public static FontFamily RegularFontFamily { - /// - /// 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"); + set { _regularFontFamily = value; } + get + { + if (_regularFontFamily != null) + { + return _regularFontFamily; + } + else if (Application.Current.Resources["FontAwesome5Regular"] is FontFamily resource) + { + return resource; + } + + return RegularFontFamilyResource; + } + } + private static FontFamily _regularFontFamily; + public static FontFamily RegularFontFamilyResource = 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 + { + set { _solidFontFamily = value; } + get + { + if (_solidFontFamily != null) + { + return _solidFontFamily; + } + else if (Application.Current.Resources["FontAwesome5Solid"] is FontFamily resource) + { + return resource; + } + + return SolidFontFamilyResource; + } } + private static FontFamily _solidFontFamily; + public static FontFamily SolidFontFamilyResource = new FontFamily("ms-appx:///FontAwesome5.UWP/Fonts/Font Awesome 5 Free-Solid-900.otf#Font Awesome 5 Free"); + + /// + /// FontAwesome5 Brands FontFamily + /// + public static FontFamily BrandsFontFamily + { + set { _brandsFontFamily = value; } + get + { + if (_brandsFontFamily != null) + { + return _brandsFontFamily; + } + else if (Application.Current.Resources["FontAwesome5Brands"] is FontFamily resource) + { + return resource; + } + + return BrandsFontFamilyResource; + } + } + private static FontFamily _brandsFontFamily; + public static FontFamily BrandsFontFamilyResource = 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..3a14530 100644 --- a/src/NuGet/FontAwesome5.nuspec +++ b/src/NuGet/FontAwesome5.nuspec @@ -1,79 +1,94 @@  - - 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 @@ - From 26ad37473efb80442064859010ec087603188dc1 Mon Sep 17 00:00:00 2001 From: Martin Topfstedt Date: Wed, 14 Jul 2021 21:18:55 +0200 Subject: [PATCH 2/4] fixed build --- .../FontAwesome5.NetCore.Example.csproj | 2 +- src/NuGet/FontAwesome5.nuspec | 5 ----- 2 files changed, 1 insertion(+), 6 deletions(-) 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/NuGet/FontAwesome5.nuspec b/src/NuGet/FontAwesome5.nuspec index 3a14530..38fa1db 100644 --- a/src/NuGet/FontAwesome5.nuspec +++ b/src/NuGet/FontAwesome5.nuspec @@ -29,11 +29,6 @@ - - - - - From b2266ca328e7506ec7d2937311cb00682ae488a1 Mon Sep 17 00:00:00 2001 From: Martin Topfstedt Date: Thu, 15 Jul 2021 20:44:00 +0200 Subject: [PATCH 3/4] updated to version 2.1.4 --- CHANGELOG.md | 4 + README.md | 17 +- .../MainWindow.xaml | 181 ++++++++---------- .../ViewModels/MainWindowViewModel.cs | 4 - .../FontAwesome5.NetCore.Example/App.xaml | 6 +- .../FodyWeavers.xsd | 10 + .../MainWindow.xaml | 38 ++-- .../MainWindow.xaml.cs | 19 +- .../ViewModels/MainWindowViewModel.cs | 75 ++++---- .../FontAwesome5.UWP.Example/App.xaml | 6 +- .../FontAwesome5Dictionary.xaml | 6 - src/FontAwesome5.Net/Fonts.cs | 106 +++++----- src/FontAwesome5.UWP/FontAwesome5.UWP.csproj | 6 - .../FontAwesome5Dictionary.xaml | 6 - src/FontAwesome5.UWP/Fonts.cs | 71 +------ 15 files changed, 219 insertions(+), 336 deletions(-) delete mode 100644 src/FontAwesome5.Net/FontAwesome5Dictionary.xaml delete mode 100644 src/FontAwesome5.UWP/FontAwesome5Dictionary.xaml diff --git a/CHANGELOG.md b/CHANGELOG.md index 8ae5d00..3316e57 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +# 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 diff --git a/README.md b/README.md index bf8fc19..768b7af 100644 --- a/README.md +++ b/README.md @@ -13,22 +13,7 @@ Font Awesome: https://github.com/FortAwesome/Font-Awesome #### Installation 1. Install the FontAwesome5 NuGet Package: ```Install-Package FontAwesome5``` -2. Add the FontAwesome5 ReosurceDictionary to your App.xaml -``` - - - - - - - - - -``` + #### Usage XAML 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 c4a228a..a59f229 100644 --- a/src/Examples/FontAwesome5.NetCore.Example/App.xaml +++ b/src/Examples/FontAwesome5.NetCore.Example/App.xaml @@ -4,10 +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/MainWindow.xaml b/src/Examples/FontAwesome5.NetCore.Example/MainWindow.xaml index 621d8c0..8d527e9 100644 --- a/src/Examples/FontAwesome5.NetCore.Example/MainWindow.xaml +++ b/src/Examples/FontAwesome5.NetCore.Example/MainWindow.xaml @@ -11,7 +11,8 @@ - + + @@ -68,8 +69,7 @@ - - + @@ -80,39 +80,23 @@ - - - - - - - - - - - - - - - - - - - - - + - + - + - + + + + + 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 be11834..a5518f4 100644 --- a/src/Examples/FontAwesome5.UWP.Example/App.xaml +++ b/src/Examples/FontAwesome5.UWP.Example/App.xaml @@ -4,10 +4,6 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="using:FontAwesome5.UWP.Example"> - - - - - + diff --git a/src/FontAwesome5.Net/FontAwesome5Dictionary.xaml b/src/FontAwesome5.Net/FontAwesome5Dictionary.xaml deleted file mode 100644 index 5d995e7..0000000 --- a/src/FontAwesome5.Net/FontAwesome5Dictionary.xaml +++ /dev/null @@ -1,6 +0,0 @@ - - pack://application:,,,/FontAwesome5.Net;component/./Fonts/#Font Awesome 5 Free Regular - pack://application:,,,/FontAwesome5.Net;component/./Fonts/#Font Awesome 5 Free Solid - pack://application:,,,/FontAwesome5.Net;component/./Fonts/#Font Awesome 5 Brands Regular - \ No newline at end of file diff --git a/src/FontAwesome5.Net/Fonts.cs b/src/FontAwesome5.Net/Fonts.cs index 4c542a6..39f497b 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; @@ -13,74 +16,67 @@ namespace FontAwesome5 /// public static class Fonts { - /// - /// FontAwesome5 Regular FontFamily - /// - public static FontFamily RegularFontFamily + static Fonts() { - set { _regularFontFamily = value; } - get - { - if (_regularFontFamily != null) - { - return _regularFontFamily; - } - else if (Application.Current.Resources["FontAwesome5Regular"] is FontFamily resource) - { - return resource; - } + _resManager = new ResourceManager("FontAwesome5.Net.g", Assembly.GetExecutingAssembly()); - return RegularFontFamilyResource; - } + var path = Path.GetTempPath(); + SaveFontFilesToDirectory(path); + LoadFromDirectory(path); } - private static FontFamily _regularFontFamily; - public static FontFamily RegularFontFamilyResource = new FontFamily(new Uri("pack://application:,,,/FontAwesome5.Net;component/"), "./Fonts/#Font Awesome 5 Free Regular"); - /// - /// FontAwesome5 Solid FontFamily - /// - public static FontFamily SolidFontFamily + public static void LoadFromResource() { - set { _solidFontFamily = value; } - get - { - if (_solidFontFamily != null) - { - return _solidFontFamily; - } - else if (Application.Current.Resources["FontAwesome5Solid"] is FontFamily resource) - { - return resource; - } + 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"); + } - return SolidFontFamilyResource; - } + 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"); } - private static FontFamily _solidFontFamily; - public static FontFamily SolidFontFamilyResource = new FontFamily(new Uri("pack://application:,,,/FontAwesome5.Net;component/"), "./Fonts/#Font Awesome 5 Free Solid"); - /// - /// FontAwesome5 Brands FontFamily - /// - public static FontFamily BrandsFontFamily + public static void SaveFontFilesToDirectory(string path) { - set { _brandsFontFamily = value; } - get + WriteResourceToFile($"Fonts/Font Awesome 5 Free-Solid-900.otf", Path.Combine(path, "Font Awesome 5 Free-Solid-900.otf")); + WriteResourceToFile($"Fonts/Font Awesome 5 Free-Regular-400.otf", Path.Combine(path, "Font Awesome 5 Free-Regular-400.otf")); + WriteResourceToFile($"Fonts/Font Awesome 5 Brands-Regular-400.otf", Path.Combine(path, "Font Awesome 5 Brands-Regular-400.otf")); + } + + private static void WriteResourceToFile(string resourceName, string fileName) + { + if (File.Exists(fileName)) { - if (_brandsFontFamily != null) - { - return _brandsFontFamily; - } - else if (Application.Current.Resources["FontAwesome5Brands"] is FontFamily resource) + return; + } + + using (var res = _resManager.GetStream(Uri.EscapeUriString(resourceName).ToLowerInvariant())) + { + using (var file = new FileStream(fileName, FileMode.Create, FileAccess.Write)) { - return resource; + res.CopyTo(file); } - - return BrandsFontFamilyResource; } } - private static FontFamily _brandsFontFamily; - public static FontFamily BrandsFontFamilyResource = new FontFamily(new Uri("pack://application:,,,/FontAwesome5.Net;component/"), "./Fonts/#Font Awesome 5 Brands Regular"); + + /// + /// FontAwesome5 Regular FontFamily + /// + public static FontFamily RegularFontFamily; + + /// + /// FontAwesome5 Solid FontFamily + /// + public static FontFamily SolidFontFamily; + + /// + /// FontAwesome5 Brands FontFamily + /// + public static FontFamily BrandsFontFamily; + /// /// FontAwesome5 Regular Typeface @@ -94,5 +90,7 @@ public static FontFamily BrandsFontFamily /// FontAwesome5 Brands Typeface /// public static Typeface BrandsTypeface => new Typeface(BrandsFontFamily, FontStyles.Normal, FontWeights.Normal, FontStretches.Normal); + + private static readonly ResourceManager _resManager; } } diff --git a/src/FontAwesome5.UWP/FontAwesome5.UWP.csproj b/src/FontAwesome5.UWP/FontAwesome5.UWP.csproj index 34ac83a..812927b 100644 --- a/src/FontAwesome5.UWP/FontAwesome5.UWP.csproj +++ b/src/FontAwesome5.UWP/FontAwesome5.UWP.csproj @@ -160,12 +160,6 @@ - - - MSBuild:Compile - Designer - - 14.0 diff --git a/src/FontAwesome5.UWP/FontAwesome5Dictionary.xaml b/src/FontAwesome5.UWP/FontAwesome5Dictionary.xaml deleted file mode 100644 index 8b20001..0000000 --- a/src/FontAwesome5.UWP/FontAwesome5Dictionary.xaml +++ /dev/null @@ -1,6 +0,0 @@ - - ms-appx:///FontAwesome5.UWP/Fonts/Font Awesome 5 Free-Regular-400.otf#Font Awesome 5 Free - ms-appx:///FontAwesome5.UWP/Fonts/Font Awesome 5 Free-Solid-900.otf#Font Awesome 5 Free - ms-appx:///FontAwesome5.UWP/Fonts/Font Awesome 5 Brands-Regular-400.otf#Font Awesome 5 Brands - \ No newline at end of file diff --git a/src/FontAwesome5.UWP/Fonts.cs b/src/FontAwesome5.UWP/Fonts.cs index ee1a4fc..f0b67fd 100644 --- a/src/FontAwesome5.UWP/Fonts.cs +++ b/src/FontAwesome5.UWP/Fonts.cs @@ -1,4 +1,8 @@ -using Windows.UI.Xaml; +using System; +using System.IO; +using System.Reflection; + +using Windows.UI.Xaml; using Windows.UI.Xaml.Media; namespace FontAwesome5 @@ -11,71 +15,16 @@ public static class Fonts /// /// FontAwesome5 Regular FontFamily /// - public static FontFamily RegularFontFamily - { - set { _regularFontFamily = value; } - get - { - if (_regularFontFamily != null) - { - return _regularFontFamily; - } - else if (Application.Current.Resources["FontAwesome5Regular"] is FontFamily resource) - { - return resource; - } - - return RegularFontFamilyResource; - } - } - private static FontFamily _regularFontFamily; - public static FontFamily RegularFontFamilyResource = new FontFamily("ms-appx:///FontAwesome5.UWP/Fonts/Font Awesome 5 Free-Regular-400.otf#Font Awesome 5 Free"); - + 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 - { - set { _solidFontFamily = value; } - get - { - if (_solidFontFamily != null) - { - return _solidFontFamily; - } - else if (Application.Current.Resources["FontAwesome5Solid"] is FontFamily resource) - { - return resource; - } - - return SolidFontFamilyResource; - } - } - private static FontFamily _solidFontFamily; - public static FontFamily SolidFontFamilyResource = new FontFamily("ms-appx:///FontAwesome5.UWP/Fonts/Font Awesome 5 Free-Solid-900.otf#Font Awesome 5 Free"); - + public static 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 FontFamily BrandsFontFamily - { - set { _brandsFontFamily = value; } - get - { - if (_brandsFontFamily != null) - { - return _brandsFontFamily; - } - else if (Application.Current.Resources["FontAwesome5Brands"] is FontFamily resource) - { - return resource; - } - - return BrandsFontFamilyResource; - } - } - private static FontFamily _brandsFontFamily; - public static FontFamily BrandsFontFamilyResource = 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"); } } From 121c19328097e91b4e2347214656e8b04f97bc18 Mon Sep 17 00:00:00 2001 From: Martin Topfstedt Date: Thu, 15 Jul 2021 20:46:58 +0200 Subject: [PATCH 4/4] improved fonts class to not keep resource manager instance --- src/FontAwesome5.Net/Fonts.cs | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/FontAwesome5.Net/Fonts.cs b/src/FontAwesome5.Net/Fonts.cs index 39f497b..a43aac2 100644 --- a/src/FontAwesome5.Net/Fonts.cs +++ b/src/FontAwesome5.Net/Fonts.cs @@ -18,8 +18,6 @@ public static class Fonts { static Fonts() { - _resManager = new ResourceManager("FontAwesome5.Net.g", Assembly.GetExecutingAssembly()); - var path = Path.GetTempPath(); SaveFontFilesToDirectory(path); LoadFromDirectory(path); @@ -41,19 +39,20 @@ public static void LoadFromDirectory(string path) public static void SaveFontFilesToDirectory(string path) { - WriteResourceToFile($"Fonts/Font Awesome 5 Free-Solid-900.otf", Path.Combine(path, "Font Awesome 5 Free-Solid-900.otf")); - WriteResourceToFile($"Fonts/Font Awesome 5 Free-Regular-400.otf", Path.Combine(path, "Font Awesome 5 Free-Regular-400.otf")); - WriteResourceToFile($"Fonts/Font Awesome 5 Brands-Regular-400.otf", Path.Combine(path, "Font Awesome 5 Brands-Regular-400.otf")); + 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(string resourceName, string fileName) + 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 res = resManager.GetStream(Uri.EscapeUriString(resourceName).ToLowerInvariant())) { using (var file = new FileStream(fileName, FileMode.Create, FileAccess.Write)) { @@ -90,7 +89,5 @@ private static void WriteResourceToFile(string resourceName, string fileName) /// FontAwesome5 Brands Typeface /// public static Typeface BrandsTypeface => new Typeface(BrandsFontFamily, FontStyles.Normal, FontWeights.Normal, FontStretches.Normal); - - private static readonly ResourceManager _resManager; } }