-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cannot use special characters like "é" or "è" #9
Comments
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 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 |
Can we use .ttf fonts (like from https://www.dafont.com/) with MGUI ? Is it any option to render text at runtime based on ttf files ? Also can we use Unicode with MGUI ? Would adding FontStashSharp support in the future be an option ? |
MGUI only supports text rendering via MonoGame's If you want to use a .ttf font file, you'll have to generate a 26c1604 I've added a sample of this to MGUI.Samples/Game1.cs Initialize method: Line 54 in 26c1604
To use unicode, you'd have to add all character ranges to the |
Thank you so much for the detailed response and the great work with this library. I always gain so much insights from these issues on git and your amazing answers. |
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.
The text was updated successfully, but these errors were encountered: