Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 28 additions & 2 deletions source/funkin/ui/AtlasText.hx
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ class AtlasText extends FlxTypedSpriteGroup<AtlasChar>

/**
* Converts all characters to fit the font's `allowedCase`.
* Uses ASCII-only conversion so Turkish (and other) locales don't substitute
* dotted/dotless `İ`/`ı` for `I`/`i` and break atlas glyph lookups.
* @param str
*/
function restrictCase(str:String):String
Expand All @@ -92,12 +94,36 @@ class AtlasText extends FlxTypedSpriteGroup<AtlasChar>
case Both:
str;
case Upper:
str.toUpperCase();
asciiUpperCase(str);
case Lower:
str.toLowerCase();
asciiLowerCase(str);
}
}

static function asciiUpperCase(str:String):String
{
var buf = new StringBuf();
for (i in 0...str.length)
{
var c = str.charCodeAt(i);
if (c != null && c >= 0x61 && c <= 0x7A) buf.addChar(c - 0x20);
else if (c != null) buf.addChar(c);
}
return buf.toString();
}

static function asciiLowerCase(str:String):String
{
var buf = new StringBuf();
for (i in 0...str.length)
{
var c = str.charCodeAt(i);
if (c != null && c >= 0x41 && c <= 0x5A) buf.addChar(c + 0x20);
else if (c != null) buf.addChar(c);
}
return buf.toString();
}

/**
* Adds new text on top of the existing text. Helper for other methods; DOESN'T CHANGE `this.text`.
* @param str The text to add, assumed to match the font's `caseAllowed`.
Expand Down
Loading