Skip to content

Commit

Permalink
Support the unpackaged format for font loading (#20790)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattleibow authored Feb 23, 2024
1 parent 0de4f22 commit 28fdc7e
Showing 1 changed file with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
}
Expand Down

0 comments on commit 28fdc7e

Please sign in to comment.