Myra icon indicating copy to clipboard operation
Myra copied to clipboard

Feature Request: Scalable Vector Fonts/Images

Open IanGungee opened this issue 4 years ago • 6 comments

Saving multiple bitmaps for different font sizes seems a sub-optimal solution. Sampling a single vector sheet, or at the very least down-scaling one largest-scale bitmap for fonts would be ideal

IanGungee avatar Aug 30 '20 01:08 IanGungee

I second this. The FontStashSharp based text renderering easily fuzzy characters when there is font size scaling. Even a slightest scale causes significant fuzziness effect, compared to MonoGame's vanilla SpriteFont rendering.

example:

var fontSystem = FontSystemFactory.Create(GraphicsDevice, 128, 128);
fontSystem.AddFont(File.ReadAllBytes("Content/Fonts/m5x7.ttf"));

batch.DrawString(fontSystem.GetFont(13), new Vector2(0, 0), Color.White);

batch.DrawString(content.Load<SpriteFont>("Fonts/m5x7"), new Vector2(100, 0), Color.White);

Font source: https://managore.itch.io/m5x7

The problem is not only related with the pixel style font here, but also applies for non-pixel style font. Pixel font enlarges the problem. Also, the antialiased, fuzzy characters look better if the font size is set larger. (smaller size characters is more fuzzy)

In my case, I have to roll back to 1.0.3 to avoid text blurring. Maybe a temporary workaround is to make a SpriteFontBase implementation that use SpriteFont as Underlying text rendering utility, and let user choose between this implementation (for sharp text rendering) and DynamicSpriteFont (for dynamic font features).

Great work for FontStashSharp. I understand the convenience brought by a dynamic font rendering engine, especially for CJK characters. It would be even better if the rendering quality can also be improved on current base.

frontwavegames avatar Jan 31 '21 08:01 frontwavegames

Unsure, if this fixes the case, however latest FontStashSharp allows to create SpriteFontBase from prerendered fonts: https://github.com/rds1983/FontStashSharp/wiki/Using-FontStashSharp-in-MonoGame,-FNA-or-Stride#staticspritefont

rds1983 avatar Feb 21 '21 22:02 rds1983

https://user-images.githubusercontent.com/23627133/108641550-0f95d880-74a0-11eb-9151-37ca43de8fa0.mp4

This is a somewhat tuned dynamic font system that can use different font sizes depending on scale, giving it extra crisp quality at most resolutions. This is not going through FontStashSharp but it shares the same underlying font renderer (StbTrueTypeSharp). What this says to me is that either Myra or FontStashSharp are not correctly tuned.

So to put it simply; this is not an issue with the font renderer (StbTrueTypeSharp) but by the usage of it, so it should be somewhat easy to fix (compared to replacing the dynamic runtime renderer with a completely different solution).

TechPizzaDev avatar Feb 21 '21 23:02 TechPizzaDev

@TechnologicalPizza I'm trying to investigate the issue further, is it possible to share your code somehow so I can take a look into how you're solving the scaling problem?

realvictorprm avatar Jun 19 '21 10:06 realvictorprm

@realvictorprm https://github.com/TechnologicalPizza/MonoGame/blob/0a5b4c226d61cabdb21373d00ed8d3ba453e977b/MonoGame.Testing/GamePLC.cs#L521 All the layout is done in this code block. The font rendering comes from my StbTrueTypeSharp fork. Cloning my MonoGame fork and pulling submodules should include most necessary files (possibly excluding some assets, not sure). I use my MonoGame.Testing project mostly as a playground so everything is extremely messy.

TechPizzaDev avatar Jun 19 '21 11:06 TechPizzaDev

Thank you very much for sharing this @TechnologicalPizza, very much appreciated!

realvictorprm avatar Jun 19 '21 11:06 realvictorprm