From b6ef243cf401314e95e19ed7db56401895f1e38e Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Thu, 31 Dec 2020 17:22:51 +0100 Subject: [PATCH] GenericFont support for zero-width spaces --- MLEM/Font/GenericFont.cs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/MLEM/Font/GenericFont.cs b/MLEM/Font/GenericFont.cs index 856cd62..0a8a40a 100644 --- a/MLEM/Font/GenericFont.cs +++ b/MLEM/Font/GenericFont.cs @@ -21,6 +21,11 @@ namespace MLEM.Font { /// Whereas a regular would have to explicitly support this character for width calculations, generic fonts implicitly support it in . /// public const char Nbsp = '\u00A0'; + /// + /// This field holds the unicode representation of a zero-width space. + /// Whereas a regular would have to explicitly support this character for width calculations and string splitting, generic fonts implicitly support it in and . + /// + public const char Zwsp = '\u8203'; /// /// The bold version of this font. @@ -108,6 +113,9 @@ namespace MLEM.Font { case Nbsp: xOffset += this.MeasureChar(' ').X; break; + case Zwsp: + // don't add width for a zero-width space + break; default: xOffset += this.MeasureChar(c).X; break; @@ -154,7 +162,7 @@ namespace MLEM.Font { /// /// Splits a string to a given maximum width, adding newline characters between each line. - /// Also splits long words. + /// Also splits long words and supports zero-width spaces. /// /// The text to split into multiple lines /// The maximum width that each line should have @@ -164,7 +172,7 @@ namespace MLEM.Font { var total = new StringBuilder(); foreach (var line in text.Split('\n')) { var curr = new StringBuilder(); - foreach (var word in line.Split(' ')) { + foreach (var word in line.Split(' ', Zwsp)) { if (this.MeasureString(word).X * scale >= width) { if (curr.Length > 0) { total.Append(curr).Append('\n');