LabelStyle displays errors on Linux and Windows
Mapsui Version
NuGet package:5.0.0
Mapsui Platform
Avalonia platform with Windows and Linux
Device
Windows PC and Linux PC
Describe the bug A clear and concise description of what the bug is.
1.LabelStyle cannot display the set text, and instead displays a small dot. No matter whether I set Chinese or English, or what font I choose, the text does not display, even if I only assign a value to Text.
2.When displaying Chinese on Windows, it shows messy codes unless I specify a certain font, such as Microsoft YaHei
To Reproduce
Expected behavior A clear and concise description of what you expected to happen.
Screenshots On Windows with Chinese:
On Windows with English and Numbers:
On Linux:
Additional context
private LabelStyle CreateUserLabelStyle(ServerTermGISModel userInfo)
{
var labelStyle = new LabelStyle
{
Text = userInfo.Name,
ForeColor = Color.White,
BackColor = new Brush(new Color(0, 0, 0, 200)),
BorderColor = new Color(169, 169, 169, 200),
BorderThickness = 1,
//Font = UtilTool.CreateCrossPlatformFont(),
RelativeOffset = new RelativeOffset(0.0, 0.8),
Enabled = true,
MinVisible = 0,
MaxVisible = double.MaxValue,
HorizontalAlignment = LabelStyle.HorizontalAlignmentEnum.Center,
VerticalAlignment = LabelStyle.VerticalAlignmentEnum.Top
};
return labelStyle;
}
Additionally, I have tried setting different fonts for the Linux platform, or leaving everything unchanged, but the displayed results are the same
Your Windows screenshot show, that your font you use doesn't have glyphs for the used Unicode characters. So use a font, that has this glyphs.
I think this is just a problem with the chosen font, like charlenni mentions.
While looking into this I was trying to create a sample for custom fonts in Mapsui, but this is problematic because you need to install the font on your system which is hard to enforce with all the frameworks/platforms/samples. So I was thinking about a way to use embedded fonts. Similarly we use embedded images and mbtiles so our samples do have to worry about it. Perhaps instead of a font family name it should be an option to use a url style path, like we use for images, for example: "embedded://path.to.my.font". This is a bigger change in core which I don't want to start with this year. I don't think it would be a breaking change so it could be part of a 5.1.0 release.
Yes, it's a problem with the chosen font, What makes me feel strange is that the font I have set up already doesn't work on Linux. I haven't found the reason yet.
You can not get any custom font to work on Linux?
Please check out this post by @bobbycannon https://github.com/Mapsui/Mapsui/issues/3233#issuecomment-3557958481. This may work for you as well.