using FontStashSharp;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using MLEM.Font;
namespace MLEM.Extended.Font {
///
public class GenericStashFont : GenericFont {
///
/// The that is being wrapped by this generic font
///
public readonly SpriteFontBase Font;
///
public override GenericFont Bold { get; }
///
public override GenericFont Italic { get; }
///
public override float LineHeight => this.Font.LineHeight;
///
/// The character spacing that will be passed to the underlying .
///
public float CharacterSpacing { get; set; }
///
/// The line spacing that will be passed to the underlying .
///
public float LineSpacing { get; set; }
///
/// Creates a new generic font using .
/// Optionally, a bold and italic version of the font can be supplied.
///
/// The font to wrap
/// A bold version of the font
/// An italic version of the font
public GenericStashFont(SpriteFontBase font, SpriteFontBase bold = null, SpriteFontBase italic = null) {
this.Font = font;
this.Bold = bold != null ? new GenericStashFont(bold) : this;
this.Italic = italic != null ? new GenericStashFont(italic) : this;
}
///
protected override float MeasureCharacter(int codePoint) {
return this.Font.MeasureString(CodePointSource.ToString(codePoint), null, this.CharacterSpacing, this.LineSpacing).X;
}
///
protected override void DrawCharacter(SpriteBatch batch, int codePoint, string character, Vector2 position, Color color, float rotation, Vector2 scale, SpriteEffects effects, float layerDepth) {
this.Font.DrawText(batch, character, position, color, rotation, Vector2.Zero, scale, layerDepth, this.CharacterSpacing, this.LineSpacing);
}
}
}