Open Tethyr79Mb opened 5 months ago
You're right, this seems to be due to the Start/End CharacterRegions of the spritefonts that MGUI comes with. I will add fallback logic to use the SpriteFont's DefaultCharacter if the desired Glyph isn't found.
If you want to use your own SpriteFonts in MGUI, which you can set their CharacterRegions to anything you wish, you can do the following in your game's initialize method right after instantiating an MGDesktop
:
protected override void Initialize()
{
// Create your MGDesktop
this.MGUIRenderer = new MainRenderer(new GameRenderHost<Game1>(this));
this.Desktop = new MGDesktop(MGUIRenderer);
// Add a FontSet to the desktop. FontSets require a collection of SpriteFonts belonging to the same font family, but at different sizes and styles (bold/italic)
// The more SpriteFonts you define, the better MGUI will be at rendering text of varying sizes and styles for that family. This is a simple example with just 2 font sizes
// See also: SpriteFontGenerator.Generate(...), which can quickly create a set of .spritefont files for you to add to your game's content
Dictionary<SpriteFont, FontMetadata> CalibriSpriteFonts = new Dictionary<SpriteFont, FontMetadata>
{
{ Content.Load<SpriteFont>("Calibri 12pt"), new FontMetadata(12, false, false) },
{ Content.Load<SpriteFont>("Calibri 12pt bold"), new FontMetadata(12, true, false) },
{ Content.Load<SpriteFont>("Calibri 12pt italic"), new FontMetadata(12, false, true) },
{ Content.Load<SpriteFont>("Calibri 14pt"), new FontMetadata(14, false, false) },
{ Content.Load<SpriteFont>("Calibri 14pt bold"), new FontMetadata(14, true, false) },
{ Content.Load<SpriteFont>("Calibri 14pt italic"), new FontMetadata(14, false, true) },
};
Desktop.FontManager.AddFontSet(new Shared.Text.FontSet("Calibri", CalibriSpriteFonts));
// Make the new FontSet the default for TextBlocks to use when no FontFamily is specified
Desktop.Theme.FontSettings.DefaultFontFamily = "Calibri";
base.Initialize();
}
Added fallback logic for missing glyphs: 96a4db5
I have a exception KeyNotFoundException when i using a special character like "é" or "è". I have set the spritefont end character region to 383. Monogame displays them however by modifying the spritefont.
Help would be appreciated thank you very much.