Closed WheelerAustin closed 5 days ago
Hi @WheelerAustin, I recently ran into the same issue. Were you able to reach a solution?
I did find a solution. I don't believe this is actually a bug as SkiaSharp.NativeAssets.Linux.NoDependencies
is supposed to work this way. Its just not very obvious.
Basically when you use SKCanvas.DrawText()
on a windows computer, the font defaults to the system font. When running on AWS lambda there is no default system font and no exception is thrown telling you this. The best path forward in my position was to simply embed a font into my project and have full control of the fonts in the jpeg.
Its really not too hard.
C:\Windows\Fonts
by coping the Consolas files and pasting into a folder I made in my project named 'Fonts'.Embedded resource
. They should show up in the csproj file like so:
<ItemGroup>
<EmbeddedResource Include="Fonts\CONSOLA.TTF" />
<EmbeddedResource Include="Fonts\CONSOLAB.TTF" />
<EmbeddedResource Include="Fonts\CONSOLAI.TTF" />
<EmbeddedResource Include="Fonts\CONSOLAZ.TTF" />
</ItemGroup>
SKPaint
using Stream consolaStream = Assembly.GetExecutingAssembly().GetManifestResourceStream("{YourProjectName}.Fonts.CONSOLA.TTF")!;
SKTypeface font = SKTypeface.FromStream(consolaStream);
using SKPaint textPaint = new() { Typeface = font, Color = SKColors.Black, TextSize = 24, IsAntialias = true };
4. Make sure to use that paint when in your ```SKCanvas.DrawText("myText", myPoint, myPaintWithConsolasTypeface);```
Hopefully this helps!
Hi @WheelerAustin, thank you for this detailed response!
When running on AWS lambda there is no default system font and no exception is thrown telling you this. The best path forward in my position was to simply embed a font into my project and have full control of the fonts in the jpeg.
Makes sense! Your code examples really help too.
Connecting some dots, I followed-up here because it seemed to be the same issue described in https://github.com/ScottPlot/ScottPlot/discussions/3825, and your response saved the day.
When I see strangers on the internet working together to create technical solutions for complex problems like this, it reminds me how awesome the open source community really is! 🚀 🚀 🚀 Thanks again
Description
When generating a png image with SKCanvas the text is missing. The image displays properly when run locally on a windows 10 environment, but the text is missing when running from AWS Lambda. There are no exceptions being thrown for me to troubleshoot with.
This code was working last year, until I upgraded to .net 8 and changed my pdf nuget to QuestPDF. Not sure of the relevance.
Code
Expected Behavior
No response
Actual Behavior
No response
Version of SkiaSharp
2.88.3 (Current)
Last Known Good Version of SkiaSharp
2.88.2 (Previous)
IDE / Editor
Visual Studio (Windows)
Platform / Operating System
Linux
Platform / Operating System Version
-AWS Lambda
Devices
No response
Relevant Screenshots
Run Locally
Run From AWS Lambda
Relevant Log Output
No response
Code of Conduct