Skip to content

Commit 9d71d32

Browse files
authored
[Windows] Optimize getting default font size and font family values (#22782)
* Typos * Font size and font family Optimizations * Remove not working code
1 parent 84a9f80 commit 9d71d32

3 files changed

Lines changed: 26 additions & 8 deletions

File tree

src/Core/src/Fonts/FontManager.Windows.cs

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
#nullable enable
2-
using System;
1+
using System;
32
using System.Collections.Concurrent;
43
using System.Collections.Generic;
54
using System.IO;
65
using Microsoft.Extensions.Logging;
76
using Microsoft.Graphics.Canvas.Text;
87
using Microsoft.Maui.ApplicationModel;
98
using Microsoft.Maui.Storage;
9+
using Microsoft.UI.Xaml;
1010
using Microsoft.UI.Xaml.Media;
1111

1212
namespace Microsoft.Maui
@@ -27,6 +27,12 @@ public class FontManager : IFontManager
2727
readonly IFontRegistrar _fontRegistrar;
2828
readonly IServiceProvider? _serviceProvider;
2929

30+
/// <remarks>Value is cached to avoid the performance hit of accessing <see cref="ResourceDictionary"/> many times.</remarks>
31+
FontFamily? _defaultFontFamily;
32+
33+
/// <remarks>Value is cached to avoid the performance hit of accessing <see cref="ResourceDictionary"/> many times.</remarks>
34+
double? _defaultFontSize;
35+
3036
/// <summary>
3137
/// Creates a new <see cref="EmbeddedFontLoader"/> instance.
3238
/// </summary>
@@ -40,12 +46,24 @@ public FontManager(IFontRegistrar fontRegistrar, IServiceProvider? serviceProvid
4046
}
4147

4248
/// <inheritdoc/>
43-
public FontFamily DefaultFontFamily =>
44-
(FontFamily)UI.Xaml.Application.Current.Resources[SystemFontFamily];
49+
public FontFamily DefaultFontFamily
50+
{
51+
get
52+
{
53+
_defaultFontFamily ??= (FontFamily)Application.Current.Resources[SystemFontFamily];
54+
return _defaultFontFamily;
55+
}
56+
}
4557

4658
/// <inheritdoc/>
47-
public double DefaultFontSize =>
48-
(double)UI.Xaml.Application.Current.Resources[SystemFontSize];
59+
public double DefaultFontSize
60+
{
61+
get
62+
{
63+
_defaultFontSize ??= (double)Application.Current.Resources[SystemFontSize];
64+
return _defaultFontSize.Value;
65+
}
66+
}
4967

5068
/// <inheritdoc/>
5169
public FontFamily GetFontFamily(Font font)

src/Essentials/src/AppInfo/AppInfo.shared.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ public enum AppPackagingModel
130130
/// <summary>The app is packaged and can be distributed through an MSIX or the store.</summary>
131131
Packaged,
132132

133-
/// <summary>The app is unpcakged and can be distributed as a collection of executable files.</summary>
133+
/// <summary>The app is unpackaged and can be distributed as a collection of executable files.</summary>
134134
Unpackaged,
135135
}
136136
}

src/Essentials/src/AppInfo/AppInfo.uwp.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class AppInfoImplementation : IAppInfo
1818
readonly ActiveWindowTracker _activeWindowTracker;
1919

2020
/// <summary>
21-
/// Intializes a new <see cref="AppInfoImplementation"/> object with default values.
21+
/// Initializes a new <see cref="AppInfoImplementation"/> object with default values.
2222
/// </summary>
2323
public AppInfoImplementation()
2424
{

0 commit comments

Comments
 (0)