mono / SkiaSharp

SkiaSharp is a cross-platform 2D graphics API for .NET platforms based on Google's Skia Graphics Library. It provides a comprehensive 2D API that can be used across mobile, server and desktop models to render images.
MIT License
4.28k stars 531 forks source link

[BUG] SKTypeface can't load any system fonts on some Linux machines #1181

Open kekekeks opened 4 years ago

kekekeks commented 4 years ago

Description

We've had several reports about SKTypeface not loading fonts on Manjaro. Today we've had a case with a snap-packaged app that could be reproduced on any machine thanks to snapcraft container technology

Code

SKTypeface.Default.FamilyName returns null SKTypeface.FromFamilyName("Sans") returns null

More details about the repro: https://github.com/AvaloniaUI/Avalonia/issues/3679

kekekeks commented 4 years ago

Also happens with CentOS 7 - https://github.com/AvaloniaUI/Avalonia/issues/3694

mattleibow commented 4 years ago

Could it be that the apps do not have access to the fonts? Can you load them manually via a path? Either the system fonts or a custom font?

kekekeks commented 4 years ago

Fonts are loadable via SkTypeface.FromFile. fc-match command line utility is able to locate the font that corresponds to the "Sans" name.

mattleibow commented 4 years ago

Is this happening with just snap packages or always?

Gillibald commented 4 years ago

Someone had this issue on Manjaro without a container. Couldn't repro it with my local setup.

kekekeks commented 4 years ago

Another repro https://github.com/AvaloniaUI/Avalonia/issues/3701

mattleibow commented 4 years ago

I'll be looking at this soon, so just to get the cases together... It always happens with snap packages? And sometimes on various linux distros?

Has anyone tried looking at listing all the fonts installed? https://docs.microsoft.com/dotnet/api/skiasharp.skfontmanager.fontfamilies

var fonts = SKFontManager.FontFamilies.ToArray();
Console.WriteLine($"first font: {fonts[0]}");

If there are fonts then something is wonky with the lookup process. If there are no fonts, then for some reason fontconfig can't find anything at all.

Gillibald commented 4 years ago

My guess is that font matching isn't working. Some people have reported that SKTypeface.FromName(..) is working if you specify the exact matching name of an installed font.

The SKTypeface.Default translates to SKTypeface.FromName(null) which is using font matching as well.

Maybe newer Fontconfig has changed in a way that breaks the SKFontmanagerImpl

kekekeks commented 4 years ago

It always happens with snap packages?

The first report with desktop Manjaro Linux (non-snap) was about a stack overflow in Avalonia code. We've identified that it was caused by SKTypeface.Default.FamilyName being null and that SKTypeface.FromFamilyName("Sans") also fails while the rest of the desktop is working fine.

We couldn't reproduce it locally.

The second report was about the same symptoms with snap packaging which can be reproduced on any machine.

The last report is from desktop Debian 10 machine.

KiruyaMomochi commented 2 years ago

Not sure if this is related, but SKTypeface.Default.FamilyName returns null for me when using japanese. (LANG=ja_JP.UTF-8).

Setting LANG to C solves the problem.

OMMDIPTA commented 1 month ago

https://github.com/mono/SkiaSharp/issues/1131#issuecomment-583640278

in publish folder there is no .ttf file.