Mapsui icon indicating copy to clipboard operation
Mapsui copied to clipboard

LabelStyle displays errors on Linux and Windows

Open Riton2013 opened this issue 2 months ago • 6 comments

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:

Image

On Windows with English and Numbers:

Image

On Linux:

Image

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;
 }

Riton2013 avatar Nov 06 '25 09:11 Riton2013

Additionally, I have tried setting different fonts for the Linux platform, or leaving everything unchanged, but the displayed results are the same

Riton2013 avatar Nov 06 '25 09:11 Riton2013

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.

charlenni avatar Nov 07 '25 10:11 charlenni

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.

pauldendulk avatar Nov 10 '25 13:11 pauldendulk

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.

Riton2013 avatar Nov 19 '25 06:11 Riton2013

You can not get any custom font to work on Linux?

pauldendulk avatar Nov 20 '25 08:11 pauldendulk

Please check out this post by @bobbycannon https://github.com/Mapsui/Mapsui/issues/3233#issuecomment-3557958481. This may work for you as well.

pauldendulk avatar Nov 21 '25 08:11 pauldendulk