mirror of
https://github.com/Ellpeck/MLEM.git
synced 2024-11-22 04:53:29 +01:00
only use nbsp in image codes if the font supports it
This commit is contained in:
parent
6b1e5f8dd9
commit
1d38262388
5 changed files with 24 additions and 1 deletions
|
@ -78,6 +78,11 @@ namespace MLEM.Extended.Font {
|
|||
batch.DrawString(this.Font, text, position, color, rotation, origin, scale, effects, layerDepth);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override bool HasCharacter(char c) {
|
||||
return this.Font.GetCharacterRegion(c) != null;
|
||||
}
|
||||
|
||||
// this fixes an issue with BitmapFonts where, if only given a single character,
|
||||
// only the width of the character itself (disregarding spacing) is returned
|
||||
private bool SingleCharacterWidthFix(string text, out Vector2 size) {
|
||||
|
|
|
@ -74,6 +74,10 @@ namespace MLEM.Ui.Style {
|
|||
public override void DrawString(SpriteBatch batch, StringBuilder text, Vector2 position, Color color, float rotation, Vector2 origin, Vector2 scale, SpriteEffects effects, float layerDepth) {
|
||||
}
|
||||
|
||||
public override bool HasCharacter(char c) {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -48,6 +48,13 @@ namespace MLEM.Font {
|
|||
///<inheritdoc cref="SpriteBatch.DrawString(SpriteFont,string,Vector2,Color,float,Vector2,float,SpriteEffects,float)"/>
|
||||
public abstract void DrawString(SpriteBatch batch, StringBuilder text, Vector2 position, Color color, float rotation, Vector2 origin, Vector2 scale, SpriteEffects effects, float layerDepth);
|
||||
|
||||
/// <summary>
|
||||
/// Returns whether this generic font supports the given character
|
||||
/// </summary>
|
||||
/// <param name="c">The character</param>
|
||||
/// <returns>Whether this generic font supports the character</returns>
|
||||
public abstract bool HasCharacter(char c);
|
||||
|
||||
/// <summary>
|
||||
/// Draws a string with the given text alignment.
|
||||
/// </summary>
|
||||
|
|
|
@ -72,5 +72,10 @@ namespace MLEM.Font {
|
|||
batch.DrawString(this.Font, text, position, color, rotation, origin, scale, effects, layerDepth);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override bool HasCharacter(char c) {
|
||||
return this.Font.Characters.Contains(c);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -29,7 +29,9 @@ namespace MLEM.Formatting.Codes {
|
|||
/// <inheritdoc />
|
||||
public override string GetReplacementString(GenericFont font) {
|
||||
if (this.replacement == null) {
|
||||
this.replacement = font.GetWidthString(font.LineHeight);
|
||||
// use non-breaking space so that the image won't be line-splitted
|
||||
var strg = font.GetWidthString(font.LineHeight, font.HasCharacter('\u00A0') ? '\u00A0' : ' ');
|
||||
this.replacement = strg.Remove(strg.Length - 1) + ' ';
|
||||
this.gapSize = font.MeasureString(this.replacement).X;
|
||||
}
|
||||
return this.replacement;
|
||||
|
|
Loading…
Reference in a new issue