Version 5.3.1 Release - BMFont Improvements
Hello everyone,
Last night version 5.3.1 of MonoGame.Extended was released. This is a maintenance release to address issues with the Bitmap Font (BMFont) file loading and rendering that have been discovered.
Thanks to dawnsbury for the detailed bug reports and reproduction repository that made these fixes easy to replicate and fix.
- GitHub: https://github.com/monogame-extended/monogame-extended
- Release Notes: https://github.com/MonoGame-Extended/Monogame-Extended/releases/tag/v5.3.1
BMFont File Loading Improvements
UTF-8 Byte Order Mark (BOM) Support
BMFont files saved with UTF-8 encoding that include a Byte Order Mark (BOM) are now properly supported. This was occurring when BMFont files were edited using third-party libraries such as SharpFNT.BitmapFont, which may save files with the UTF-8 BOM preamble.
Previously, the presence of the preamble would cause the file format detection to fail with an "Invalid BMFont file" error. The reader now detects and skips the UTF-8 BOM preamble when present, allowing these files to load correctly.
Reference: https://github.com/MonoGame-Extended/Monogame-Extended/issues/1073
Negative Spacing Support
BMFont files can now use negative spacing values for both horizontal and vertical spacing. While the BMFont specifications defines spacing as unsigned bytes, tools like LibGDX Hiero allow negative spacing, and users can manually edit font files to use negative values for better visual results.
The SpacingHoriz and SpacingVert fields in the InfoBlock struct have been changed from byte to sbyte to support negative values:
[StructLayout(LayoutKind.Explicit)]
public struct InfoBlock
{
// ...
[FieldOffset(11)] public sbyte SpacingHoriz;
[FieldOffset(12)] public sbyte SpacingVert;
// ...
}
This change maintains binary compatibility (both types are single-byte values) while enabling spacing adjustments that font generation tools other than AngleCode BMFont Generator supports.
Reference: https://github.com/MonoGame-Extended/Monogame-Extended/issues/1074
Invalid Character Glyph Support
BMFont files that define an invalid character glyph (e.g. character ID -1) are now properly supported. The invalid character glyph serves as a fallback for missing characters. While the BMFont specifications defines the character id as an unsigned integer, users can manually edit the BMFont file to add the fall back font character id -1 manually.
To address this, the CharacterBlock.ID field has been changed from uint to int to allow negative character IDs
[StructLayout(LayoutKind.Explicit)]
public struct CharacterBlock
{
public const int StructSize = 20;
[FieldOffset(0)] public int ID;
// ...
}
This change maintains binary compatibility (both types are 4-byte values) while enabling negative character ID support.
Reference: https://github.com/MonoGame-Extended/Monogame-Extended/issues/1075
