| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Pinging @Jonarw who can hopefully comment on the comment regarding WASM
Small follow up: this code in SkiaRenderContext.cs (line 869, linked previously) results, for some reason, in a typeface with family "Noto Mono".
typeface = SKTypeface.FromFamilyName(fontFamily, new SKFontStyle((int)fontWeight, (int)SKFontStyleWidth.Normal, SKFontStyleSlant.Upright));
This happens no matter the fontFamily requested. This seems strange; a similar call from a Blazor component, where I am painting to an html canvas using SkiaSharp, works fine. I am having a hard time understanding the difference. In both cases I have a .NET 9 Blazor WebAssembly app, using SkiaSharp; so what could cause this to work in Blazor directly, but not when it happens inside OxyPlot.SkiaSharp?
I suspect this is related to this issue:
mono/SkiaSharp#1902
Which I see you already found yourself.
After taking just a very quick look I am not sure if there is an obvious way to fix this on our side.
Thank you for taking a look. I also think this needs some work in SkiaSharp rather than in OxyPlot, I will close this issue for the time being. Acutazlly, in the other control where I use SKCanvasView, there is also only the default monospaced font, but it is less obvious.
It is a shame, this makes OxyPlot currently unusable in Blazor from my perspective, cause having only and always the "Noto Mono" looks rather clumsy, especially in the context of a modern Blazor application. Hope to see a resolution some time soon!
Coming back to this, I have found that if I remove #if NETSTANDARD2_0_OR_GREATER around this code, build OxyPlot.SkiaSharp myself, and then run it with a project where I embed a custom font as an embedded resource, this does work.
However, using the nuget package, this does not work. I have to manually download the nuget packages, unpack them and copy over and reference the netstandard2 versions, then it works. Could this be because NETSTANDARD2_0_OR_GREATER is not set when building OxyPlot for .NET8? Nuget will probably automatically pick that version for my NET9 project.
Could there be a way to make this work out of the box for WASM? For example, the code currently in between #if #endif could instead be wrapped in if(RuntimeInformation.IsOSPlatform(OSPlatform.Create("WEBASSEMBLY"))){ ...code... }. That way, I can use OxyPlot inside Blazor and benefit from updates via Nuget.
I don't think we even target NetStandard 1.x anymore, so may be those checks should just be deleted.
Even better! I think is little against trying to load a font from embedded resources if it's not found.
For now, I have solved this by specifying the target framework on the OxyPlot packages via the use of the Paket package manager. But removing the check would be better of course.
A thought on this: it would be nice if one could also manually load fonts, so they could be in any assembly, as opposed to only in the entry assembly.
For anyone wanting to get going with OxyPlot in Blazor Wasm, I upgraded the library referenced above: https://github.com/CodingConnected/OxyPlot.SkiaSharp.Blazor
It contains a demo app. In order to use a custom font, embed it in the client Wasm app, and set it as the default on the plot. Because the project uses Paket for dependency management, it explicitely uses the netstandard2 versions of OxyPlot.Core and OxyPlot.SkiaSharp. I'll add some info on how to build it later (basically: run dotnet paket restore and/or dotnet paket install and then build it; though you might have to restore the tool first).
Loading fonts in a Wasm scenario remains hard for me to get working. Auto-loading embedded fonts through this code works sometimes, but sometimes not and it's hard to pinpoint why.
I altered the OxyPlot sources to allow manually loading a specific font into the rendercontext for SkiaSharp, through a public method on the skia rendercontext. This allows me to easily load fonts from an arbitrary library and works really well. Also, this might enable me to share typefaces among multiple instances of this Blazor component, and thus only having to read fonts from embedded resources once; where otherwise each instance would have its own local cache with its own loaded typefaces.
Would this be an acceptable solution to add to OxyPlot? I'll happily create a PR. It involves minor changes, mainly adding a simple public method to SkiaRenderContext.
@VisualMelon Once #2116 is merged, I can create a new PR which allows manually loading typefaces. It would be very nice to have this in the Nuget package, I hope that is an option, so I can move away from maintaining my own "flavor" of OxyPlot...
| Back | FazBrowse Home | New Git URL |
Platform: SkiaSharp / WebAssembly
.NET version: .NET 9
Expected behaviour
Setting DefaultFont on PlotModel should have an effect.
Actual behaviour
The font never changes, it is always a monospaced font, which would seem to be a sort of fallback default in OxyPlot. For example, given this model:
var model = new PlotModel { Title = "Cake Type Popularity", DefaultFont = "Arial" }; ... code to add series etc...this is the result:
I am using this library in Blazor WebAssembly project, which I upgraded to .NET 9. Given this code inside of OxyPlot, I am wondering if this is a sort of "design choice"?
Using different fonts should be possible, I am using the Blazor SKCanvasView (which is used here as well to display the plot) elsewhere also, and can load system fonts without issue. Maybe embedding a font could help, but that introduces all kinds of licensing questions I would rather avoid...
Alas, is there a reason and/or potential fix for this behaviour of OxyPlot.SkiaSharp in a WASM context?
[Edit] Actually, I am also only seeing the "Noto Mono" font in the other app where I use SKCanvasView.