1
0
Fork 0
mirror of https://github.com/Ellpeck/MLEM.git synced 2024-11-22 04:53:29 +01:00

Expose character and line spacing in GenericStashFont

closes #16
This commit is contained in:
Ell 2024-01-30 20:47:05 +01:00
parent ed5c4b44d4
commit 2eaf0c0cee
2 changed files with 13 additions and 2 deletions

View file

@ -50,6 +50,7 @@ Fixes
### MLEM.Extended ### MLEM.Extended
Improvements Improvements
- Updated to FontStashSharp 1.3.0's API - Updated to FontStashSharp 1.3.0's API
- Expose character and line spacing in GenericStashFont
### MLEM.Data ### MLEM.Data
Fixes Fixes

View file

@ -11,6 +11,7 @@ namespace MLEM.Extended.Font {
/// The <see cref="SpriteFontBase"/> that is being wrapped by this generic font /// The <see cref="SpriteFontBase"/> that is being wrapped by this generic font
/// </summary> /// </summary>
public readonly SpriteFontBase Font; public readonly SpriteFontBase Font;
/// <inheritdoc /> /// <inheritdoc />
public override GenericFont Bold { get; } public override GenericFont Bold { get; }
/// <inheritdoc /> /// <inheritdoc />
@ -18,6 +19,15 @@ namespace MLEM.Extended.Font {
/// <inheritdoc /> /// <inheritdoc />
public override float LineHeight => this.Font.LineHeight; public override float LineHeight => this.Font.LineHeight;
/// <summary>
/// The character spacing that will be passed to the underlying <see cref="Font"/>.
/// </summary>
public float CharacterSpacing { get; set; }
/// <summary>
/// The line spacing that will be passed to the underlying <see cref="Font"/>.
/// </summary>
public float LineSpacing { get; set; }
/// <summary> /// <summary>
/// Creates a new generic font using <see cref="SpriteFontBase"/>. /// Creates a new generic font using <see cref="SpriteFontBase"/>.
/// Optionally, a bold and italic version of the font can be supplied. /// Optionally, a bold and italic version of the font can be supplied.
@ -33,12 +43,12 @@ namespace MLEM.Extended.Font {
/// <inheritdoc /> /// <inheritdoc />
protected override float MeasureCharacter(int codePoint) { protected override float MeasureCharacter(int codePoint) {
return this.Font.MeasureString(CodePointSource.ToString(codePoint)).X; return this.Font.MeasureString(CodePointSource.ToString(codePoint), null, this.CharacterSpacing, this.LineSpacing).X;
} }
/// <inheritdoc /> /// <inheritdoc />
protected override void DrawCharacter(SpriteBatch batch, int codePoint, string character, Vector2 position, Color color, float rotation, Vector2 scale, SpriteEffects effects, float layerDepth) { 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.Font.DrawText(batch, character, position, color, rotation, Vector2.Zero, scale, layerDepth, this.CharacterSpacing, this.LineSpacing);
} }
} }