Avalonia icon indicating copy to clipboard operation
Avalonia copied to clipboard

Chinese character is messy code in Project.Web

Open ismlsmile opened this issue 2 years ago • 3 comments

  1. Project is created by "Avalonia Cross Platform Application(AvaloniaUI) " template in VS 2022
  2. It is ok in Project.Desktop

1

ismlsmile avatar Sep 12 '22 02:09 ismlsmile

I think this is something related to fonts. All avalonia web fonts are mono for reason I don't know

rabbitism avatar Sep 12 '22 14:09 rabbitism

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")  
        }
    }
 }

Gillibald avatar Sep 12 '22 14:09 Gillibald

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?

rabbitism avatar Sep 14 '22 03:09 rabbitism

字体的问题,不能算是bug,avalonia的wasm里默认使用一种mono西文字体,并且无法使用系统中安装的其他字体 所以我们要使用资源中的自定义字体,亲测有效(貌似只有ttf的字体有效) image 屏幕截图 2023-01-24 082920

ly5222518000 avatar Jan 23 '23 15:01 ly5222518000

@ly5222518000 Hi, do you know how to use Source Han Sans SC? I cannot find the proper typeface name.

rabbitism avatar Jan 27 '23 04:01 rabbitism

@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

memorydream avatar Jan 28 '23 03:01 memorydream