Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Windows] Optimize getting default font size and font family values #22782

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 24 additions & 6 deletions src/Core/src/Fonts/FontManager.Windows.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#nullable enable
using System;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.IO;
using Microsoft.Extensions.Logging;
using Microsoft.Graphics.Canvas.Text;
using Microsoft.Maui.ApplicationModel;
using Microsoft.Maui.Storage;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Media;

namespace Microsoft.Maui
Expand All @@ -27,6 +27,12 @@ public class FontManager : IFontManager
readonly IFontRegistrar _fontRegistrar;
readonly IServiceProvider? _serviceProvider;

/// <remarks>Value is cached to avoid the performance hit of accessing <see cref="ResourceDictionary"/> many times.</remarks>
FontFamily? _defaultFontFamily;

mattleibow marked this conversation as resolved.
Show resolved Hide resolved
/// <remarks>Value is cached to avoid the performance hit of accessing <see cref="ResourceDictionary"/> many times.</remarks>
double? _defaultFontSize;

/// <summary>
/// Creates a new <see cref="EmbeddedFontLoader"/> instance.
/// </summary>
Expand All @@ -40,12 +46,24 @@ public FontManager(IFontRegistrar fontRegistrar, IServiceProvider? serviceProvid
}

/// <inheritdoc/>
public FontFamily DefaultFontFamily =>
(FontFamily)UI.Xaml.Application.Current.Resources[SystemFontFamily];
public FontFamily DefaultFontFamily
{
get
{
_defaultFontFamily ??= (FontFamily)Application.Current.Resources[SystemFontFamily];
return _defaultFontFamily;
}
}

/// <inheritdoc/>
public double DefaultFontSize =>
(double)UI.Xaml.Application.Current.Resources[SystemFontSize];
public double DefaultFontSize
{
get
{
_defaultFontSize ??= (double)Application.Current.Resources[SystemFontSize];
return _defaultFontSize.Value;
}
}

/// <inheritdoc/>
public FontFamily GetFontFamily(Font font)
Expand Down
2 changes: 1 addition & 1 deletion src/Essentials/src/AppInfo/AppInfo.shared.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public enum AppPackagingModel
/// <summary>The app is packaged and can be distributed through an MSIX or the store.</summary>
Packaged,

/// <summary>The app is unpcakged and can be distributed as a collection of executable files.</summary>
/// <summary>The app is unpackaged and can be distributed as a collection of executable files.</summary>
Unpackaged,
}
}
2 changes: 1 addition & 1 deletion src/Essentials/src/AppInfo/AppInfo.uwp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class AppInfoImplementation : IAppInfo
readonly ActiveWindowTracker _activeWindowTracker;

/// <summary>
/// Intializes a new <see cref="AppInfoImplementation"/> object with default values.
/// Initializes a new <see cref="AppInfoImplementation"/> object with default values.
/// </summary>
public AppInfoImplementation()
{
Expand Down
Loading