Skip to content

Commit

Permalink
fix(fonts): [Android] Adjust backward compatibilty for explicit Andro…
Browse files Browse the repository at this point in the history
…idAssets-included fonts
  • Loading branch information
jeromelaban committed Jan 20, 2023
1 parent 0614768 commit 98acad0
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/Uno.UI/UI/Xaml/Extensions/FontHelper.Android.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ internal partial class FontHelper
// with UWP. Keep this behavior for backward compatibility.
var legacySource = source.TrimStart("/assets/", StringComparison.OrdinalIgnoreCase);

if (!TryLoadFromPath(style, legacySource, out typeface))
// The path for AndroidAssets is not encoded, unlike assets processed by the RetargetAssets tool.
if (!TryLoadFromPath(style, legacySource, out typeface, encodePath: false))
{
throw new InvalidOperationException($"Unable to find [{fontFamily.Source}] from the application's assets.");
}
Expand Down Expand Up @@ -99,7 +100,7 @@ internal partial class FontHelper
}
}

private static bool TryLoadFromPath(TypefaceStyle style, string source, out Typeface? typeface)
private static bool TryLoadFromPath(TypefaceStyle style, string source, out Typeface? typeface, bool encodePath = true)
{
source = FontFamilyHelper.RemoveHashFamilyName(source);

Expand All @@ -108,7 +109,9 @@ private static bool TryLoadFromPath(TypefaceStyle style, string source, out Type
typeof(FontHelper).Log().Debug($"Searching for font as asset [{source}]");
}

var encodedSource = AndroidResourceNameEncoder.EncodeFileSystemPath(source, prefix: "");
var encodedSource = encodePath
? AndroidResourceNameEncoder.EncodeFileSystemPath(source, prefix: "")
: source;

// We need to lookup assets manually, as assets are stored this way by android, but windows
// is case insensitive.
Expand Down

0 comments on commit 98acad0

Please sign in to comment.