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

[Uno WASM] Setting font crashes runtime #1784

Open
mikernet opened this issue Jan 27, 2025 · 4 comments
Open

[Uno WASM] Setting font crashes runtime #1784

mikernet opened this issue Jan 27, 2025 · 4 comments

Comments

@mikernet
Copy link

mikernet commented Jan 27, 2025

Describe the bug
Changing the font from the default crashes the runtime when a chart is first drawn.

Image

Image

To Reproduce
Using:

    private static async Task<SKTypeface> LoadTypefaceFromApplicationUriAsync(Uri uri)
    {
        var file = await StorageFile.GetFileFromApplicationUriAsync(uri);
        var stream = await file.OpenStreamForReadAsync();
        return SKTypeface.FromStream(stream);
    }

    // App.xaml.cs OnLauched()

    var fontUri = new Uri(RootFrame.FontFamily.Source, UriKind.Absolute);
    DefaultSKTypeface = await LoadTypefaceFromApplicationUriAsync(fontUri);

The above code successfully loads the Open Sans font that is the default on Uno WASM into DefaultSKTypeface, but if it is used anywhere in LiveCharts, such as setting it on an axis label or setting it globally like:

    LiveCharts.Configure(config => {
        config.HasGlobalSKTypeface(DefaultSKTypeface);
    });

Then the runtime crashes as per above as soon as a page with a chart is shown. The code above works fine on WinUI and Desktop targets. Commenting out the line that sets the typeface stops the app from crashing and showing any of the errors indicated above in the console.

Expected behavior
A clear and concise description of what you expected to happen.

Desktop (please complete the following information):

  • OS: Windows 11
  • Browser: Edge

Additional context
Tested with both rc4.5 and rc5.1.

@mikernet
Copy link
Author

I also tried embedding the Arial font into the project and using that with the same result.

@mikernet
Copy link
Author

Doing config.HasGlobalSKTypeface(SKTypeface.Default); (which sets it to Noto Mono) also causes it to crash.

@mikernet
Copy link
Author

The problem is here:

var shaper = paint.Typeface is not null ? new SKShaper(paint.Typeface) : null;

It crashes when it tries to load the harfbuzz library to create the SKShaper. Not sure what the fix is though.

@mikernet
Copy link
Author

mikernet commented Jan 27, 2025

Adding this to the project fixed the issue:

  <ItemGroup Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'browserwasm'">
    <PackageReference Include="HarfBuzzSharp.NativeAssets.WebAssembly" Version="7.3.0.3" />
  </ItemGroup>

Out of curiosity - why does it need the shaper only for non-default fonts?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant