Skip to content

Commit

Permalink
Expose character and line spacing in GenericStashFont
Browse files Browse the repository at this point in the history
closes #16
  • Loading branch information
Ellpeck committed Jan 30, 2024
1 parent ed5c4b4 commit 2eaf0c0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ Fixes
### MLEM.Extended
Improvements
- Updated to FontStashSharp 1.3.0's API
- Expose character and line spacing in GenericStashFont

### MLEM.Data
Fixes
Expand Down
14 changes: 12 additions & 2 deletions MLEM.Extended/Font/GenericStashFont.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,23 @@ public class GenericStashFont : GenericFont {
/// The <see cref="SpriteFontBase"/> that is being wrapped by this generic font
/// </summary>
public readonly SpriteFontBase Font;

/// <inheritdoc />
public override GenericFont Bold { get; }
/// <inheritdoc />
public override GenericFont Italic { get; }
/// <inheritdoc />
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>
/// Creates a new generic font using <see cref="SpriteFontBase"/>.
/// Optionally, a bold and italic version of the font can be supplied.
Expand All @@ -33,12 +43,12 @@ public GenericStashFont(SpriteFontBase font, SpriteFontBase bold = null, SpriteF

/// <inheritdoc />
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 />
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);
}

}
Expand Down

0 comments on commit 2eaf0c0

Please sign in to comment.