Avalonia
Avalonia copied to clipboard
Chinese character is messy code in Project.Web
- Project is created by "Avalonia Cross Platform Application(AvaloniaUI) " template in VS 2022
- It is ok in Project.Desktop
I think this is something related to fonts. All avalonia web fonts are mono for reason I don't know
Embedd a font into your application and define it as a fallback like so:
https://fonts.google.com/noto/specimen/Noto+Sans+TC
.With(new FontManagerOptions
{
FontFallbacks = new[]
{
new FontFallback
{
FontFamily = new FontFamily("avares://YourAssembly/FontFolder#Noto Sans TC")
}
}
}
Embedd a font into your application and define it as a fallback like so:
https://fonts.google.com/noto/specimen/Noto+Sans+TC
.With(new FontManagerOptions { FontFallbacks = new[] { new FontFallback { FontFamily = new FontFamily("avares://YourAssembly/FontFolder#Noto Sans TC") } } }
Is it possible for Avalonia web apps to utilize system fonts?
字体的问题,不能算是bug,avalonia的wasm里默认使用一种mono西文字体,并且无法使用系统中安装的其他字体
所以我们要使用资源中的自定义字体,亲测有效(貌似只有ttf的字体有效)
@ly5222518000 Hi, do you know how to use Source Han Sans SC? I cannot find the proper typeface name.
@ly5222518000 Hi, do you know how to use Source Han Sans SC? I cannot find the proper typeface name.
You should can use some font viewer get it
I use SKTypeface.FromFile()
load a font then get font's family name, like this:
public CustomFontManagerImpl()
{
var filePath = Path.Combine(ProgramInfo.BaseDirectory, "Assets/Fonts/SourceHanSansSC-Normal.otf");
_defaultSKT = SKTypeface.FromFile(filePath);
_defaultTypeface = new Typeface($"{filePath}#{_defaultSKT.FamilyName}");
_customTypefaces = new[] { _defaultTypeface };
_defaultFamilyName = _defaultTypeface.FontFamily.FamilyNames.PrimaryFamilyName;
}
Because I got different SourceHanSansSC family name between Windows and Linux, not test it on web