1
0
Fork 0
mirror of https://github.com/Ellpeck/MLEM.git synced 2024-05-16 06:08:46 +02:00

only use nbsp in image codes if the font supports it

This commit is contained in:
Ellpeck 2020-06-04 22:18:53 +02:00
parent 6b1e5f8dd9
commit 1d38262388
5 changed files with 24 additions and 1 deletions

View file

@ -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) {

View file

@ -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;
}
}
}

View file

@ -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>

View file

@ -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);
}
}
}

View file

@ -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;