From 28fdc7e14a4b48561805b10a47f651d413a79f51 Mon Sep 17 00:00:00 2001 From: Matthew Leibowitz Date: Fri, 23 Feb 2024 17:59:37 +0200 Subject: [PATCH] Support the unpackaged format for font loading (#20790) --- .../FontImageSourceService.Windows.cs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/Core/src/ImageSources/FontImageSourceService/FontImageSourceService.Windows.cs b/src/Core/src/ImageSources/FontImageSourceService/FontImageSourceService.Windows.cs index 56567b43cbf7..91dbff0e08cc 100644 --- a/src/Core/src/ImageSources/FontImageSourceService/FontImageSourceService.Windows.cs +++ b/src/Core/src/ImageSources/FontImageSourceService/FontImageSourceService.Windows.cs @@ -6,8 +6,10 @@ using Microsoft.Graphics.Canvas; using Microsoft.Graphics.Canvas.Text; using Microsoft.Graphics.Canvas.UI.Xaml; +using Microsoft.Maui.ApplicationModel; using Microsoft.Maui.Devices; using Microsoft.Maui.Graphics; +using Microsoft.Maui.Storage; using WImageSource = Microsoft.UI.Xaml.Media.ImageSource; namespace Microsoft.Maui @@ -122,6 +124,18 @@ string GetFontSource(IFontImageSource imageSource) } } + // unpackaged apps can't load files using packaged schemes + if (!AppInfoUtils.IsPackagedApp) + { + var fontUri = new Uri(fontSource, UriKind.RelativeOrAbsolute); + + var path = fontUri.AbsolutePath.TrimStart('/'); + if (FileSystemUtils.TryGetAppPackageFileUri(path, out var uri)) + { + fontSource = uri + fontUri.Fragment; + } + } + return fontSource; } }