mirror of
https://github.com/AlexMacocian/MonoGame.Extended.git
synced 2026-07-17 16:09:29 +00:00
3a5269cfea
* Removed MonoGame.Extended.Animations This project was just a shell that referenced MonoGame.Extended.csproj. It added no additional functionality. * Rework BitmapFonts for new project organization. * Cleanup namespaces * Cleanup namespaces * Move MonoGame.Extended.Collision into base project * Moved MonoGame.Extended.Entities into base project * Moved MonoGame.Extended.Graphics into base project * Moved MonoGame.Extended.Graphics into base project * Moved MonoGame.Extended.Input into base project * Moved MonoGame.Extended.Particles into base project * Moved MonoGame.Extended.Tiled into base project * Moved MonoGame.Extended.Tiled into base project * Moved MonoGame.Extended.Tweening into base project * Removing SpriteFactory support This will be added back in at a later date once the SpriteFactory application has been updated * Update TexturePacker content import support * Only needs to reference base project now * Moved to Serialization namespace * Moved Json serialization to Serialization.Json namespace * Moved TexturePacker content DTOs to the Content namespace * Renamed to Texture2DRegion.Extensions.cs * Cleaned up namespace * Moved ReadTiledMapProperties into the ContentReaderExtensions * Created an Extended content manager * Moved Tweening tests to base test project * Moved Tiled test to base test project * Moved Entities Tests to base test project * Moved Entities tests to base test project * Moved Collisions tests to base test project * Moved Pipeline Tiled test to Pipeline tests project * Use `var` instead of full type name * Add Tiled namespace * Correct `Metadata` property name to new `Meta` property name * Cleanup namespace * Add effects namespace * Add Content namespace * Update using statements to new namespaces * Move Pipeline Tiled tests to Pipeline test project * Use correct namespace * Use `var` instead of typing out nested types * Remove unused namespaces * Update to new namespaces * Remove unused namespaces * Update to new namespaces * Remove dependency on Particles csproj * Update included content on build * Add embedded resources * Merge multi csproj structure into single csproj structure * TexturePackerPoint properties should be `double` not `int` * Update csproj * Use dotnet tool to rebuild effects * Move effect compilation to targets file This will ensure the effects are always built * Fix workflow to build effects on linux * Set wine path * Export instead of using actions env section * Revert back to manual effect compile until automation can be solved on GitHub Ubuntu runner
94 lines
3.2 KiB
C#
94 lines
3.2 KiB
C#
using MonoGame.Extended.BitmapFonts;
|
|
using MonoGame.Extended.Graphics;
|
|
|
|
namespace MonoGame.Extended.Tests.BitmapFonts
|
|
{
|
|
public class BitmapFontTests
|
|
{
|
|
[Fact]
|
|
public void BitmapFont_Constructor_Test()
|
|
{
|
|
var font = CreateTestFont();
|
|
|
|
Assert.Equal("Impact", font.Face);
|
|
Assert.Equal(22, font.LineHeight);
|
|
}
|
|
|
|
[Fact]
|
|
public void BitmapFont_MeasureString_SingleWord_Test()
|
|
{
|
|
var font = CreateTestFont();
|
|
var size = font.MeasureString("fox");
|
|
|
|
Assert.Equal(40, size.Width);
|
|
Assert.Equal(font.LineHeight, size.Height);
|
|
}
|
|
|
|
[Fact]
|
|
public void BitmapFont_MeasureString_WithLetterSpacing_Test()
|
|
{
|
|
var font = CreateTestFont();
|
|
font.LetterSpacing = 3;
|
|
|
|
var size = font.MeasureString("fox");
|
|
|
|
Assert.Equal(46, size.Width);
|
|
Assert.Equal(size.Height, font.LineHeight);
|
|
}
|
|
|
|
[Fact]
|
|
public void BitmapFont_MeasureString_MultipleLines_Test()
|
|
{
|
|
var font = CreateTestFont();
|
|
//var size = font.MeasureString("box fox\nbox of fox");
|
|
var size = font.MeasureString("box fox\nbox of fox");
|
|
|
|
Assert.Equal(123, size.Width);
|
|
Assert.Equal(size.Height, font.LineHeight * 2);
|
|
}
|
|
|
|
[Fact]
|
|
public void BitmapFont_MeasureString_EmptyString_Test()
|
|
{
|
|
var font = CreateTestFont();
|
|
var size = font.MeasureString(string.Empty);
|
|
|
|
Assert.Equal(0, size.Width);
|
|
Assert.Equal(0, size.Height);
|
|
}
|
|
|
|
// Test added for issue #695
|
|
// https://github.com/craftworkgames/MonoGame.Extended/issues/695
|
|
//
|
|
// Issue claims measure string does not account for space at the end of string.
|
|
[Fact]
|
|
public void BitmapFont_MeasureString_SpaceAtEnd_Test()
|
|
{
|
|
var font = CreateTestFont();
|
|
|
|
var noSpaceAtEnd = font.MeasureString("bfox");
|
|
var spaceAtEnd = font.MeasureString("bfox ");
|
|
|
|
Assert.NotEqual(noSpaceAtEnd, spaceAtEnd);
|
|
|
|
}
|
|
|
|
private static BitmapFont CreateTestFont()
|
|
{
|
|
var textureRegion = new Texture2DRegion("Test Font", x: 219, y: 61, width: 16, height: 18);
|
|
var regions = new[]
|
|
{
|
|
// extracted from 'Impact' font. 'x' is particularly interesting because it has a negative x offset
|
|
new BitmapFontCharacter(textureRegion: textureRegion, character: ' ', xOffset: 0, yOffset: 0, xAdvance: 6),
|
|
new BitmapFontCharacter(textureRegion: textureRegion, character: 'b', xOffset: 0, yOffset: 7, xAdvance: 17),
|
|
new BitmapFontCharacter(textureRegion: textureRegion, character: 'f', xOffset: 0, yOffset: 7, xAdvance: 9),
|
|
new BitmapFontCharacter(textureRegion: textureRegion, character: 'o', xOffset: 0, yOffset: 11, xAdvance: 16),
|
|
new BitmapFontCharacter(textureRegion: textureRegion, character: 'x', xOffset: -1, yOffset: 11, xAdvance: 13),
|
|
};
|
|
|
|
var font = new BitmapFont("Impact", size: 32, lineHeight: 22, regions);
|
|
return font;
|
|
}
|
|
}
|
|
}
|