SixLabors.Fonts is a typography library, written in pure C#, and it’s awesome. This is a quick wrapper for MonoGame users to enjoy!
This does not support the content pipeline and I do not plan on adding support for it. It loads fonts from file paths.
FontEngine engine = new();
MonoGameFont font = engine.GetFont("some-cool-font", 24f);
batch.DrawText(font, "Hello, world!", new Vector2(10, 10));
You can find more examples as well as explanations in the GitHub repository:
This package is also available on NuGet:
Released v1.1.0: added color parameter to SpriteBatch.DrawText().
I should have put this in v1.0.0, but I forgot, oops!
Sorry for my ignorance, but I am trying to find out what is the advantage of using these fonts instead of spritefonts or any other font type?
or is it just another font management system instead of the default content manager?
- They look MUCH better than spritefonts when scaled. Since it only creates the exact glyphs you need at runtime, they are the correct scale and don’t have the jpeginess when scaled.
- They load faster. I’ve noticed spritefonts with lots of glyphs can take a second to laod, especially on mobile.
- Better glyph support. Spritefonts only have the glyphs declared ahead of time in the .spritefont file. Spritefontplus can load any glyph in the font. Onn that note…
- Easier language support. For example, if you are on Android, using Roboto, and want to support Japanese, can just swap out to Noto and you are done.
- Don’t have to deal with spritefont bugs. This is my personal opinion, but spritefonts look terrible, there are tons of kearning issues and whitespace characters have serious issues.
- Requires a plugin to use with the content pipeline. I’ve got one floating around somewhere if you are interested.
- Spritefontplus has linespace issues. If you are writing multiple lines of text, will have to manually pad the lines unlike vanilla spritefont.linespacing
- I don’t think rotation works correctly
- SpriteEffects like flipVertical and flipHorizontal don’t work
- Can’t just drop in and replace spritefont. The kearnin, linespac, and font size differences are enough that if you switch an existing project from sdpritefont → spreitfontplus, you’ll have to go through the whole project and fiddle with every text placement.
IMO the pros vastly outweigh the cons, and spritefontplus looks 100x more professional that plain spritefont. Personally I use it in every one of my projects unless I have to use flipVertical or flipHorizontal.
Hope this helps. Cheers!
While what @dmanning23 said mostly applies here, I’d like to point out that this is a wrapper over SixLabor.Fonts, not SpriteFontPlus/FontStashSharp. This package, however, contains no code to integrate with the content pipeline (I’m not at all familiar with the pipeline, so I don’t know how much of a hassle it’d be to make it work). The extension methods for SpriteBatch, i.e. the methods that draw text to the screen are also pretty limited. This was done for a personal project and released for anybody else that might need it.
By the way, if you intend on using this, be wary that I haven’t benchmarked it and that it might be very slow. The drawing of the text involves creating a new texture (this happens every frame). This is probably a lot of performance being lost, and work could be done to optimise it, I just don’t have the ability to do that at the moment.
Edit: for any serious project, you probably want to be using FontStashSharp, unless you have issues that this package doesn’t have.
hahaha dang, yeah totally different font library
ignore everything I said
Thanks for the details dmanning23 and DimitarBogdanov!
Quite interesting, well I am not targeting mobile at this moment, mainly Windows , and maybe Mac/Linux in the future.
For now I spent quite a lot of time making Spritefont look good in pretty much all situations but I use a lot of memory to make that happen since I load the same font in many sizes and pick up the closest one to the size I want to display. It works fine but my problem will be if I start to support Japanese, Chinese and other languages that require a new set of glyphs, I will end up loading the same fonts many times and I may ran out of memory because of that or wasting a lot of resources.
If this wrapper have perfomance issues due to creating a new texture every frame then I don’t think I can use it for now, even if the pros are more than the cons.
I am still wondering what should be the best way to support multiple languages.
FontStashSharp can load TTF fonts, and then it’s up to the font to support the character glyphs. Successfully worked with Cyrillic for me, it works with anything Unicode supports. Here’s the repo (you can find the package on NuGet as well) - GitHub - FontStashSharp/FontStashSharp: C# port of https://github.com/memononen/fontstash
im starting to wonder if Maui might be worth waiting for if you are targeting mobile. I for one will try to use googles translate cloud service to deploy and not even bother to do localization… this depends on using the new Android launcher that lets you put multiple windows. My game has minimal text so this might be an option to let higher level code dev with it… I just dont thnk the tower of babel approach s doable wth all the nuaces around langueses and ui and fonts, som im willing to split code paths on this one.
MAUI doesn’t/won’t support Linux, so if you’re targeting both desktop and mobile, you’ll suffer from that downside, also I’m not quite sure how you’d go about integrating it with MonoGame at all.
P.S. If you’re going to use a translation service to provide localisation, please at least use a decent one. Google Translate, quite frankly, sucks. It’s better to not have any localisation than to use that, it’ll just degrade the quality of your game. I’d go with something like DeepL, which is miles ahead in quality (still not perfect, though).
Or just use a service like Crowdin and do localisation properly. It’s not that difficult to do, and Crowdin specifically is community-sourced, which means you won’t spend a dime on localisation.
thanks for the tips on cloud services, google will give you 300 a month and theyh you pay depending on usage… so its a small tax f you get lucky enough to surpass the tree tier.
reason is my game spread all over the world last time,
and the aliens in talk poolry machine translated jibberish , according to its premise , so anyways so a bad translation on my game dialog is fine, and for User interface control, settings , instructions, its is better than them havng for the user to use and OCR on my raster instructions or copy paste from some window and put n xlate. facebook xlate is decent and google xlate is good enough for me because i dont even speak the languages n the coutries i live in half the time.
Linux, well that looks lke the Elephant in the maui room. but if you llook at Steam its a TINY market share and so many linux types basically dont believe that software should cost any money so they probably might not give me any ether , or watch an ad , even if they hate microsoft more than indies, they are cheap , grad students with no money, so mabye i dont care. i care about mac, pc, androind and ios, mabye consoles. I was hoping Maui could cut out Xamarin but it does not. so rightnow i think it could die.
I dont try ANY ui framework Microsoft does unless its 10+ years old. (there are several competing inhouse( , im basically using the oldest framework, died on silverlight, aborted UWP, but i am using WPF which stil works. what im talking about is going directly to Java text windows ( input and output) for android, and splitting paths on this one. For desktop its a physical keyboard i might split UI for that as well or use MG text. However, there is a project called SILK at .net I am closely monitoring , nothign to do with text but its a interesting early stage wth c++ to c# wrapper generation and symbolic transplilng. its a unification code generator might help the wth the whole monogame strategy so im trying to see what they are doing…its quite new.
i do think this image engine should be used for alot of stuff monogame users do oncethey start to call data on a texture…, because it uses SIMD, intrinsics, and stays out of the graphics thread. i noticed SILK .net uses it. if you are passsing stuff from gpu to cpu back and forth its expensive and nuanced and mght requre semaphones and locks whch arent gong to behave the same on androd if they work at all. … I dont think this image engine s that easy to use , cannot handle gigantic CAD images but its fast and stable and about 3 years of hard work.
Nez also has some interesting font solutions but this looks better, and they maintainer uses FNA mainly now, so new monogame might not work…
i use monogame to build shaders from one code, to and to draw 60 at vsync, fps and never block any threads any more ,or do anything on its update. all the rest like images and physics is done on background threads va producer /consumer and do not use GPU
Just in summary:
Both Font SixLabors and FontStash :
- can both use TTF and do work outside the content pipeline.
- If you plan multi-language support both will work better than SpriteFont
- Glyphs are rendered as needed so size will always look perfect , while spritefont will not in different resolutions
- Load faster
- FontStash support multi color letters
- SixLabors may be slow, since it needs to create a new texture per frame, FontStash is at this moment unknown if it has the same logic as SixLabors
- SixLabors doesn’t support sprite font effects , flip vertical/horizontal
- SixLabors rotations may not work correctly
I would like to know which one returns the best performance and less overhead , if anyone have tested both please update here. I am still undecided on which one to use.