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

[Android] Allow to use system fonts #15010

Merged
merged 5 commits into from
May 19, 2023
Merged

[Android] Allow to use system fonts #15010

merged 5 commits into from
May 19, 2023

Conversation

jsuarezruiz
Copy link
Contributor

@jsuarezruiz jsuarezruiz commented May 10, 2023

Description of Change

Allow to use Android system fonts directly.

<VerticalStackLayout VerticalOptions="Center">
    <Label
        Text="Hello world" />
    <Label
        FontFamily="monospace"
        Text="Hello world" />
    <Label
        FontFamily="serif"
        Text="Hello world" />
</VerticalStackLayout>

Screenshot_1683643513
image

Issues Fixed

Fixes #11422

@jsuarezruiz jsuarezruiz added t/bug Something isn't working platform/android 🤖 area-fonts Custom fonts and Font related API's labels May 10, 2023
@jsuarezruiz jsuarezruiz requested a review from mattleibow May 11, 2023 07:52
@github-actions
Copy link
Contributor

Thank you for your pull request. We are auto-formatting your source code to follow our code guidelines.

@mattleibow mattleibow merged commit 46e02ac into main May 19, 2023
@mattleibow mattleibow deleted the fix-11422 branch May 19, 2023 07:17
rmarinho pushed a commit that referenced this pull request May 30, 2023
@jonathanpeppers
Copy link
Member

jonathanpeppers commented Jun 19, 2023

@jsuarezruiz these changes cause an exception to be thrown several times on startup in an app I've been testing:

06-19 15:31:19.834  5706  5706 I DOTNET  : Unable to load font 'sans-serif-medium' from assets.
06-19 15:31:19.840  5706  5706 I DOTNET  : Unable to load font 'sans-serif-medium.ttf' from assets.
06-19 15:31:19.840  5706  5706 I DOTNET  : Unable to load font 'Fonts/sans-serif-medium.ttf' from assets.
06-19 15:31:19.841  5706  5706 I DOTNET  : Unable to load font 'fonts/sans-serif-medium.ttf' from assets.
06-19 15:31:19.841  5706  5706 I DOTNET  : Unable to load font 'sans-serif-medium.otf' from assets.
06-19 15:31:19.842  5706  5706 I DOTNET  : Unable to load font 'Fonts/sans-serif-medium.otf' from assets.
06-19 15:31:19.842  5706  5706 I DOTNET  : Unable to load font 'fonts/sans-serif-medium.otf' from assets.

if (warning)
_serviceProvider?.CreateLogger<FontManager>()?.LogWarning(ex, "Unable to load font '{Font}' from assets.", fontfamily);

(NOTE: I changed the above to Console.WriteLine() and fixed the missing $ locally)

On a Pixel 5, dotnet-trace shows a decent amount of time doing this:

64.98ms microsoft.maui!Microsoft.Maui.Handlers.LabelHandler.MapFont(Microsoft.Maui.Handlers.ILabelHandler,Microsoft.Maui.ILabel)
38.92ms microsoft.maui!Microsoft.Maui.FontManager.LoadTypefaceFromAsset(string,bool)

I open the Shell flyout in this app to see these:

https://github.com/supershopping/ShellFlyoutLagging

Is there something going wrong here?

@jsuarezruiz
Copy link
Contributor Author

@jsuarezruiz these changes cause an exception to be thrown several times on startup in an app I've been testing:

06-19 15:31:19.834  5706  5706 I DOTNET  : Unable to load font 'sans-serif-medium' from assets.
06-19 15:31:19.840  5706  5706 I DOTNET  : Unable to load font 'sans-serif-medium.ttf' from assets.
06-19 15:31:19.840  5706  5706 I DOTNET  : Unable to load font 'Fonts/sans-serif-medium.ttf' from assets.
06-19 15:31:19.841  5706  5706 I DOTNET  : Unable to load font 'fonts/sans-serif-medium.ttf' from assets.
06-19 15:31:19.841  5706  5706 I DOTNET  : Unable to load font 'sans-serif-medium.otf' from assets.
06-19 15:31:19.842  5706  5706 I DOTNET  : Unable to load font 'Fonts/sans-serif-medium.otf' from assets.
06-19 15:31:19.842  5706  5706 I DOTNET  : Unable to load font 'fonts/sans-serif-medium.otf' from assets.

if (warning)
_serviceProvider?.CreateLogger<FontManager>()?.LogWarning(ex, "Unable to load font '{Font}' from assets.", fontfamily);

(NOTE: I changed the above to Console.WriteLine() and fixed the missing $ locally)

On a Pixel 5, dotnet-trace shows a decent amount of time doing this:

64.98ms microsoft.maui!Microsoft.Maui.Handlers.LabelHandler.MapFont(Microsoft.Maui.Handlers.ILabelHandler,Microsoft.Maui.ILabel)
38.92ms microsoft.maui!Microsoft.Maui.FontManager.LoadTypefaceFromAsset(string,bool)

I open the Shell flyout in this app to see these:

https://github.com/supershopping/ShellFlyoutLagging

Is there something going wrong here?

I think you found this one: #13239
Searching the possible origin, could be:

https://github.com/dotnet/maui/blob/main/src/Controls/src/Core/Platform/Android/BottomNavigationViewUtils.cs#L218
https://github.com/dotnet/maui/blob/main/src/Controls/src/Core/Compatibility/Handlers/Shell/Android/ShellItemRenderer.cs#L248

@jonathanpeppers
Copy link
Member

Ok, I think we should add a couple more cases: #15759

It seems to help performance to avoid these lookups.

@github-actions github-actions bot locked and limited conversation to collaborators Dec 10, 2023
@samhouts samhouts added the fixed-in-8.0.0-preview.5.8529 Look for this fix in 8.0.0-preview.5.8529! label Aug 2, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-fonts Custom fonts and Font related API's fixed-in-8.0.0-preview.5.8529 Look for this fix in 8.0.0-preview.5.8529! platform/android 🤖 t/bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unable to load font 'monospace'
5 participants